Skip to content

Commit

Permalink
Add sfence when stop ring buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Jobczyk <[email protected]>

Source: 5011046
  • Loading branch information
LukaszJobczyk authored and Compute-Runtime-Automation committed Nov 29, 2022
1 parent 9a8d4ee commit 4798c8a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions shared/source/direct_submission/direct_submission_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class DirectSubmissionHw {
GraphicsAllocation *switchRingBuffersAllocations();
virtual uint64_t updateTagValue() = 0;
virtual void getTagAddressValue(TagData &tagData) = 0;
void unblockGpu();

void cpuCachelineFlush(void *ptr, size_t size);

Expand Down
27 changes: 15 additions & 12 deletions shared/source/direct_submission/direct_submission_hw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::makeResourcesResident(DirectSubm
return ret;
}

template <typename GfxFamily, typename Dispatcher>
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::unblockGpu() {
if (sfenceMode >= DirectSubmissionSfenceMode::BeforeSemaphoreOnly) {
CpuIntrinsics::sfence();
}

semaphoreData->QueueWorkCount = currentQueueWorkCount;

if (sfenceMode == DirectSubmissionSfenceMode::BeforeAndAfterSemaphore) {
CpuIntrinsics::sfence();
}
}

template <typename GfxFamily, typename Dispatcher>
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::cpuCachelineFlush(void *ptr, size_t size) {
if (disableCpuCacheFlush) {
Expand Down Expand Up @@ -273,8 +286,7 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::stopRingBuffer() {
EncodeNoop<GfxFamily>::alignToCacheLine(ringCommandStream);

cpuCachelineFlush(flushPtr, getSizeEnd());

semaphoreData->QueueWorkCount = currentQueueWorkCount;
this->unblockGpu();
cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);

this->handleStopRingBuffer();
Expand Down Expand Up @@ -478,16 +490,7 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchCommandBuffer(BatchBuffe
reserved = *ringBufferStart;
}

if (sfenceMode >= DirectSubmissionSfenceMode::BeforeSemaphoreOnly) {
CpuIntrinsics::sfence();
}

//unblock GPU
semaphoreData->QueueWorkCount = currentQueueWorkCount;

if (sfenceMode == DirectSubmissionSfenceMode::BeforeAndAfterSemaphore) {
CpuIntrinsics::sfence();
}
this->unblockGpu();

cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);
currentQueueWorkCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,26 @@ HWTEST_F(DirectSubmissionDispatchBufferTest, givenDebugFlagSetWhenDispatchingWor
EXPECT_EQ(initialCounterValue + expectedCount, CpuIntrinsicsTests::sfenceCounter);
}
}

HWTEST_F(DirectSubmissionDispatchBufferTest, givenDebugFlagSetWhenStoppingRingbufferThenProgramSfenceInstruction) {
DebugManagerStateRestore restorer{};

using Dispatcher = BlitterDispatcher<FamilyType>;

FlushStampTracker flushStamp(true);

for (int32_t debugFlag : {-1, 0, 1, 2}) {
DebugManager.flags.DirectSubmissionInsertSfenceInstructionPriorToSubmission.set(debugFlag);

MockDirectSubmissionHw<FamilyType, Dispatcher> directSubmission(*pDevice->getDefaultEngine().commandStreamReceiver);
EXPECT_TRUE(directSubmission.initialize(true, true));

auto initialCounterValue = CpuIntrinsicsTests::sfenceCounter.load();

EXPECT_TRUE(directSubmission.stopRingBuffer());

uint32_t expectedCount = (debugFlag == -1) ? 2 : static_cast<uint32_t>(debugFlag);

EXPECT_EQ(initialCounterValue + expectedCount, CpuIntrinsicsTests::sfenceCounter);
}
}

0 comments on commit 4798c8a

Please sign in to comment.