From c45e32f81286425f2532f0e1bc602565dc3a1d5c Mon Sep 17 00:00:00 2001 From: Rashmica Gupta Date: Wed, 2 May 2018 14:30:25 +1000 Subject: [PATCH] powerpc: Add AT_PLATFORM and AT_BASE_PLATFORM Some PowerPC machines can operate in a mode that appears different to a process than the actual hardware. AT_PLATFORM indicates the supported instruction set and AT_BASE_PLATFORM indicates the actual microarchitecture of the hardware. Signed-off-by: Rashmica Gupta --- include/cpuinfo_ppc.h | 2 ++ include/internal/hwcaps.h | 7 +++++++ src/cpuinfo_ppc.c | 1 + src/hwcaps.c | 24 +++++++++++++++++++++++- src/utils/list_cpu_features.c | 2 ++ test/cpuinfo_ppc_test.cc | 3 +++ test/hwcaps_for_testing.cc | 13 +++++++++++++ test/hwcaps_for_testing.h | 1 + 8 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/cpuinfo_ppc.h b/include/cpuinfo_ppc.h index 82de865..654155d 100644 --- a/include/cpuinfo_ppc.h +++ b/include/cpuinfo_ppc.h @@ -16,6 +16,7 @@ #define CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_ #include "cpu_features_macros.h" +#include "internal/hwcaps.h" CPU_FEATURES_START_CPP_NAMESPACE @@ -77,6 +78,7 @@ typedef struct { char model[64]; // 0 terminated string char machine[64]; // 0 terminated string char cpu[64]; // 0 terminated string + PlatformType type; } PPCPlatformStrings; PPCPlatformStrings GetPPCPlatformStrings(void); diff --git a/include/internal/hwcaps.h b/include/internal/hwcaps.h index 1d5567e..830cde3 100644 --- a/include/internal/hwcaps.h +++ b/include/internal/hwcaps.h @@ -119,6 +119,13 @@ typedef struct { HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void); +typedef struct { + char platform[64]; // 0 terminated string + char base_platform[64]; // 0 terminated string +} PlatformType; + +PlatformType CpuFeatures_GetPlatformType(void); + CPU_FEATURES_END_CPP_NAMESPACE #endif // CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_ diff --git a/src/cpuinfo_ppc.c b/src/cpuinfo_ppc.c index 9c2fd99..59b9ecc 100644 --- a/src/cpuinfo_ppc.c +++ b/src/cpuinfo_ppc.c @@ -168,6 +168,7 @@ PPCPlatformStrings GetPPCPlatformStrings(void) { PPCPlatformStrings strings = kEmptyPPCPlatformStrings; FillProcCpuInfoData(&strings); + strings.type = CpuFeatures_GetPlatformType(); return strings; } diff --git a/src/hwcaps.c b/src/hwcaps.c index e670bc4..c67c5e6 100644 --- a/src/hwcaps.c +++ b/src/hwcaps.c @@ -12,9 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "internal/hwcaps.h" +#include +#include + #include "cpu_features_macros.h" #include "internal/filesystem.h" +#include "internal/hwcaps.h" +#include "internal/string_view.h" #if defined(NDEBUG) #define D(...) @@ -71,6 +75,9 @@ static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) { #include #define AT_HWCAP 16 #define AT_HWCAP2 26 +#define AT_PLATFORM 15 +#define AT_BASE_PLATFORM 24 + typedef unsigned long getauxval_func_t(unsigned long); static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) { @@ -152,6 +159,21 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) { return capabilities; } +PlatformType kEmptyPlatformType; + +PlatformType CpuFeatures_GetPlatformType(void) { + PlatformType type = kEmptyPlatformType; + char *platform = (char *)GetHardwareCapabilitiesFor(AT_PLATFORM); + char *base_platform = (char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM); + + if (platform != NULL) + CpuFeatures_StringView_CopyString(str(platform), type.platform, + sizeof(type.platform)); + if (base_platform != NULL) + CpuFeatures_StringView_CopyString(str(base_platform), type.base_platform, + sizeof(type.base_platform)); + return type; +} #else // (defined(HWCAPS_SUPPORTED) //////////////////////////////////////////////////////////////////////////////// diff --git a/src/utils/list_cpu_features.c b/src/utils/list_cpu_features.c index 80ad0b9..a5f7f8c 100644 --- a/src/utils/list_cpu_features.c +++ b/src/utils/list_cpu_features.c @@ -198,6 +198,8 @@ static void PrintFeatures(const Printer printer) { PrintS(printer, "model", strings.model); PrintS(printer, "machine", strings.machine); PrintS(printer, "cpu", strings.cpu); + PrintS(printer, "instruction set", strings.type.platform); + PrintS(printer, "microarchitecture", strings.type.base_platform); PrintFlags(printer, &info.features); #endif } diff --git a/test/cpuinfo_ppc_test.cc b/test/cpuinfo_ppc_test.cc index f6485c4..5d5e798 100644 --- a/test/cpuinfo_ppc_test.cc +++ b/test/cpuinfo_ppc_test.cc @@ -57,11 +57,14 @@ timebase : 512000000 platform : pSeries model : IBM,8406-70Y machine : CHRP IBM,8406-70Y)"); + SetPlatformTypes("power7", "power8"); const auto strings = GetPPCPlatformStrings(); ASSERT_STREQ(strings.platform, "pSeries"); ASSERT_STREQ(strings.model, "IBM,8406-70Y"); ASSERT_STREQ(strings.machine, "CHRP IBM,8406-70Y"); ASSERT_STREQ(strings.cpu, "POWER7 (architected), altivec supported"); + ASSERT_STREQ(strings.type.platform, "power7"); + ASSERT_STREQ(strings.type.base_platform, "power8"); } TEST(CpustringsPPCTest, Firestone) { diff --git a/test/hwcaps_for_testing.cc b/test/hwcaps_for_testing.cc index 0e78813..07f68e8 100644 --- a/test/hwcaps_for_testing.cc +++ b/test/hwcaps_for_testing.cc @@ -12,12 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "hwcaps_for_testing.h" +#include "internal/string_view.h" namespace cpu_features { namespace { static auto* const g_hardware_capabilities = new HardwareCapabilities(); +static auto* const g_platform_types = new PlatformType(); } // namespace void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) { @@ -29,4 +33,13 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) { return *g_hardware_capabilities; } +void SetPlatformTypes(const char* platform, const char* base_platform) { + CpuFeatures_StringView_CopyString(str(platform), g_platform_types->platform, + sizeof(g_platform_types->platform)); + CpuFeatures_StringView_CopyString(str(base_platform), + g_platform_types->base_platform, + sizeof(g_platform_types->base_platform)); +} + +PlatformType CpuFeatures_GetPlatformType(void) { return *g_platform_types; } } // namespace cpu_features diff --git a/test/hwcaps_for_testing.h b/test/hwcaps_for_testing.h index bd20957..0d03777 100644 --- a/test/hwcaps_for_testing.h +++ b/test/hwcaps_for_testing.h @@ -20,6 +20,7 @@ namespace cpu_features { void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2); +void SetPlatformTypes(const char *platform, const char *base_platform); } // namespace cpu_features