Skip to content

Commit 92f067b

Browse files
Add CpuInfo::isCpuFlagPresent() method
Related-To: NEO-5276 Signed-off-by: Igor Venevtsev <[email protected]>
1 parent efcd05d commit 92f067b

File tree

9 files changed

+218
-4
lines changed

9 files changed

+218
-4
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
processor : 0
2+
vendor_id : GenuineIntel
3+
cpu family : 6
4+
model : 94
5+
model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
6+
stepping : 3
7+
microcode : 0xdc
8+
cpu MHz : 900.565
9+
cache size : 6144 KB
10+
physical id : 0
11+
siblings : 4
12+
core id : 0
13+
cpu cores : 4
14+
apicid : 0
15+
initial apicid : 0
16+
fpu : yes
17+
fpu_exception : yes
18+
cpuid level : 22
19+
wp : yes
20+
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
21+
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds
22+
bogomips : 6399.96
23+
clflush size : 64
24+
cache_alignment : 64
25+
address sizes : 39 bits physical, 48 bits virtual
26+
power management:
27+
28+
processor : 1
29+
vendor_id : GenuineIntel
30+
cpu family : 6
31+
model : 94
32+
model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
33+
stepping : 3
34+
microcode : 0xdc
35+
cpu MHz : 900.224
36+
cache size : 6144 KB
37+
physical id : 0
38+
siblings : 4
39+
core id : 1
40+
cpu cores : 4
41+
apicid : 2
42+
initial apicid : 2
43+
fpu : yes
44+
fpu_exception : yes
45+
cpuid level : 22
46+
wp : yes
47+
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
48+
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds
49+
bogomips : 6399.96
50+
clflush size : 64
51+
cache_alignment : 64
52+
address sizes : 39 bits physical, 48 bits virtual
53+
power management:
54+
55+
processor : 2
56+
vendor_id : GenuineIntel
57+
cpu family : 6
58+
model : 94
59+
model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
60+
stepping : 3
61+
microcode : 0xdc
62+
cpu MHz : 900.065
63+
cache size : 6144 KB
64+
physical id : 0
65+
siblings : 4
66+
core id : 2
67+
cpu cores : 4
68+
apicid : 4
69+
initial apicid : 4
70+
fpu : yes
71+
fpu_exception : yes
72+
cpuid level : 22
73+
wp : yes
74+
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
75+
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds
76+
bogomips : 6399.96
77+
clflush size : 64
78+
cache_alignment : 64
79+
address sizes : 39 bits physical, 48 bits virtual
80+
power management:
81+
82+
processor : 3
83+
vendor_id : GenuineIntel
84+
cpu family : 6
85+
model : 94
86+
model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
87+
stepping : 3
88+
microcode : 0xdc
89+
cpu MHz : 900.670
90+
cache size : 6144 KB
91+
physical id : 0
92+
siblings : 4
93+
core id : 3
94+
cpu cores : 4
95+
apicid : 6
96+
initial apicid : 6
97+
fpu : yes
98+
fpu_exception : yes
99+
cpuid level : 22
100+
wp : yes
101+
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
102+
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds
103+
bogomips : 6399.96
104+
clflush size : 64
105+
cache_alignment : 64
106+
address sizes : 39 bits physical, 48 bits virtual
107+
power management:
108+

shared/source/utilities/cpu_info.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -217,6 +217,8 @@ struct CpuInfo {
217217
return instance;
218218
}
219219

220+
bool isCpuFlagPresent(const char *cpuFlag);
221+
220222
static void (*cpuidexFunc)(int *, int, int);
221223
static void (*cpuidFunc)(int[4], int);
222224

shared/source/utilities/linux/cpu_info.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#include "shared/source/utilities/cpu_info.h"
99

10+
#include "shared/source/os_interface/linux/os_inc.h"
11+
1012
#include <cpuid.h>
13+
#include <fstream>
14+
#include <sstream>
15+
#include <string>
1116

1217
namespace NEO {
1318

@@ -37,4 +42,22 @@ void CpuInfo::cpuidex(
3742
cpuidexFunc(reinterpret_cast<int *>(cpuInfo), functionId, subfunctionId);
3843
}
3944

45+
bool CpuInfo::isCpuFlagPresent(const char *cpuFlag) {
46+
std::ifstream ifs(std::string(Os::sysFsProcPathPrefix) + "/cpuinfo");
47+
std::string line;
48+
while (std::getline(ifs, line)) {
49+
if (line.substr(0, 5) == "flags") {
50+
std::stringstream ss(line);
51+
std::string flag;
52+
while (ss >> flag) {
53+
if (flag == cpuFlag) {
54+
return true;
55+
}
56+
}
57+
}
58+
}
59+
60+
return false;
61+
}
62+
4063
} // namespace NEO

shared/source/utilities/windows/cpu_info.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -37,4 +37,8 @@ void CpuInfo::cpuidex(
3737
cpuidexFunc(reinterpret_cast<int *>(cpuInfo), functionId, subfunctionId);
3838
}
3939

40+
bool CpuInfo::isCpuFlagPresent(const char *cpuFlag) {
41+
return false;
42+
}
43+
4044
} // namespace NEO

shared/test/unit_test/utilities/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2019-2020 Intel Corporation
2+
# Copyright (C) 2019-2021 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -23,3 +23,5 @@ target_sources(${TARGET_NAME} PRIVATE
2323
${CMAKE_CURRENT_SOURCE_DIR}/timer_util_tests.cpp
2424
${CMAKE_CURRENT_SOURCE_DIR}/vec_tests.cpp
2525
)
26+
27+
add_subdirectories()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (C) 2021 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
set(UTILITIES_CPUINFO_TESTS_LINUX
8+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_linux.cpp
10+
)
11+
12+
if(UNIX)
13+
target_sources(${TARGET_NAME} PRIVATE
14+
${UTILITIES_CPUINFO_TESTS_LINUX}
15+
)
16+
endif()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/helpers/file_io.h"
9+
#include "shared/source/utilities/cpu_info.h"
10+
11+
#include "gtest/gtest.h"
12+
13+
using namespace NEO;
14+
15+
TEST(CpuInfo, givenProcCpuinfoFileExistsWhenIsCpuFlagPresentIsCalledThenValidValueIsReturned) {
16+
std::string cpuinfoFile = "test_files/linux/proc/cpuinfo";
17+
EXPECT_TRUE(fileExists(cpuinfoFile));
18+
19+
CpuInfo testCpuInfo;
20+
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("fpu"));
21+
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("vme"));
22+
EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("nonExistingCpuFlag"));
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (C) 2019-2021 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
set(UTILITIES_CPUINFO_TESTS_WINDOWS
8+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_windows.cpp
10+
)
11+
12+
if(WIN32)
13+
target_sources(${TARGET_NAME} PRIVATE
14+
${UTILITIES_CPUINFO_TESTS_WINDOWS}
15+
)
16+
endif()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/utilities/cpu_info.h"
9+
10+
#include "gtest/gtest.h"
11+
12+
using namespace NEO;
13+
14+
TEST(CpuInfo, givenIsCpuFlagPresentCalledThenFalseIsReturned) {
15+
CpuInfo testCpuInfo;
16+
17+
EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("fpu"));
18+
EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("vme"));
19+
EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("nonExistingCpuFlag"));
20+
}

0 commit comments

Comments
 (0)