Skip to content

Commit 9024e4a

Browse files
feature: add detection of cpu waitpkg support
Related-To: NEO-9737 Signed-off-by: Zbigniew Zdanowicz <[email protected]>
1 parent 88db02e commit 9024e4a

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

shared/source/utilities/cpu_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace NEO {
1919
struct CpuInfo {
2020
static const uint64_t featureNone = 0x000000000ULL;
21+
static const uint64_t featureWaitPkg = 0x000000001ULL;
2122
static const uint64_t featureAvX2 = 0x000800000ULL;
2223
static const uint64_t featureNeon = 0x001000000ULL;
2324
static const uint64_t featureClflush = 0x2000000000ULL;

shared/source/utilities/x86_64/cpu_info_x86_64.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021-2022 Intel Corporation
2+
* Copyright (C) 2021-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -13,31 +13,42 @@
1313

1414
namespace NEO {
1515
void CpuInfo::detect() const {
16+
constexpr uint32_t processorInfo = 1;
17+
constexpr uint32_t extendedFeatures = 0x7;
18+
constexpr uint32_t extendedFunctionId = 0x80000000;
19+
constexpr uint32_t addressSize = 0x80000008;
20+
constexpr size_t eax = 0;
21+
constexpr size_t ebx = 1;
22+
constexpr size_t ecx = 2;
23+
constexpr size_t edx = 3;
24+
1625
uint32_t cpuInfo[4] = {};
1726

1827
cpuid(cpuInfo, 0u);
19-
auto numFunctionIds = cpuInfo[0];
20-
if (numFunctionIds >= 1u) {
21-
cpuid(cpuInfo, 1u);
28+
auto numFunctionIds = cpuInfo[eax];
29+
if (numFunctionIds >= processorInfo) {
30+
cpuid(cpuInfo, processorInfo);
2231
{
23-
features |= cpuInfo[3] & BIT(19) ? featureClflush : featureNone;
32+
features |= cpuInfo[edx] & BIT(19) ? featureClflush : featureNone;
2433
}
2534
}
2635

27-
if (numFunctionIds >= 7u) {
28-
cpuid(cpuInfo, 7u);
36+
if (numFunctionIds >= extendedFeatures) {
37+
cpuid(cpuInfo, extendedFeatures);
2938
{
3039
auto mask = BIT(5) | BIT(3) | BIT(8);
31-
features |= (cpuInfo[1] & mask) == mask ? featureAvX2 : featureNone;
40+
features |= (cpuInfo[ebx] & mask) == mask ? featureAvX2 : featureNone;
41+
42+
features |= (cpuInfo[ecx] & BIT(5)) ? featureWaitPkg : featureNone;
3243
}
3344
}
3445

35-
cpuid(cpuInfo, 0x80000000);
36-
auto maxExtendedId = cpuInfo[0];
37-
if (maxExtendedId >= 0x80000008) {
38-
cpuid(cpuInfo, 0x80000008);
46+
cpuid(cpuInfo, extendedFunctionId);
47+
auto maxExtendedId = cpuInfo[eax];
48+
if (maxExtendedId >= addressSize) {
49+
cpuid(cpuInfo, addressSize);
3950
{
40-
virtualAddressSize = (cpuInfo[0] >> 8) & 0xFF;
51+
virtualAddressSize = (cpuInfo[eax] >> 8) & 0xFF;
4152
}
4253
}
4354
}

shared/test/unit_test/utilities/x86_64/cpuinfo_tests_x86_64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ TEST(CpuInfoTest, giveFunctionIsNotAvailableWhenFeatureIsNotSupportedThenMaskBit
5151

5252
EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2));
5353
EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush));
54+
EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureWaitPkg));
5455

5556
CpuInfo::cpuidFunc = defaultCpuidFunc;
5657
}
@@ -63,6 +64,7 @@ TEST(CpuInfoTest, giveFunctionIsAvailableWhenFeatureIsNotSupportedThenMaskBitIsO
6364

6465
EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2));
6566
EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush));
67+
EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureWaitPkg));
6668

6769
CpuInfo::cpuidFunc = defaultCpuidFunc;
6870
}
@@ -75,6 +77,7 @@ TEST(CpuInfoTest, whenFeatureIsSupportedThenMaskBitIsOn) {
7577

7678
EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2));
7779
EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush));
80+
EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureWaitPkg));
7881

7982
CpuInfo::cpuidFunc = defaultCpuidFunc;
8083
}

0 commit comments

Comments
 (0)