From 2213b8808f31931dc1872b719d45a8b1dcd9bb10 Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Wed, 11 Mar 2020 16:50:49 +0100 Subject: [PATCH] Detect new CPU features using cpuid Change-Id: Ie82e1ae4d21e758a0b27b59dd130793f6cf7d14f Signed-off-by: Zbigniew Zdanowicz --- shared/source/utilities/cpu_info.h | 18 ++++++++++++++---- .../test/unit_test/utilities/cpuinfo_tests.cpp | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/shared/source/utilities/cpu_info.h b/shared/source/utilities/cpu_info.h index 03d38aca5d..e6579557c8 100644 --- a/shared/source/utilities/cpu_info.h +++ b/shared/source/utilities/cpu_info.h @@ -49,6 +49,8 @@ struct CpuInfo { static const uint64_t featureSha = 0x800000000ULL; static const uint64_t featureMpx = 0x1000000000ULL; static const uint64_t featureClflush = 0x2000000000ULL; + static const uint64_t featureTsc = 0x4000000000ULL; + static const uint64_t featureRdtscp = 0x8000000000ULL; CpuInfo() : features(featureNone) { } @@ -74,10 +76,18 @@ struct CpuInfo { features |= cpuInfo[3] & BIT(0) ? featureFpu : featureNone; } + { + features |= cpuInfo[3] & BIT(4) ? featureTsc : featureNone; + } + { features |= cpuInfo[3] & BIT(15) ? featureCmov : featureNone; } + { + features |= cpuInfo[3] & BIT(19) ? featureClflush : featureNone; + } + { features |= cpuInfo[3] & BIT(23) ? featureMmx : featureNone; } @@ -141,10 +151,6 @@ struct CpuInfo { { features |= cpuInfo[2] & BIT(30) ? featureRdrnd : featureNone; } - - { - features |= cpuInfo[3] & BIT(19) ? featureClflush : featureNone; - } } if (numFunctionIds >= 7u) { @@ -175,6 +181,10 @@ struct CpuInfo { { features |= cpuInfo[2] & BIT(5) ? featureLzcnt : featureNone; } + + { + features |= cpuInfo[3] & BIT(27) ? featureRdtscp : featureNone; + } } } diff --git a/shared/test/unit_test/utilities/cpuinfo_tests.cpp b/shared/test/unit_test/utilities/cpuinfo_tests.cpp index abc694d689..a1d1cddb91 100644 --- a/shared/test/unit_test/utilities/cpuinfo_tests.cpp +++ b/shared/test/unit_test/utilities/cpuinfo_tests.cpp @@ -62,6 +62,8 @@ TEST(CpuInfoTest, giveFunctionIsNotAvailableWhenFeatureIsNotSupportedThenMaskBit EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRtm)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush)); + EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureTsc)); + EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdtscp)); CpuInfo::cpuidFunc = defaultCpuidFunc; } @@ -96,6 +98,8 @@ TEST(CpuInfoTest, giveFunctionIsAvailableWhenFeatureIsNotSupportedThenMaskBitIsO EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRtm)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2)); EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush)); + EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureTsc)); + EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdtscp)); CpuInfo::cpuidFunc = defaultCpuidFunc; } @@ -130,6 +134,8 @@ TEST(CpuInfoTest, whenFeatureIsSupportedThenMaskBitIsOn) { EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureRtm)); EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2)); EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush)); + EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureTsc)); + EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdtscp)); CpuInfo::cpuidFunc = defaultCpuidFunc; }