diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index 8be72c900c..2fc29ad329 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -842,4 +842,9 @@ const RootDeviceEnvironment &CommandStreamReceiver::peekRootDeviceEnvironment() return *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]; } +uint32_t CommandStreamReceiver::getCompletionValue(const GraphicsAllocation &gfxAllocation) { + auto osContextId = osContext->getContextId(); + return gfxAllocation.getTaskCount(osContextId); +} + } // namespace NEO diff --git a/shared/source/command_stream/command_stream_receiver.h b/shared/source/command_stream/command_stream_receiver.h index a2adf04a1a..bf6d15175d 100644 --- a/shared/source/command_stream/command_stream_receiver.h +++ b/shared/source/command_stream/command_stream_receiver.h @@ -321,13 +321,16 @@ class CommandStreamReceiver { MOCKABLE_VIRTUAL bool isGpuHangDetected() const; - virtual uint64_t getCompletionAddress() { - return 0; + uint64_t getCompletionAddress() { + uint64_t completionFenceAddress = castToUint64(const_cast(getTagAddress())); + if (completionFenceAddress == 0) { + return 0; + } + completionFenceAddress += completionFenceOffset; + return completionFenceAddress; } - virtual uint32_t getCompletionValue(const GraphicsAllocation &gfxAllocation) { - return 0; - } + uint32_t getCompletionValue(const GraphicsAllocation &gfxAllocation); protected: void cleanupResources(); @@ -406,6 +409,7 @@ class CommandStreamReceiver { uint32_t activePartitions = 1; uint32_t activePartitionsConfig = 1; uint32_t postSyncWriteOffset = 0; + uint32_t completionFenceOffset = 0; const uint32_t rootDeviceIndex; const DeviceBitfield deviceBitfield; diff --git a/shared/source/os_interface/linux/drm_command_stream.h b/shared/source/os_interface/linux/drm_command_stream.h index 9f2be78d30..871c5ddc2b 100644 --- a/shared/source/os_interface/linux/drm_command_stream.h +++ b/shared/source/os_interface/linux/drm_command_stream.h @@ -62,10 +62,6 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver { gemCloseWorkerOperationMode = gemCloseWorkerMode::gemCloseWorkerInactive; } - uint64_t getCompletionAddress() override; - - uint32_t getCompletionValue(const GraphicsAllocation &gfxAllocation) override; - void printBOsForSubmit(ResidencyContainer &allocationsForResidency, GraphicsAllocation &cmdBufferAllocation); using CommandStreamReceiver::pageTableManager; diff --git a/shared/source/os_interface/linux/drm_command_stream.inl b/shared/source/os_interface/linux/drm_command_stream.inl index 2b66a013f0..eaf8e77b1e 100644 --- a/shared/source/os_interface/linux/drm_command_stream.inl +++ b/shared/source/os_interface/linux/drm_command_stream.inl @@ -38,6 +38,8 @@ DrmCommandStreamReceiver::DrmCommandStreamReceiver(ExecutionEnvironme gemCloseWorkerMode mode) : BaseClass(executionEnvironment, rootDeviceIndex, deviceBitfield), gemCloseWorkerOperationMode(mode) { + this->completionFenceOffset = Drm::completionFenceOffset; + auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get(); this->drm = rootDeviceEnvironment->osInterface->getDriverModel()->as(); @@ -315,20 +317,4 @@ template inline bool DrmCommandStreamReceiver::isUserFenceWaitActive() { return (this->drm->isVmBindAvailable() && useUserFenceWait); } - -template -uint64_t DrmCommandStreamReceiver::getCompletionAddress() { - uint64_t completionFenceAddress = castToUint64(const_cast(getTagAddress())); - if (completionFenceAddress == 0) { - return 0; - } - completionFenceAddress += Drm::completionFenceOffset; - return completionFenceAddress; -} - -template -uint32_t DrmCommandStreamReceiver::getCompletionValue(const GraphicsAllocation &gfxAllocation) { - auto osContextId = osContext->getContextId(); - return gfxAllocation.getTaskCount(osContextId); -} } // namespace NEO diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index dbdc8f8e36..a3d4ac3a6c 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -59,16 +59,23 @@ struct CommandStreamReceiverTest : public DeviceFixture, DeviceFixture::TearDown(); } - CommandStreamReceiver *commandStreamReceiver; - MemoryManager *memoryManager; - InternalAllocationStorage *internalAllocationStorage; + CommandStreamReceiver *commandStreamReceiver = nullptr; + MemoryManager *memoryManager = nullptr; + InternalAllocationStorage *internalAllocationStorage = nullptr; }; -TEST_F(CommandStreamReceiverTest, givenOsAgnosticCsrWhenGettingCompletionValueOrAddressThenZeroIsReturned) { - EXPECT_EQ(0u, commandStreamReceiver->getCompletionAddress()); - +TEST_F(CommandStreamReceiverTest, givenOsAgnosticCsrWhenGettingCompletionValueThenProperTaskCountIsReturned) { MockGraphicsAllocation allocation{}; - EXPECT_EQ(0u, commandStreamReceiver->getCompletionValue(allocation)); + uint32_t expectedValue = 0x1234; + + auto &osContext = commandStreamReceiver->getOsContext(); + allocation.updateTaskCount(expectedValue, osContext.getContextId()); + EXPECT_EQ(expectedValue, commandStreamReceiver->getCompletionValue(allocation)); +} + +TEST_F(CommandStreamReceiverTest, givenOsAgnosticCsrWhenGettingCompletionAddressThenProperAddressIsReturned) { + auto expectedAddress = castToUint64(const_cast(commandStreamReceiver->getTagAddress())); + EXPECT_EQ(expectedAddress, commandStreamReceiver->getCompletionAddress()); } HWTEST_F(CommandStreamReceiverTest, WhenCreatingCsrThenDefaultValuesAreSet) {