diff --git a/opencl/test/unit_test/test_files/linux/proc/cpuinfo b/opencl/test/unit_test/test_files/linux/proc/cpuinfo new file mode 100644 index 0000000000..abbe64bf12 --- /dev/null +++ b/opencl/test/unit_test/test_files/linux/proc/cpuinfo @@ -0,0 +1,108 @@ +processor : 0 +vendor_id : GenuineIntel +cpu family : 6 +model : 94 +model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz +stepping : 3 +microcode : 0xdc +cpu MHz : 900.565 +cache size : 6144 KB +physical id : 0 +siblings : 4 +core id : 0 +cpu cores : 4 +apicid : 0 +initial apicid : 0 +fpu : yes +fpu_exception : yes +cpuid level : 22 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds +bogomips : 6399.96 +clflush size : 64 +cache_alignment : 64 +address sizes : 39 bits physical, 48 bits virtual +power management: + +processor : 1 +vendor_id : GenuineIntel +cpu family : 6 +model : 94 +model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz +stepping : 3 +microcode : 0xdc +cpu MHz : 900.224 +cache size : 6144 KB +physical id : 0 +siblings : 4 +core id : 1 +cpu cores : 4 +apicid : 2 +initial apicid : 2 +fpu : yes +fpu_exception : yes +cpuid level : 22 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds +bogomips : 6399.96 +clflush size : 64 +cache_alignment : 64 +address sizes : 39 bits physical, 48 bits virtual +power management: + +processor : 2 +vendor_id : GenuineIntel +cpu family : 6 +model : 94 +model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz +stepping : 3 +microcode : 0xdc +cpu MHz : 900.065 +cache size : 6144 KB +physical id : 0 +siblings : 4 +core id : 2 +cpu cores : 4 +apicid : 4 +initial apicid : 4 +fpu : yes +fpu_exception : yes +cpuid level : 22 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds +bogomips : 6399.96 +clflush size : 64 +cache_alignment : 64 +address sizes : 39 bits physical, 48 bits virtual +power management: + +processor : 3 +vendor_id : GenuineIntel +cpu family : 6 +model : 94 +model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz +stepping : 3 +microcode : 0xdc +cpu MHz : 900.670 +cache size : 6144 KB +physical id : 0 +siblings : 4 +core id : 3 +cpu cores : 4 +apicid : 6 +initial apicid : 6 +fpu : yes +fpu_exception : yes +cpuid level : 22 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds +bogomips : 6399.96 +clflush size : 64 +cache_alignment : 64 +address sizes : 39 bits physical, 48 bits virtual +power management: + diff --git a/shared/source/utilities/cpu_info.h b/shared/source/utilities/cpu_info.h index b093f7c9ad..bfcc44b263 100644 --- a/shared/source/utilities/cpu_info.h +++ b/shared/source/utilities/cpu_info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -217,6 +217,8 @@ struct CpuInfo { return instance; } + bool isCpuFlagPresent(const char *cpuFlag); + static void (*cpuidexFunc)(int *, int, int); static void (*cpuidFunc)(int[4], int); diff --git a/shared/source/utilities/linux/cpu_info.cpp b/shared/source/utilities/linux/cpu_info.cpp index 7b4b825b47..566bb31e38 100644 --- a/shared/source/utilities/linux/cpu_info.cpp +++ b/shared/source/utilities/linux/cpu_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,7 +7,12 @@ #include "shared/source/utilities/cpu_info.h" +#include "shared/source/os_interface/linux/os_inc.h" + #include +#include +#include +#include namespace NEO { @@ -37,4 +42,22 @@ void CpuInfo::cpuidex( cpuidexFunc(reinterpret_cast(cpuInfo), functionId, subfunctionId); } +bool CpuInfo::isCpuFlagPresent(const char *cpuFlag) { + std::ifstream ifs(std::string(Os::sysFsProcPathPrefix) + "/cpuinfo"); + std::string line; + while (std::getline(ifs, line)) { + if (line.substr(0, 5) == "flags") { + std::stringstream ss(line); + std::string flag; + while (ss >> flag) { + if (flag == cpuFlag) { + return true; + } + } + } + } + + return false; +} + } // namespace NEO diff --git a/shared/source/utilities/windows/cpu_info.cpp b/shared/source/utilities/windows/cpu_info.cpp index c41b51d5ee..168d2884b9 100644 --- a/shared/source/utilities/windows/cpu_info.cpp +++ b/shared/source/utilities/windows/cpu_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -37,4 +37,8 @@ void CpuInfo::cpuidex( cpuidexFunc(reinterpret_cast(cpuInfo), functionId, subfunctionId); } +bool CpuInfo::isCpuFlagPresent(const char *cpuFlag) { + return false; +} + } // namespace NEO diff --git a/shared/test/unit_test/utilities/CMakeLists.txt b/shared/test/unit_test/utilities/CMakeLists.txt index 88efd6e392..171fad3b71 100644 --- a/shared/test/unit_test/utilities/CMakeLists.txt +++ b/shared/test/unit_test/utilities/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2019-2020 Intel Corporation +# Copyright (C) 2019-2021 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -23,3 +23,5 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/timer_util_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vec_tests.cpp ) + +add_subdirectories() diff --git a/shared/test/unit_test/utilities/linux/CMakeLists.txt b/shared/test/unit_test/utilities/linux/CMakeLists.txt new file mode 100644 index 0000000000..778ea91e5a --- /dev/null +++ b/shared/test/unit_test/utilities/linux/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(UTILITIES_CPUINFO_TESTS_LINUX + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_linux.cpp +) + +if(UNIX) + target_sources(${TARGET_NAME} PRIVATE + ${UTILITIES_CPUINFO_TESTS_LINUX} + ) +endif() diff --git a/shared/test/unit_test/utilities/linux/cpuinfo_tests_linux.cpp b/shared/test/unit_test/utilities/linux/cpuinfo_tests_linux.cpp new file mode 100644 index 0000000000..7bedd47582 --- /dev/null +++ b/shared/test/unit_test/utilities/linux/cpuinfo_tests_linux.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/file_io.h" +#include "shared/source/utilities/cpu_info.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +TEST(CpuInfo, givenProcCpuinfoFileExistsWhenIsCpuFlagPresentIsCalledThenValidValueIsReturned) { + std::string cpuinfoFile = "test_files/linux/proc/cpuinfo"; + EXPECT_TRUE(fileExists(cpuinfoFile)); + + CpuInfo testCpuInfo; + EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("fpu")); + EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("vme")); + EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("nonExistingCpuFlag")); +} diff --git a/shared/test/unit_test/utilities/windows/CMakeLists.txt b/shared/test/unit_test/utilities/windows/CMakeLists.txt new file mode 100644 index 0000000000..de4ad532fb --- /dev/null +++ b/shared/test/unit_test/utilities/windows/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright (C) 2019-2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(UTILITIES_CPUINFO_TESTS_WINDOWS + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_windows.cpp +) + +if(WIN32) + target_sources(${TARGET_NAME} PRIVATE + ${UTILITIES_CPUINFO_TESTS_WINDOWS} + ) +endif() diff --git a/shared/test/unit_test/utilities/windows/cpuinfo_tests_windows.cpp b/shared/test/unit_test/utilities/windows/cpuinfo_tests_windows.cpp new file mode 100644 index 0000000000..3c7010b5b1 --- /dev/null +++ b/shared/test/unit_test/utilities/windows/cpuinfo_tests_windows.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/utilities/cpu_info.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +TEST(CpuInfo, givenIsCpuFlagPresentCalledThenFalseIsReturned) { + CpuInfo testCpuInfo; + + EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("fpu")); + EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("vme")); + EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("nonExistingCpuFlag")); +}