From b74280beb67ed3c7c7c25ca9a3255e606357e0cf Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Thu, 6 Sep 2018 09:03:07 +0200 Subject: [PATCH] Check EnableTimestampPacket debug variable once and set as CSR mode Change-Id: Ia6e7caa96f3b46b30590fb46a1fb37fa153adeb4 --- runtime/command_queue/enqueue_common.h | 2 +- runtime/command_queue/gpgpu_walker.h | 2 +- .../command_stream_receiver.cpp | 2 ++ .../command_stream/command_stream_receiver.h | 4 ++++ .../command_stream_receiver_hw.inl | 4 ++-- .../command_queue/enqueue_kernel_tests.cpp | 6 ++--- ...mmand_stream_receiver_flush_task_tests.cpp | 12 ++++------ .../command_stream_receiver_tests.cpp | 12 ++++++++++ unit_tests/helpers/timestamp_packet_tests.cpp | 23 ++++++++----------- .../libult/ult_command_stream_receiver.h | 1 + unit_tests/mocks/mock_csr.h | 1 + 11 files changed, 41 insertions(+), 28 deletions(-) diff --git a/runtime/command_queue/enqueue_common.h b/runtime/command_queue/enqueue_common.h index c414d6e2e9..8be9f0a98a 100644 --- a/runtime/command_queue/enqueue_common.h +++ b/runtime/command_queue/enqueue_common.h @@ -242,7 +242,7 @@ void CommandQueueHw::enqueueHandler(Surface **surfacesForResidency, } TimestampPacket *timestampPacket = nullptr; - if (DebugManager.flags.EnableTimestampPacket.get()) { + if (device->peekCommandStreamReceiver()->peekTimestampPacketWriteEnabled()) { obtainNewTimestampPacketNode(); timestampPacket = timestampPacketNode->tag; } diff --git a/runtime/command_queue/gpgpu_walker.h b/runtime/command_queue/gpgpu_walker.h index a82a3f35ab..1a54cdb076 100644 --- a/runtime/command_queue/gpgpu_walker.h +++ b/runtime/command_queue/gpgpu_walker.h @@ -291,7 +291,7 @@ LinearStream &getCommandStream(CommandQueue &commandQueue, bool reserveProfiling SchedulerKernel &scheduler = commandQueue.getDevice().getExecutionEnvironment()->getBuiltIns()->getSchedulerKernel(parentKernel->getContext()); expectedSizeCS += EnqueueOperation::getSizeRequiredCS(eventType, reserveProfilingCmdsSpace, reservePerfCounterCmdsSpace, commandQueue, &scheduler); } - if (DebugManager.flags.EnableTimestampPacket.get()) { + if (commandQueue.getDevice().peekCommandStreamReceiver()->peekTimestampPacketWriteEnabled()) { expectedSizeCS += 2 * sizeof(typename GfxFamily::PIPE_CONTROL); } return commandQueue.getCS(expectedSizeCS); diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 0c66698e91..c99f827bca 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -48,6 +48,8 @@ CommandStreamReceiver::CommandStreamReceiver(ExecutionEnvironment &executionEnvi for (int i = 0; i < IndirectHeap::NUM_TYPES; ++i) { indirectHeap[i] = nullptr; } + + timestampPacketWriteEnabled = DebugManager.flags.EnableTimestampPacket.get(); } CommandStreamReceiver::~CommandStreamReceiver() { diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 5c4a971283..ddd00b8699 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -155,6 +155,8 @@ class CommandStreamReceiver { return kmdNotifyHelper.get(); } + bool peekTimestampPacketWriteEnabled() const { return timestampPacketWriteEnabled; } + size_t defaultSshSize; protected: @@ -162,6 +164,8 @@ class CommandStreamReceiver { disableL3Cache = val; } + bool timestampPacketWriteEnabled = false; + // taskCount - # of tasks submitted uint32_t taskCount = 0; // current taskLevel. Used for determining if a PIPE_CONTROL is needed. diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index 2efeb98553..4da02ca75e 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -181,7 +181,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( epiloguePipeControlLocation = ptrOffset(commandStreamTask.getCpuBase(), commandStreamTask.getUsed()); - if ((dispatchFlags.outOfOrderExecutionAllowed || DebugManager.flags.EnableTimestampPacket.get()) && + if ((dispatchFlags.outOfOrderExecutionAllowed || timestampPacketWriteEnabled) && !dispatchFlags.dcFlush) { currentPipeControlForNooping = epiloguePipeControlLocation; } @@ -355,7 +355,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 (!DebugManager.flags.EnableTimestampPacket.get()) { + if (!timestampPacketWriteEnabled) { addPipeControl(commandStreamCSR, false); } this->taskLevel = taskLevel; diff --git a/unit_tests/command_queue/enqueue_kernel_tests.cpp b/unit_tests/command_queue/enqueue_kernel_tests.cpp index d1453fd0f4..aded19ef3e 100644 --- a/unit_tests/command_queue/enqueue_kernel_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_tests.cpp @@ -1577,9 +1577,8 @@ HWTEST_F(EnqueueKernelTest, givenNonVMEKernelWhenEnqueueKernelThenDispatchFlagsD } HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingNonBlockedThenMakeItResident) { - DebugManagerStateRestore restore; - DebugManager.flags.EnableTimestampPacket.set(true); auto &csr = pDevice->getUltCommandStreamReceiver(); + csr.timestampPacketWriteEnabled = true; MockKernelWithInternals mockKernel(*pDevice, context); auto mockCmdQ = std::make_unique>(context, pDevice, nullptr); @@ -1593,9 +1592,8 @@ HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingNonBlockedThenMake } HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingBlockedThenMakeItResidentOnSubmit) { - DebugManagerStateRestore restore; - DebugManager.flags.EnableTimestampPacket.set(true); auto &csr = pDevice->getUltCommandStreamReceiver(); + csr.timestampPacketWriteEnabled = true; MockKernelWithInternals mockKernel(*pDevice, context); auto mockCmdQ = std::make_unique>(context, pDevice, nullptr); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp index ccffe5055f..7797315b3a 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp @@ -297,10 +297,9 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, higherTaskLevelShouldSendAPipeCont EXPECT_NE(cmdList.end(), itorPC); } -HWTEST_F(CommandStreamReceiverFlushTaskTests, givenHigherTaskLevelWhenDebugVariableIsEnabledThenDontAddPipeControl) { - DebugManagerStateRestore restore; - DebugManager.flags.EnableTimestampPacket.set(true); +HWTEST_F(CommandStreamReceiverFlushTaskTests, givenHigherTaskLevelWhenTimestampPacketWriteIsEnabledThenDontAddPipeControl) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); + commandStreamReceiver.timestampPacketWriteEnabled = true; commandStreamReceiver.isPreambleSent = true; configureCSRtoNonDirtyState(); commandStreamReceiver.taskLevel = taskLevel; @@ -2919,8 +2918,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenCsrInBatch EXPECT_NE(itorPipeControl, itorBatchBufferStartSecond); } -HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSetToFalseWhenDebugVariableIsSetThenNoopPipeControl) { - DebugManagerStateRestore restore; +HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSetToFalseWhenTimestampPacketWriteIsEnabledThenNoopPipeControl) { CommandQueueHw commandQueue(nullptr, pDevice, 0); auto &commandStream = commandQueue.getCS(4096u); @@ -2938,7 +2936,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSe auto taskLevelPriorToSubmission = mockCsr->peekTaskLevel(); - DebugManager.flags.EnableTimestampPacket.set(false); + mockCsr->timestampPacketWriteEnabled = false; mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice); mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice); @@ -2949,7 +2947,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSe mockCsr->flushBatchedSubmissions(); - DebugManager.flags.EnableTimestampPacket.set(true); + mockCsr->timestampPacketWriteEnabled = true; mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice); mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 7d826c442c..3e9ed35b97 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -303,6 +303,18 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWithoutTagAllocationWhenGetTagAllo EXPECT_EQ(nullptr, csr.getTagAllocation()); } +TEST(CommandStreamReceiverSimpleTest, givenDebugVariableEnabledWhenCreatingCsrThenEnableTimestampPacketWriteMode) { + DebugManagerStateRestore restore; + + DebugManager.flags.EnableTimestampPacket.set(true); + MockCommandStreamReceiver csr1; + EXPECT_TRUE(csr1.peekTimestampPacketWriteEnabled()); + + DebugManager.flags.EnableTimestampPacket.set(false); + MockCommandStreamReceiver csr2; + EXPECT_FALSE(csr2.peekTimestampPacketWriteEnabled()); +} + TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllocationIsCalledThenCorrectAllocationIsReturned) { MockCommandStreamReceiver csr; GraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); diff --git a/unit_tests/helpers/timestamp_packet_tests.cpp b/unit_tests/helpers/timestamp_packet_tests.cpp index a4e821ad54..7dc1252491 100644 --- a/unit_tests/helpers/timestamp_packet_tests.cpp +++ b/unit_tests/helpers/timestamp_packet_tests.cpp @@ -24,7 +24,6 @@ #include "runtime/helpers/options.h" #include "runtime/helpers/timestamp_packet.h" #include "runtime/utilities/tag_allocator.h" -#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/hw_parse.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_device.h" @@ -127,20 +126,18 @@ TEST_F(TimestampPacketTests, whenAskedForStampAddressThenReturnWithValidOffset) } } -HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEstimatingStreamSizeThenAddTwoPipeControls) { - DebugManagerStateRestore restore; - DebugManager.flags.EnableTimestampPacket.set(false); - +HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEstimatingStreamSizeThenAddTwoPipeControls) { auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); MockCommandQueue cmdQ(nullptr, device.get(), nullptr); MockKernelWithInternals kernel1(*device); MockKernelWithInternals kernel2(*device); MockMultiDispatchInfo multiDispatchInfo(std::vector({kernel1.mockKernel, kernel2.mockKernel})); + device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = false; getCommandStream(cmdQ, false, false, multiDispatchInfo); auto sizeWithDisabled = cmdQ.requestedCmdStreamSize; - DebugManager.flags.EnableTimestampPacket.set(true); + device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; getCommandStream(cmdQ, false, false, multiDispatchInfo); auto sizeWithEnabled = cmdQ.requestedCmdStreamSize; @@ -208,9 +205,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWhenDispat EXPECT_EQ(2u, walkersFound); } -HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenObtainNewStampAndPassToEvent) { - DebugManagerStateRestore restore; - DebugManager.flags.EnableTimestampPacket.set(false); +HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThenObtainNewStampAndPassToEvent) { auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); auto mockMemoryManager = new MockMemoryManager(); @@ -221,13 +216,15 @@ HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenObtain auto cmdQ = std::make_unique>(&context, device.get(), nullptr); MockKernelWithInternals kernel(*device, &context); + device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = false; + size_t gws[] = {1, 1, 1}; cmdQ->enqueueKernel(kernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); EXPECT_EQ(nullptr, cmdQ->timestampPacketNode); EXPECT_EQ(nullptr, mockTagAllocator->usedTags.peekHead()); - DebugManager.flags.EnableTimestampPacket.set(true); + device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; cl_event event1, event2; // obtain first node for cmdQ and event1 @@ -269,17 +266,17 @@ HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenObtain EXPECT_EQ(node2, mockTagAllocator->releaseReferenceNodes.at(3)); } -HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenWriteWalkerStamp) { +HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThenWriteWalkerStamp) { using GPGPU_WALKER = typename FamilyType::GPGPU_WALKER; using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; - DebugManagerStateRestore restore; - DebugManager.flags.EnableTimestampPacket.set(true); auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); MockContext context(device.get()); auto cmdQ = std::make_unique>(&context, device.get(), nullptr); MockKernelWithInternals kernel(*device, &context); + device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; + size_t gws[] = {1, 1, 1}; cmdQ->enqueueKernel(kernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); EXPECT_NE(nullptr, cmdQ->timestampPacketNode); diff --git a/unit_tests/libult/ult_command_stream_receiver.h b/unit_tests/libult/ult_command_stream_receiver.h index 7db593506a..f0da3c37bb 100644 --- a/unit_tests/libult/ult_command_stream_receiver.h +++ b/unit_tests/libult/ult_command_stream_receiver.h @@ -61,6 +61,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { using BaseClass::CommandStreamReceiver::submissionAggregator; using BaseClass::CommandStreamReceiver::taskCount; using BaseClass::CommandStreamReceiver::taskLevel; + using BaseClass::CommandStreamReceiver::timestampPacketWriteEnabled; UltCommandStreamReceiver(const UltCommandStreamReceiver &) = delete; UltCommandStreamReceiver &operator=(const UltCommandStreamReceiver &) = delete; diff --git a/unit_tests/mocks/mock_csr.h b/unit_tests/mocks/mock_csr.h index 55c41fec2f..af8a0a9a10 100644 --- a/unit_tests/mocks/mock_csr.h +++ b/unit_tests/mocks/mock_csr.h @@ -161,6 +161,7 @@ class MockCsrHw2 : public CommandStreamReceiverHw { using CommandStreamReceiver::mediaVfeStateDirty; using CommandStreamReceiver::taskCount; using CommandStreamReceiver::taskLevel; + using CommandStreamReceiver::timestampPacketWriteEnabled; MockCsrHw2(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment) : CommandStreamReceiverHw(hwInfoIn, executionEnvironment) {}