Attach UUID to SbaAllocations

Related-To: NEO-7630
Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwolinski
2023-04-06 12:09:57 +00:00
committed by Compute-Runtime-Automation
parent a114448792
commit a1066177a5
9 changed files with 203 additions and 10 deletions

View File

@@ -0,0 +1,21 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/os_interface/linux/os_context_linux.h"
namespace NEO {
class MockOsContextLinux : public OsContextLinux {
public:
using OsContextLinux::drmContextIds;
MockOsContextLinux(Drm &drm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)
: OsContextLinux(drm, rootDeviceIndex, contextId, engineDescriptor) {}
};
static_assert(sizeof(OsContextLinux) == sizeof(MockOsContextLinux));
} // namespace NEO

View File

@@ -19,6 +19,7 @@
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/linux/mock_drm_command_stream_receiver.h"
#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h"
#include "shared/test/common/mocks/linux/mock_os_context_linux.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_gfx_partition.h"
@@ -3922,6 +3923,143 @@ TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledWhenIsaIsRegisteredTh
EXPECT_EQ(static_cast<uint32_t>(allocation.storageInfo.subDeviceBitfield.to_ulong()), *data);
}
TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledAndSubDeviceBitfieldSetWhenSbaTrackingBufferIsRegisteredThenDeviceContextIdIsPassedAsPayload) {
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]);
for (uint32_t i = 3; i < 3 + static_cast<uint32_t>(DrmResourceClass::MaxSize); i++) {
drm.classHandles.push_back(i);
}
drm.registeredClass = DrmResourceClass::MaxSize;
MockBufferObject bo(&drm, 3, 0, 0, 1);
MockDrmAllocation allocation(AllocationType::DEBUG_SBA_TRACKING_BUFFER, MemoryPool::LocalMemory);
allocation.storageInfo.tileInstanced = false;
allocation.storageInfo.subDeviceBitfield = 0b0010;
allocation.bufferObjects[0] = &bo;
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
allocation.setOsContext(&osContext);
osContext.drmContextIds.clear();
osContext.drmContextIds.push_back(3u);
osContext.drmContextIds.push_back(5u);
const auto processId = 0xABCEDF;
uint64_t offlineDumpContextId = static_cast<uint64_t>(processId) << 32 | static_cast<uint64_t>(5u);
allocation.registerBOBindExtHandle(&drm);
EXPECT_EQ(2u, bo.bindExtHandles.size());
EXPECT_EQ(DrmMockResources::registerResourceReturnHandle, bo.bindExtHandles[0]);
uint64_t *data = reinterpret_cast<uint64_t *>(drm.registeredData);
EXPECT_EQ(offlineDumpContextId, *data);
allocation.freeRegisteredBOBindExtHandles(&drm);
EXPECT_EQ(2u, drm.unregisterCalledCount);
}
TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledAndSubDeviceBitfieldNotSetWhenSbaTrackingBufferIsRegisteredThenContextIdIsTakenFromDevice0AndPassedAsPayload) {
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]);
for (uint32_t i = 3; i < 3 + static_cast<uint32_t>(DrmResourceClass::MaxSize); i++) {
drm.classHandles.push_back(i);
}
drm.registeredClass = DrmResourceClass::MaxSize;
MockBufferObject bo(&drm, 3, 0, 0, 1);
MockDrmAllocation allocation(AllocationType::DEBUG_SBA_TRACKING_BUFFER, MemoryPool::LocalMemory);
allocation.storageInfo.tileInstanced = false;
allocation.bufferObjects[0] = &bo;
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
allocation.setOsContext(&osContext);
osContext.drmContextIds.clear();
osContext.drmContextIds.push_back(3u);
osContext.drmContextIds.push_back(5u);
const auto processId = 0xABCEDF;
uint64_t offlineDumpContextId = static_cast<uint64_t>(processId) << 32 | static_cast<uint64_t>(3u);
allocation.registerBOBindExtHandle(&drm);
EXPECT_EQ(2u, bo.bindExtHandles.size());
EXPECT_EQ(DrmMockResources::registerResourceReturnHandle, bo.bindExtHandles[0]);
uint64_t *data = reinterpret_cast<uint64_t *>(drm.registeredData);
EXPECT_EQ(offlineDumpContextId, *data);
allocation.freeRegisteredBOBindExtHandles(&drm);
EXPECT_EQ(2u, drm.unregisterCalledCount);
}
TEST_F(DrmAllocationTests, givenTwoBufferObjectsAndTileInstancedSbaAndSubDeviceBitfieldWhenSbaTrackingBufferIsRegisteredThenContextIdIsTakenFromBufferObjectIndexAndPassedAsPayload) {
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]);
for (uint32_t i = 3; i < 3 + static_cast<uint32_t>(DrmResourceClass::MaxSize); i++) {
drm.classHandles.push_back(i);
}
drm.registeredClass = DrmResourceClass::MaxSize;
MockBufferObject bo0(&drm, 3, 0, 0, 1);
MockBufferObject bo1(&drm, 3, 0, 0, 1);
MockDrmAllocation allocation(AllocationType::DEBUG_SBA_TRACKING_BUFFER, MemoryPool::LocalMemory);
allocation.storageInfo.subDeviceBitfield = 0b0011;
allocation.storageInfo.tileInstanced = true;
allocation.bufferObjects[0] = &bo0;
allocation.bufferObjects[1] = &bo1;
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
allocation.setOsContext(&osContext);
osContext.drmContextIds.clear();
osContext.drmContextIds.push_back(3u);
osContext.drmContextIds.push_back(5u);
const auto processId = 0xABCEDF;
uint64_t offlineDumpContextIdBo1 = static_cast<uint64_t>(processId) << 32 | static_cast<uint64_t>(5u);
allocation.registerBOBindExtHandle(&drm);
EXPECT_EQ(2u, bo0.bindExtHandles.size());
EXPECT_EQ(2u, bo1.bindExtHandles.size());
EXPECT_EQ(DrmMockResources::registerResourceReturnHandle, bo0.bindExtHandles[0]);
EXPECT_EQ(DrmMockResources::registerResourceReturnHandle, bo1.bindExtHandles[0]);
uint64_t *dataBo1 = reinterpret_cast<uint64_t *>(drm.registeredData);
EXPECT_EQ(offlineDumpContextIdBo1, *dataBo1);
allocation.freeRegisteredBOBindExtHandles(&drm);
EXPECT_EQ(3u, drm.unregisterCalledCount);
}
TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledWhenSbaTrackingBufferIsRegisteredWithoutOsContextThenHandleIsNotAddedToBO) {
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]);
for (uint32_t i = 3; i < 3 + static_cast<uint32_t>(DrmResourceClass::MaxSize); i++) {
drm.classHandles.push_back(i);
}
drm.registeredClass = DrmResourceClass::MaxSize;
MockBufferObject bo(&drm, 3, 0, 0, 1);
MockDrmAllocation allocation(AllocationType::DEBUG_SBA_TRACKING_BUFFER, MemoryPool::LocalMemory);
allocation.bufferObjects[0] = &bo;
allocation.registerBOBindExtHandle(&drm);
EXPECT_EQ(1u, bo.bindExtHandles.size());
EXPECT_EQ(DrmMockResources::registerResourceReturnHandle, bo.bindExtHandles[0]);
allocation.freeRegisteredBOBindExtHandles(&drm);
EXPECT_EQ(1u, drm.unregisterCalledCount);
}
TEST_F(DrmAllocationTests, givenDrmAllocationWhenSetCacheRegionIsCalledForDefaultRegionThenReturnTrue) {
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -57,6 +57,7 @@ TEST(DrmUuidTest, whenResourceClassIsUsedToIndexClassNamesThenCorrectNamesAreRet
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::ContextSaveArea)].first, "I915_UUID_L0_SIP_AREA");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::ModuleHeapDebugArea)].first, "I915_UUID_L0_MODULE_AREA");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::SbaTrackingBuffer)].first, "I915_UUID_L0_SBA_AREA");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::ContextID)].first, "I915_UUID_L0_CONTEXT_ID");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::L0ZebinModule)].first, "L0_ZEBIN_MODULE");
}

View File

@@ -9,6 +9,7 @@
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_os_context_linux.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
@@ -39,18 +40,10 @@ TEST(OSContextLinux, givenInitializeContextWhenContextCreateIoctlFailsThenContex
}
TEST(OSContextLinux, givenOsContextLinuxWhenQueryingForOfflineDumpContextIdThenCorrectValueIsReturned) {
class OsContextLinuxMock : public OsContextLinux {
public:
using OsContextLinux::drmContextIds;
OsContextLinuxMock(Drm &drm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)
: OsContextLinux(drm, rootDeviceIndex, contextId, engineDescriptor) {}
};
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
OsContextLinuxMock osContext(*mock, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
MockOsContextLinux osContext(*mock, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
osContext.drmContextIds.clear();
osContext.drmContextIds.push_back(1u);