Skip to content

Commit 4ea4520

Browse files
Defer direct submission control until first submit
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 0cde8eb commit 4ea4520

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

shared/source/command_stream/command_stream_receiver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "shared/source/command_stream/preemption.h"
1414
#include "shared/source/command_stream/scratch_space_controller.h"
1515
#include "shared/source/device/device.h"
16+
#include "shared/source/direct_submission/direct_submission_controller.h"
1617
#include "shared/source/execution_environment/root_device_environment.h"
1718
#include "shared/source/gmm_helper/page_table_mngr.h"
1819
#include "shared/source/helpers/array_count.h"
@@ -385,6 +386,13 @@ AubSubCaptureStatus CommandStreamReceiver::checkAndActivateAubSubCapture(const s
385386

386387
void CommandStreamReceiver::addAubComment(const char *comment) {}
387388

389+
void CommandStreamReceiver::startControllingDirectSubmissions() {
390+
auto controller = this->executionEnvironment.directSubmissionController.get();
391+
if (controller) {
392+
controller->startControlling();
393+
}
394+
}
395+
388396
GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) {
389397
UNRECOVERABLE_IF(debugSurface != nullptr);
390398
debugSurface = getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, getOsContext().getDeviceBitfield()});

shared/source/command_stream/command_stream_receiver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ class CommandStreamReceiver {
235235

236236
uint32_t getRootDeviceIndex() { return rootDeviceIndex; }
237237

238+
void startControllingDirectSubmissions();
239+
238240
virtual bool initDirectSubmission(Device &device, OsContext &osContext) {
239241
return true;
240242
}

shared/source/direct_submission/direct_submission_controller.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,19 @@ void DirectSubmissionController::unregisterDirectSubmission(CommandStreamReceive
4242
directSubmissions.erase(csr);
4343
}
4444

45+
void DirectSubmissionController::startControlling() {
46+
this->runControlling.store(true);
47+
}
48+
4549
void *DirectSubmissionController::controlDirectSubmissionsState(void *self) {
4650
auto controller = reinterpret_cast<DirectSubmissionController *>(self);
4751

52+
while (!controller->runControlling.load()) {
53+
if (!controller->keepControlling.load()) {
54+
return nullptr;
55+
}
56+
}
57+
4858
while (true) {
4959

5060
auto start = std::chrono::steady_clock::now();

shared/source/direct_submission/direct_submission_controller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class DirectSubmissionController {
2525
void registerDirectSubmission(CommandStreamReceiver *csr);
2626
void unregisterDirectSubmission(CommandStreamReceiver *csr);
2727

28+
void startControlling();
29+
2830
static bool isSupported();
2931

3032
protected:
@@ -41,6 +43,7 @@ class DirectSubmissionController {
4143

4244
std::unique_ptr<Thread> directSubmissionControllingThread;
4345
std::atomic_bool keepControlling = true;
46+
std::atomic_bool runControlling = false;
4447

4548
int timeout = 5;
4649
};

shared/source/os_interface/linux/drm_command_stream.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, Reside
109109
}
110110

111111
if (this->directSubmission.get()) {
112+
this->startControllingDirectSubmissions();
112113
return this->directSubmission->dispatchCommandBuffer(batchBuffer, *this->flushStamp.get());
113114
}
114115
if (this->blitterDirectSubmission.get()) {
116+
this->startControllingDirectSubmissions();
115117
return this->blitterDirectSubmission->dispatchCommandBuffer(batchBuffer, *this->flushStamp.get());
116118
}
117119

shared/test/unit_test/direct_submission/direct_submission_controller_tests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ TEST(DirectSubmissionControllerTests, givenDirectSubmissionControllerWhenTimeout
8787
csr.taskCount.store(9u);
8888

8989
DirectSubmissionControllerMock controller;
90+
executionEnvironment.directSubmissionController.reset(&controller);
91+
csr.startControllingDirectSubmissions();
9092
controller.registerDirectSubmission(&csr);
9193

9294
while (!controller.directSubmissions[&csr].isStopped) {
@@ -97,6 +99,26 @@ TEST(DirectSubmissionControllerTests, givenDirectSubmissionControllerWhenTimeout
9799
EXPECT_EQ(controller.directSubmissions[&csr].taskCount, 9u);
98100

99101
controller.unregisterDirectSubmission(&csr);
102+
executionEnvironment.directSubmissionController.release();
103+
}
104+
105+
TEST(DirectSubmissionControllerTests, givenDirectSubmissionControllerWithStartedControllingWhenShuttingDownThenNoHang) {
106+
DirectSubmissionControllerMock controller;
107+
EXPECT_NE(controller.directSubmissionControllingThread.get(), nullptr);
108+
109+
controller.startControlling();
110+
controller.keepControlling.store(false);
111+
controller.directSubmissionControllingThread->join();
112+
controller.directSubmissionControllingThread.reset();
113+
}
114+
115+
TEST(DirectSubmissionControllerTests, givenDirectSubmissionControllerWithNotStartedControllingWhenShuttingDownThenNoHang) {
116+
DirectSubmissionControllerMock controller;
117+
EXPECT_NE(controller.directSubmissionControllingThread.get(), nullptr);
118+
119+
controller.keepControlling.store(false);
120+
controller.directSubmissionControllingThread->join();
121+
controller.directSubmissionControllingThread.reset();
100122
}
101123

102124
} // namespace NEO

0 commit comments

Comments
 (0)