Skip to content

Commit 8f38f4e

Browse files
fix command stream receiver: stop calling virtual methods in dtor
make getCompletionAddress and getCompletionValue non-virtual methods Related-To: NEO-6643 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 4cb46ee commit 8f38f4e

File tree

5 files changed

+30
-32
lines changed

5 files changed

+30
-32
lines changed

shared/source/command_stream/command_stream_receiver.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,9 @@ const RootDeviceEnvironment &CommandStreamReceiver::peekRootDeviceEnvironment()
842842
return *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
843843
}
844844

845+
uint32_t CommandStreamReceiver::getCompletionValue(const GraphicsAllocation &gfxAllocation) {
846+
auto osContextId = osContext->getContextId();
847+
return gfxAllocation.getTaskCount(osContextId);
848+
}
849+
845850
} // namespace NEO

shared/source/command_stream/command_stream_receiver.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,16 @@ class CommandStreamReceiver {
321321

322322
MOCKABLE_VIRTUAL bool isGpuHangDetected() const;
323323

324-
virtual uint64_t getCompletionAddress() {
325-
return 0;
324+
uint64_t getCompletionAddress() {
325+
uint64_t completionFenceAddress = castToUint64(const_cast<uint32_t *>(getTagAddress()));
326+
if (completionFenceAddress == 0) {
327+
return 0;
328+
}
329+
completionFenceAddress += completionFenceOffset;
330+
return completionFenceAddress;
326331
}
327332

328-
virtual uint32_t getCompletionValue(const GraphicsAllocation &gfxAllocation) {
329-
return 0;
330-
}
333+
uint32_t getCompletionValue(const GraphicsAllocation &gfxAllocation);
331334

332335
protected:
333336
void cleanupResources();
@@ -406,6 +409,7 @@ class CommandStreamReceiver {
406409
uint32_t activePartitions = 1;
407410
uint32_t activePartitionsConfig = 1;
408411
uint32_t postSyncWriteOffset = 0;
412+
uint32_t completionFenceOffset = 0;
409413

410414
const uint32_t rootDeviceIndex;
411415
const DeviceBitfield deviceBitfield;

shared/source/os_interface/linux/drm_command_stream.h

-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
6262
gemCloseWorkerOperationMode = gemCloseWorkerMode::gemCloseWorkerInactive;
6363
}
6464

65-
uint64_t getCompletionAddress() override;
66-
67-
uint32_t getCompletionValue(const GraphicsAllocation &gfxAllocation) override;
68-
6965
void printBOsForSubmit(ResidencyContainer &allocationsForResidency, GraphicsAllocation &cmdBufferAllocation);
7066

7167
using CommandStreamReceiver::pageTableManager;

shared/source/os_interface/linux/drm_command_stream.inl

+2-16
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver(ExecutionEnvironme
3838
gemCloseWorkerMode mode)
3939
: BaseClass(executionEnvironment, rootDeviceIndex, deviceBitfield), gemCloseWorkerOperationMode(mode) {
4040

41+
this->completionFenceOffset = Drm::completionFenceOffset;
42+
4143
auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get();
4244

4345
this->drm = rootDeviceEnvironment->osInterface->getDriverModel()->as<Drm>();
@@ -315,20 +317,4 @@ template <typename GfxFamily>
315317
inline bool DrmCommandStreamReceiver<GfxFamily>::isUserFenceWaitActive() {
316318
return (this->drm->isVmBindAvailable() && useUserFenceWait);
317319
}
318-
319-
template <typename GfxFamily>
320-
uint64_t DrmCommandStreamReceiver<GfxFamily>::getCompletionAddress() {
321-
uint64_t completionFenceAddress = castToUint64(const_cast<uint32_t *>(getTagAddress()));
322-
if (completionFenceAddress == 0) {
323-
return 0;
324-
}
325-
completionFenceAddress += Drm::completionFenceOffset;
326-
return completionFenceAddress;
327-
}
328-
329-
template <typename GfxFamily>
330-
uint32_t DrmCommandStreamReceiver<GfxFamily>::getCompletionValue(const GraphicsAllocation &gfxAllocation) {
331-
auto osContextId = osContext->getContextId();
332-
return gfxAllocation.getTaskCount(osContextId);
333-
}
334320
} // namespace NEO

shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,23 @@ struct CommandStreamReceiverTest : public DeviceFixture,
5959
DeviceFixture::TearDown();
6060
}
6161

62-
CommandStreamReceiver *commandStreamReceiver;
63-
MemoryManager *memoryManager;
64-
InternalAllocationStorage *internalAllocationStorage;
62+
CommandStreamReceiver *commandStreamReceiver = nullptr;
63+
MemoryManager *memoryManager = nullptr;
64+
InternalAllocationStorage *internalAllocationStorage = nullptr;
6565
};
6666

67-
TEST_F(CommandStreamReceiverTest, givenOsAgnosticCsrWhenGettingCompletionValueOrAddressThenZeroIsReturned) {
68-
EXPECT_EQ(0u, commandStreamReceiver->getCompletionAddress());
69-
67+
TEST_F(CommandStreamReceiverTest, givenOsAgnosticCsrWhenGettingCompletionValueThenProperTaskCountIsReturned) {
7068
MockGraphicsAllocation allocation{};
71-
EXPECT_EQ(0u, commandStreamReceiver->getCompletionValue(allocation));
69+
uint32_t expectedValue = 0x1234;
70+
71+
auto &osContext = commandStreamReceiver->getOsContext();
72+
allocation.updateTaskCount(expectedValue, osContext.getContextId());
73+
EXPECT_EQ(expectedValue, commandStreamReceiver->getCompletionValue(allocation));
74+
}
75+
76+
TEST_F(CommandStreamReceiverTest, givenOsAgnosticCsrWhenGettingCompletionAddressThenProperAddressIsReturned) {
77+
auto expectedAddress = castToUint64(const_cast<uint32_t *>(commandStreamReceiver->getTagAddress()));
78+
EXPECT_EQ(expectedAddress, commandStreamReceiver->getCompletionAddress());
7279
}
7380

7481
HWTEST_F(CommandStreamReceiverTest, WhenCreatingCsrThenDefaultValuesAreSet) {

0 commit comments

Comments
 (0)