Skip to content

Commit e0c892e

Browse files
Add lock to downloading allocations on tbx
When running multiple threads, one thread could clear allocationsForDownload while another was iterating over it. Signed-off-by: Dominik Dabek <[email protected]>
1 parent 60d6505 commit e0c892e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

shared/source/command_stream/tbx_command_stream_receiver_hw.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ void TbxCommandStreamReceiverHw<GfxFamily>::flushSubmissionsAndDownloadAllocatio
485485
pollAddress = ptrOffset(pollAddress, this->postSyncWriteOffset);
486486
}
487487

488+
auto lockCSR = this->obtainUniqueOwnership();
488489
for (GraphicsAllocation *graphicsAllocation : this->allocationsForDownload) {
489490
downloadAllocation(*graphicsAllocation);
490491
}
@@ -555,6 +556,7 @@ void TbxCommandStreamReceiverHw<GfxFamily>::downloadAllocations() {
555556
}
556557
pollAddress = ptrOffset(pollAddress, this->postSyncWriteOffset);
557558
}
559+
auto lockCSR = this->obtainUniqueOwnership();
558560
for (GraphicsAllocation *graphicsAllocation : this->allocationsForDownload) {
559561
downloadAllocation(*graphicsAllocation);
560562
}

shared/test/common/mocks/mock_tbx_csr.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -87,8 +87,14 @@ struct MockTbxCsrRegisterDownloadedAllocations : TbxCommandStreamReceiverHw<GfxF
8787
void flushTagUpdate() override {
8888
flushTagCalled = true;
8989
}
90+
91+
std::unique_lock<CommandStreamReceiver::MutexType> obtainUniqueOwnership() override {
92+
obtainUniqueOwnershipCalled++;
93+
return TbxCommandStreamReceiverHw<GfxFamily>::obtainUniqueOwnership();
94+
}
9095
std::set<GraphicsAllocation *> downloadedAllocations;
9196
bool flushBatchedSubmissionsCalled = false;
9297
bool flushTagCalled = false;
98+
size_t obtainUniqueOwnershipCalled = 0;
9399
};
94100
} // namespace NEO

shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenLatestFlushedTaskCountLowerThanTagWhenF
394394
tbxCsr.latestFlushedTaskCount = 0u;
395395
EXPECT_FALSE(tbxCsr.flushTagCalled);
396396

397+
EXPECT_EQ(0u, tbxCsr.obtainUniqueOwnershipCalled);
397398
tbxCsr.flushSubmissionsAndDownloadAllocations(1u);
399+
EXPECT_EQ(1u, tbxCsr.obtainUniqueOwnershipCalled);
398400

399401
EXPECT_TRUE(tbxCsr.flushTagCalled);
400402
}
@@ -410,7 +412,9 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenDownloadAllocatoinsCalledThen
410412
MockGraphicsAllocation allocation1, allocation2, allocation3;
411413
tbxCsr.allocationsForDownload = {&allocation1, &allocation2, &allocation3};
412414

415+
EXPECT_EQ(0u, tbxCsr.obtainUniqueOwnershipCalled);
413416
tbxCsr.downloadAllocations();
417+
EXPECT_EQ(1u, tbxCsr.obtainUniqueOwnershipCalled);
414418

415419
std::set<GraphicsAllocation *> expectedDownloadedAllocations = {tbxCsr.getTagAllocation(), &allocation1, &allocation2, &allocation3};
416420
EXPECT_EQ(0u, tbxCsr.allocationsForDownload.size());

0 commit comments

Comments
 (0)