From 3958cd909a222cbe4968f4f84d807af949b717ad Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Tue, 27 Mar 2018 09:58:00 +0200 Subject: [PATCH] [18/n] Internal 4GB allocator. - Remove IH from preemption functions. - This is one of parts of complete IH removal. Change-Id: Ic19a6e2e1f5d9df25785c2c982c52b581b57a605 --- .../command_stream_receiver_hw.h | 2 +- .../command_stream_receiver_hw.inl | 7 +- runtime/command_stream/preemption.cpp | 10 -- runtime/command_stream/preemption.h | 3 +- runtime/command_stream/preemption.inl | 4 +- runtime/gen8/preemption.cpp | 2 +- runtime/gen9/preemption.cpp | 2 +- unit_tests/preemption/preemption_tests.cpp | 99 +------------------ 8 files changed, 12 insertions(+), 117 deletions(-) diff --git a/runtime/command_stream/command_stream_receiver_hw.h b/runtime/command_stream/command_stream_receiver_hw.h index 73a0ecba2c..28e10a08a6 100644 --- a/runtime/command_stream/command_stream_receiver_hw.h +++ b/runtime/command_stream/command_stream_receiver_hw.h @@ -78,7 +78,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { uint64_t generalStateBase); protected: - void programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags, const LinearStream &ih); + void programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags); void programL3(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t &newL3Config); void programPreamble(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t &newL3Config); void programPipelineSelect(LinearStream &csr, DispatchFlags &dispatchFlags); diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index fa6bbacfa6..986d21b202 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -194,7 +194,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( auto commandStreamStartCSR = commandStreamCSR.getUsed(); initPageTableManagerRegisters(commandStreamCSR); - programPreemption(commandStreamCSR, dispatchFlags, ih); + programPreemption(commandStreamCSR, dispatchFlags); programCoherency(commandStreamCSR, dispatchFlags); programL3(commandStreamCSR, dispatchFlags, newL3Config); programPipelineSelect(commandStreamCSR, dispatchFlags); @@ -592,10 +592,9 @@ inline void CommandStreamReceiverHw::waitForTaskCountWithKmdNotifyFal } template -inline void CommandStreamReceiverHw::programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags, - const LinearStream &ih) { +inline void CommandStreamReceiverHw::programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags) { PreemptionHelper::programCmdStream(csr, dispatchFlags.preemptionMode, this->lastPreemptionMode, preemptionCsrAllocation, - ih, *memoryManager->device); + *memoryManager->device); this->lastPreemptionMode = dispatchFlags.preemptionMode; } diff --git a/runtime/command_stream/preemption.cpp b/runtime/command_stream/preemption.cpp index 8eeb0e3a2e..2cbb1a5c04 100644 --- a/runtime/command_stream/preemption.cpp +++ b/runtime/command_stream/preemption.cpp @@ -127,16 +127,6 @@ void PreemptionHelper::initializeInstructionHeapSipKernelReservedBlock(LinearStr UNRECOVERABLE_IF(err != 0); } -// verify that SIP CSR kernel resides at the begining of the InstructionHeap -bool PreemptionHelper::isValidInstructionHeapForMidThreadPreemption(const LinearStream &ih, Device &device) { - const SipKernel &sip = BuiltIns::getInstance().getSipKernel(SipKernelType::Csr, device); - if (ih.getUsed() < sip.getBinarySize()) { - return false; - } - - return (0 == memcmp(ih.getCpuBase(), sip.getBinary(), sip.getBinarySize())); -} - PreemptionMode PreemptionHelper::getDefaultPreemptionMode(const HardwareInfo &hwInfo) { return DebugManager.flags.ForcePreemptionMode.get() == -1 ? hwInfo.capabilityTable.defaultPreemptionMode diff --git a/runtime/command_stream/preemption.h b/runtime/command_stream/preemption.h index 4d20676635..d00c81b746 100644 --- a/runtime/command_stream/preemption.h +++ b/runtime/command_stream/preemption.h @@ -43,7 +43,6 @@ class PreemptionHelper { static size_t getInstructionHeapSipKernelReservedSize(Device &device); static void initializeInstructionHeapSipKernelReservedBlock(LinearStream &ih, Device &device); - static bool isValidInstructionHeapForMidThreadPreemption(const LinearStream &ih, Device &device); template static size_t getRequiredPreambleSize(const Device &device); @@ -56,7 +55,7 @@ class PreemptionHelper { template static void programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, - GraphicsAllocation *preemptionCsr, const LinearStream &ih, Device &device); + GraphicsAllocation *preemptionCsr, Device &device); template static size_t getPreemptionWaCsSize(const Device &device); diff --git a/runtime/command_stream/preemption.inl b/runtime/command_stream/preemption.inl index 2a075269d8..da950171ba 100644 --- a/runtime/command_stream/preemption.inl +++ b/runtime/command_stream/preemption.inl @@ -94,10 +94,8 @@ void PreemptionHelper::programPreamble(LinearStream &preambleCmdStream, const De template void PreemptionHelper::programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, - GraphicsAllocation *preemptionCsr, - const LinearStream &ih, Device &device) { + GraphicsAllocation *preemptionCsr, Device &device) { if (oldPreemptionMode == newPreemptionMode) { - DEBUG_BREAK_IF((newPreemptionMode == PreemptionMode::MidThread) && (false == isValidInstructionHeapForMidThreadPreemption(ih, device))); return; } diff --git a/runtime/gen8/preemption.cpp b/runtime/gen8/preemption.cpp index 69c657633f..86afde7595 100644 --- a/runtime/gen8/preemption.cpp +++ b/runtime/gen8/preemption.cpp @@ -41,7 +41,7 @@ struct PreemptionConfig { template <> void PreemptionHelper::programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, - GraphicsAllocation *preemptionCsr, const LinearStream &ih, Device &device) { + GraphicsAllocation *preemptionCsr, Device &device) { if (newPreemptionMode == oldPreemptionMode) { return; } diff --git a/runtime/gen9/preemption.cpp b/runtime/gen9/preemption.cpp index 810c0851e7..4003304c7a 100644 --- a/runtime/gen9/preemption.cpp +++ b/runtime/gen9/preemption.cpp @@ -46,7 +46,7 @@ struct PreemptionConfig { template void PreemptionHelper::programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, GraphicsAllocation *preemptionCsr, - const LinearStream &ih, Device &device); + Device &device); template void PreemptionHelper::programPreamble(LinearStream &preambleCmdStream, const Device &device, const GraphicsAllocation *preemptionCsr); template size_t PreemptionHelper::getRequiredPreambleSize(const Device &device); template size_t PreemptionHelper::getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode); diff --git a/unit_tests/preemption/preemption_tests.cpp b/unit_tests/preemption/preemption_tests.cpp index c421864507..1c8bd2a4a9 100644 --- a/unit_tests/preemption/preemption_tests.cpp +++ b/unit_tests/preemption/preemption_tests.cpp @@ -334,95 +334,6 @@ TEST(PreemptionTest, whenPreemptionModeIsNotMidThreadThenInstructionHeapSipKerne ASSERT_EQ(0U, instructionHeap.getUsed()); } -TEST(PreemptionTest, instructionHeapIsInvalidIfItSmallerThanSipKernel) { - char instructionHeapBuffer[4096]; - LinearStream instructionHeap(instructionHeapBuffer, sizeof(instructionHeapBuffer)); - auto mockDevice = std::unique_ptr(MockDevice::create(nullptr)); - mockDevice->setPreemptionMode(PreemptionMode::MidThread); - - char sipPattern[] = {2, 3, 5, 11, 13, 17, 19, 23, 29, 31, 37, 39, 41}; - instructionHeap.getSpace(sizeof(sipPattern) - 1); - memcpy_s(instructionHeapBuffer, sizeof(instructionHeapBuffer), sipPattern, sizeof(sipPattern)); - - { - MockBuiltins mockBuiltins; - mockBuiltins.overrideGlobalBuiltins(); - { - auto sipOverride = std::unique_ptr(new OCLRT::SipKernel(OCLRT::SipKernelType::Csr, - getSipProgramWithCustomBinary())); - mockBuiltins.overrideSipKernel(std::move(sipOverride)); - } - - EXPECT_FALSE(PreemptionHelper::isValidInstructionHeapForMidThreadPreemption(instructionHeap, *mockDevice)); - } -} - -TEST(PreemptionTest, instructionHeapIsInvalidIfItDoesNotContainSipKernelAtTheBegining) { - char instructionHeapBuffer[4096]; - LinearStream instructionHeap(instructionHeapBuffer, sizeof(instructionHeapBuffer)); - auto mockDevice = std::unique_ptr(MockDevice::create(nullptr)); - mockDevice->setPreemptionMode(PreemptionMode::MidThread); - - char sipPattern[] = {2, 3, 5, 11, 13, 17, 19, 23, 29, 31, 37, 39, 41}; - instructionHeap.getSpace(sizeof(instructionHeapBuffer)); - memcpy_s(instructionHeapBuffer + 1, sizeof(instructionHeapBuffer) - 1, sipPattern, sizeof(sipPattern)); - - { - MockBuiltins mockBuiltins; - mockBuiltins.overrideGlobalBuiltins(); - { - auto sipOverride = std::unique_ptr(new OCLRT::SipKernel(OCLRT::SipKernelType::Csr, getSipProgramWithCustomBinary())); - mockBuiltins.overrideSipKernel(std::move(sipOverride)); - } - - EXPECT_FALSE(PreemptionHelper::isValidInstructionHeapForMidThreadPreemption(instructionHeap, *mockDevice)); - } -} - -TEST(PreemptionTest, instructionHeapIsValidIfItContainSipKernelAtTheBegining) { - char instructionHeapBuffer[4096]; - LinearStream instructionHeap(instructionHeapBuffer, sizeof(instructionHeapBuffer)); - auto mockDevice = std::unique_ptr(MockDevice::create(nullptr)); - mockDevice->setPreemptionMode(PreemptionMode::MidThread); - - instructionHeap.getSpace(sizeof(instructionHeapBuffer)); - - { - MockBuiltins mockBuiltins; - mockBuiltins.overrideGlobalBuiltins(); - { - auto sipOverride = std::unique_ptr(new OCLRT::SipKernel(OCLRT::SipKernelType::Csr, getSipProgramWithCustomBinary())); - memcpy_s(instructionHeapBuffer, sizeof(instructionHeapBuffer), sipOverride->getBinary(), sipOverride->getBinarySize()); - mockBuiltins.overrideSipKernel(std::move(sipOverride)); - } - - EXPECT_TRUE(PreemptionHelper::isValidInstructionHeapForMidThreadPreemption(instructionHeap, *mockDevice)); - } -} - -TEST(PreemptionTest, whenPreemptionModeIsMidThreadThenInstructionHeapSipKernelReservedBlockIsProperlyInitialized) { - char instructionHeapBuffer[4096]; - memset(instructionHeapBuffer, 7, sizeof(instructionHeapBuffer)); - LinearStream instructionHeap(instructionHeapBuffer, sizeof(instructionHeapBuffer)); - auto mockDevice = std::unique_ptr(MockDevice::create(nullptr)); - mockDevice->setPreemptionMode(PreemptionMode::MidThread); - { - size_t sipSize = 0u; - MockBuiltins mockBuiltins; - mockBuiltins.overrideGlobalBuiltins(); - { - auto sipOverride = std::unique_ptr(new OCLRT::SipKernel(OCLRT::SipKernelType::Csr, getSipProgramWithCustomBinary())); - sipSize = sipOverride->getBinarySize(); - mockBuiltins.overrideSipKernel(std::move(sipOverride)); - } - - EXPECT_EQ(sipSize, PreemptionHelper::getInstructionHeapSipKernelReservedSize(*mockDevice)); - PreemptionHelper::initializeInstructionHeapSipKernelReservedBlock(instructionHeap, *mockDevice); - EXPECT_TRUE(PreemptionHelper::isValidInstructionHeapForMidThreadPreemption(instructionHeap, *mockDevice)); - EXPECT_EQ(7, instructionHeapBuffer[sipSize]); // check for overflow - } -} - struct PreemptionHwTest : ::testing::Test, ::testing::WithParamInterface { }; @@ -440,7 +351,7 @@ HWTEST_P(PreemptionHwTest, getRequiredCmdStreamSizeReturns0WhenPreemptionModeIsN tmpBuiltins.overrideSipKernel(std::unique_ptr(new OCLRT::SipKernel{SipKernelType::Csr, getSipProgramWithCustomBinary()})); tmpBuiltins.overrideGlobalBuiltins(); PreemptionHelper::programCmdStream(cmdStream, mode, mode, - nullptr, LinearStream(nullptr, 0), *mockDevice); + nullptr, *mockDevice); } EXPECT_EQ(0U, cmdStream.getUsed()); } @@ -469,7 +380,7 @@ HWTEST_P(PreemptionHwTest, getRequiredCmdStreamSizeReturnsSizeOfMiLoadRegisterIm MockGraphicsAllocation csrSurface((void *)minCsrAlignment, minCsrSize); PreemptionHelper::programCmdStream(cmdStream, mode, differentPreemptionMode, - nullptr, LinearStream(nullptr, 0), *mockDevice); + nullptr, *mockDevice); EXPECT_EQ(requiredSize, cmdStream.getUsed()); } @@ -480,9 +391,7 @@ HWTEST_P(PreemptionHwTest, programCmdStreamAddsProperMiLoadRegisterImmCommandToT if (false == GetPreemptionTestHwDetails().supportsPreemptionProgramming()) { LinearStream cmdStream(nullptr, 0U); - LinearStream instructionHeap(nullptr, 0U); - PreemptionHelper::programCmdStream(cmdStream, mode, differentPreemptionMode, nullptr, - instructionHeap, *mockDevice); + PreemptionHelper::programCmdStream(cmdStream, mode, differentPreemptionMode, nullptr, *mockDevice); EXPECT_EQ(0U, cmdStream.getUsed()); return; } @@ -506,7 +415,7 @@ HWTEST_P(PreemptionHwTest, programCmdStreamAddsProperMiLoadRegisterImmCommandToT MockGraphicsAllocation csrSurface((void *)minCsrAlignment, minCsrSize); PreemptionHelper::programCmdStream(cmdStream, mode, differentPreemptionMode, - &csrSurface, LinearStream(nullptr, 0), *mockDevice); + &csrSurface, *mockDevice); HardwareParse cmdParser; cmdParser.parseCommands(cmdStream);