Skip to content

Commit 4798c8a

Browse files
Add sfence when stop ring buffer
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com> Source: 5011046
1 parent 9a8d4ee commit 4798c8a

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

shared/source/direct_submission/direct_submission_hw.h

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class DirectSubmissionHw {
107107
GraphicsAllocation *switchRingBuffersAllocations();
108108
virtual uint64_t updateTagValue() = 0;
109109
virtual void getTagAddressValue(TagData &tagData) = 0;
110+
void unblockGpu();
110111

111112
void cpuCachelineFlush(void *ptr, size_t size);
112113

shared/source/direct_submission/direct_submission_hw.inl

+15-12
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::makeResourcesResident(DirectSubm
159159
return ret;
160160
}
161161

162+
template <typename GfxFamily, typename Dispatcher>
163+
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::unblockGpu() {
164+
if (sfenceMode >= DirectSubmissionSfenceMode::BeforeSemaphoreOnly) {
165+
CpuIntrinsics::sfence();
166+
}
167+
168+
semaphoreData->QueueWorkCount = currentQueueWorkCount;
169+
170+
if (sfenceMode == DirectSubmissionSfenceMode::BeforeAndAfterSemaphore) {
171+
CpuIntrinsics::sfence();
172+
}
173+
}
174+
162175
template <typename GfxFamily, typename Dispatcher>
163176
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::cpuCachelineFlush(void *ptr, size_t size) {
164177
if (disableCpuCacheFlush) {
@@ -273,8 +286,7 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::stopRingBuffer() {
273286
EncodeNoop<GfxFamily>::alignToCacheLine(ringCommandStream);
274287

275288
cpuCachelineFlush(flushPtr, getSizeEnd());
276-
277-
semaphoreData->QueueWorkCount = currentQueueWorkCount;
289+
this->unblockGpu();
278290
cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);
279291

280292
this->handleStopRingBuffer();
@@ -478,16 +490,7 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchCommandBuffer(BatchBuffe
478490
reserved = *ringBufferStart;
479491
}
480492

481-
if (sfenceMode >= DirectSubmissionSfenceMode::BeforeSemaphoreOnly) {
482-
CpuIntrinsics::sfence();
483-
}
484-
485-
//unblock GPU
486-
semaphoreData->QueueWorkCount = currentQueueWorkCount;
487-
488-
if (sfenceMode == DirectSubmissionSfenceMode::BeforeAndAfterSemaphore) {
489-
CpuIntrinsics::sfence();
490-
}
493+
this->unblockGpu();
491494

492495
cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);
493496
currentQueueWorkCount++;

shared/test/unit_test/direct_submission/direct_submission_tests_2.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,26 @@ HWTEST_F(DirectSubmissionDispatchBufferTest, givenDebugFlagSetWhenDispatchingWor
879879
EXPECT_EQ(initialCounterValue + expectedCount, CpuIntrinsicsTests::sfenceCounter);
880880
}
881881
}
882+
883+
HWTEST_F(DirectSubmissionDispatchBufferTest, givenDebugFlagSetWhenStoppingRingbufferThenProgramSfenceInstruction) {
884+
DebugManagerStateRestore restorer{};
885+
886+
using Dispatcher = BlitterDispatcher<FamilyType>;
887+
888+
FlushStampTracker flushStamp(true);
889+
890+
for (int32_t debugFlag : {-1, 0, 1, 2}) {
891+
DebugManager.flags.DirectSubmissionInsertSfenceInstructionPriorToSubmission.set(debugFlag);
892+
893+
MockDirectSubmissionHw<FamilyType, Dispatcher> directSubmission(*pDevice->getDefaultEngine().commandStreamReceiver);
894+
EXPECT_TRUE(directSubmission.initialize(true, true));
895+
896+
auto initialCounterValue = CpuIntrinsicsTests::sfenceCounter.load();
897+
898+
EXPECT_TRUE(directSubmission.stopRingBuffer());
899+
900+
uint32_t expectedCount = (debugFlag == -1) ? 2 : static_cast<uint32_t>(debugFlag);
901+
902+
EXPECT_EQ(initialCounterValue + expectedCount, CpuIntrinsicsTests::sfenceCounter);
903+
}
904+
}

0 commit comments

Comments
 (0)