From a25eedb5ac22838d6c57d58ee53c74ad51fb846a Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Mon, 22 Jan 2024 17:58:57 +0000 Subject: [PATCH] feature: add print of cpu flags and address size upon detection Related-To: NEO-9737 Signed-off-by: Zbigniew Zdanowicz --- .../debug_settings/debug_variables_base.inl | 1 + .../utilities/x86_64/cpu_info_x86_64.cpp | 6 +- shared/test/common/test_files/igdrcl.config | 1 + .../utilities/x86_64/cpuinfo_tests_x86_64.cpp | 56 +++++++++++++------ 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 9f33ab28b2..994573b000 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -317,6 +317,7 @@ DECLARE_DEBUG_VARIABLE(bool, PrintKernelDispatchParameters, false, "Prints kerne DECLARE_DEBUG_VARIABLE(bool, LogGdiCalls, false, "Log GDI calls") DECLARE_DEBUG_VARIABLE(bool, LogGdiCallsToFile, false, "Log GDI calls to file") DECLARE_DEBUG_VARIABLE(bool, PrintGmmCompressionParams, false, "Print Gmm compression resource params") +DECLARE_DEBUG_VARIABLE(bool, PrintCpuFlags, false, "Print CPU Flags and properties upon detection") /*PERFORMANCE FLAGS*/ DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForBuffers, false, "When active all buffer allocations will not share memory with CPU.") diff --git a/shared/source/utilities/x86_64/cpu_info_x86_64.cpp b/shared/source/utilities/x86_64/cpu_info_x86_64.cpp index 59fed907f8..3bfb8f60a1 100644 --- a/shared/source/utilities/x86_64/cpu_info_x86_64.cpp +++ b/shared/source/utilities/x86_64/cpu_info_x86_64.cpp @@ -1,10 +1,11 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/utilities/cpu_info.h" #ifndef BIT @@ -51,5 +52,8 @@ void CpuInfo::detect() const { virtualAddressSize = (cpuInfo[eax] >> 8) & 0xFF; } } + if (debugManager.flags.PrintCpuFlags.get()) { + printf("CPUFlags:\nCLFlush: %d Avx2: %d WaitPkg: %d\nVirtual Address Size %u\n", !!(features & featureClflush), !!(features & featureAvX2), !!(features & featureWaitPkg), virtualAddressSize); + } } } // namespace NEO diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 2ed48dfbd7..eec88f2441 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -137,6 +137,7 @@ EnableBOMmapCreate = -1 EnableHostPtrTracking = -1 EnableNV12 = 1 EnablePackedYuv = 1 +PrintCpuFlags = 0 EnableDeferredDeleter = 1 EnableAsyncDestroyAllocations = 1 EnableAsyncEventsHandler = 1 diff --git a/shared/test/unit_test/utilities/x86_64/cpuinfo_tests_x86_64.cpp b/shared/test/unit_test/utilities/x86_64/cpuinfo_tests_x86_64.cpp index 7d750c8727..e46c7de338 100644 --- a/shared/test/unit_test/utilities/x86_64/cpuinfo_tests_x86_64.cpp +++ b/shared/test/unit_test/utilities/x86_64/cpuinfo_tests_x86_64.cpp @@ -1,19 +1,35 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/utilities/cpu_info.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/test_macros/hw_test.h" #include "shared/test/unit_test/mocks/mock_cpuid_functions.h" #include "gtest/gtest.h" using namespace NEO; -TEST(CpuInfoTest, giveFunctionIsNotAvailableWhenFeatureIsNotSupportedThenMaskBitIsOff) { - void (*defaultCpuidFunc)(int *, int) = CpuInfo::cpuidFunc; +struct CpuInfoFixture { + using CpuIdFuncT = void (*)(int *, int); + void setUp() { + defaultCpuidFunc = CpuInfo::cpuidFunc; + } + + void tearDown() { + CpuInfo::cpuidFunc = defaultCpuidFunc; + } + + CpuIdFuncT defaultCpuidFunc; +}; + +using CpuInfoTest = Test; + +TEST_F(CpuInfoTest, giveFunctionIsNotAvailableWhenFeatureIsNotSupportedThenMaskBitIsOff) { CpuInfo::cpuidFunc = mockCpuidFunctionNotAvailableDisableAll; CpuInfo testCpuInfo; @@ -21,12 +37,9 @@ TEST(CpuInfoTest, giveFunctionIsNotAvailableWhenFeatureIsNotSupportedThenMaskBit EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureWaitPkg)); - - CpuInfo::cpuidFunc = defaultCpuidFunc; } -TEST(CpuInfoTest, giveFunctionIsAvailableWhenFeatureIsNotSupportedThenMaskBitIsOff) { - void (*defaultCpuidFunc)(int *, int) = CpuInfo::cpuidFunc; +TEST_F(CpuInfoTest, giveFunctionIsAvailableWhenFeatureIsNotSupportedThenMaskBitIsOff) { CpuInfo::cpuidFunc = mockCpuidFunctionAvailableDisableAll; CpuInfo testCpuInfo; @@ -34,12 +47,9 @@ TEST(CpuInfoTest, giveFunctionIsAvailableWhenFeatureIsNotSupportedThenMaskBitIsO EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureWaitPkg)); - - CpuInfo::cpuidFunc = defaultCpuidFunc; } -TEST(CpuInfoTest, whenFeatureIsSupportedThenMaskBitIsOn) { - void (*defaultCpuidFunc)(int *, int) = CpuInfo::cpuidFunc; +TEST_F(CpuInfoTest, whenFeatureIsSupportedThenMaskBitIsOn) { CpuInfo::cpuidFunc = mockCpuidEnableAll; CpuInfo testCpuInfo; @@ -47,19 +57,14 @@ TEST(CpuInfoTest, whenFeatureIsSupportedThenMaskBitIsOn) { EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2)); EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush)); EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureWaitPkg)); - - CpuInfo::cpuidFunc = defaultCpuidFunc; } -TEST(CpuInfoTest, WhenGettingVirtualAddressSizeThenCorrectResultIsReturned) { - void (*defaultCpuidFunc)(int *, int) = CpuInfo::cpuidFunc; +TEST_F(CpuInfoTest, WhenGettingVirtualAddressSizeThenCorrectResultIsReturned) { CpuInfo::cpuidFunc = mockCpuidReport36BitVirtualAddressSize; CpuInfo testCpuInfo; EXPECT_EQ(36u, testCpuInfo.getVirtualAddressSize()); - - CpuInfo::cpuidFunc = defaultCpuidFunc; } TEST(CpuInfo, WhenGettingCpuidexThenOperationSucceeds) { @@ -69,3 +74,20 @@ TEST(CpuInfo, WhenGettingCpuidexThenOperationSucceeds) { uint32_t subleaf = 0; cpuInfo.cpuidex(cpuRegsInfo, 4, subleaf); } + +TEST_F(CpuInfoTest, GivenPrintCpuFlagsEnabledWhenGettingVirtualAddressSizeThenCpuFlagsAndAddressSizePrinted) { + DebugManagerStateRestore restore; + debugManager.flags.PrintCpuFlags.set(true); + + CpuInfo::cpuidFunc = mockCpuidReport36BitVirtualAddressSize; + + CpuInfo testCpuInfo; + + testing::internal::CaptureStdout(); + auto addressSize = testCpuInfo.getVirtualAddressSize(); + std::string output = testing::internal::GetCapturedStdout(); + + EXPECT_EQ(36u, addressSize); + std::string expectedString = "CPUFlags:\nCLFlush: 1 Avx2: 1 WaitPkg: 1\nVirtual Address Size 36\n"; + EXPECT_STREQ(output.c_str(), expectedString.c_str()); +}