From 377aebce0603899eb7f7e13aecf77761ebd64d2c Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Thu, 28 Mar 2019 14:15:51 +0100 Subject: [PATCH] Move PIPE_CONTROL related functions to PipeControlHelper Change-Id: Ie8220b06d2aa35a9fd0083b7db6925b577564d36 Signed-off-by: Maciej Dziuban --- runtime/command_queue/gpgpu_walker_base.inl | 4 +- .../command_stream/command_stream_receiver.h | 2 - .../command_stream_receiver_hw.h | 5 --- .../command_stream_receiver_hw.inl | 44 ++----------------- .../gen8/command_stream_receiver_hw_gen8.cpp | 6 --- runtime/gen8/hw_helper_gen8.cpp | 6 +++ .../gen9/command_stream_receiver_hw_gen9.cpp | 7 --- runtime/gen9/hw_helper_gen9.cpp | 7 +++ runtime/helpers/hw_helper.h | 4 ++ runtime/helpers/hw_helper_common.inl | 38 ++++++++++++++++ ...and_stream_receiver_flush_task_1_tests.cpp | 4 +- ...and_stream_receiver_flush_task_2_tests.cpp | 4 +- ...and_stream_receiver_flush_task_3_tests.cpp | 4 +- ...stream_receiver_flush_task_gmock_tests.cpp | 2 +- unit_tests/kernel/kernel_tests.cpp | 3 -- unit_tests/libult/mock_gfx_family.h | 8 ++++ unit_tests/mocks/mock_csr.h | 3 -- 17 files changed, 75 insertions(+), 76 deletions(-) diff --git a/runtime/command_queue/gpgpu_walker_base.inl b/runtime/command_queue/gpgpu_walker_base.inl index 95ac3f264d..99750718e8 100644 --- a/runtime/command_queue/gpgpu_walker_base.inl +++ b/runtime/command_queue/gpgpu_walker_base.inl @@ -65,7 +65,7 @@ void GpgpuWalkerHelper::dispatchScheduler( using MI_BATCH_BUFFER_START = typename GfxFamily::MI_BATCH_BUFFER_START; bool dcFlush = false; - commandQueue.getCommandStreamReceiver().addPipeControl(commandStream, dcFlush); + PipeControlHelper::addPipeControl(commandStream, dcFlush); uint32_t interfaceDescriptorIndex = devQueueHw.schedulerIDIndex; const size_t offsetInterfaceDescriptorTable = devQueueHw.colorCalcStateSize; @@ -157,7 +157,7 @@ void GpgpuWalkerHelper::dispatchScheduler( // Do not put BB_START only when returning in first Scheduler run if (devQueueHw.getSchedulerReturnInstance() != 1) { - commandQueue.getCommandStreamReceiver().addPipeControl(commandStream, true); + PipeControlHelper::addPipeControl(commandStream, true); // Add BB Start Cmd to the SLB in the Primary Batch Buffer auto *bbStart = static_cast(commandStream.getSpace(sizeof(MI_BATCH_BUFFER_START))); diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index b303f6d669..9cbfead3ec 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -80,8 +80,6 @@ class CommandStreamReceiver { void makeResidentHostPtrAllocation(GraphicsAllocation *gfxAllocation); virtual void waitBeforeMakingNonResidentWhenRequired() {} - virtual void addPipeControl(LinearStream &commandStream, bool dcFlush) = 0; - void ensureCommandBufferAllocation(LinearStream &commandStream, size_t minimumRequiredSize, size_t additionalAllocationSize); MemoryManager *getMemoryManager() const; diff --git a/runtime/command_stream/command_stream_receiver_hw.h b/runtime/command_stream/command_stream_receiver_hw.h index 21c63ed434..4a172ab438 100644 --- a/runtime/command_stream/command_stream_receiver_hw.h +++ b/runtime/command_stream/command_stream_receiver_hw.h @@ -38,10 +38,6 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { void flushBatchedSubmissions() override; - PIPE_CONTROL *addPipeControlBase(LinearStream &commandStream, bool dcFlush); - void addPipeControl(LinearStream &commandStream, bool dcFlush) override; - int getRequiredPipeControlSize() const; - static void addBatchBufferEnd(LinearStream &commandStream, void **patchLocation); void addBatchBufferStart(MI_BATCH_BUFFER_START *commandBufferMemory, uint64_t startAddress, bool secondary); static void alignToCacheLine(LinearStream &commandStream); @@ -86,7 +82,6 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { void programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags); virtual void initPageTableManagerRegisters(LinearStream &csr){}; - void addPipeControlWA(LinearStream &commandStream); void addClearSLMWorkAround(typename GfxFamily::PIPE_CONTROL *pCmd); PIPE_CONTROL *addPipeControlCmd(LinearStream &commandStream); size_t getSshHeapSize(); diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index abef77dac9..c73c05cd97 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -189,7 +189,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( } //Some architectures (SKL) requires to have pipe control prior to pipe control with tag write, add it here - addPipeControlWA(commandStreamTask); + PipeControlHelper::addPipeControlWA(commandStreamTask); auto address = getTagAllocation()->getGpuAddress(); auto pCmd = PipeControlHelper::obtainPipeControlAndProgramPostSyncOperation(&commandStreamTask, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, address, taskCount + 1, dispatchFlags.dcFlush); @@ -362,7 +362,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( // Add a PC if we have a dependency on a previous walker to avoid concurrency issues. if (taskLevel > this->taskLevel) { if (!timestampPacketWriteEnabled) { - addPipeControl(commandStreamCSR, false); + PipeControlHelper::addPipeControl(commandStreamCSR, false); } this->taskLevel = taskLevel; DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "this->taskCount", this->taskCount); @@ -507,7 +507,7 @@ inline void CommandStreamReceiverHw::flushBatchedSubmissions() { ResidencyContainer surfacesForSubmit; ResourcePackage resourcePackage; - auto pipeControlLocationSize = getRequiredPipeControlSize(); + auto pipeControlLocationSize = PipeControlHelper::getRequiredPipeControlSize(); void *currentPipeControlForNooping = nullptr; void *epiloguePipeControlLocation = nullptr; @@ -583,33 +583,6 @@ inline void CommandStreamReceiverHw::flushBatchedSubmissions() { } } -template -typename GfxFamily::PIPE_CONTROL *CommandStreamReceiverHw::addPipeControlBase(LinearStream &commandStream, bool dcFlush) { - addPipeControlWA(commandStream); - - auto pCmd = reinterpret_cast(commandStream.getSpace(sizeof(PIPE_CONTROL))); - *pCmd = GfxFamily::cmdInitPipeControl; - pCmd->setCommandStreamerStallEnable(true); - pCmd->setDcFlushEnable(dcFlush); - - if (DebugManager.flags.FlushAllCaches.get()) { - pCmd->setDcFlushEnable(true); - pCmd->setRenderTargetCacheFlushEnable(true); - pCmd->setInstructionCacheInvalidateEnable(true); - pCmd->setTextureCacheInvalidationEnable(true); - pCmd->setPipeControlFlushEnable(true); - pCmd->setVfCacheInvalidationEnable(true); - pCmd->setConstantCacheInvalidationEnable(true); - pCmd->setStateCacheInvalidationEnable(true); - } - return pCmd; -} - -template -void CommandStreamReceiverHw::addPipeControl(LinearStream &commandStream, bool dcFlush) { - CommandStreamReceiverHw::addPipeControlBase(commandStream, dcFlush); -} - template size_t CommandStreamReceiverHw::getRequiredCmdStreamSizeAligned(const DispatchFlags &dispatchFlags, Device &device) { size_t size = getRequiredCmdStreamSize(dispatchFlags, device); @@ -628,7 +601,7 @@ size_t CommandStreamReceiverHw::getRequiredCmdStreamSize(const Dispat if (!this->isStateSipSent || device.isSourceLevelDebuggerActive()) { size += PreemptionHelper::getRequiredStateSipCmdSize(device); } - size += getRequiredPipeControlSize(); + size += PipeControlHelper::getRequiredPipeControlSize(); size += sizeof(typename GfxFamily::MI_BATCH_BUFFER_START); size += getCmdSizeForL3Config(); @@ -802,13 +775,4 @@ bool CommandStreamReceiverHw::detectInitProgrammingFlagsRequired(cons return DebugManager.flags.ForceCsrReprogramming.get(); } -template -void CommandStreamReceiverHw::addPipeControlWA(LinearStream &commandStream) { -} - -template -int CommandStreamReceiverHw::getRequiredPipeControlSize() const { - const auto pipeControlCount = KernelCommandsHelper::isPipeControlWArequired() ? 2u : 1u; - return pipeControlCount * sizeof(typename GfxFamily::PIPE_CONTROL); -} } // namespace NEO diff --git a/runtime/gen8/command_stream_receiver_hw_gen8.cpp b/runtime/gen8/command_stream_receiver_hw_gen8.cpp index 20e52860ec..e01a627b67 100644 --- a/runtime/gen8/command_stream_receiver_hw_gen8.cpp +++ b/runtime/gen8/command_stream_receiver_hw_gen8.cpp @@ -24,12 +24,6 @@ template <> void CommandStreamReceiverHw::programComputeMode(LinearStream &stream, DispatchFlags &dispatchFlags) { } -template <> -void CommandStreamReceiverHw::addPipeControl(LinearStream &commandStream, bool dcFlush) { - auto pCmd = CommandStreamReceiverHw::addPipeControlBase(commandStream, dcFlush); - pCmd->setDcFlushEnable(true); -} - template <> void populateFactoryTable>() { extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE]; diff --git a/runtime/gen8/hw_helper_gen8.cpp b/runtime/gen8/hw_helper_gen8.cpp index e8dc27a8e8..1be19f39af 100644 --- a/runtime/gen8/hw_helper_gen8.cpp +++ b/runtime/gen8/hw_helper_gen8.cpp @@ -28,6 +28,12 @@ void HwHelperHw::setupHardwareCapabilities(HardwareCapabilities *caps, c caps->isStatelesToStatefullWithOffsetSupported = false; } +template <> +void PipeControlHelper::addPipeControl(LinearStream &commandStream, bool dcFlush) { + auto pCmd = PipeControlHelper::addPipeControlBase(commandStream, dcFlush); + pCmd->setDcFlushEnable(true); +} + template class AubHelperHw; template class HwHelperHw; template class FlatBatchBufferHelperHw; diff --git a/runtime/gen9/command_stream_receiver_hw_gen9.cpp b/runtime/gen9/command_stream_receiver_hw_gen9.cpp index 97a32b8f34..d684b834b1 100644 --- a/runtime/gen9/command_stream_receiver_hw_gen9.cpp +++ b/runtime/gen9/command_stream_receiver_hw_gen9.cpp @@ -24,13 +24,6 @@ template <> void CommandStreamReceiverHw::programComputeMode(LinearStream &stream, DispatchFlags &dispatchFlags) { } -template <> -void CommandStreamReceiverHw::addPipeControlWA(LinearStream &commandStream) { - auto pCmd = (Family::PIPE_CONTROL *)commandStream.getSpace(sizeof(Family::PIPE_CONTROL)); - *pCmd = Family::cmdInitPipeControl; - pCmd->setCommandStreamerStallEnable(true); -} - template <> void populateFactoryTable>() { extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE]; diff --git a/runtime/gen9/hw_helper_gen9.cpp b/runtime/gen9/hw_helper_gen9.cpp index f32c04f5fe..1c99b6c54f 100644 --- a/runtime/gen9/hw_helper_gen9.cpp +++ b/runtime/gen9/hw_helper_gen9.cpp @@ -28,6 +28,13 @@ SipKernelType HwHelperHw::getSipKernelType(bool debuggingActive) { return SipKernelType::DbgCsrLocal; } +template <> +void PipeControlHelper::addPipeControlWA(LinearStream &commandStream) { + auto pCmd = static_cast(commandStream.getSpace(sizeof(Family::PIPE_CONTROL))); + *pCmd = Family::cmdInitPipeControl; + pCmd->setCommandStreamerStallEnable(true); +} + template class AubHelperHw; template class HwHelperHw; template class FlatBatchBufferHelperHw; diff --git a/runtime/helpers/hw_helper.h b/runtime/helpers/hw_helper.h index 0e48110f38..22f28a5c36 100644 --- a/runtime/helpers/hw_helper.h +++ b/runtime/helpers/hw_helper.h @@ -189,6 +189,10 @@ struct PipeControlHelper { uint64_t gpuAddress, uint64_t immediateData, bool dcFlush); + static void addPipeControlWA(LinearStream &commandStream); + static PIPE_CONTROL *addPipeControlBase(LinearStream &commandStream, bool dcFlush); + static void addPipeControl(LinearStream &commandStream, bool dcFlush); + static int getRequiredPipeControlSize(); }; union SURFACE_STATE_BUFFER_LENGTH { diff --git a/runtime/helpers/hw_helper_common.inl b/runtime/helpers/hw_helper_common.inl index eb3b7722cb..94cacd2942 100644 --- a/runtime/helpers/hw_helper_common.inl +++ b/runtime/helpers/hw_helper_common.inl @@ -12,6 +12,7 @@ #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/hw_helper.h" #include "runtime/helpers/hw_info.h" +#include "runtime/helpers/kernel_commands.h" #include "runtime/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/memory_constants.h" #include "runtime/os_interface/os_interface.h" @@ -209,4 +210,41 @@ typename Family::PIPE_CONTROL *PipeControlHelper::obtainPipeControlAndPr return pipeControl; } +template +typename GfxFamily::PIPE_CONTROL *PipeControlHelper::addPipeControlBase(LinearStream &commandStream, bool dcFlush) { + PipeControlHelper::addPipeControlWA(commandStream); + + auto pCmd = reinterpret_cast(commandStream.getSpace(sizeof(PIPE_CONTROL))); + *pCmd = GfxFamily::cmdInitPipeControl; + pCmd->setCommandStreamerStallEnable(true); + pCmd->setDcFlushEnable(dcFlush); + + if (DebugManager.flags.FlushAllCaches.get()) { + pCmd->setDcFlushEnable(true); + pCmd->setRenderTargetCacheFlushEnable(true); + pCmd->setInstructionCacheInvalidateEnable(true); + pCmd->setTextureCacheInvalidationEnable(true); + pCmd->setPipeControlFlushEnable(true); + pCmd->setVfCacheInvalidationEnable(true); + pCmd->setConstantCacheInvalidationEnable(true); + pCmd->setStateCacheInvalidationEnable(true); + } + return pCmd; +} + +template +void PipeControlHelper::addPipeControlWA(LinearStream &commandStream) { +} + +template +void PipeControlHelper::addPipeControl(LinearStream &commandStream, bool dcFlush) { + PipeControlHelper::addPipeControlBase(commandStream, dcFlush); +} + +template +int PipeControlHelper::getRequiredPipeControlSize() { + const auto pipeControlCount = KernelCommandsHelper::isPipeControlWArequired() ? 2u : 1u; + return pipeControlCount * sizeof(typename GfxFamily::PIPE_CONTROL); +} + } // namespace NEO diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_1_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_1_tests.cpp index 7ff45b4349..4c7fd468a2 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_1_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_1_tests.cpp @@ -90,7 +90,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTaskIsSu //we do level change that will emit PPC, fill all the space so only BB end fits. taskLevel++; - auto ppcSize = mockCsr.getRequiredPipeControlSize(); + auto ppcSize = PipeControlHelper::getRequiredPipeControlSize(); auto fillSize = MemoryConstants::cacheLineSize - ppcSize - sizeof(typename FamilyType::MI_BATCH_BUFFER_END); csrCommandStream.getSpace(fillSize); auto expectedUsedSize = 2 * MemoryConstants::cacheLineSize; @@ -895,7 +895,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, FlushTaskBlockingHasPipeControlWit auto &commandStreamReceiver = commandQueue.getCommandStreamReceiver(); - size_t pipeControlCount = static_cast &>(commandStreamReceiver).getRequiredPipeControlSize() / sizeof(PIPE_CONTROL); + size_t pipeControlCount = PipeControlHelper::getRequiredPipeControlSize() / sizeof(PIPE_CONTROL); auto &commandStreamTask = commandQueue.getCS(1024); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp index ac9c4dbc43..3f9bea15c1 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp @@ -742,12 +742,10 @@ HWTEST_F(UltCommandStreamReceiverTest, addPipeControlWithFlushAllCaches) { DebugManagerStateRestore dbgRestorer; DebugManager.flags.FlushAllCaches.set(true); - auto &csr = pDevice->getCommandStreamReceiver(); - char buff[sizeof(PIPE_CONTROL) * 3]; LinearStream stream(buff, sizeof(PIPE_CONTROL) * 3); - csr.addPipeControl(stream, false); + PipeControlHelper::addPipeControl(stream, false); parseCommands(stream, 0); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp index 1be4e991b7..4db8976fb5 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp @@ -1462,7 +1462,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDcFlushArgumentIsTrueWhenCall std::unique_ptr buffer(new uint8_t[128]); LinearStream commandStream(buffer.get(), 128); - pDevice->getCommandStreamReceiver().addPipeControl(commandStream, true); + PipeControlHelper::addPipeControl(commandStream, true); auto pipeControlOffset = KernelCommandsHelper::isPipeControlWArequired() ? sizeof(PIPE_CONTROL) : 0u; auto pipeControlAddress = buffer.get() + pipeControlOffset; auto pipeControl = genCmdCast(pipeControlAddress); @@ -1476,7 +1476,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDcFlushArgumentIsFalseWhenCal std::unique_ptr buffer(new uint8_t[128]); LinearStream commandStream(buffer.get(), 128); - pDevice->getCommandStreamReceiver().addPipeControl(commandStream, false); + PipeControlHelper::addPipeControl(commandStream, false); auto pipeControlOffset = KernelCommandsHelper::isPipeControlWArequired() ? sizeof(PIPE_CONTROL) : 0u; auto pipeControlAddress = buffer.get() + pipeControlOffset; auto pipeControl = genCmdCast(pipeControlAddress); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp index 292a9f7a11..d864265659 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp @@ -75,7 +75,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskGmockTests, givenCsrInBatchingModeThreeRe dispatchFlags.outOfOrderExecutionAllowed = true; EXPECT_CALL(*mockHelper, setPatchInfoData(::testing::_)).Times(10); - EXPECT_CALL(*mockHelper, removePatchInfoData(::testing::_)).Times(4 * mockCsr->getRequiredPipeControlSize() / sizeof(PIPE_CONTROL)); + EXPECT_CALL(*mockHelper, removePatchInfoData(::testing::_)).Times(4 * PipeControlHelper::getRequiredPipeControlSize() / sizeof(PIPE_CONTROL)); EXPECT_CALL(*mockHelper, registerCommandChunk(::testing::_)).Times(4); EXPECT_CALL(*mockHelper, registerBatchBufferStartAddress(::testing::_, ::testing::_)).Times(3); diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index e483fd219f..8d88b1aa5a 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -542,9 +542,6 @@ class CommandStreamReceiverMock : public CommandStreamReceiver { return flushStamp->peekStamp(); } - void addPipeControl(LinearStream &commandStream, bool dcFlush) override { - } - void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, bool forcePowerSavingMode) override { } diff --git a/unit_tests/libult/mock_gfx_family.h b/unit_tests/libult/mock_gfx_family.h index da8123bc7e..4f81a47458 100644 --- a/unit_tests/libult/mock_gfx_family.h +++ b/unit_tests/libult/mock_gfx_family.h @@ -170,6 +170,14 @@ struct GENX { } inline void setGenericMediaStateClear(const bool value) { } + inline void setRenderTargetCacheFlushEnable(const bool value) { + } + inline void setInstructionCacheInvalidateEnable(const bool value) { + } + inline void setVfCacheInvalidationEnable(const bool value) { + } + inline void setConstantCacheInvalidationEnable(const bool value) { + } } PIPE_CONTROL; typedef struct tagMI_LOAD_REGISTER_IMM { diff --git a/unit_tests/mocks/mock_csr.h b/unit_tests/mocks/mock_csr.h index 720cef9f99..02dc8885f9 100644 --- a/unit_tests/mocks/mock_csr.h +++ b/unit_tests/mocks/mock_csr.h @@ -240,9 +240,6 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, bool forcePowerSavingMode) override { } - void addPipeControl(LinearStream &commandStream, bool dcFlush) override { - } - void setOSInterface(OSInterface *osInterface); CommandStreamReceiverType getType() override {