Skip to content

Commit b74280b

Browse files
Check EnableTimestampPacket debug variable once and set as CSR mode
Change-Id: Ia6e7caa96f3b46b30590fb46a1fb37fa153adeb4
1 parent a8beec9 commit b74280b

11 files changed

+41
-28
lines changed

runtime/command_queue/enqueue_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
242242
}
243243

244244
TimestampPacket *timestampPacket = nullptr;
245-
if (DebugManager.flags.EnableTimestampPacket.get()) {
245+
if (device->peekCommandStreamReceiver()->peekTimestampPacketWriteEnabled()) {
246246
obtainNewTimestampPacketNode();
247247
timestampPacket = timestampPacketNode->tag;
248248
}

runtime/command_queue/gpgpu_walker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ LinearStream &getCommandStream(CommandQueue &commandQueue, bool reserveProfiling
291291
SchedulerKernel &scheduler = commandQueue.getDevice().getExecutionEnvironment()->getBuiltIns()->getSchedulerKernel(parentKernel->getContext());
292292
expectedSizeCS += EnqueueOperation<GfxFamily>::getSizeRequiredCS(eventType, reserveProfilingCmdsSpace, reservePerfCounterCmdsSpace, commandQueue, &scheduler);
293293
}
294-
if (DebugManager.flags.EnableTimestampPacket.get()) {
294+
if (commandQueue.getDevice().peekCommandStreamReceiver()->peekTimestampPacketWriteEnabled()) {
295295
expectedSizeCS += 2 * sizeof(typename GfxFamily::PIPE_CONTROL);
296296
}
297297
return commandQueue.getCS(expectedSizeCS);

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ CommandStreamReceiver::CommandStreamReceiver(ExecutionEnvironment &executionEnvi
4848
for (int i = 0; i < IndirectHeap::NUM_TYPES; ++i) {
4949
indirectHeap[i] = nullptr;
5050
}
51+
52+
timestampPacketWriteEnabled = DebugManager.flags.EnableTimestampPacket.get();
5153
}
5254

5355
CommandStreamReceiver::~CommandStreamReceiver() {

runtime/command_stream/command_stream_receiver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,17 @@ class CommandStreamReceiver {
155155
return kmdNotifyHelper.get();
156156
}
157157

158+
bool peekTimestampPacketWriteEnabled() const { return timestampPacketWriteEnabled; }
159+
158160
size_t defaultSshSize;
159161

160162
protected:
161163
void setDisableL3Cache(bool val) {
162164
disableL3Cache = val;
163165
}
164166

167+
bool timestampPacketWriteEnabled = false;
168+
165169
// taskCount - # of tasks submitted
166170
uint32_t taskCount = 0;
167171
// current taskLevel. Used for determining if a PIPE_CONTROL is needed.

runtime/command_stream/command_stream_receiver_hw.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
181181

182182
epiloguePipeControlLocation = ptrOffset(commandStreamTask.getCpuBase(), commandStreamTask.getUsed());
183183

184-
if ((dispatchFlags.outOfOrderExecutionAllowed || DebugManager.flags.EnableTimestampPacket.get()) &&
184+
if ((dispatchFlags.outOfOrderExecutionAllowed || timestampPacketWriteEnabled) &&
185185
!dispatchFlags.dcFlush) {
186186
currentPipeControlForNooping = epiloguePipeControlLocation;
187187
}
@@ -355,7 +355,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
355355

356356
// Add a PC if we have a dependency on a previous walker to avoid concurrency issues.
357357
if (taskLevel > this->taskLevel) {
358-
if (!DebugManager.flags.EnableTimestampPacket.get()) {
358+
if (!timestampPacketWriteEnabled) {
359359
addPipeControl(commandStreamCSR, false);
360360
}
361361
this->taskLevel = taskLevel;

unit_tests/command_queue/enqueue_kernel_tests.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,9 +1577,8 @@ HWTEST_F(EnqueueKernelTest, givenNonVMEKernelWhenEnqueueKernelThenDispatchFlagsD
15771577
}
15781578

15791579
HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingNonBlockedThenMakeItResident) {
1580-
DebugManagerStateRestore restore;
1581-
DebugManager.flags.EnableTimestampPacket.set(true);
15821580
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
1581+
csr.timestampPacketWriteEnabled = true;
15831582
MockKernelWithInternals mockKernel(*pDevice, context);
15841583
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
15851584

@@ -1593,9 +1592,8 @@ HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingNonBlockedThenMake
15931592
}
15941593

15951594
HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingBlockedThenMakeItResidentOnSubmit) {
1596-
DebugManagerStateRestore restore;
1597-
DebugManager.flags.EnableTimestampPacket.set(true);
15981595
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
1596+
csr.timestampPacketWriteEnabled = true;
15991597
MockKernelWithInternals mockKernel(*pDevice, context);
16001598
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
16011599

unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, higherTaskLevelShouldSendAPipeCont
297297
EXPECT_NE(cmdList.end(), itorPC);
298298
}
299299

300-
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenHigherTaskLevelWhenDebugVariableIsEnabledThenDontAddPipeControl) {
301-
DebugManagerStateRestore restore;
302-
DebugManager.flags.EnableTimestampPacket.set(true);
300+
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenHigherTaskLevelWhenTimestampPacketWriteIsEnabledThenDontAddPipeControl) {
303301
auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver<FamilyType>();
302+
commandStreamReceiver.timestampPacketWriteEnabled = true;
304303
commandStreamReceiver.isPreambleSent = true;
305304
configureCSRtoNonDirtyState<FamilyType>();
306305
commandStreamReceiver.taskLevel = taskLevel;
@@ -2919,8 +2918,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenCsrInBatch
29192918
EXPECT_NE(itorPipeControl, itorBatchBufferStartSecond);
29202919
}
29212920

2922-
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSetToFalseWhenDebugVariableIsSetThenNoopPipeControl) {
2923-
DebugManagerStateRestore restore;
2921+
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSetToFalseWhenTimestampPacketWriteIsEnabledThenNoopPipeControl) {
29242922
CommandQueueHw<FamilyType> commandQueue(nullptr, pDevice, 0);
29252923
auto &commandStream = commandQueue.getCS(4096u);
29262924

@@ -2938,7 +2936,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSe
29382936

29392937
auto taskLevelPriorToSubmission = mockCsr->peekTaskLevel();
29402938

2941-
DebugManager.flags.EnableTimestampPacket.set(false);
2939+
mockCsr->timestampPacketWriteEnabled = false;
29422940
mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice);
29432941
mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice);
29442942

@@ -2949,7 +2947,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSe
29492947

29502948
mockCsr->flushBatchedSubmissions();
29512949

2952-
DebugManager.flags.EnableTimestampPacket.set(true);
2950+
mockCsr->timestampPacketWriteEnabled = true;
29532951
mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice);
29542952
mockCsr->flushTask(commandStream, 0, dsh, ioh, ssh, taskLevelPriorToSubmission, dispatchFlags, *pDevice);
29552953

unit_tests/command_stream/command_stream_receiver_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,18 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWithoutTagAllocationWhenGetTagAllo
303303
EXPECT_EQ(nullptr, csr.getTagAllocation());
304304
}
305305

306+
TEST(CommandStreamReceiverSimpleTest, givenDebugVariableEnabledWhenCreatingCsrThenEnableTimestampPacketWriteMode) {
307+
DebugManagerStateRestore restore;
308+
309+
DebugManager.flags.EnableTimestampPacket.set(true);
310+
MockCommandStreamReceiver csr1;
311+
EXPECT_TRUE(csr1.peekTimestampPacketWriteEnabled());
312+
313+
DebugManager.flags.EnableTimestampPacket.set(false);
314+
MockCommandStreamReceiver csr2;
315+
EXPECT_FALSE(csr2.peekTimestampPacketWriteEnabled());
316+
}
317+
306318
TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllocationIsCalledThenCorrectAllocationIsReturned) {
307319
MockCommandStreamReceiver csr;
308320
GraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);

unit_tests/helpers/timestamp_packet_tests.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "runtime/helpers/options.h"
2525
#include "runtime/helpers/timestamp_packet.h"
2626
#include "runtime/utilities/tag_allocator.h"
27-
#include "unit_tests/helpers/debug_manager_state_restore.h"
2827
#include "unit_tests/helpers/hw_parse.h"
2928
#include "unit_tests/mocks/mock_context.h"
3029
#include "unit_tests/mocks/mock_device.h"
@@ -127,20 +126,18 @@ TEST_F(TimestampPacketTests, whenAskedForStampAddressThenReturnWithValidOffset)
127126
}
128127
}
129128

130-
HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEstimatingStreamSizeThenAddTwoPipeControls) {
131-
DebugManagerStateRestore restore;
132-
DebugManager.flags.EnableTimestampPacket.set(false);
133-
129+
HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEstimatingStreamSizeThenAddTwoPipeControls) {
134130
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
135131
MockCommandQueue cmdQ(nullptr, device.get(), nullptr);
136132
MockKernelWithInternals kernel1(*device);
137133
MockKernelWithInternals kernel2(*device);
138134
MockMultiDispatchInfo multiDispatchInfo(std::vector<Kernel *>({kernel1.mockKernel, kernel2.mockKernel}));
139135

136+
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = false;
140137
getCommandStream<FamilyType, CL_COMMAND_NDRANGE_KERNEL>(cmdQ, false, false, multiDispatchInfo);
141138
auto sizeWithDisabled = cmdQ.requestedCmdStreamSize;
142139

143-
DebugManager.flags.EnableTimestampPacket.set(true);
140+
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
144141
getCommandStream<FamilyType, CL_COMMAND_NDRANGE_KERNEL>(cmdQ, false, false, multiDispatchInfo);
145142
auto sizeWithEnabled = cmdQ.requestedCmdStreamSize;
146143

@@ -208,9 +205,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWhenDispat
208205
EXPECT_EQ(2u, walkersFound);
209206
}
210207

211-
HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenObtainNewStampAndPassToEvent) {
212-
DebugManagerStateRestore restore;
213-
DebugManager.flags.EnableTimestampPacket.set(false);
208+
HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThenObtainNewStampAndPassToEvent) {
214209

215210
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
216211
auto mockMemoryManager = new MockMemoryManager();
@@ -221,13 +216,15 @@ HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenObtain
221216
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&context, device.get(), nullptr);
222217
MockKernelWithInternals kernel(*device, &context);
223218

219+
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = false;
220+
224221
size_t gws[] = {1, 1, 1};
225222

226223
cmdQ->enqueueKernel(kernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
227224
EXPECT_EQ(nullptr, cmdQ->timestampPacketNode);
228225
EXPECT_EQ(nullptr, mockTagAllocator->usedTags.peekHead());
229226

230-
DebugManager.flags.EnableTimestampPacket.set(true);
227+
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
231228
cl_event event1, event2;
232229

233230
// obtain first node for cmdQ and event1
@@ -269,17 +266,17 @@ HWTEST_F(TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenObtain
269266
EXPECT_EQ(node2, mockTagAllocator->releaseReferenceNodes.at(3));
270267
}
271268

272-
HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenDebugVariableEnabledWhenEnqueueingThenWriteWalkerStamp) {
269+
HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThenWriteWalkerStamp) {
273270
using GPGPU_WALKER = typename FamilyType::GPGPU_WALKER;
274271
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
275-
DebugManagerStateRestore restore;
276-
DebugManager.flags.EnableTimestampPacket.set(true);
277272

278273
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
279274
MockContext context(device.get());
280275
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&context, device.get(), nullptr);
281276
MockKernelWithInternals kernel(*device, &context);
282277

278+
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
279+
283280
size_t gws[] = {1, 1, 1};
284281
cmdQ->enqueueKernel(kernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
285282
EXPECT_NE(nullptr, cmdQ->timestampPacketNode);

unit_tests/libult/ult_command_stream_receiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily> {
6161
using BaseClass::CommandStreamReceiver::submissionAggregator;
6262
using BaseClass::CommandStreamReceiver::taskCount;
6363
using BaseClass::CommandStreamReceiver::taskLevel;
64+
using BaseClass::CommandStreamReceiver::timestampPacketWriteEnabled;
6465

6566
UltCommandStreamReceiver(const UltCommandStreamReceiver &) = delete;
6667
UltCommandStreamReceiver &operator=(const UltCommandStreamReceiver &) = delete;

unit_tests/mocks/mock_csr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class MockCsrHw2 : public CommandStreamReceiverHw<GfxFamily> {
161161
using CommandStreamReceiver::mediaVfeStateDirty;
162162
using CommandStreamReceiver::taskCount;
163163
using CommandStreamReceiver::taskLevel;
164+
using CommandStreamReceiver::timestampPacketWriteEnabled;
164165

165166
MockCsrHw2(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment) : CommandStreamReceiverHw<GfxFamily>(hwInfoIn, executionEnvironment) {}
166167

0 commit comments

Comments
 (0)