Skip to content

Add system info query #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opencl/test/unit_test/os_interface/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux
${CMAKE_CURRENT_SOURCE_DIR}/drm_neo_create.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_os_memory_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_system_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_system_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_uuid_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/file_logger_linux_tests.cpp
Expand Down
16 changes: 16 additions & 0 deletions opencl/test/unit_test/os_interface/linux/drm_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/helpers/hw_info.h"

#include "opencl/test/unit_test/os_interface/linux/drm_mock_device_blob.h"

#include <cstring>

const int DrmMock::mockFd;
Expand Down Expand Up @@ -265,6 +267,20 @@ void DrmMockEngine::handleQueryItem(drm_i915_query_item *queryItem) {
}
}
break;
case DRM_I915_QUERY_HWCONFIG_TABLE: {
if (failQueryDeviceBlob) {
queryItem->length = -EINVAL;
} else {
int deviceBlobSize = sizeof(dummyDeviceBlobData);
if (queryItem->length == 0) {
queryItem->length = deviceBlobSize;
} else {
EXPECT_EQ(deviceBlobSize, queryItem->length);
auto deviceBlobData = reinterpret_cast<uint32_t *>(queryItem->data_ptr);
memcpy(deviceBlobData, &dummyDeviceBlobData, deviceBlobSize);
}
}
} break;
}
}

Expand Down
1 change: 1 addition & 0 deletions opencl/test/unit_test/os_interface/linux/drm_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class DrmMockEngine : public DrmMock {
int handleRemainingRequests(unsigned long request, void *arg) override;

void handleQueryItem(drm_i915_query_item *queryItem);
bool failQueryDeviceBlob = false;
};

class DrmMockResources : public DrmMock {
Expand Down
148 changes: 148 additions & 0 deletions opencl/test/unit_test/os_interface/linux/drm_mock_device_blob.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#pragma once

#include "drm/intel_hwconfig_types.h"

static constexpr uint32_t dummyDeviceBlobData[] = {
INTEL_HWCONFIG_MAX_SLICES_SUPPORTED,
1,
0x01,
INTEL_HWCONFIG_MAX_DUAL_SUBSLICES_SUPPORTED,
1,
0x02,
INTEL_HWCONFIG_MAX_NUM_EU_PER_DSS,
1,
0x03,
INTEL_HWCONFIG_NUM_PIXEL_PIPES,
1,
0x04,
INTEL_HWCONFIG_MAX_NUM_GEOMETRY_PIPES,
1,
0x05,
INTEL_HWCONFIG_L3_CACHE_SIZE_IN_KB,
1,
0x06,
INTEL_HWCONFIG_L3_BANK_COUNT,
1,
0x07,
INTEL_HWCONFIG_L3_CACHE_WAYS_SIZE_IN_BYTES,
1,
0x08,
INTEL_HWCONFIG_L3_CACHE_WAYS_PER_SECTOR,
1,
0x09,
INTEL_HWCONFIG_MAX_MEMORY_CHANNELS,
1,
0x0A,
INTEL_HWCONFIG_MEMORY_TYPE,
1,
0x0B,
INTEL_HWCONFIG_CACHE_TYPES,
1,
0x0C,
INTEL_HWCONFIG_LOCAL_MEMORY_PAGE_SIZES_SUPPORTED,
1,
0x0D,
INTEL_HWCONFIG_SLM_SIZE_IN_KB,
1,
0x0E,
INTEL_HWCONFIG_NUM_THREADS_PER_EU,
1,
0x0F,
INTEL_HWCONFIG_TOTAL_VS_THREADS,
1,
0x10,
INTEL_HWCONFIG_TOTAL_GS_THREADS,
1,
0x11,
INTEL_HWCONFIG_TOTAL_HS_THREADS,
1,
0x12,
INTEL_HWCONFIG_TOTAL_DS_THREADS,
1,
0x13,
INTEL_HWCONFIG_TOTAL_VS_THREADS_POCS,
1,
0x14,
INTEL_HWCONFIG_TOTAL_PS_THREADS,
1,
0x15,
INTEL_HWCONFIG_MAX_FILL_RATE,
1,
0x16,
INTEL_HWCONFIG_MAX_RCS,
1,
0x17,
INTEL_HWCONFIG_MAX_CCS,
1,
0x18,
INTEL_HWCONFIG_MAX_VCS,
1,
0x19,
INTEL_HWCONFIG_MAX_VECS,
1,
0x1A,
INTEL_HWCONFIG_MAX_COPY_CS,
1,
0x1B,
INTEL_HWCONFIG_URB_SIZE_IN_KB,
1,
0x1C,
INTEL_HWCONFIG_MIN_VS_URB_ENTRIES,
1,
0x1D,
INTEL_HWCONFIG_MAX_VS_URB_ENTRIES,
1,
0x1E,
INTEL_HWCONFIG_MIN_PCS_URB_ENTRIES,
1,
0x1E,
INTEL_HWCONFIG_MAX_PCS_URB_ENTRIES,
1,
0x1F,
INTEL_HWCONFIG_MIN_HS_URB_ENTRIES,
1,
0x20,
INTEL_HWCONFIG_MAX_HS_URB_ENTRIES,
1,
0x21,
INTEL_HWCONFIG_MIN_GS_URB_ENTRIES,
1,
0x22,
INTEL_HWCONFIG_MAX_GS_URB_ENTRIES,
1,
0x23,
INTEL_HWCONFIG_MIN_DS_URB_ENTRIES,
1,
0x24,
INTEL_HWCONFIG_MAX_DS_URB_ENTRIES,
1,
0x25,
INTEL_HWCONFIG_PUSH_CONSTANT_URB_RESERVED_SIZE,
1,
0x26,
INTEL_HWCONFIG_POCS_PUSH_CONSTANT_URB_RESERVED_SIZE,
1,
0x27,
INTEL_HWCONFIG_URB_REGION_ALIGNMENT_SIZE_IN_BYTES,
1,
0x28,
INTEL_HWCONFIG_URB_ALLOCATION_SIZE_UNITS_IN_BYTES,
1,
0x29,
INTEL_HWCONFIG_MAX_URB_SIZE_CCS_IN_BYTES,
1,
0x2A,
INTEL_HWCONFIG_VS_MIN_DEREF_BLOCK_SIZE_HANDLE_COUNT,
1,
0x2B,
INTEL_HWCONFIG_DS_MIN_DEREF_BLOCK_SIZE_HANDLE_COUNT,
1,
0x2C,
};
99 changes: 90 additions & 9 deletions opencl/test/unit_test/os_interface/linux/drm_system_info_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@

#include "opencl/test/unit_test/helpers/gtest_helpers.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock_device_blob.h"

#include "gmock/gmock.h"

using namespace NEO;

TEST(DrmSystemInfoTest, whenQueryingSystemInfoThenSystemInfoIsNotCreatedAndNoIoctlsAreCalled) {
TEST(DrmSystemInfoTest, whenQueryingSystemInfoThenSystemInfoIsNotCreatedAndIoctlsAreCalledOnce) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);

EXPECT_FALSE(drm.querySystemInfo());

EXPECT_EQ(nullptr, drm.getSystemInfo());
EXPECT_EQ(0u, drm.ioctlCallsCount);
EXPECT_EQ(1u, drm.ioctlCallsCount);
}

TEST(DrmSystemInfoTest, givenSystemInfoCreatedWhenQueryingSpecificAtrributesThenReturnZero) {
Expand All @@ -46,11 +47,11 @@ TEST(DrmSystemInfoTest, givenSystemInfoCreatedWhenQueryingSpecificAtrributesThen
EXPECT_EQ(0u, systemInfo.getMaxCCS());
}

TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoTrueThenSystemInfoIsNotCreatedAndDebugMessageIsNotPrinted) {
TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoFalseThenSystemInfoIsNotCreatedAndDebugMessageIsNotPrinted) {
struct DrmMockToQuerySystemInfo : public DrmMock {
DrmMockToQuerySystemInfo(RootDeviceEnvironment &rootDeviceEnvironment)
: DrmMock(rootDeviceEnvironment) {}
bool querySystemInfo() override { return true; }
bool querySystemInfo() override { return false; }
};

DebugManagerStateRestore restorer;
Expand All @@ -74,23 +75,103 @@ TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoTrueThenSystemI
EXPECT_THAT(::testing::internal::GetCapturedStdout(), ::testing::IsEmpty());
}

TEST(DrmSystemInfoTest, givenSystemInfoWhenSetupHardwareInfoThenFinishedWithSuccess) {
TEST(DrmSystemInfoTest, whenQueryingSystemInfoThenSystemInfoIsCreatedAndReturnsNonZeros) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMockEngine drm(*executionEnvironment->rootDeviceEnvironments[0]);

EXPECT_TRUE(drm.querySystemInfo());

auto systemInfo = drm.getSystemInfo();
EXPECT_NE(nullptr, systemInfo);

EXPECT_NE(0u, systemInfo->getL3CacheSizeInKb());
EXPECT_NE(0u, systemInfo->getL3BankCount());
EXPECT_NE(0u, systemInfo->getMaxFillRate());
EXPECT_NE(0u, systemInfo->getTotalVsThreads());
EXPECT_NE(0u, systemInfo->getTotalHsThreads());
EXPECT_NE(0u, systemInfo->getTotalDsThreads());
EXPECT_NE(0u, systemInfo->getTotalGsThreads());
EXPECT_NE(0u, systemInfo->getTotalPsThreads());
EXPECT_NE(0u, systemInfo->getMaxEuPerDualSubSlice());
EXPECT_NE(0u, systemInfo->getMaxSlicesSupported());
EXPECT_NE(0u, systemInfo->getMaxDualSubSlicesSupported());
EXPECT_NE(0u, systemInfo->getMaxDualSubSlicesSupported());
EXPECT_NE(0u, systemInfo->getMaxRCS());
EXPECT_NE(0u, systemInfo->getMaxCCS());

EXPECT_EQ(2u, drm.ioctlCallsCount);
}

TEST(DrmSystemInfoTest, givenSystemInfoCreatedFromDeviceBlobWhenQueryingSpecificAtrributesThenReturnCorrectValues) {
SystemInfoImpl systemInfo(dummyDeviceBlobData, sizeof(dummyDeviceBlobData));

EXPECT_EQ(0x06u, systemInfo.getL3CacheSizeInKb());
EXPECT_EQ(0x07u, systemInfo.getL3BankCount());
EXPECT_EQ(0x16u, systemInfo.getMaxFillRate());
EXPECT_EQ(0x10u, systemInfo.getTotalVsThreads());
EXPECT_EQ(0x12u, systemInfo.getTotalHsThreads());
EXPECT_EQ(0x13u, systemInfo.getTotalDsThreads());
EXPECT_EQ(0x11u, systemInfo.getTotalGsThreads());
EXPECT_EQ(0x15u, systemInfo.getTotalPsThreads());
EXPECT_EQ(0x03u, systemInfo.getMaxEuPerDualSubSlice());
EXPECT_EQ(0x01u, systemInfo.getMaxSlicesSupported());
EXPECT_EQ(0x02u, systemInfo.getMaxDualSubSlicesSupported());
EXPECT_EQ(0x02u, systemInfo.getMaxDualSubSlicesSupported());
EXPECT_EQ(0x17u, systemInfo.getMaxRCS());
EXPECT_EQ(0x18u, systemInfo.getMaxCCS());
}

TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoFailsThenSystemInfoIsNotCreatedAndDebugMessageIsPrinted) {
DebugManagerStateRestore restorer;
DebugManager.flags.PrintDebugMessages.set(true);

auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
DrmMockEngine drm(*executionEnvironment->rootDeviceEnvironments[0]);

HardwareInfo hwInfo = *defaultHwInfo;
auto setupHardwareInfo = [](HardwareInfo *, bool) {};
DeviceDescriptor device = {0, &hwInfo, setupHardwareInfo, GTTYPE_UNDEFINED};

drm.systemInfo.reset(new SystemInfoImpl(nullptr, 0));

::testing::internal::CaptureStdout();

drm.failQueryDeviceBlob = true;
int ret = drm.setupHardwareInfo(&device, false);
EXPECT_EQ(ret, 0);
EXPECT_THAT(::testing::internal::GetCapturedStdout(), ::testing::IsEmpty());
EXPECT_EQ(nullptr, drm.getSystemInfo());

EXPECT_THAT(::testing::internal::GetCapturedStdout(), ::testing::HasSubstr("INFO: System Info query failed!\n"));
}

TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoSucceedsThenSystemInfoIsCreatedAndUsedToSetHardwareInfoAttributes) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DrmMockEngine drm(*executionEnvironment->rootDeviceEnvironments[0]);

HardwareInfo hwInfo = *defaultHwInfo;

auto setupHardwareInfo = [](HardwareInfo *, bool) {};
GT_SYSTEM_INFO &gtSystemInfo = hwInfo.gtSystemInfo;
DeviceDescriptor device = {0, &hwInfo, setupHardwareInfo, GTTYPE_UNDEFINED};

int ret = drm.setupHardwareInfo(&device, false);
EXPECT_EQ(ret, 0);
EXPECT_NE(nullptr, drm.getSystemInfo());

EXPECT_GT_VAL(gtSystemInfo.L3CacheSizeInKb, 0u);
EXPECT_GT(gtSystemInfo.L3BankCount, 0u);
EXPECT_GT(gtSystemInfo.MaxFillRate, 0u);
EXPECT_GT(gtSystemInfo.TotalVsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalHsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalDsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalGsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalPsThreadsWindowerRange, 0u);
EXPECT_GT(gtSystemInfo.TotalDsThreads, 0u);
EXPECT_GT(gtSystemInfo.MaxEuPerSubSlice, 0u);
EXPECT_GT(gtSystemInfo.MaxSlicesSupported, 0u);
EXPECT_GT(gtSystemInfo.MaxSubSlicesSupported, 0u);
EXPECT_GT(gtSystemInfo.MaxDualSubSlicesSupported, 0u);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "opencl/test/unit_test/os_interface/linux/hw_info_config_linux_tests.h"

#include "shared/source/helpers/hw_helper.h"
#include "shared/source/os_interface/linux/system_info_impl.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
Expand Down Expand Up @@ -598,3 +599,38 @@ HWTEST2_F(HwConfigLinux, GivenDifferentValuesFromTopologyQueryWhenConfiguringHwI

EXPECT_EQ(hwInfo.gtSystemInfo.MaxDualSubSlicesSupported, outHwInfo.gtSystemInfo.MaxDualSubSlicesSupported);
}

TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenSystemInfoIsCreatedThenSetHardwareInfoAttributesWithZeros) {
struct DrmMockToQuerySystemInfo : public DrmMock {
DrmMockToQuerySystemInfo(RootDeviceEnvironment &rootDeviceEnvironment)
: DrmMock(rootDeviceEnvironment) {}
bool querySystemInfo() override { return true; }
};
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DrmMockToQuerySystemInfo drm(*executionEnvironment->rootDeviceEnvironments[0]);

HardwareInfo hwInfo = *defaultHwInfo;
auto setupHardwareInfo = [](HardwareInfo *, bool) {};
GT_SYSTEM_INFO &gtSystemInfo = hwInfo.gtSystemInfo;
DeviceDescriptor device = {0, &hwInfo, setupHardwareInfo, GTTYPE_UNDEFINED};

drm.systemInfo.reset(new SystemInfoImpl(nullptr, 0));
int ret = drm.setupHardwareInfo(&device, false);
EXPECT_EQ(ret, 0);

EXPECT_EQ(0u, gtSystemInfo.L3CacheSizeInKb);
EXPECT_EQ(0u, gtSystemInfo.L3BankCount);
EXPECT_EQ(0u, gtSystemInfo.MaxFillRate);
EXPECT_EQ(0u, gtSystemInfo.TotalVsThreads);
EXPECT_EQ(0u, gtSystemInfo.TotalHsThreads);
EXPECT_EQ(0u, gtSystemInfo.TotalDsThreads);
EXPECT_EQ(0u, gtSystemInfo.TotalGsThreads);
EXPECT_EQ(0u, gtSystemInfo.TotalPsThreadsWindowerRange);
EXPECT_EQ(0u, gtSystemInfo.TotalDsThreads);
EXPECT_EQ(0u, gtSystemInfo.MaxEuPerSubSlice);
EXPECT_EQ(0u, gtSystemInfo.MaxSlicesSupported);
EXPECT_EQ(0u, gtSystemInfo.MaxSubSlicesSupported);
EXPECT_EQ(0u, gtSystemInfo.MaxDualSubSlicesSupported);
}
Loading