Skip to content

Commit 0ca8ee7

Browse files
Additional programming for source level debugger.
- always program STATE_BASE_ADDRESS and STATE_SIP Change-Id: Iea6327d062b4efdddd3b0060d3105b29745b9cba
1 parent f9b4838 commit 0ca8ee7

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

runtime/command_stream/command_stream_receiver_hw.inl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
302302
}
303303

304304
//Reprogram state base address if required
305-
if (isStateBaseAddressDirty) {
305+
if (isStateBaseAddressDirty || device.isSourceLevelDebuggerActive()) {
306306
auto pCmd = addPipeControlCmd(commandStreamCSR);
307307
pCmd->setTextureCacheInvalidationEnable(true);
308308
pCmd->setDcFlushEnable(true);
@@ -621,7 +621,7 @@ template <typename GfxFamily>
621621
size_t CommandStreamReceiverHw<GfxFamily>::getRequiredCmdStreamSize(const DispatchFlags &dispatchFlags, Device &device) {
622622
size_t size = getRequiredCmdSizeForPreamble(device);
623623
size += getRequiredStateBaseAddressSize();
624-
if (!this->isStateSipSent) {
624+
if (!this->isStateSipSent || device.isSourceLevelDebuggerActive()) {
625625
size += PreemptionHelper::getRequiredStateSipCmdSize<GfxFamily>(device);
626626
}
627627
size += getRequiredPipeControlSize();
@@ -689,7 +689,7 @@ inline size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForPreemption(const
689689

690690
template <typename GfxFamily>
691691
inline void CommandStreamReceiverHw<GfxFamily>::programStateSip(LinearStream &cmdStream, Device &device) {
692-
if (!this->isStateSipSent) {
692+
if (!this->isStateSipSent || device.isSourceLevelDebuggerActive()) {
693693
PreemptionHelper::programStateSip<GfxFamily>(cmdStream, device);
694694
this->isStateSipSent = true;
695695
}

unit_tests/command_stream/command_stream_receiver_hw_tests.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ HWTEST_F(UltCommandStreamReceiverTest, givenSentStateSipFlagSetWhenGetRequiredSt
115115
EXPECT_EQ(sizeForStateSip, sizeWithStateSipIsNotSent - sizeWhenSipIsSent);
116116
}
117117

118+
HWTEST_F(UltCommandStreamReceiverTest, givenSentStateSipFlagSetAndSourceLevelDebuggerIsActiveWhenGetRequiredStateSipCmdSizeIsCalledThenStateSipCmdSizeIsIncluded) {
119+
auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver<FamilyType>();
120+
DispatchFlags dispatchFlags;
121+
122+
commandStreamReceiver.isStateSipSent = true;
123+
auto sizeWithoutSourceKernelDebugging = commandStreamReceiver.getRequiredCmdStreamSize(dispatchFlags, *pDevice);
124+
125+
pDevice->setSourceLevelDebuggerActive(true);
126+
commandStreamReceiver.isStateSipSent = true;
127+
auto sizeWithSourceKernelDebugging = commandStreamReceiver.getRequiredCmdStreamSize(dispatchFlags, *pDevice);
128+
129+
auto sizeForStateSip = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(*pDevice);
130+
EXPECT_EQ(sizeForStateSip, sizeWithSourceKernelDebugging - sizeWithoutSourceKernelDebugging - PreambleHelper<FamilyType>::getKernelDebuggingCommandsSize(true));
131+
}
132+
118133
HWTEST_F(UltCommandStreamReceiverTest, givenPreambleSentAndThreadArbitrationPolicyChangedWhenEstimatingPreambleCmdSizeThenResultDependsOnPolicyProgrammingCmdSize) {
119134
auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver<FamilyType>();
120135
commandStreamReceiver.isPreambleSent = true;

unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,78 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs
115115
alignedFree(buffer);
116116
}
117117
}
118+
119+
HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebuggerAndWhenFlushTaskIsCalledThenAlwaysProgramStateBaseAddressAndSip) {
120+
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
121+
using STATE_SIP = typename FamilyType::STATE_SIP;
122+
123+
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
124+
125+
if (device->getHardwareInfo().capabilityTable.defaultPreemptionMode == PreemptionMode::MidThread) {
126+
device->setSourceLevelDebuggerActive(true);
127+
device->allocatePreemptionAllocationIfNotPresent();
128+
auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0], *device->executionEnvironment);
129+
130+
device->resetCommandStreamReceiver(mockCsr);
131+
132+
mockCsr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch);
133+
134+
CommandQueueHw<FamilyType> commandQueue(nullptr, device.get(), 0);
135+
auto &commandStream = commandQueue.getCS(4096u);
136+
auto &preambleStream = mockCsr->getCS(0);
137+
138+
DispatchFlags dispatchFlags;
139+
dispatchFlags.preemptionMode = PreemptionMode::Disabled;
140+
141+
void *buffer = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize64k);
142+
143+
std::unique_ptr<MockGraphicsAllocation> allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize));
144+
std::unique_ptr<IndirectHeap> heap(new IndirectHeap(allocation.get()));
145+
146+
mockCsr->flushTask(commandStream,
147+
0,
148+
*heap.get(),
149+
*heap.get(),
150+
*heap.get(),
151+
0,
152+
dispatchFlags,
153+
*device);
154+
155+
mockCsr->flushBatchedSubmissions();
156+
157+
mockCsr->flushTask(commandStream,
158+
0,
159+
*heap.get(),
160+
*heap.get(),
161+
*heap.get(),
162+
0,
163+
dispatchFlags,
164+
*device);
165+
166+
auto sipType = SipKernel::getSipKernelType(device->getHardwareInfo().pPlatform->eRenderCoreFamily, true);
167+
auto sipAllocation = device->getExecutionEnvironment()->getBuiltIns()->getSipKernel(sipType, *device.get()).getSipAllocation();
168+
169+
HardwareParse hwParser;
170+
hwParser.parseCommands<FamilyType>(preambleStream);
171+
auto itorStateBaseAddr = find<STATE_BASE_ADDRESS *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
172+
auto itorStateSip = find<STATE_SIP *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
173+
174+
ASSERT_NE(hwParser.cmdList.end(), itorStateBaseAddr);
175+
ASSERT_NE(hwParser.cmdList.end(), itorStateSip);
176+
177+
auto itorStateBaseAddr2 = find<STATE_BASE_ADDRESS *>(std::next(itorStateBaseAddr), hwParser.cmdList.end());
178+
auto itorStateSip2 = find<STATE_SIP *>(std::next(itorStateSip), hwParser.cmdList.end());
179+
180+
ASSERT_NE(hwParser.cmdList.end(), itorStateBaseAddr2);
181+
ASSERT_NE(hwParser.cmdList.end(), itorStateSip2);
182+
183+
STATE_BASE_ADDRESS *sba = (STATE_BASE_ADDRESS *)*itorStateBaseAddr2;
184+
STATE_SIP *stateSipCmd = (STATE_SIP *)*itorStateSip2;
185+
EXPECT_LT(reinterpret_cast<void *>(sba), reinterpret_cast<void *>(stateSipCmd));
186+
187+
auto sipAddress = stateSipCmd->getSystemInstructionPointer();
188+
189+
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress);
190+
alignedFree(buffer);
191+
}
192+
}

0 commit comments

Comments
 (0)