Skip to content

Commit 9d502de

Browse files
Refactor waitOnCompletionFence method in DrmMemoryManager
get completion address and value from command stream receiver Related-To: NEO-6643 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent e32f624 commit 9d502de

File tree

9 files changed

+59
-35
lines changed

9 files changed

+59
-35
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ struct DrmCommandStreamMultiTileMemExecFixture {
5151
executionEnvironment->prepareRootDeviceEnvironments(1u);
5252
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(NEO::defaultHwInfo.get());
5353
executionEnvironment->initializeMemoryManager();
54-
device.reset(MockDevice::create<MockDevice>(executionEnvironment, 0));
5554

56-
osContext = std::make_unique<OsContextLinux>(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor(device->getDeviceBitfield()));
57-
osContext->ensureContextInitialized();
55+
VariableBackup<UltHwConfig> backup(&ultHwConfig);
56+
ultHwConfig.useHwCsr = true;
57+
device.reset(MockDevice::create<MockDevice>(executionEnvironment, 0));
5858
}
5959

6060
void TearDown() {
@@ -64,7 +64,6 @@ struct DrmCommandStreamMultiTileMemExecFixture {
6464
DebugManagerStateRestore dbgRestore;
6565
std::unique_ptr<VariableBackup<bool>> osLocalMemoryBackup;
6666
std::unique_ptr<MockDevice> device;
67-
std::unique_ptr<OsContext> osContext;
6867
MockExecutionEnvironment *executionEnvironment = nullptr;
6968
DrmMockCustom *mock = nullptr;
7069
DrmMemoryManager *memoryManager = nullptr;
@@ -73,7 +72,11 @@ struct DrmCommandStreamMultiTileMemExecFixture {
7372
using DrmCommandStreamMultiTileMemExecTest = Test<DrmCommandStreamMultiTileMemExecFixture>;
7473

7574
HWCMDTEST_F(IGFX_XE_HP_CORE, DrmCommandStreamMultiTileMemExecTest, GivenDrmSupportsCompletionFenceAndVmBindWhenCallingCsrExecThenMultipleTagAllocationIsPassed) {
75+
auto osContext = std::make_unique<OsContextLinux>(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor(device->getDeviceBitfield()));
76+
osContext->ensureContextInitialized();
77+
7678
auto *testCsr = new TestedDrmCommandStreamReceiver<FamilyType>(*executionEnvironment, 0, device->getDeviceBitfield());
79+
auto device = std::unique_ptr<MockDevice>(MockDevice::create<MockDevice>(executionEnvironment, 0));
7780
device->resetCommandStreamReceiver(testCsr);
7881
EXPECT_EQ(2u, testCsr->activePartitions);
7982
testCsr->setupContext(*osContext.get());

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5920,27 +5920,4 @@ TEST_F(DrmMemoryManagerTest, givenCompletionFenceEnabledWhenHandlingCompletionOf
59205920
memoryManager->freeGraphicsMemory(allocation);
59215921
}
59225922

5923-
HWTEST_F(DrmMemoryManagerTest, givenCompletionFenceEnabledWhenHandlingCompletionAndTagAddressIsNullThenDoNotCallWaitUserFence) {
5924-
mock->ioctl_expected.total = -1;
5925-
5926-
VariableBackup<bool> backupFenceSupported{&mock->completionFenceSupported, true};
5927-
VariableBackup<bool> backupVmBindCallParent{&mock->isVmBindAvailableCall.callParent, false};
5928-
VariableBackup<bool> backupVmBindReturnValue{&mock->isVmBindAvailableCall.returnValue, true};
5929-
5930-
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, 1024, AllocationType::COMMAND_BUFFER});
5931-
auto engine = memoryManager->getRegisteredEngines()[0];
5932-
allocation->updateTaskCount(2, engine.osContext->getContextId());
5933-
5934-
auto testCsr = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(engine.commandStreamReceiver);
5935-
auto backupTagAddress = testCsr->tagAddress;
5936-
testCsr->tagAddress = nullptr;
5937-
5938-
memoryManager->handleFenceCompletion(allocation);
5939-
EXPECT_EQ(0u, mock->waitUserFenceCall.called);
5940-
5941-
testCsr->tagAddress = backupTagAddress;
5942-
5943-
memoryManager->freeGraphicsMemory(allocation);
5944-
}
5945-
59465923
} // namespace NEO

shared/source/command_stream/command_stream_receiver.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ class CommandStreamReceiver {
319319

320320
MOCKABLE_VIRTUAL bool isGpuHangDetected() const;
321321

322+
virtual uint64_t getCompletionAddress() {
323+
return 0;
324+
}
325+
326+
virtual uint32_t getCompletionValue(const GraphicsAllocation &gfxAllocation) {
327+
return 0;
328+
}
329+
322330
protected:
323331
void cleanupResources();
324332
void printDeviceIndex();

shared/source/os_interface/linux/drm_command_stream.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ 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+
6569
void printBOsForSubmit(ResidencyContainer &allocationsForResidency, GraphicsAllocation &cmdBufferAllocation);
6670

6771
using CommandStreamReceiver::pageTableManager;

shared/source/os_interface/linux/drm_command_stream.inl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,16 @@ inline bool DrmCommandStreamReceiver<GfxFamily>::isUserFenceWaitActive() {
316316
return (this->drm->isVmBindAvailable() && useUserFenceWait);
317317
}
318318

319+
template <typename GfxFamily>
320+
uint64_t DrmCommandStreamReceiver<GfxFamily>::getCompletionAddress() {
321+
uint64_t completionFenceAddress = castToUint64(const_cast<uint32_t *>(getTagAddress()));
322+
completionFenceAddress += Drm::completionFenceOffset;
323+
return completionFenceAddress;
324+
}
325+
326+
template <typename GfxFamily>
327+
uint32_t DrmCommandStreamReceiver<GfxFamily>::getCompletionValue(const GraphicsAllocation &gfxAllocation) {
328+
auto osContextId = osContext->getContextId();
329+
return gfxAllocation.getTaskCount(osContextId);
330+
}
319331
} // namespace NEO

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,14 +1526,13 @@ void DrmMemoryManager::waitOnCompletionFence(GraphicsAllocation *allocation) {
15261526

15271527
uint32_t activeHwContexts = csr->getActivePartitions();
15281528
auto osContextId = osContext->getContextId();
1529-
auto allocationTaskCount = allocation->getTaskCount(osContextId);
1530-
uint64_t completionFenceAddress = castToUint64(const_cast<uint32_t *>(csr->getTagAddress()));
1529+
auto allocationTaskCount = csr->getCompletionValue(*allocation);
1530+
uint64_t completionFenceAddress = csr->getCompletionAddress();
15311531
if (completionFenceAddress == 0) {
15321532
continue;
15331533
}
15341534

15351535
if (allocation->isUsedByOsContext(osContextId)) {
1536-
completionFenceAddress += Drm::completionFenceOffset;
15371536
Drm &drm = getDrm(csr->getRootDeviceIndex());
15381537
auto &ctxVector = static_cast<const OsContextLinux *>(osContext)->getDrmContextIds();
15391538

shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ struct CommandStreamReceiverTest : public DeviceFixture,
6464
InternalAllocationStorage *internalAllocationStorage;
6565
};
6666

67+
TEST_F(CommandStreamReceiverTest, givenOsAgnosticCsrWhenGettingCompletionValueOrAddressThenZeroIsReturned) {
68+
EXPECT_EQ(0u, commandStreamReceiver->getCompletionAddress());
69+
70+
MockGraphicsAllocation allocation{};
71+
EXPECT_EQ(0u, commandStreamReceiver->getCompletionValue(allocation));
72+
}
73+
6774
HWTEST_F(CommandStreamReceiverTest, WhenCreatingCsrThenDefaultValuesAreSet) {
6875
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
6976
EXPECT_EQ(0u, csr.peekTaskLevel());

shared/test/unit_test/os_interface/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
99
${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests_linux.cpp
1010
${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests_linux.h
1111
${CMAKE_CURRENT_SOURCE_DIR}/drm_bind_tests.cpp
12-
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_l0_tests.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests.cpp
1313
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_engine_info_tests.cpp
1414
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_impl.h
1515
${CMAKE_CURRENT_SOURCE_DIR}/drm_query_topology_upstream_tests.cpp

shared/test/unit_test/os_interface/linux/drm_command_stream_l0_tests.cpp renamed to shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "shared/test/common/libult/linux/drm_mock.h"
1818
#include "shared/test/common/mocks/linux/mock_drm_command_stream_receiver.h"
1919
#include "shared/test/common/mocks/mock_execution_environment.h"
20+
#include "shared/test/common/mocks/mock_graphics_allocation.h"
2021
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
2122
#include "shared/test/common/test_macros/test.h"
2223

@@ -28,7 +29,7 @@ extern ApiSpecificConfig::ApiType apiTypeForUlts;
2829
} //namespace NEO
2930
using namespace NEO;
3031

31-
class DrmCommandStreamTestL0 : public ::testing::Test {
32+
class DrmCommandStreamTest : public ::testing::Test {
3233
public:
3334
template <typename GfxFamily>
3435
void SetUpT() {
@@ -89,13 +90,26 @@ class DrmCommandStreamTestL0 : public ::testing::Test {
8990
};
9091

9192
template <typename GfxFamily>
92-
struct MockDrmCsrL0 : public DrmCommandStreamReceiver<GfxFamily> {
93+
struct MockDrmCsr : public DrmCommandStreamReceiver<GfxFamily> {
9394
using DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver;
9495
using DrmCommandStreamReceiver<GfxFamily>::dispatchMode;
9596
};
9697

97-
HWTEST_TEMPLATED_F(DrmCommandStreamTestL0, givenL0ApiConfigWhenCreatingDrmCsrThenEnableImmediateDispatch) {
98+
HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenL0ApiConfigWhenCreatingDrmCsrThenEnableImmediateDispatch) {
9899
VariableBackup<ApiSpecificConfig::ApiType> backup(&apiTypeForUlts, ApiSpecificConfig::L0);
99-
MockDrmCsrL0<FamilyType> csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive);
100+
MockDrmCsr<FamilyType> csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive);
100101
EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode);
101102
}
103+
104+
HWTEST_TEMPLATED_F(DrmCommandStreamTest, whenGettingCompletionValueThenTaskCountOfAllocationIsReturned) {
105+
MockGraphicsAllocation allocation{};
106+
uint32_t expectedValue = 0x1234;
107+
allocation.updateTaskCount(expectedValue, osContext->getContextId());
108+
EXPECT_EQ(expectedValue, csr->getCompletionValue(allocation));
109+
}
110+
111+
HWTEST_TEMPLATED_F(DrmCommandStreamTest, whenGettingCompletionAddressThenOffsettedTagAddressIsReturned) {
112+
uint64_t tagAddress = castToUint64(const_cast<uint32_t *>(csr->getTagAddress()));
113+
auto expectedAddress = tagAddress + Drm::completionFenceOffset;
114+
EXPECT_EQ(expectedAddress, csr->getCompletionAddress());
115+
}

0 commit comments

Comments
 (0)