Skip to content

Commit c2a4835

Browse files
Add wait mechanism to drm direct submission
Related-To: NEO-4338 Change-Id: Ibef00cb774fc0564f95b3b6ba8c0934798a5957e Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 321f649 commit c2a4835

File tree

8 files changed

+47
-12
lines changed

8 files changed

+47
-12
lines changed

opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class TestedDrmCommandStreamReceiver : public DrmCommandStreamReceiver<GfxFamily
1717
using CommandStreamReceiver::globalFenceAllocation;
1818
using CommandStreamReceiver::makeResident;
1919
using DrmCommandStreamReceiver<GfxFamily>::residency;
20+
using CommandStreamReceiverHw<GfxFamily>::directSubmission;
2021
using CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiver::lastSentSliceCount;
2122

2223
TestedDrmCommandStreamReceiver(gemCloseWorkerMode mode, ExecutionEnvironment &executionEnvironment)

opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "shared/source/command_stream/preemption.h"
9+
#include "shared/source/direct_submission/linux/drm_direct_submission.h"
910
#include "shared/source/gmm_helper/gmm_helper.h"
1011
#include "shared/source/gmm_helper/page_table_mngr.h"
1112
#include "shared/source/gmm_helper/resource_info.h"
@@ -1288,7 +1289,6 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, FlushNotAligned) {
12881289
}
12891290

12901291
struct DrmCommandStreamDirectSubmissionTest : public DrmCommandStreamEnhancedTest {
1291-
12921292
template <typename GfxFamily>
12931293
void SetUpT() {
12941294
DebugManager.flags.EnableDirectSubmission.set(1u);
@@ -1308,6 +1308,11 @@ struct DrmCommandStreamDirectSubmissionTest : public DrmCommandStreamEnhancedTes
13081308
DebugManagerStateRestore restorer;
13091309
};
13101310

1311+
template <typename GfxFamily>
1312+
struct MockDrmDirectSubmission : public DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>> {
1313+
using DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>>::currentTagData;
1314+
};
1315+
13111316
HWTEST_TEMPLATED_F(DrmCommandStreamDirectSubmissionTest, givenEnabledDirectSubmissionWhenFlushThenFlushStampIsNotUpdated) {
13121317
auto &cs = csr->getCS();
13131318
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
@@ -1320,6 +1325,9 @@ HWTEST_TEMPLATED_F(DrmCommandStreamDirectSubmissionTest, givenEnabledDirectSubmi
13201325
csr->flush(batchBuffer, csr->getResidencyAllocations());
13211326

13221327
EXPECT_EQ(csr->obtainCurrentFlushStamp(), flushStamp);
1328+
1329+
auto directSubmission = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(csr)->directSubmission.get();
1330+
static_cast<MockDrmDirectSubmission<FamilyType> *>(directSubmission)->currentTagData.tagValue = 0u;
13231331
}
13241332

13251333
HWTEST_TEMPLATED_F(DrmCommandStreamDirectSubmissionTest, givenEnabledDirectSubmissionWhenFlushThenCommandBufferAllocationIsResident) {
@@ -1334,6 +1342,9 @@ HWTEST_TEMPLATED_F(DrmCommandStreamDirectSubmissionTest, givenEnabledDirectSubmi
13341342

13351343
auto memoryOperationsInterface = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get();
13361344
EXPECT_EQ(memoryOperationsInterface->isResident(device.get(), *batchBuffer.commandBufferAllocation), MemoryOperationsStatus::SUCCESS);
1345+
1346+
auto directSubmission = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(csr)->directSubmission.get();
1347+
static_cast<MockDrmDirectSubmission<FamilyType> *>(directSubmission)->currentTagData.tagValue = 0u;
13371348
}
13381349

13391350
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, CheckDrmFree) {

shared/source/direct_submission/direct_submission_hw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace NEO {
1919
struct RingSemaphoreData {
2020
uint32_t QueueWorkCount;
2121
uint8_t ReservedCacheline[60];
22-
uint32_t Reserved1Uint32;
22+
uint32_t tagAllocation;
2323
uint32_t Reserved2Uint32;
2424
uint32_t Reserved3Uint32;
2525
uint32_t Reserved4Uint32;

shared/source/direct_submission/direct_submission_hw.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::allocateResources() {
8686
memset(semaphorePtr, 0, sizeof(RingSemaphoreData));
8787
semaphoreData->QueueWorkCount = 0;
8888
cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);
89-
workloadModeOneStoreAddress = static_cast<volatile void *>(&semaphoreData->Reserved1Uint32);
89+
workloadModeOneStoreAddress = static_cast<volatile void *>(&semaphoreData->Reserved4Uint32);
9090
*static_cast<volatile uint32_t *>(workloadModeOneStoreAddress) = 0u;
9191

9292
auto ret = makeResourcesResident(allocations);

shared/source/direct_submission/linux/drm_direct_submission.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ class DrmDirectSubmission : public DirectSubmissionHw<GfxFamily, Dispatcher> {
2929
void handleSwitchRingBuffers() override;
3030
uint64_t updateTagValue() override;
3131
void getTagAddressValue(TagData &tagData) override;
32+
33+
void wait(uint32_t taskCountToWait);
34+
35+
TagData currentTagData;
36+
volatile uint32_t *tagAddress;
3237
};
3338
} // namespace NEO

shared/source/direct_submission/linux/drm_direct_submission.inl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ inline std::unique_ptr<DirectSubmissionHw<GfxFamily, Dispatcher>> DirectSubmissi
2424
template <typename GfxFamily, typename Dispatcher>
2525
DrmDirectSubmission<GfxFamily, Dispatcher>::DrmDirectSubmission(Device &device,
2626
OsContext &osContext)
27-
: DirectSubmissionHw<GfxFamily, Dispatcher>(device, osContext) {
28-
this->disableMonitorFence = true;
29-
}
27+
: DirectSubmissionHw<GfxFamily, Dispatcher>(device, osContext){};
3028

3129
template <typename GfxFamily, typename Dispatcher>
3230
inline DrmDirectSubmission<GfxFamily, Dispatcher>::~DrmDirectSubmission() {
3331
if (this->ringStart) {
32+
this->wait(static_cast<uint32_t>(this->currentTagData.tagValue));
3433
this->stopRingBuffer();
35-
auto bb = static_cast<DrmAllocation *>(this->ringCommandStream.getGraphicsAllocation())->getBO();
34+
auto bb = static_cast<DrmAllocation *>(this->ringBuffer)->getBO();
3635
bb->wait(-1);
3736
}
3837
this->deallocateResources();
3938
}
4039

4140
template <typename GfxFamily, typename Dispatcher>
4241
bool DrmDirectSubmission<GfxFamily, Dispatcher>::allocateOsResources() {
42+
this->currentTagData.tagAddress = this->semaphoreGpuVa + MemoryConstants::cacheLineSize;
43+
this->currentTagData.tagValue = 0u;
44+
this->tagAddress = reinterpret_cast<volatile uint32_t *>(reinterpret_cast<uint8_t *>(this->semaphorePtr) + MemoryConstants::cacheLineSize);
4345
return true;
4446
}
4547

@@ -76,16 +78,30 @@ bool DrmDirectSubmission<GfxFamily, Dispatcher>::handleResidency() {
7678

7779
template <typename GfxFamily, typename Dispatcher>
7880
void DrmDirectSubmission<GfxFamily, Dispatcher>::handleSwitchRingBuffers() {
81+
if (this->ringStart) {
82+
if (this->completionRingBuffers[this->currentRingBuffer] != 0) {
83+
this->wait(static_cast<uint32_t>(this->completionRingBuffers[this->currentRingBuffer]));
84+
}
85+
}
7986
}
8087

8188
template <typename GfxFamily, typename Dispatcher>
8289
uint64_t DrmDirectSubmission<GfxFamily, Dispatcher>::updateTagValue() {
90+
this->currentTagData.tagValue++;
91+
this->completionRingBuffers[this->currentRingBuffer] = this->currentTagData.tagValue;
8392
return 0ull;
8493
}
8594

8695
template <typename GfxFamily, typename Dispatcher>
8796
void DrmDirectSubmission<GfxFamily, Dispatcher>::getTagAddressValue(TagData &tagData) {
88-
tagData.tagAddress = 0ull;
89-
tagData.tagValue = 0ull;
97+
tagData.tagAddress = this->currentTagData.tagAddress;
98+
tagData.tagValue = this->currentTagData.tagValue + 1;
99+
}
100+
101+
template <typename GfxFamily, typename Dispatcher>
102+
void DrmDirectSubmission<GfxFamily, Dispatcher>::wait(uint32_t taskCountToWait) {
103+
while (taskCountToWait > *this->tagAddress) {
104+
}
90105
}
106+
91107
} // namespace NEO

shared/test/unit_test/direct_submission/direct_submission_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ HWTEST_F(DirectSubmissionDispatchBufferTest,
461461
EXPECT_EQ(0x40u + 1u, storeData->getDataDword0());
462462
uint64_t expectedGpuVa = directSubmission.semaphoreGpuVa;
463463
auto semaphore = static_cast<RingSemaphoreData *>(directSubmission.semaphorePtr);
464-
expectedGpuVa += ptrDiff(&semaphore->Reserved1Uint32, directSubmission.semaphorePtr);
464+
expectedGpuVa += ptrDiff(&semaphore->Reserved4Uint32, directSubmission.semaphorePtr);
465465
EXPECT_EQ(expectedGpuVa, storeData->getAddress());
466466
}
467467

shared/test/unit_test/direct_submission/linux/drm_direct_submission_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ template <typename GfxFamily, typename Dispatcher>
4646
struct MockDrmDirectSubmission : public DrmDirectSubmission<GfxFamily, Dispatcher> {
4747
using BaseClass = DrmDirectSubmission<GfxFamily, Dispatcher>;
4848
using BaseClass::allocateResources;
49+
using BaseClass::currentTagData;
4950
using BaseClass::DrmDirectSubmission;
5051
using BaseClass::getTagAddressValue;
5152
using BaseClass::handleResidency;
5253
using BaseClass::submit;
5354
using BaseClass::switchRingBuffers;
55+
using BaseClass::tagAddress;
5456
using BaseClass::updateTagValue;
5557
};
5658

@@ -74,8 +76,8 @@ HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenCallingLinuxImplem
7476

7577
TagData tagData = {1ull, 1ull};
7678
drmDirectSubmission.getTagAddressValue(tagData);
77-
EXPECT_EQ(0ull, tagData.tagAddress);
78-
EXPECT_EQ(0ull, tagData.tagValue);
79+
EXPECT_EQ(drmDirectSubmission.currentTagData.tagAddress, tagData.tagAddress);
80+
EXPECT_EQ(drmDirectSubmission.currentTagData.tagValue + 1, tagData.tagValue);
7981
}
8082

8183
HWTEST_F(DrmDirectSubmissionTest, whenCreateDirectSubmissionThenValidObjectIsReturned) {

0 commit comments

Comments
 (0)