mirror of
https://github.com/google/cpu_features.git
synced 2025-04-28 15:33:37 +02:00
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 <rashmica.gupta@au1.ibm.com>
This commit is contained in:
parent
1c8bf0ecd8
commit
c45e32f812
@ -16,6 +16,7 @@
|
|||||||
#define CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_
|
#define CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_
|
||||||
|
|
||||||
#include "cpu_features_macros.h"
|
#include "cpu_features_macros.h"
|
||||||
|
#include "internal/hwcaps.h"
|
||||||
|
|
||||||
CPU_FEATURES_START_CPP_NAMESPACE
|
CPU_FEATURES_START_CPP_NAMESPACE
|
||||||
|
|
||||||
@ -77,6 +78,7 @@ typedef struct {
|
|||||||
char model[64]; // 0 terminated string
|
char model[64]; // 0 terminated string
|
||||||
char machine[64]; // 0 terminated string
|
char machine[64]; // 0 terminated string
|
||||||
char cpu[64]; // 0 terminated string
|
char cpu[64]; // 0 terminated string
|
||||||
|
PlatformType type;
|
||||||
} PPCPlatformStrings;
|
} PPCPlatformStrings;
|
||||||
|
|
||||||
PPCPlatformStrings GetPPCPlatformStrings(void);
|
PPCPlatformStrings GetPPCPlatformStrings(void);
|
||||||
|
@ -119,6 +119,13 @@ typedef struct {
|
|||||||
|
|
||||||
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
|
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
|
CPU_FEATURES_END_CPP_NAMESPACE
|
||||||
|
|
||||||
#endif // CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_
|
#endif // CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_
|
||||||
|
@ -168,6 +168,7 @@ PPCPlatformStrings GetPPCPlatformStrings(void) {
|
|||||||
PPCPlatformStrings strings = kEmptyPPCPlatformStrings;
|
PPCPlatformStrings strings = kEmptyPPCPlatformStrings;
|
||||||
|
|
||||||
FillProcCpuInfoData(&strings);
|
FillProcCpuInfoData(&strings);
|
||||||
|
strings.type = CpuFeatures_GetPlatformType();
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/hwcaps.c
24
src/hwcaps.c
@ -12,9 +12,13 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "internal/hwcaps.h"
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "cpu_features_macros.h"
|
#include "cpu_features_macros.h"
|
||||||
#include "internal/filesystem.h"
|
#include "internal/filesystem.h"
|
||||||
|
#include "internal/hwcaps.h"
|
||||||
|
#include "internal/string_view.h"
|
||||||
|
|
||||||
#if defined(NDEBUG)
|
#if defined(NDEBUG)
|
||||||
#define D(...)
|
#define D(...)
|
||||||
@ -71,6 +75,9 @@ static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#define AT_HWCAP 16
|
#define AT_HWCAP 16
|
||||||
#define AT_HWCAP2 26
|
#define AT_HWCAP2 26
|
||||||
|
#define AT_PLATFORM 15
|
||||||
|
#define AT_BASE_PLATFORM 24
|
||||||
|
|
||||||
typedef unsigned long getauxval_func_t(unsigned long);
|
typedef unsigned long getauxval_func_t(unsigned long);
|
||||||
|
|
||||||
static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
||||||
@ -152,6 +159,21 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
|
|||||||
return capabilities;
|
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)
|
#else // (defined(HWCAPS_SUPPORTED)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -198,6 +198,8 @@ static void PrintFeatures(const Printer printer) {
|
|||||||
PrintS(printer, "model", strings.model);
|
PrintS(printer, "model", strings.model);
|
||||||
PrintS(printer, "machine", strings.machine);
|
PrintS(printer, "machine", strings.machine);
|
||||||
PrintS(printer, "cpu", strings.cpu);
|
PrintS(printer, "cpu", strings.cpu);
|
||||||
|
PrintS(printer, "instruction set", strings.type.platform);
|
||||||
|
PrintS(printer, "microarchitecture", strings.type.base_platform);
|
||||||
PrintFlags(printer, &info.features);
|
PrintFlags(printer, &info.features);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,14 @@ timebase : 512000000
|
|||||||
platform : pSeries
|
platform : pSeries
|
||||||
model : IBM,8406-70Y
|
model : IBM,8406-70Y
|
||||||
machine : CHRP IBM,8406-70Y)");
|
machine : CHRP IBM,8406-70Y)");
|
||||||
|
SetPlatformTypes("power7", "power8");
|
||||||
const auto strings = GetPPCPlatformStrings();
|
const auto strings = GetPPCPlatformStrings();
|
||||||
ASSERT_STREQ(strings.platform, "pSeries");
|
ASSERT_STREQ(strings.platform, "pSeries");
|
||||||
ASSERT_STREQ(strings.model, "IBM,8406-70Y");
|
ASSERT_STREQ(strings.model, "IBM,8406-70Y");
|
||||||
ASSERT_STREQ(strings.machine, "CHRP IBM,8406-70Y");
|
ASSERT_STREQ(strings.machine, "CHRP IBM,8406-70Y");
|
||||||
ASSERT_STREQ(strings.cpu, "POWER7 (architected), altivec supported");
|
ASSERT_STREQ(strings.cpu, "POWER7 (architected), altivec supported");
|
||||||
|
ASSERT_STREQ(strings.type.platform, "power7");
|
||||||
|
ASSERT_STREQ(strings.type.base_platform, "power8");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpustringsPPCTest, Firestone) {
|
TEST(CpustringsPPCTest, Firestone) {
|
||||||
|
@ -12,12 +12,16 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "hwcaps_for_testing.h"
|
#include "hwcaps_for_testing.h"
|
||||||
|
#include "internal/string_view.h"
|
||||||
|
|
||||||
namespace cpu_features {
|
namespace cpu_features {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static auto* const g_hardware_capabilities = new HardwareCapabilities();
|
static auto* const g_hardware_capabilities = new HardwareCapabilities();
|
||||||
|
static auto* const g_platform_types = new PlatformType();
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) {
|
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) {
|
||||||
@ -29,4 +33,13 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
|
|||||||
return *g_hardware_capabilities;
|
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
|
} // namespace cpu_features
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
namespace cpu_features {
|
namespace cpu_features {
|
||||||
|
|
||||||
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2);
|
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2);
|
||||||
|
void SetPlatformTypes(const char *platform, const char *base_platform);
|
||||||
|
|
||||||
} // namespace cpu_features
|
} // namespace cpu_features
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user