2019-09-19 01:32:33 +08:00
|
|
|
/*
|
2022-05-16 22:06:56 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2019-09-19 01:32:33 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-06-10 18:52:05 +08:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
2020-06-10 18:47:58 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
|
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
2022-08-09 22:26:49 +08:00
|
|
|
#include "shared/test/unit_test/fixtures/preemption_fixture.h"
|
2020-06-02 16:14:02 +08:00
|
|
|
|
2019-09-19 01:32:33 +08:00
|
|
|
using namespace NEO;
|
|
|
|
|
2020-06-10 18:47:58 +08:00
|
|
|
template <>
|
2022-07-25 23:30:11 +08:00
|
|
|
PreemptionTestHwDetails getPreemptionTestHwDetails<Gen12LpFamily>() {
|
2020-06-10 18:47:58 +08:00
|
|
|
PreemptionTestHwDetails ret;
|
|
|
|
ret.modeToRegValueMap[PreemptionMode::ThreadGroup] = DwordBuilder::build(1, true) | DwordBuilder::build(2, true, false);
|
|
|
|
ret.modeToRegValueMap[PreemptionMode::MidBatch] = DwordBuilder::build(2, true) | DwordBuilder::build(1, true, false);
|
|
|
|
ret.modeToRegValueMap[PreemptionMode::MidThread] = DwordBuilder::build(2, true, false) | DwordBuilder::build(1, true, false);
|
|
|
|
ret.defaultRegValue = ret.modeToRegValueMap[PreemptionMode::MidBatch];
|
|
|
|
ret.regAddress = 0x2580u;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-19 01:32:33 +08:00
|
|
|
using Gen12LpPreemptionTests = DevicePreemptionTests;
|
|
|
|
|
2020-06-18 20:24:59 +08:00
|
|
|
GEN12LPTEST_F(Gen12LpPreemptionTests, whenProgramStateSipIsCalledThenStateSipCmdIsAddedToStream) {
|
2021-10-17 20:21:29 +08:00
|
|
|
size_t requiredSize = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(*device, false);
|
2020-06-18 20:24:59 +08:00
|
|
|
StackVec<char, 1024> streamStorage(1024);
|
|
|
|
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
|
2019-09-19 01:32:33 +08:00
|
|
|
|
2020-06-18 20:24:59 +08:00
|
|
|
EXPECT_NE(0U, requiredSize);
|
2022-06-21 18:28:33 +08:00
|
|
|
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
|
2020-06-18 20:24:59 +08:00
|
|
|
EXPECT_NE(0U, cmdStream.getUsed());
|
2019-09-19 01:32:33 +08:00
|
|
|
}
|
|
|
|
|
2020-10-22 16:21:05 +08:00
|
|
|
GEN12LPTEST_F(Gen12LpPreemptionTests, WhenGettingPreemptionWaCsSizeThenZeroIsReturned) {
|
2019-09-19 01:32:33 +08:00
|
|
|
size_t expectedSize = 0;
|
2020-06-10 18:47:58 +08:00
|
|
|
EXPECT_EQ(expectedSize, PreemptionHelper::getPreemptionWaCsSize<FamilyType>(*device));
|
2019-09-19 01:32:33 +08:00
|
|
|
}
|
|
|
|
|
2020-10-22 16:21:05 +08:00
|
|
|
GEN12LPTEST_F(Gen12LpPreemptionTests, WhenApplyingPreemptionWaCmdsThenNothingIsAdded) {
|
2019-09-19 01:32:33 +08:00
|
|
|
size_t usedSize = 0;
|
2020-06-10 18:52:05 +08:00
|
|
|
StackVec<char, 1024> streamStorage(1024);
|
|
|
|
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
|
2019-09-19 01:32:33 +08:00
|
|
|
|
2020-06-10 18:47:58 +08:00
|
|
|
PreemptionHelper::applyPreemptionWaCmdsBegin<FamilyType>(&cmdStream, *device);
|
2019-09-19 01:32:33 +08:00
|
|
|
EXPECT_EQ(usedSize, cmdStream.getUsed());
|
2020-06-10 18:47:58 +08:00
|
|
|
PreemptionHelper::applyPreemptionWaCmdsEnd<FamilyType>(&cmdStream, *device);
|
2019-09-19 01:32:33 +08:00
|
|
|
EXPECT_EQ(usedSize, cmdStream.getUsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
GEN12LPTEST_F(Gen12LpPreemptionTests, givenInterfaceDescriptorDataWhenMidThreadPreemptionModeThenSetDisableThreadPreemptionBitToDisable) {
|
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
|
|
|
|
INTERFACE_DESCRIPTOR_DATA iddArg;
|
|
|
|
iddArg = FamilyType::cmdInitInterfaceDescriptorData;
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::MidThread);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
}
|
|
|
|
|
|
|
|
GEN12LPTEST_F(Gen12LpPreemptionTests, givenInterfaceDescriptorDataWhenNoMidThreadPreemptionModeThenSetDisableThreadPreemptionBitToEnable) {
|
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
|
|
|
|
INTERFACE_DESCRIPTOR_DATA iddArg;
|
|
|
|
iddArg = FamilyType::cmdInitInterfaceDescriptorData;
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::Disabled);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::MidBatch);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::ThreadGroup);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
}
|
2020-04-28 22:48:23 +08:00
|
|
|
|
|
|
|
GEN12LPTEST_F(Gen12LpPreemptionTests, WhenProgrammingPreemptionThenExpectLoarRegisterCommandRemapFlagEnabled) {
|
|
|
|
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
|
|
|
|
|
|
|
|
const size_t bufferSize = 128;
|
|
|
|
uint8_t buffer[bufferSize];
|
|
|
|
LinearStream cmdStream(buffer, bufferSize);
|
|
|
|
|
|
|
|
PreemptionHelper::programCmdStream<FamilyType>(cmdStream, PreemptionMode::ThreadGroup, PreemptionMode::Initial, nullptr);
|
|
|
|
auto lriCommand = genCmdCast<MI_LOAD_REGISTER_IMM *>(cmdStream.getCpuBase());
|
|
|
|
ASSERT_NE(nullptr, lriCommand);
|
|
|
|
EXPECT_TRUE(lriCommand->getMmioRemapEnable());
|
|
|
|
}
|