/* * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/command_stream/preemption.h" #include "shared/source/command_stream/stream_properties.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/preamble/preamble_fixture.h" #include "reg_configs_common.h" using namespace NEO; typedef PreambleFixture IclSlm; GEN11TEST_F(IclSlm, WhenL3ConfigIsDispatchedThenProperRegisterAddressAndValueAreProgrammed) { typedef ICLFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; LinearStream &cs = linearStream; uint32_t l3Config = PreambleHelper::getL3Config(*defaultHwInfo, true); PreambleHelper::programL3(&cs, l3Config); parseCommands(cs); auto itorLRI = find(cmdList.begin(), cmdList.end()); ASSERT_NE(cmdList.end(), itorLRI); const auto &lri = *reinterpret_cast(*itorLRI); auto RegisterOffset = L3CNTLRegisterOffset::registerOffset; EXPECT_EQ(RegisterOffset, lri.getRegisterOffset()); EXPECT_EQ(0u, lri.getDataDword() & 1); } GEN11TEST_F(IclSlm, givenGen11WhenProgramingL3ThenErrorDetectionBehaviorControlBitSet) { uint32_t l3Config = PreambleHelper::getL3Config(*defaultHwInfo, true); uint32_t errorDetectionBehaviorControlBit = 1 << 9; EXPECT_TRUE((l3Config & errorDetectionBehaviorControlBit) != 0); } GEN11TEST_F(IclSlm, WhenCheckingL3IsConfigurableThenExpectItToBeFalse) { bool isL3Programmable = PreambleHelper::isL3Configurable(*defaultHwInfo); EXPECT_FALSE(isL3Programmable); } typedef PreambleFixture Gen11UrbEntryAllocationSize; GEN11TEST_F(Gen11UrbEntryAllocationSize, WhenPreambleRetrievesUrbEntryAllocationSizeThenValueIsCorrect) { uint32_t actualVal = PreambleHelper::getUrbEntryAllocationSize(); EXPECT_EQ(0x782u, actualVal); } typedef PreambleVfeState Gen11PreambleVfeState; GEN11TEST_F(Gen11PreambleVfeState, GivenWaOffWhenProgrammingVfeStateThenProgrammingIsCorrect) { typedef typename ICLFamily::PIPE_CONTROL PIPE_CONTROL; testWaTable->flags.waSendMIFLUSHBeforeVFE = 0; LinearStream &cs = linearStream; auto pVfeCmd = PreambleHelper::getSpaceForVfeState(&linearStream, pDevice->getHardwareInfo(), EngineGroupType::RenderCompute); StreamProperties emptyProperties{}; PreambleHelper::programVfeState(pVfeCmd, pDevice->getHardwareInfo(), 0u, 0, 168u, emptyProperties); parseCommands(cs); auto itorPC = find(cmdList.begin(), cmdList.end()); ASSERT_NE(cmdList.end(), itorPC); const auto &pc = *reinterpret_cast(*itorPC); EXPECT_FALSE(pc.getRenderTargetCacheFlushEnable()); EXPECT_FALSE(pc.getDepthCacheFlushEnable()); EXPECT_FALSE(pc.getDcFlushEnable()); EXPECT_EQ(1u, pc.getCommandStreamerStallEnable()); } GEN11TEST_F(Gen11PreambleVfeState, GivenWaOnWhenProgrammingVfeStateThenProgrammingIsCorrect) { typedef typename ICLFamily::PIPE_CONTROL PIPE_CONTROL; testWaTable->flags.waSendMIFLUSHBeforeVFE = 1; LinearStream &cs = linearStream; auto pVfeCmd = PreambleHelper::getSpaceForVfeState(&linearStream, pDevice->getHardwareInfo(), EngineGroupType::RenderCompute); StreamProperties emptyProperties{}; PreambleHelper::programVfeState(pVfeCmd, pDevice->getHardwareInfo(), 0u, 0, 168u, emptyProperties); parseCommands(cs); auto itorPC = find(cmdList.begin(), cmdList.end()); ASSERT_NE(cmdList.end(), itorPC); const auto &pc = *reinterpret_cast(*itorPC); EXPECT_TRUE(pc.getRenderTargetCacheFlushEnable()); EXPECT_TRUE(pc.getDepthCacheFlushEnable()); EXPECT_TRUE(pc.getDcFlushEnable()); EXPECT_EQ(1u, pc.getCommandStreamerStallEnable()); } typedef PreambleFixture PreemptionWatermarkGen11; GEN11TEST_F(PreemptionWatermarkGen11, WhenPreambleIsCreatedThenWorkAroundsIsNotProgrammed) { PreambleHelper::programGenSpecificPreambleWorkArounds(&linearStream, *defaultHwInfo); parseCommands(linearStream); auto cmd = findMmioCmd(cmdList.begin(), cmdList.end(), FfSliceCsChknReg2::address); ASSERT_EQ(nullptr, cmd); MockDevice mockDevice; mockDevice.setDebuggerActive(false); size_t expectedSize = PreemptionHelper::getRequiredPreambleSize(mockDevice); EXPECT_EQ(expectedSize, PreambleHelper::getAdditionalCommandsSize(mockDevice)); mockDevice.setDebuggerActive(true); expectedSize += PreambleHelper::getKernelDebuggingCommandsSize(mockDevice.isDebuggerActive()); EXPECT_EQ(expectedSize, PreambleHelper::getAdditionalCommandsSize(mockDevice)); } typedef PreambleFixture ThreadArbitrationGen11; GEN11TEST_F(ThreadArbitrationGen11, givenPreambleWhenItIsProgrammedThenThreadArbitrationIsNotSet) { DebugManagerStateRestore dbgRestore; DebugManager.flags.ForcePreemptionMode.set(static_cast(PreemptionMode::Disabled)); typedef ICLFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; typedef ICLFamily::PIPE_CONTROL PIPE_CONTROL; LinearStream &cs = linearStream; uint32_t l3Config = PreambleHelper::getL3Config(*defaultHwInfo, true); MockDevice mockDevice; PreambleHelper::programPreamble(&linearStream, mockDevice, l3Config, ThreadArbitrationPolicy::RoundRobin, nullptr); parseCommands(cs); auto ppC = find(cmdList.begin(), cmdList.end()); ASSERT_EQ(cmdList.end(), ppC); auto cmd = findMmioCmd(cmdList.begin(), cmdList.end(), RowChickenReg4::address); ASSERT_EQ(nullptr, cmd); MockDevice device; EXPECT_EQ(0u, PreambleHelper::getAdditionalCommandsSize(device)); EXPECT_EQ(sizeof(MI_LOAD_REGISTER_IMM) + sizeof(PIPE_CONTROL), PreambleHelper::getThreadArbitrationCommandsSize()); } GEN11TEST_F(ThreadArbitrationGen11, whenThreadArbitrationPolicyIsProgrammedThenCorrectValuesAreSet) { DebugManagerStateRestore dbgRestore; DebugManager.flags.ForcePreemptionMode.set(static_cast(PreemptionMode::Disabled)); typedef ICLFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; typedef ICLFamily::PIPE_CONTROL PIPE_CONTROL; LinearStream &cs = linearStream; MockDevice mockDevice; PreambleHelper::programThreadArbitration(&linearStream, ThreadArbitrationPolicy::RoundRobin); parseCommands(cs); auto ppC = find(cmdList.begin(), cmdList.end()); ASSERT_NE(ppC, cmdList.end()); auto cmd = findMmioCmd(cmdList.begin(), cmdList.end(), RowChickenReg4::address); ASSERT_NE(nullptr, cmd); EXPECT_EQ(RowChickenReg4::regDataForArbitrationPolicy[ThreadArbitrationPolicy::RoundRobin], cmd->getDataDword()); MockDevice device; EXPECT_EQ(0u, PreambleHelper::getAdditionalCommandsSize(device)); EXPECT_EQ(sizeof(MI_LOAD_REGISTER_IMM) + sizeof(PIPE_CONTROL), PreambleHelper::getThreadArbitrationCommandsSize()); } GEN11TEST_F(ThreadArbitrationGen11, GivenDefaultWhenProgrammingPreambleThenArbitrationPolicyIsRoundRobin) { EXPECT_EQ(ThreadArbitrationPolicy::RoundRobinAfterDependency, HwHelperHw::get().getDefaultThreadArbitrationPolicy()); } GEN11TEST_F(ThreadArbitrationGen11, whenGetSupportThreadArbitrationPoliciesIsCalledThenAllPoliciesAreReturned) { auto supportedPolicies = PreambleHelper::getSupportedThreadArbitrationPolicies(); EXPECT_EQ(3u, supportedPolicies.size()); EXPECT_NE(supportedPolicies.end(), std::find(supportedPolicies.begin(), supportedPolicies.end(), ThreadArbitrationPolicy::AgeBased)); EXPECT_NE(supportedPolicies.end(), std::find(supportedPolicies.begin(), supportedPolicies.end(), ThreadArbitrationPolicy::RoundRobin)); EXPECT_NE(supportedPolicies.end(), std::find(supportedPolicies.begin(), supportedPolicies.end(), ThreadArbitrationPolicy::RoundRobinAfterDependency)); } using PreambleFixtureGen11 = PreambleFixture; GEN11TEST_F(PreambleFixtureGen11, whenKernelDebuggingCommandsAreProgrammedThenCorrectRegisterAddressesAndValuesAreSet) { typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; auto bufferSize = PreambleHelper::getKernelDebuggingCommandsSize(true); auto buffer = std::unique_ptr(new char[bufferSize]); LinearStream stream(buffer.get(), bufferSize); PreambleHelper::programKernelDebugging(&stream); HardwareParse hwParser; hwParser.parseCommands(stream); auto cmdList = hwParser.getCommandsList(); ASSERT_EQ(2u, cmdList.size()); auto it = cmdList.begin(); MI_LOAD_REGISTER_IMM *pCmd = reinterpret_cast(*it); EXPECT_EQ(0x20d8u, pCmd->getRegisterOffset()); EXPECT_EQ((1u << 5) | (1u << 21), pCmd->getDataDword()); it++; pCmd = reinterpret_cast(*it); EXPECT_EQ(0xe400u, pCmd->getRegisterOffset()); EXPECT_EQ((1u << 7) | (1u << 4), pCmd->getDataDword()); }