diff --git a/include/cpuinfo.h b/include/cpuinfo.h index 15625e02..8e5decc1 100644 --- a/include/cpuinfo.h +++ b/include/cpuinfo.h @@ -603,19 +603,19 @@ enum cpuinfo_uarch { cpuinfo_uarch_taishan_v110 = 0x00C00100, /** IBM POWER 7. */ - cpuinfo_uarch_power7 = 0x00D00100, + cpuinfo_uarch_power7 = 0x00D00100, /** IBM POWER 7p. */ - cpuinfo_uarch_power7p = 0x00D00101, + cpuinfo_uarch_power7p = 0x00D00101, /** IBM POWER 8. */ - cpuinfo_uarch_power8 = 0x00D00200, + cpuinfo_uarch_power8 = 0x00D00200, /** IBM POWER8E. */ - cpuinfo_uarch_power8e = 0x00D00201, + cpuinfo_uarch_power8e = 0x00D00201, /** IBM POWER8NVL */ cpuinfo_uarch_power8nvl = 0x00D00202, /** IBM POWER 9. */ - cpuinfo_uarch_power9 = 0x00D00303, + cpuinfo_uarch_power9 = 0x00D00303, /** IBM POWER 10. */ - cpuinfo_uarch_power10 = 0x00D00400, + cpuinfo_uarch_power10 = 0x00D00400, }; struct cpuinfo_processor { @@ -2245,13 +2245,13 @@ static inline bool cpuinfo_has_riscv_v(void) { } #if CPUINFO_ARCH_PPC64 - struct cpuinfo_powerpc_isa { - bool vsx; - bool htm; - bool mma; - }; +struct cpuinfo_powerpc_isa { + bool vsx; + bool htm; + bool mma; +}; - extern struct cpuinfo_powerpc_isa cpuinfo_isa; +extern struct cpuinfo_powerpc_isa cpuinfo_isa; #endif static inline bool cpuinfo_has_powerpc_vsx(void) { diff --git a/src/linux/processors.c b/src/linux/processors.c index 6c9622da..114ada79 100644 --- a/src/linux/processors.c +++ b/src/linux/processors.c @@ -285,29 +285,31 @@ bool cpuinfo_linux_get_processor_package_id(uint32_t processor, uint32_t package bool cpuinfo_linux_get_processor_online_status(uint32_t processor, uint32_t* online_status_ptr) { char processor_online_filename[PROCESSOR_ONLINE_FILENAME_SIZE]; - const int chars_formatted = - snprintf(processor_online_filename, PROCESSOR_ONLINE_FILENAME_SIZE, PROCESSOR_ONLINE_FILENAME_FORMAT, processor); - if ((unsigned int)chars_formatted >= PROCESSOR_ONLINE_FILENAME_SIZE) { + const int chars_formatted = snprintf( + processor_online_filename, PROCESSOR_ONLINE_FILENAME_SIZE, PROCESSOR_ONLINE_FILENAME_FORMAT, processor); + if ((unsigned int)chars_formatted >= PROCESSOR_ONLINE_FILENAME_SIZE) { cpuinfo_log_warning("failed to format filename for online status of processor %" PRIu32, processor); return 0; } uint32_t online_status; - if (cpuinfo_linux_parse_small_file(processor_online_filename, PROCESSOR_ONLINE_FILESIZE, uint32_parser, &online_status)) { + if (cpuinfo_linux_parse_small_file( + processor_online_filename, PROCESSOR_ONLINE_FILESIZE, uint32_parser, &online_status)) { cpuinfo_log_debug( "parsed online status value of %" PRIu32 " for logical processor %" PRIu32 " from %s", online_status, processor, processor_online_filename); - *online_status_ptr = online_status; - return true; + *online_status_ptr = online_status; + return true; } else { - cpuinfo_log_info( - "failed to parse online status for processor %" PRIu32 " from %s", processor, processor_online_filename); - return false; + cpuinfo_log_info( + "failed to parse online status for processor %" PRIu32 " from %s", + processor, + processor_online_filename); + return false; } } - static bool max_processor_number_parser(uint32_t processor_list_start, uint32_t processor_list_end, void* context) { uint32_t* processor_number_ptr = (uint32_t*)context; const uint32_t processor_list_last = processor_list_end - 1; diff --git a/src/powerpc/api.h b/src/powerpc/api.h index 79464f68..34ab330b 100644 --- a/src/powerpc/api.h +++ b/src/powerpc/api.h @@ -5,17 +5,14 @@ #include -enum cpuinfo_powerpc_chipset_vendor { - cpuinfo_powerpc_chipset_vendor_unknown = 0, - cpuinfo_powerpc_chipset_vendor_ibm -}; +enum cpuinfo_powerpc_chipset_vendor { cpuinfo_powerpc_chipset_vendor_unknown = 0, cpuinfo_powerpc_chipset_vendor_ibm }; void cpuinfo_powerpc_decode_vendor_uarch( uint32_t vendor_id, enum cpuinfo_vendor vendor[restrict static 1], enum cpuinfo_uarch uarch[restrict static 1]); void cpuinfo_powerpc_decode_cache( - struct cpuinfo_cache l1i[restrict static 1], - struct cpuinfo_cache l1d[restrict static 1], - struct cpuinfo_cache l2[restrict static 1], - struct cpuinfo_cache l3[restrict static 1]); + struct cpuinfo_cache l1i[restrict static 1], + struct cpuinfo_cache l1d[restrict static 1], + struct cpuinfo_cache l2[restrict static 1], + struct cpuinfo_cache l3[restrict static 1]); diff --git a/src/powerpc/cache.c b/src/powerpc/cache.c index 0ddd5331..ace751a4 100644 --- a/src/powerpc/cache.c +++ b/src/powerpc/cache.c @@ -1,10 +1,10 @@ -#include #include +#include #include #include -#include #include +#include #include #include @@ -12,17 +12,15 @@ #include #include -#define NUM_CACHE 4 -#define BUF_SIZE 128 +#define NUM_CACHE 4 +#define BUF_SIZE 128 -int path_exist(const char *path) -{ +int path_exist(const char* path) { return (access(path, F_OK) == 0); } -void read_str(char *result, size_t len, const char *path) -{ - FILE *f; +void read_str(char* result, size_t len, const char* path) { + FILE* f; f = fopen(path, "r"); @@ -34,21 +32,20 @@ void read_str(char *result, size_t len, const char *path) result[len - 1] = '\0'; } -void decode_cache_features(uint32_t cache_features[], unsigned long geometry) -{ +void decode_cache_features(uint32_t cache_features[], unsigned long geometry) { cache_features[1] = (geometry >> 16) & 0xffff; cache_features[2] = geometry & 0xffff; - /* If associativity = 65535 it means upper limit of 16 bit of AT_L%d_CACHEGEOMETRY has reached so we calculate it from, size, sets and line_size*/ - if(cache_features[1] == 65535) - cache_features[1] = cache_features[0]/(cache_features[2]*cache_features[3]); + /* If associativity = 65535 it means upper limit of 16 bit of AT_L%d_CACHEGEOMETRY has reached so we calculate + * it from, size, sets and line_size*/ + if (cache_features[1] == 65535) + cache_features[1] = cache_features[0] / (cache_features[2] * cache_features[3]); } void cpuinfo_powerpc_decode_cache( struct cpuinfo_cache l1i[restrict static 1], struct cpuinfo_cache l1d[restrict static 1], struct cpuinfo_cache l2[restrict static 1], - struct cpuinfo_cache l3[restrict static 1]) -{ + struct cpuinfo_cache l3[restrict static 1]) { char buf[BUF_SIZE]; char result[BUF_SIZE]; uint32_t cache_features[NUM_CACHE]; @@ -56,11 +53,10 @@ void cpuinfo_powerpc_decode_cache( uint32_t size = 0, sets = 0; size_t len; - for(i = 0; i < NUM_CACHE; i++) { - - sprintf (buf, "/sys/devices/system/cpu/cpu%d/cache/index%d/number_of_sets", i); - if(path_exist(buf)) - read_str(result, sizeof(result), buf); + for (i = 0; i < NUM_CACHE; i++) { + sprintf(buf, "/sys/devices/system/cpu/cpu%d/cache/index%d/number_of_sets", i); + if (path_exist(buf)) + read_str(result, sizeof(result), buf); sets = atoi(result); cache_features[3] = sets; @@ -73,8 +69,8 @@ void cpuinfo_powerpc_decode_cache( size = getauxval(AT_L1D_CACHESIZE); cache_features[0] = size; decode_cache_features(cache_features, geometry); - sets = size/(cache_features[1] * cache_features[2]); - *l1d = (struct cpuinfo_cache) { + sets = size / (cache_features[1] * cache_features[2]); + *l1d = (struct cpuinfo_cache){ .size = size, .associativity = cache_features[1], .line_size = cache_features[2], @@ -88,44 +84,40 @@ void cpuinfo_powerpc_decode_cache( size = getauxval(AT_L1I_CACHESIZE); cache_features[0] = size; decode_cache_features(cache_features, geometry); - sets = size/(cache_features[1] * cache_features[2]); - *l1i = (struct cpuinfo_cache) { + sets = size / (cache_features[1] * cache_features[2]); + *l1i = (struct cpuinfo_cache){ .size = size, .associativity = cache_features[1], .line_size = cache_features[2], .sets = sets, - .partitions = 1 - }; + .partitions = 1}; break; case 2: geometry = getauxval(AT_L2_CACHEGEOMETRY); size = getauxval(AT_L2_CACHESIZE); cache_features[0] = size; decode_cache_features(cache_features, geometry); - sets = size/(cache_features[1] * cache_features[2]); - *l2 = (struct cpuinfo_cache) { + sets = size / (cache_features[1] * cache_features[2]); + *l2 = (struct cpuinfo_cache){ .size = size, .associativity = cache_features[1], .line_size = cache_features[2], .sets = sets, - .partitions = 1 - }; + .partitions = 1}; break; case 3: geometry = getauxval(AT_L3_CACHEGEOMETRY); size = getauxval(AT_L3_CACHESIZE); cache_features[0] = size; decode_cache_features(cache_features, geometry); - sets = size/(cache_features[1] * cache_features[2]); - *l3 = (struct cpuinfo_cache) { + sets = size / (cache_features[1] * cache_features[2]); + *l3 = (struct cpuinfo_cache){ .size = size, .associativity = cache_features[1], .line_size = cache_features[2], .sets = sets, - .partitions = 1 - }; + .partitions = 1}; break; - } } } diff --git a/src/powerpc/linux/api.h b/src/powerpc/linux/api.h index 739a519d..a03aaa73 100644 --- a/src/powerpc/linux/api.h +++ b/src/powerpc/linux/api.h @@ -7,47 +7,47 @@ #include #include -#include #include +#include /* No hard limit in the kernel, maximum length observed on non-rogue kernels is 64 */ #define CPUINFO_HARDWARE_VALUE_MAX 64 /* from /arch/powerpc/kernel/cputable.c */ -#define CPUINFO_POWERPC_LINUX_FEATURE_64 UINT32_C(0x40000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_ALTIVEC UINT32_C(0x10000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_FPU UINT32_C(0x08000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMU UINT32_C(0x04000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_NO_TB UINT32_C(0x00100000) -#define CPUINFO_POWERPC_LINUX_FEATURE_SMT UINT32_C(0x00004000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_DFP UINT32_C(0x00000400) -#define CPUINFO_POWERPC_LINUX_FEATURE_POWER6_EXT UINT32_C(0x00000200) -#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_VSX UINT32_C(0x00000080) -#define CPUINFO_POWERPC_LINUX_FEATURE_TRUE_LE UINT32_C(0x00000002) +#define CPUINFO_POWERPC_LINUX_FEATURE_64 UINT32_C(0x40000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_ALTIVEC UINT32_C(0x10000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_FPU UINT32_C(0x08000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMU UINT32_C(0x04000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_NO_TB UINT32_C(0x00100000) +#define CPUINFO_POWERPC_LINUX_FEATURE_SMT UINT32_C(0x00004000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_DFP UINT32_C(0x00000400) +#define CPUINFO_POWERPC_LINUX_FEATURE_POWER6_EXT UINT32_C(0x00000200) +#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_VSX UINT32_C(0x00000080) +#define CPUINFO_POWERPC_LINUX_FEATURE_TRUE_LE UINT32_C(0x00000002) #define CPUINFO_POWERPC_LINUX_FEATURE_PPC_LE UINT32_C(0x00000001 -#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07 UINT32_C(0x80000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HTM UINT32_C(0x40000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_DSCR UINT32_C(0x20000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_EBB UINT32_C(0x10000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_ISEL UINT32_C(0x08000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_TAR UINT32_C(0x04000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_VEC_CRYPTO UINT32_C(0x02000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NOSC UINT32_C(0x01000000) -#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00 UINT32_C(0x00800000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_IEEE128 UINT32_C(0x00400000) -#define CPUINFO_POWERPC_LINUX_FEATURE_DARN UINT32_C(0x00200000) -#define CPUINFO_POWERPC_LINUX_FEATURE_SCV UINT32_C(0x00100000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NO_SUSPEND UINT32_C(0x00080000) -#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1 UINT32_C(0x00040000) -#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMA UINT32_C(0x00020000) +#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07 UINT32_C(0x80000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HTM UINT32_C(0x40000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_DSCR UINT32_C(0x20000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_EBB UINT32_C(0x10000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_ISEL UINT32_C(0x08000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_TAR UINT32_C(0x04000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_VEC_CRYPTO UINT32_C(0x02000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NOSC UINT32_C(0x01000000) +#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00 UINT32_C(0x00800000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_IEEE128 UINT32_C(0x00400000) +#define CPUINFO_POWERPC_LINUX_FEATURE_DARN UINT32_C(0x00200000) +#define CPUINFO_POWERPC_LINUX_FEATURE_SCV UINT32_C(0x00100000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NO_SUSPEND UINT32_C(0x00080000) +#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1 UINT32_C(0x00040000) +#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMA UINT32_C(0x00020000) #define CPUINFO_POWERPC_LINUX_VALID_ARCHITECTURE UINT32_C(0x00010000) -#define CPUINFO_POWERPC_LINUX_VALID_IMPLEMENTER UINT32_C(0x00020000) -#define CPUINFO_POWERPC_LINUX_VALID_REVISION UINT32_C(0x00040000) -#define CPUINFO_POWERPC_LINUX_VALID_PROCESSOR UINT32_C(0x00080000) -#define CPUINFO_POWERPC_LINUX_VALID_VERSION UINT32_C(0x00100000) -#define CPUINFO_POWERPC_LINUX_VALID_FEATURES UINT32_C(0x00200000) -#define CPUINFO_POWERPC_LINUX_VALID_PVR UINT32_C(0x001F0000) +#define CPUINFO_POWERPC_LINUX_VALID_IMPLEMENTER UINT32_C(0x00020000) +#define CPUINFO_POWERPC_LINUX_VALID_REVISION UINT32_C(0x00040000) +#define CPUINFO_POWERPC_LINUX_VALID_PROCESSOR UINT32_C(0x00080000) +#define CPUINFO_POWERPC_LINUX_VALID_VERSION UINT32_C(0x00100000) +#define CPUINFO_POWERPC_LINUX_VALID_FEATURES UINT32_C(0x00200000) +#define CPUINFO_POWERPC_LINUX_VALID_PVR UINT32_C(0x001F0000) /** * Definition of a powerpc64 Linux processor. It is composed of the base processor @@ -99,10 +99,14 @@ struct cpuinfo_powerpc_linux_processor { * @param[isa] - Reference to cpuinfo_powerpc_isa structure to populate. */ void cpuinfo_powerpc_linux_hwcap_from_getauxval(uint32_t isa_feature[]); -CPUINFO_INTERNAL void cpuinfo_ppc64_linux_decode_isa_from_hwcap(uint32_t hwcap, uint32_t hwcap2, struct cpuinfo_powerpc_isa isa[restrict static 1]); +CPUINFO_INTERNAL void cpuinfo_ppc64_linux_decode_isa_from_hwcap( + uint32_t hwcap, + uint32_t hwcap2, + struct cpuinfo_powerpc_isa isa[restrict static 1]); bool cpuinfo_powerpc_linux_parse_proc_cpuinfo( - uint32_t max_processors_count,struct cpuinfo_powerpc_linux_processor processors[restrict static max_processors_count]); + uint32_t max_processors_count, + struct cpuinfo_powerpc_linux_processor processors[restrict static max_processors_count]); /* Used to determine which uarch is associated with the current thread. */ extern CPUINFO_INTERNAL const uint32_t* cpuinfo_linux_cpu_to_uarch_index_map; diff --git a/src/powerpc/linux/cpuinfo.c b/src/powerpc/linux/cpuinfo.c index 3e31ceee..1567f9f8 100644 --- a/src/powerpc/linux/cpuinfo.c +++ b/src/powerpc/linux/cpuinfo.c @@ -1,13 +1,13 @@ #include +#include #include #include #include -#include #include +#include #include #include -#include /* * Size, in chars, of the on-stack buffer used for parsing lines of /proc/cpuinfo. @@ -22,11 +22,8 @@ struct proc_cpuinfo_parser_state { struct cpuinfo_powerpc_linux_processor dummy_processor; }; -static uint32_t parse_processor_number( - const char* processor_start, - const char* processor_end) -{ - const size_t processor_length = (size_t) (processor_end - processor_start); +static uint32_t parse_processor_number(const char* processor_start, const char* processor_end) { + const size_t processor_length = (size_t)(processor_end - processor_start); if (processor_length == 0) { cpuinfo_log_warning("Processor number in /proc/cpuinfo is ignored: string is empty"); @@ -35,10 +32,12 @@ static uint32_t parse_processor_number( uint32_t processor_number = 0; for (const char* digit_ptr = processor_start; digit_ptr != processor_end; digit_ptr++) { - const uint32_t digit = (uint32_t) (*digit_ptr - '0'); + const uint32_t digit = (uint32_t)(*digit_ptr - '0'); if (digit >= 10) { - cpuinfo_log_warning("non-decimal suffix %.*s in /proc/cpuinfo processor number is ignored", - (int) (processor_end - digit_ptr), digit_ptr); + cpuinfo_log_warning( + "non-decimal suffix %.*s in /proc/cpuinfo processor number is ignored", + (int)(processor_end - digit_ptr), + digit_ptr); break; } @@ -49,10 +48,9 @@ static uint32_t parse_processor_number( } static void parse_cpu_architecture( - const char *cpu_architecture_start, - const char *cpu_architecture_end, - struct cpuinfo_powerpc_linux_processor *processor) -{ + const char* cpu_architecture_start, + const char* cpu_architecture_end, + struct cpuinfo_powerpc_linux_processor* processor) { const size_t cpu_arch_name_length = 5; if (!memcmp(cpu_architecture_start, "POWER", cpu_arch_name_length)) { @@ -66,7 +64,7 @@ static void parse_cpu_architecture( const char* cpu_arch_ptr = cpu_architecture_start + cpu_arch_name_length; uint32_t arch_version = 0; for (; cpu_arch_ptr != cpu_architecture_end; cpu_arch_ptr++) { - const uint32_t digit = (uint32_t) (*cpu_arch_ptr - '0'); + const uint32_t digit = (uint32_t)(*cpu_arch_ptr - '0'); if (digit >= 10) { break; @@ -74,7 +72,7 @@ static void parse_cpu_architecture( arch_version = arch_version * 10 + digit; } - switch(arch_version) { + switch (arch_version) { case 7: /* POWER7 */ if (*cpu_arch_ptr == ' ') { processor->core.uarch = cpuinfo_uarch_power7; @@ -113,25 +111,28 @@ static void parse_cpu_architecture( break; default: unsupported: - cpuinfo_log_warning("CPU architecture %.*s in /proc/cpuinfo is ignored due to a unsupported architecture version", - (int) (cpu_architecture_end - cpu_architecture_start), cpu_architecture_start); + cpuinfo_log_warning( + "CPU architecture %.*s in /proc/cpuinfo is ignored due to a unsupported architecture version", + (int)(cpu_architecture_end - cpu_architecture_start), + cpu_architecture_start); } processor->flags |= CPUINFO_POWERPC_LINUX_VALID_PROCESSOR; processor->core.disabled = false; } else { - cpuinfo_log_warning("processor %.*s in /proc/cpuinfo is ignored due not a Power processor", - (int) (cpu_architecture_end - cpu_architecture_start), cpu_architecture_start); + cpuinfo_log_warning( + "processor %.*s in /proc/cpuinfo is ignored due not a Power processor", + (int)(cpu_architecture_end - cpu_architecture_start), + cpu_architecture_start); } } static void parse_cpu_pvr( - const char *cpu_revision_start, - const char *cpu_revision_end, - struct cpuinfo_powerpc_linux_processor *processor) -{ + const char* cpu_revision_start, + const char* cpu_revision_end, + struct cpuinfo_powerpc_linux_processor* processor) { const char* cpu_rev_ptr = cpu_revision_start; uint16_t revision = 0; - uint16_t version = 0; + uint16_t version = 0; processor->core.pvr = 0x0; for (; cpu_rev_ptr != cpu_revision_end; cpu_rev_ptr++) { @@ -151,12 +152,14 @@ static void parse_cpu_pvr( cpu_rev_ptr++; break; } - uint32_t digit = (uint32_t) (*cpu_rev_ptr - '0'); + uint32_t digit = (uint32_t)(*cpu_rev_ptr - '0'); if (digit >= 10) { digit = digit - 0x27; if ((digit < 10) || (digit > 15)) { - cpuinfo_log_warning("cpu revision %.*s in /proc/cpuinfo is ignored due non number", - (int) (cpu_revision_end - cpu_revision_start), cpu_revision_start); + cpuinfo_log_warning( + "cpu revision %.*s in /proc/cpuinfo is ignored due non number", + (int)(cpu_revision_end - cpu_revision_start), + cpu_revision_start); return; } } @@ -164,18 +167,20 @@ static void parse_cpu_pvr( } /* Parse version. */ - uint16_t version = 0; + uint16_t version = 0; for (; cpu_rev_ptr != cpu_revision_end; cpu_rev_ptr++) { if (*cpu_rev_ptr == ')') { cpu_rev_ptr++; break; } - uint32_t digit = (uint32_t) (*cpu_rev_ptr - '0'); + uint32_t digit = (uint32_t)(*cpu_rev_ptr - '0'); if (digit >= 10) { digit = digit - 0x27; if ((digit < 10) || (digit > 15)) { - cpuinfo_log_warning("cpu version %.*s in /proc/cpuinfo is ignored due non number", - (int) (cpu_revision_end - cpu_revision_start), cpu_revision_start); + cpuinfo_log_warning( + "cpu version %.*s in /proc/cpuinfo is ignored due non number", + (int)(cpu_revision_end - cpu_revision_start), + cpu_revision_start); return; } } @@ -185,8 +190,10 @@ static void parse_cpu_pvr( processor->core.pvr |= (revision << 16); processor->core.pvr |= version; } else { - cpuinfo_log_warning("cpu revision %.*s in /proc/cpuinfo is ignored due non PVR information", - (int) (cpu_revision_end - cpu_revision_start), cpu_revision_start); + cpuinfo_log_warning( + "cpu revision %.*s in /proc/cpuinfo is ignored due non PVR information", + (int)(cpu_revision_end - cpu_revision_start), + cpu_revision_start); } } @@ -194,9 +201,7 @@ static bool parse_line( const char* line_start, const char* line_end, struct proc_cpuinfo_parser_state state[restrict static 1], - uint64_t line_number) -{ - + uint64_t line_number) { /* Empty line. Skip. */ if (line_start == line_end) { return true; @@ -212,10 +217,12 @@ static bool parse_line( /* Skip line if no ':' separator was found. */ if (separator == line_end) { - cpuinfo_log_warning("Line %.*s in /proc/cpuinfo is ignored: key/value separator ':' not found", - (int) (line_end - line_start), line_start); + cpuinfo_log_warning( + "Line %.*s in /proc/cpuinfo is ignored: key/value separator ':' not found", + (int)(line_end - line_start), + line_start); return true; - } + } /* Skip trailing spaces in key part. */ const char* key_end = separator; @@ -227,8 +234,10 @@ static bool parse_line( /* Skip line if key contains nothing but spaces. */ if (key_end == line_start) { - cpuinfo_log_warning("Line %.*s in /proc/cpuinfo is ignored: key contains only spaces", - (int) (line_end - line_start), line_start); + cpuinfo_log_warning( + "Line %.*s in /proc/cpuinfo is ignored: key contains only spaces", + (int)(line_end - line_start), + line_start); return true; } @@ -242,8 +251,10 @@ static bool parse_line( /* Value part contains nothing but spaces. Skip line. */ if (value_start == line_end) { - cpuinfo_log_warning("Line %.*s in /proc/cpuinfo is ignored: value contains only spaces", - (int) (line_end - line_start), line_start); + cpuinfo_log_warning( + "Line %.*s in /proc/cpuinfo is ignored: value contains only spaces", + (int)(line_end - line_start), + line_start); } /* Skip trailing spaces in value part (if any) */ @@ -255,10 +266,10 @@ static bool parse_line( } /* Declarations to return */ - const uint32_t processor_index = state->processor_index; + const uint32_t processor_index = state->processor_index; const uint32_t max_processors_count = state->max_processors_count; struct cpuinfo_powerpc_linux_processor* processors = state->processors; - struct cpuinfo_powerpc_linux_processor* processor = &state->dummy_processor; + struct cpuinfo_powerpc_linux_processor* processor = &state->dummy_processor; if (processor_index < max_processors_count) { processor = &processors[processor_index]; @@ -277,15 +288,15 @@ static bool parse_line( case 5: if (memcmp(line_start, "clock", key_length) == 0) { parse_cpu_architecture(value_start, value_end, processor); - } else { - goto unknown; - } + } else { + goto unknown; + } case 7: if (memcmp(line_start, "machine", key_length) == 0) { parse_cpu_architecture(value_start, value_end, processor); - } else { - goto unknown; - } + } else { + goto unknown; + } case 8: if (memcmp(line_start, "revision", key_length) == 0) { parse_cpu_pvr(value_start, value_end, processor); @@ -302,24 +313,23 @@ static bool parse_line( break; default: unknown: - cpuinfo_log_debug("unknown /proc/cpuinfo key: %.*s", (int) key_length, line_start); + cpuinfo_log_debug("unknown /proc/cpuinfo key: %.*s", (int)key_length, line_start); } return true; } bool cpuinfo_powerpc_linux_parse_proc_cpuinfo( uint32_t max_processors_count, - struct cpuinfo_powerpc_linux_processor processors[restrict static max_processors_count]) -{ + struct cpuinfo_powerpc_linux_processor processors[restrict static max_processors_count]) { struct proc_cpuinfo_parser_state state = { .processor_index = 0, .max_processors_count = max_processors_count, .processors = processors, }; - for (int i = 0 ; i < max_processors_count; i++) + for (int i = 0; i < max_processors_count; i++) processors[i].core.disabled = true; - return cpuinfo_linux_parse_multiline_file("/proc/cpuinfo", BUFFER_SIZE, - (cpuinfo_line_callback) parse_line, &state); + return cpuinfo_linux_parse_multiline_file( + "/proc/cpuinfo", BUFFER_SIZE, (cpuinfo_line_callback)parse_line, &state); } diff --git a/src/powerpc/linux/init.c b/src/powerpc/linux/init.c index 54260a8a..0553f066 100644 --- a/src/powerpc/linux/init.c +++ b/src/powerpc/linux/init.c @@ -234,7 +234,7 @@ void cpuinfo_powerpc_linux_init(void) { const struct cpuinfo_processor** linux_cpu_to_processor_map = NULL; const struct cpuinfo_core** linux_cpu_to_core_map = NULL; uint32_t* linux_cpu_to_uarch_index_map = NULL; - struct cpuinfo_cache* l1i = NULL; + struct cpuinfo_cache* l1i = NULL; struct cpuinfo_cache* l1d = NULL; struct cpuinfo_cache* l2 = NULL; struct cpuinfo_cache* l3 = NULL; @@ -287,9 +287,7 @@ void cpuinfo_powerpc_linux_init(void) { goto cleanup; } - - - uint32_t online_status=1; + uint32_t online_status = 1; /* Populate processor information. */ for (size_t processor = 0; processor < max_processor_id; processor++) { if (!bitmask_all(powerpc_linux_processors[processor].flags, CPUINFO_LINUX_FLAG_VALID)) { @@ -300,41 +298,40 @@ void cpuinfo_powerpc_linux_init(void) { /* Populate core information. */ for (size_t processor = 0; processor < max_processor_id; processor++) { - if (!bitmask_all(powerpc_linux_processors[processor].flags, CPUINFO_LINUX_FLAG_VALID)) { - continue; - } - online_status = 1; - cpuinfo_linux_get_processor_online_status(processor, &online_status); - - if (online_status == 1) { - /* Populate processor start and count information. - */ - if (!cpuinfo_linux_detect_core_cpus( - max_processor_id, - processor, - (cpuinfo_siblings_callback)core_cpus_parser, - powerpc_linux_processors)) { - cpuinfo_log_error("failed to detect core cpus for processor %zu.", processor); - goto cleanup; - } - - /* Populate core ID information. */ - if (cpuinfo_linux_get_processor_core_id(processor, &powerpc_linux_processors[processor].core.core_id)) { - powerpc_linux_processors[processor].flags |= CPUINFO_LINUX_FLAG_CORE_ID; - } - + if (!bitmask_all(powerpc_linux_processors[processor].flags, CPUINFO_LINUX_FLAG_VALID)) { + continue; + } + online_status = 1; + cpuinfo_linux_get_processor_online_status(processor, &online_status); - /** - * Populate the vendor and uarch of this core from /proc/cpuinfo. - */ - if (!cpuinfo_powerpc_linux_parse_proc_cpuinfo(max_processor_id,powerpc_linux_processors)) { - cpuinfo_log_error("failed to parse processor information from /proc/cpuinfo"); - return; - } - } + if (online_status == 1) { + /* Populate processor start and count information. + */ + if (!cpuinfo_linux_detect_core_cpus( + max_processor_id, + processor, + (cpuinfo_siblings_callback)core_cpus_parser, + powerpc_linux_processors)) { + cpuinfo_log_error("failed to detect core cpus for processor %zu.", processor); + goto cleanup; + } + + /* Populate core ID information. */ + if (cpuinfo_linux_get_processor_core_id( + processor, &powerpc_linux_processors[processor].core.core_id)) { + powerpc_linux_processors[processor].flags |= CPUINFO_LINUX_FLAG_CORE_ID; + } + + /** + * Populate the vendor and uarch of this core from /proc/cpuinfo. + */ + if (!cpuinfo_powerpc_linux_parse_proc_cpuinfo(max_processor_id, powerpc_linux_processors)) { + cpuinfo_log_error("failed to parse processor information from /proc/cpuinfo"); + return; + } + } } - /* Populate cluster information. * power10, the number of cores and the clusters are same. */ @@ -342,30 +339,32 @@ void cpuinfo_powerpc_linux_init(void) { if (!bitmask_all(powerpc_linux_processors[processor].flags, CPUINFO_LINUX_FLAG_VALID)) { continue; } - online_status= 1; + online_status = 1; cpuinfo_linux_get_processor_online_status(processor, &online_status); if (online_status == 1) { - if (!cpuinfo_linux_detect_core_cpus( - max_processor_id, - processor, - (cpuinfo_siblings_callback)cluster_cpus_parser, - powerpc_linux_processors)) { - cpuinfo_log_warning("failed to detect cluster cpus for processor %zu.", processor); - goto cleanup; + if (!cpuinfo_linux_detect_core_cpus( + max_processor_id, + processor, + (cpuinfo_siblings_callback)cluster_cpus_parser, + powerpc_linux_processors)) { + cpuinfo_log_warning("failed to detect cluster cpus for processor %zu.", processor); + goto cleanup; + } + + /** + * Populate the vendor, uarch and frequency of this cluster from + * this core. + */ + powerpc_linux_processors[processor].cluster.vendor = + powerpc_linux_processors[processor].core.vendor; + powerpc_linux_processors[processor].cluster.uarch = + powerpc_linux_processors[processor].core.uarch; + powerpc_linux_processors[processor].cluster.frequency = + powerpc_linux_processors[processor].core.frequency; + powerpc_linux_processors[processor].cluster.pvr = powerpc_linux_processors[processor].core.pvr; } - - /** - * Populate the vendor, uarch and frequency of this cluster from - * this core. - */ - powerpc_linux_processors[processor].cluster.vendor = powerpc_linux_processors[processor].core.vendor; - powerpc_linux_processors[processor].cluster.uarch = powerpc_linux_processors[processor].core.uarch; - powerpc_linux_processors[processor].cluster.frequency = powerpc_linux_processors[processor].core.frequency; - powerpc_linux_processors[processor].cluster.pvr = powerpc_linux_processors[processor].core.pvr; } - } - /* Populate package information. */ for (size_t processor = 0; processor < max_processor_id; processor++) { @@ -374,14 +373,14 @@ void cpuinfo_powerpc_linux_init(void) { } cpuinfo_linux_get_processor_online_status(processor, &online_status); if (online_status == 1) { - if (!cpuinfo_linux_detect_package_cpus( - max_processor_id, - processor, - (cpuinfo_siblings_callback)package_cpus_parser, - powerpc_linux_processors)) { - cpuinfo_log_warning("failed to detect package cpus for processor %zu.", processor); - goto cleanup; - } + if (!cpuinfo_linux_detect_package_cpus( + max_processor_id, + processor, + (cpuinfo_siblings_callback)package_cpus_parser, + powerpc_linux_processors)) { + cpuinfo_log_warning("failed to detect package cpus for processor %zu.", processor); + goto cleanup; + } } } @@ -389,32 +388,45 @@ void cpuinfo_powerpc_linux_init(void) { for (size_t processor = 1; processor < max_processor_id; processor++) { cpuinfo_linux_get_processor_online_status(processor, &online_status); if (online_status == 1) { - if (powerpc_linux_processors[processor].package_leader_id == processor) - { - powerpc_linux_processors[processor].core.core_id = 0; - powerpc_linux_processors[processor].cluster.cluster_id = 0; - powerpc_linux_processors[processor].cluster.core_start = powerpc_linux_processors[online_processor].cluster.core_start + powerpc_linux_processors[online_processor].cluster.core_count; - powerpc_linux_processors[processor].package.core_start = powerpc_linux_processors[online_processor].package.core_start + powerpc_linux_processors[online_processor].package.core_count; - powerpc_linux_processors[processor].package.cluster_start = powerpc_linux_processors[online_processor].package.cluster_start + powerpc_linux_processors[online_processor].package.cluster_count; - } - else { - if (powerpc_linux_processors[processor].core.processor_start != powerpc_linux_processors[online_processor].core.processor_start) - powerpc_linux_processors[processor].core.core_id = powerpc_linux_processors[online_processor].core.core_id + 1; - else - powerpc_linux_processors[processor].core.core_id = powerpc_linux_processors[online_processor].core.core_id; - if (powerpc_linux_processors[processor].cluster.processor_start != powerpc_linux_processors[online_processor].cluster.processor_start) { - powerpc_linux_processors[processor].cluster.core_start = powerpc_linux_processors[online_processor].cluster.core_start + powerpc_linux_processors[online_processor].cluster.core_count; - powerpc_linux_processors[processor].cluster.cluster_id = powerpc_linux_processors[online_processor].cluster.cluster_id + 1; - } - else - { - powerpc_linux_processors[processor].cluster.core_start = powerpc_linux_processors[online_processor].cluster.core_start; - powerpc_linux_processors[processor].cluster.cluster_id = powerpc_linux_processors[online_processor].cluster.cluster_id; - } - powerpc_linux_processors[processor].package.core_start = powerpc_linux_processors[online_processor].package.core_start; - powerpc_linux_processors[processor].package.cluster_start = powerpc_linux_processors[online_processor].package.cluster_start; - } - online_processor = processor; + if (powerpc_linux_processors[processor].package_leader_id == processor) { + powerpc_linux_processors[processor].core.core_id = 0; + powerpc_linux_processors[processor].cluster.cluster_id = 0; + powerpc_linux_processors[processor].cluster.core_start = + powerpc_linux_processors[online_processor].cluster.core_start + + powerpc_linux_processors[online_processor].cluster.core_count; + powerpc_linux_processors[processor].package.core_start = + powerpc_linux_processors[online_processor].package.core_start + + powerpc_linux_processors[online_processor].package.core_count; + powerpc_linux_processors[processor].package.cluster_start = + powerpc_linux_processors[online_processor].package.cluster_start + + powerpc_linux_processors[online_processor].package.cluster_count; + } else { + if (powerpc_linux_processors[processor].core.processor_start != + powerpc_linux_processors[online_processor].core.processor_start) + powerpc_linux_processors[processor].core.core_id = + powerpc_linux_processors[online_processor].core.core_id + 1; + else + powerpc_linux_processors[processor].core.core_id = + powerpc_linux_processors[online_processor].core.core_id; + if (powerpc_linux_processors[processor].cluster.processor_start != + powerpc_linux_processors[online_processor].cluster.processor_start) { + powerpc_linux_processors[processor].cluster.core_start = + powerpc_linux_processors[online_processor].cluster.core_start + + powerpc_linux_processors[online_processor].cluster.core_count; + powerpc_linux_processors[processor].cluster.cluster_id = + powerpc_linux_processors[online_processor].cluster.cluster_id + 1; + } else { + powerpc_linux_processors[processor].cluster.core_start = + powerpc_linux_processors[online_processor].cluster.core_start; + powerpc_linux_processors[processor].cluster.cluster_id = + powerpc_linux_processors[online_processor].cluster.cluster_id; + } + powerpc_linux_processors[processor].package.core_start = + powerpc_linux_processors[online_processor].package.core_start; + powerpc_linux_processors[processor].package.cluster_start = + powerpc_linux_processors[online_processor].package.cluster_start; + } + online_processor = processor; } } @@ -443,82 +455,87 @@ void cpuinfo_powerpc_linux_init(void) { } cpuinfo_linux_get_processor_online_status(processor, &online_status); if (online_status == 1) { - /** - * All comparisons to the leader id values MUST be done against - * the 'linux_id' as opposed to 'processor'. The sort function - * above no longer allows us to make the assumption that these - * two values are the same. - */ - uint32_t linux_id = powerpc_linux_processors[processor].processor.linux_id; - - valid_processors_count++; - if (powerpc_linux_processors[processor].core_leader_id == linux_id) { - valid_cores_count++; - } - if (powerpc_linux_processors[processor].cluster_leader_id == linux_id) { - valid_clusters_count++; - } - if (powerpc_linux_processors[processor].package_leader_id == linux_id) { - valid_packages_count++; - } - /** - * As we've sorted by micro-architecture, when the uarch differs - * between two entries, a unique uarch has been observed. - */ - if (last_uarch != powerpc_linux_processors[processor].core.uarch || valid_uarchs_count == 0) { - valid_uarchs_count++; - last_uarch = powerpc_linux_processors[processor].core.uarch; - } + /** + * All comparisons to the leader id values MUST be done against + * the 'linux_id' as opposed to 'processor'. The sort function + * above no longer allows us to make the assumption that these + * two values are the same. + */ + uint32_t linux_id = powerpc_linux_processors[processor].processor.linux_id; + + valid_processors_count++; + if (powerpc_linux_processors[processor].core_leader_id == linux_id) { + valid_cores_count++; + } + if (powerpc_linux_processors[processor].cluster_leader_id == linux_id) { + valid_clusters_count++; + } + if (powerpc_linux_processors[processor].package_leader_id == linux_id) { + valid_packages_count++; + } + /** + * As we've sorted by micro-architecture, when the uarch differs + * between two entries, a unique uarch has been observed. + */ + if (last_uarch != powerpc_linux_processors[processor].core.uarch || valid_uarchs_count == 0) { + valid_uarchs_count++; + last_uarch = powerpc_linux_processors[processor].core.uarch; + } } } smt = valid_processors_count / (valid_cores_count); /* 1 cache instance for consecutive 4 even/odd threads, if core has 8 threads then 2 cache instances */ - cache_count = max_processor_id/4; + cache_count = max_processor_id / 4; /* Asiigning linux_id's for all the online processors in consecutive manner. * This is only needed in other than SMT8 modes. */ - if (smt !=8) - { - size_t online_id = 0; - for (size_t processor = 0; processor < max_processor_id; processor++) { - cpuinfo_linux_get_processor_online_status(processor, &online_status); - if (online_status == 1) { - if (online_id != powerpc_linux_processors[processor].processor.linux_id) - { - if (powerpc_linux_processors[processor].core_leader_id == powerpc_linux_processors[processor].processor.linux_id) { - powerpc_linux_processors[processor].core_leader_id = online_id; - powerpc_linux_processors[processor].core.processor_start = powerpc_linux_processors[processor].core_leader_id; + if (smt != 8) { + size_t online_id = 0; + for (size_t processor = 0; processor < max_processor_id; processor++) { + cpuinfo_linux_get_processor_online_status(processor, &online_status); + if (online_status == 1) { + if (online_id != powerpc_linux_processors[processor].processor.linux_id) { + if (powerpc_linux_processors[processor].core_leader_id == + powerpc_linux_processors[processor].processor.linux_id) { + powerpc_linux_processors[processor].core_leader_id = online_id; + powerpc_linux_processors[processor].core.processor_start = + powerpc_linux_processors[processor].core_leader_id; + } + if (powerpc_linux_processors[processor].cluster_leader_id == + powerpc_linux_processors[processor].processor.linux_id) { + powerpc_linux_processors[processor].cluster_leader_id = online_id; + powerpc_linux_processors[processor].cluster.processor_start = + powerpc_linux_processors[processor].cluster_leader_id; + } + if (powerpc_linux_processors[processor].package_leader_id == + powerpc_linux_processors[processor].processor.linux_id) { + powerpc_linux_processors[processor].package_leader_id = online_id; + powerpc_linux_processors[processor].package.processor_start = + powerpc_linux_processors[processor].package_leader_id; + } + powerpc_linux_processors[processor].processor.linux_id = online_id; + } + online_id++; + } } - if (powerpc_linux_processors[processor].cluster_leader_id == powerpc_linux_processors[processor].processor.linux_id) { - powerpc_linux_processors[processor].cluster_leader_id = online_id; - powerpc_linux_processors[processor].cluster.processor_start = powerpc_linux_processors[processor].cluster_leader_id; - } - if (powerpc_linux_processors[processor].package_leader_id == powerpc_linux_processors[processor].processor.linux_id) { - powerpc_linux_processors[processor].package_leader_id = online_id; - powerpc_linux_processors[processor].package.processor_start = powerpc_linux_processors[processor].package_leader_id; - } - powerpc_linux_processors[processor].processor.linux_id = online_id; - } - online_id++; - } - } } if (cache_count != 0) { - l1i = calloc(cache_count, sizeof(struct cpuinfo_cache)); - l1d = calloc(cache_count, sizeof(struct cpuinfo_cache)); - l2 = calloc(cache_count, sizeof(struct cpuinfo_cache)); - l3 = calloc(cache_count, sizeof(struct cpuinfo_cache)); - if (l3 == NULL) { - cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" L3 caches", - cache_count * sizeof(struct cpuinfo_cache), cache_count); - goto cleanup; - } + l1i = calloc(cache_count, sizeof(struct cpuinfo_cache)); + l1d = calloc(cache_count, sizeof(struct cpuinfo_cache)); + l2 = calloc(cache_count, sizeof(struct cpuinfo_cache)); + l3 = calloc(cache_count, sizeof(struct cpuinfo_cache)); + if (l3 == NULL) { + cpuinfo_log_error( + "failed to allocate %zu bytes for descriptions of %" PRIu32 " L3 caches", + cache_count * sizeof(struct cpuinfo_cache), + cache_count); + goto cleanup; + } } - /* Allocate and populate final public ABI structures. */ processors = calloc(valid_processors_count, sizeof(struct cpuinfo_processor)); if (processors == NULL) { @@ -600,245 +617,254 @@ void cpuinfo_powerpc_linux_init(void) { size_t valid_uarchs_index = 0; last_uarch = cpuinfo_uarch_unknown; for (size_t processor = 0; processor < max_processor_id; processor++) { - cpuinfo_linux_get_processor_online_status(processor, &online_status); - if (online_status == 1) { - if (!bitmask_all(powerpc_linux_processors[processor].flags, CPUINFO_LINUX_FLAG_VALID)) { - continue; - } - /** - * All comparisons to the leader id values MUST be done against - * the 'linux_id' as opposed to 'processor'. The sort function - * above no longer allows us to make the assumption that these - * two values are the same. + cpuinfo_linux_get_processor_online_status(processor, &online_status); + if (online_status == 1) { + if (!bitmask_all(powerpc_linux_processors[processor].flags, CPUINFO_LINUX_FLAG_VALID)) { + continue; + } + /** + * All comparisons to the leader id values MUST be done against + * the 'linux_id' as opposed to 'processor'. The sort function + * above no longer allows us to make the assumption that these + * two values are the same. + */ + uint32_t linux_id = powerpc_linux_processors[processor].processor.linux_id; + + /* Create uarch entry if this uarch has not been seen before. */ + if (last_uarch != powerpc_linux_processors[processor].core.uarch || valid_uarchs_index == 0) { + uarchs[valid_uarchs_index++].uarch = powerpc_linux_processors[processor].core.uarch; + last_uarch = powerpc_linux_processors[processor].core.uarch; + } + + /* Copy cpuinfo_processor information. */ + memcpy(&processors[valid_processors_index++], + &powerpc_linux_processors[processor].processor, + sizeof(struct cpuinfo_processor)); + + /* Update uarch processor count. */ + uarchs[valid_uarchs_index - 1].processor_count++; + + /* Copy cpuinfo_core information, if this is the leader. */ + if (powerpc_linux_processors[processor].core_leader_id == linux_id) { + memcpy(&cores[valid_cores_index++], + &powerpc_linux_processors[processor].core, + sizeof(struct cpuinfo_core)); + /* Update uarch core count. */ + uarchs[valid_uarchs_index - 1].core_count++; + } + + /* Copy cpuinfo_cluster information, if this is the leader. */ + if (powerpc_linux_processors[processor].cluster_leader_id == linux_id) { + memcpy(&clusters[valid_clusters_index++], + &powerpc_linux_processors[processor].cluster, + sizeof(struct cpuinfo_cluster)); + } + + /* Copy cpuinfo_package information, if this is the leader. */ + if (powerpc_linux_processors[processor].package_leader_id == linux_id) { + memcpy(&packages[valid_packages_index++], + &powerpc_linux_processors[processor].package, + sizeof(struct cpuinfo_package)); + } + + /* Commit pointers on the final structures. */ + processors[valid_processors_index - 1].core = &cores[valid_cores_index - 1]; + processors[valid_processors_index - 1].cluster = &clusters[valid_clusters_index - 1]; + processors[valid_processors_index - 1].package = &packages[valid_packages_index - 1]; + + cores[valid_cores_index - 1].cluster = &clusters[valid_clusters_index - 1]; + cores[valid_cores_index - 1].package = &packages[valid_packages_index - 1]; + + clusters[valid_clusters_index - 1].package = &packages[valid_packages_index - 1]; + + linux_cpu_to_processor_map[linux_id] = &processors[valid_processors_index - 1]; + linux_cpu_to_core_map[linux_id] = &cores[valid_cores_index - 1]; + linux_cpu_to_uarch_index_map[linux_id] = valid_uarchs_index - 1; + } + } + + uint32_t l1i_index = UINT32_MAX, l1d_index = UINT32_MAX, l2_index = UINT32_MAX, l3_index = UINT32_MAX; + for (uint32_t i = 0; i < valid_processors_count; i++) { + struct cpuinfo_cache temp_l1i = {0}, temp_l1d = {0}, temp_l2 = {0}, temp_l3 = {0}; + cpuinfo_powerpc_decode_cache(&temp_l1i, &temp_l1d, &temp_l2, &temp_l3); + /* Power10, even threads of a core shares 1 cache and odd threads of a core shares the another one + * test/init.cc is expecting continuous therads for cache instance so disabled the check in init.cc for + * PPC64. */ - uint32_t linux_id = powerpc_linux_processors[processor].processor.linux_id; - - /* Create uarch entry if this uarch has not been seen before. */ - if (last_uarch != powerpc_linux_processors[processor].core.uarch || valid_uarchs_index == 0) { - uarchs[valid_uarchs_index++].uarch = powerpc_linux_processors[processor].core.uarch; - last_uarch = powerpc_linux_processors[processor].core.uarch; - } - - /* Copy cpuinfo_processor information. */ - memcpy(&processors[valid_processors_index++], - &powerpc_linux_processors[processor].processor, - sizeof(struct cpuinfo_processor)); - - /* Update uarch processor count. */ - uarchs[valid_uarchs_index - 1].processor_count++; - - /* Copy cpuinfo_core information, if this is the leader. */ - if (powerpc_linux_processors[processor].core_leader_id == linux_id) { - memcpy(&cores[valid_cores_index++], - &powerpc_linux_processors[processor].core, - sizeof(struct cpuinfo_core)); - /* Update uarch core count. */ - uarchs[valid_uarchs_index - 1].core_count++; - } - - /* Copy cpuinfo_cluster information, if this is the leader. */ - if (powerpc_linux_processors[processor].cluster_leader_id == linux_id) { - memcpy(&clusters[valid_clusters_index++], - &powerpc_linux_processors[processor].cluster, - sizeof(struct cpuinfo_cluster)); - } - - /* Copy cpuinfo_package information, if this is the leader. */ - if (powerpc_linux_processors[processor].package_leader_id == linux_id) { - memcpy(&packages[valid_packages_index++], - &powerpc_linux_processors[processor].package, - sizeof(struct cpuinfo_package)); + if (temp_l1i.size != 0) { + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) { + /* new cache */ + l1i[++l1i_index] = (struct cpuinfo_cache){ + .size = temp_l1i.size, + .associativity = temp_l1i.associativity, + .sets = temp_l1i.sets, + .partitions = 1, + .line_size = temp_l1i.line_size, + .flags = temp_l1i.flags, + .processor_start = i, + .processor_count = 1, + }; + } else if ( + (smt == 8 && (i % 8 == 1)) || (smt == 4 && (i % 4 == 1)) || + (smt == 2 && (i % 2 == 1))) { + l1i[++l1i_index] = (struct cpuinfo_cache){ + .size = temp_l1i.size, + .associativity = temp_l1i.associativity, + .sets = temp_l1i.sets, + .partitions = 1, + .line_size = temp_l1i.line_size, + .flags = temp_l1i.flags, + .processor_start = i, + .processor_count = 1, + }; + } else { + /* another processor sharing the same cache. */ + if (i % 2 == 0) + l1i[l1i_index - 1].processor_count += 1; + else + l1i[l1i_index].processor_count += 1; + } + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) + processors[i].cache.l1i = &l1i[l1i_index]; + else if (i % 2 == 0) + processors[i].cache.l1i = &l1i[l1i_index - 1]; + else + processors[i].cache.l1i = &l1i[l1i_index]; + } + + if (temp_l1d.size != 0) { + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) { + /* new cache */ + l1d[++l1d_index] = (struct cpuinfo_cache){ + .size = temp_l1d.size, + .associativity = temp_l1d.associativity, + .sets = temp_l1d.sets, + .partitions = 1, + .line_size = temp_l1d.line_size, + .flags = temp_l1d.flags, + .processor_start = i, + .processor_count = 1, + }; + } else if ( + (smt == 8 && (i % 8 == 1)) || (smt == 4 && (i % 4 == 1)) || + (smt == 2 && (i % 2 == 1))) { + /* new cache */ + l1d[++l1d_index] = (struct cpuinfo_cache){ + .size = temp_l1d.size, + .associativity = temp_l1d.associativity, + .sets = temp_l1d.sets, + .partitions = 1, + .line_size = temp_l1d.line_size, + .flags = temp_l1d.flags, + .processor_start = i, + .processor_count = 1, + }; + } else { + /* another processor sharing the same cache. */ + if (i % 2 == 0) + l1d[l1d_index - 1].processor_count += 1; + else + l1d[l1d_index].processor_count += 1; + } + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) + processors[i].cache.l1d = &l1d[l1d_index]; + else if (i % 2 == 0) + processors[i].cache.l1d = &l1d[l1d_index - 1]; + else + processors[i].cache.l1d = &l1d[l1d_index]; + } + + if (temp_l2.size != 0) { + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) { + /* new cache */ + l2[++l2_index] = (struct cpuinfo_cache){ + .size = temp_l2.size, + .associativity = temp_l2.associativity, + .sets = temp_l2.sets, + .partitions = 1, + .line_size = temp_l2.line_size, + .flags = temp_l2.flags, + .processor_start = i, + .processor_count = 1, + }; + } else if ( + (smt == 8 && (i % 8 == 1)) || (smt == 4 && (i % 4 == 1)) || + (smt == 2 && (i % 2 == 1))) { + l2[++l2_index] = (struct cpuinfo_cache){ + .size = temp_l2.size, + .associativity = temp_l2.associativity, + .sets = temp_l2.sets, + .partitions = 1, + .line_size = temp_l2.line_size, + .flags = temp_l2.flags, + .processor_start = i, + .processor_count = 1, + }; + } else { + /* another processor sharing the same cache. */ + if (i % 2 == 0) + l2[l2_index - 1].processor_count += 1; + else + l2[l2_index].processor_count += 1; + } + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) + processors[i].cache.l2 = &l2[l2_index]; + else if (i % 2 == 0) + processors[i].cache.l2 = &l2[l2_index - 1]; + else + processors[i].cache.l2 = &l2[l2_index]; + } + + if (temp_l3.size != 0) { + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) { + /* new cache */ + l3[++l3_index] = (struct cpuinfo_cache){ + .size = temp_l3.size, + .associativity = temp_l3.associativity, + .sets = temp_l3.sets, + .partitions = 1, + .line_size = temp_l3.line_size, + .flags = temp_l3.flags, + .processor_start = i, + .processor_count = 1, + }; + } else if ( + (smt == 8 && (i % 8 == 1)) || (smt == 4 && (i % 4 == 1)) || + (smt == 2 && (i % 2 == 1))) { + l3[++l3_index] = (struct cpuinfo_cache){ + .size = temp_l3.size, + .associativity = temp_l3.associativity, + .sets = temp_l3.sets, + .partitions = 1, + .line_size = temp_l3.line_size, + .flags = temp_l3.flags, + .processor_start = i, + .processor_count = 1, + }; + } else { + /* another processor sharing the same cache. */ + if (i % 2 == 0) + l3[l3_index - 1].processor_count += 1; + else + l3[l3_index].processor_count += 1; + } + if ((smt == 8 && (i % 8 == 0)) || (smt == 4 && (i % 4 == 0)) || (smt == 2 && (i % 2 == 0)) || + (smt == 1)) + processors[i].cache.l3 = &l3[l3_index]; + else if (i % 2 == 0) + processors[i].cache.l3 = &l3[l3_index - 1]; + else + processors[i].cache.l3 = &l3[l3_index]; } - - /* Commit pointers on the final structures. */ - processors[valid_processors_index - 1].core = &cores[valid_cores_index - 1]; - processors[valid_processors_index - 1].cluster = &clusters[valid_clusters_index - 1]; - processors[valid_processors_index - 1].package = &packages[valid_packages_index - 1]; - - cores[valid_cores_index - 1].cluster = &clusters[valid_clusters_index - 1]; - cores[valid_cores_index - 1].package = &packages[valid_packages_index - 1]; - - clusters[valid_clusters_index - 1].package = &packages[valid_packages_index - 1]; - - linux_cpu_to_processor_map[linux_id] = &processors[valid_processors_index - 1]; - linux_cpu_to_core_map[linux_id] = &cores[valid_cores_index - 1]; - linux_cpu_to_uarch_index_map[linux_id] = valid_uarchs_index - 1; - } } - uint32_t l1i_index = UINT32_MAX, l1d_index = UINT32_MAX, l2_index = UINT32_MAX, l3_index = UINT32_MAX; - for (uint32_t i = 0; i < valid_processors_count; i++) { - struct cpuinfo_cache temp_l1i = {0}, temp_l1d = {0}, temp_l2 = {0}, temp_l3 = {0}; - cpuinfo_powerpc_decode_cache(&temp_l1i, &temp_l1d, &temp_l2, &temp_l3); - /* Power10, even threads of a core shares 1 cache and odd threads of a core shares the another one - * test/init.cc is expecting continuous therads for cache instance so disabled the check in init.cc for PPC64. - */ - if (temp_l1i.size != 0) { - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) { - /* new cache */ - l1i[++l1i_index] = (struct cpuinfo_cache){ - .size = temp_l1i.size, - .associativity = temp_l1i.associativity, - .sets = temp_l1i.sets, - .partitions = 1, - .line_size = temp_l1i.line_size, - .flags = temp_l1i.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else if ((smt == 8 && (i%8 == 1)) || (smt == 4 && (i%4 == 1)) || (smt == 2 && (i%2 == 1))) { - l1i[++l1i_index] = (struct cpuinfo_cache){ - .size = temp_l1i.size, - .associativity = temp_l1i.associativity, - .sets = temp_l1i.sets, - .partitions = 1, - .line_size = temp_l1i.line_size, - .flags = temp_l1i.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else { - /* another processor sharing the same cache. */ - if (i%2 == 0) - l1i[l1i_index-1].processor_count += 1; - else - l1i[l1i_index].processor_count += 1; - } - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) - processors[i].cache.l1i = &l1i[l1i_index]; - else if (i%2 == 0) - processors[i].cache.l1i = &l1i[l1i_index-1]; - else - processors[i].cache.l1i = &l1i[l1i_index]; - } - - if (temp_l1d.size != 0) { - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) { - /* new cache */ - l1d[++l1d_index] = (struct cpuinfo_cache){ - .size = temp_l1d.size, - .associativity = temp_l1d.associativity, - .sets = temp_l1d.sets, - .partitions = 1, - .line_size = temp_l1d.line_size, - .flags = temp_l1d.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else if ((smt == 8 && (i%8 == 1)) || (smt == 4 && (i%4 == 1)) || (smt == 2 && (i%2 == 1))) { - /* new cache */ - l1d[++l1d_index] = (struct cpuinfo_cache){ - .size = temp_l1d.size, - .associativity = temp_l1d.associativity, - .sets = temp_l1d.sets, - .partitions = 1, - .line_size = temp_l1d.line_size, - .flags = temp_l1d.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else { - /* another processor sharing the same cache. */ - if (i%2 == 0) - l1d[l1d_index-1].processor_count += 1; - else - l1d[l1d_index].processor_count += 1; - } - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) - processors[i].cache.l1d = &l1d[l1d_index]; - else if (i%2 == 0) - processors[i].cache.l1d = &l1d[l1d_index-1]; - else - processors[i].cache.l1d = &l1d[l1d_index]; - } - - if (temp_l2.size != 0) { - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) { - /* new cache */ - l2[++l2_index] = (struct cpuinfo_cache){ - .size = temp_l2.size, - .associativity = temp_l2.associativity, - .sets = temp_l2.sets, - .partitions = 1, - .line_size = temp_l2.line_size, - .flags = temp_l2.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else if ((smt == 8 && (i%8 == 1)) || (smt == 4 && (i%4 == 1)) || (smt == 2 && (i%2 == 1))) { - l2[++l2_index] = (struct cpuinfo_cache){ - .size = temp_l2.size, - .associativity = temp_l2.associativity, - .sets = temp_l2.sets, - .partitions = 1, - .line_size = temp_l2.line_size, - .flags = temp_l2.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else { - /* another processor sharing the same cache. */ - if (i%2 == 0) - l2[l2_index-1].processor_count += 1; - else - l2[l2_index].processor_count += 1; - } - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) - processors[i].cache.l2 = &l2[l2_index]; - else if (i%2 == 0) - processors[i].cache.l2 = &l2[l2_index-1]; - else - processors[i].cache.l2 = &l2[l2_index]; - } - - if (temp_l3.size != 0) { - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) { - /* new cache */ - l3[++l3_index] = (struct cpuinfo_cache){ - .size = temp_l3.size, - .associativity = temp_l3.associativity, - .sets = temp_l3.sets, - .partitions = 1, - .line_size = temp_l3.line_size, - .flags = temp_l3.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else if ((smt == 8 && (i%8 == 1)) || (smt == 4 && (i%4 == 1)) || (smt == 2 && (i%2 == 1))) { - l3[++l3_index] = (struct cpuinfo_cache){ - .size = temp_l3.size, - .associativity = temp_l3.associativity, - .sets = temp_l3.sets, - .partitions = 1, - .line_size = temp_l3.line_size, - .flags = temp_l3.flags, - .processor_start = i, - .processor_count = 1, - }; - } - else { - /* another processor sharing the same cache. */ - if (i%2 ==0 ) - l3[l3_index-1].processor_count += 1; - else - l3[l3_index].processor_count += 1; - } - if ((smt == 8 && (i%8 == 0)) || (smt == 4 && (i%4 == 0)) || (smt == 2 && (i%2 == 0)) || (smt ==1)) - processors[i].cache.l3 = &l3[l3_index]; - else if ( i%2 == 0) - processors[i].cache.l3 = &l3[l3_index-1]; - else - processors[i].cache.l3 = &l3[l3_index]; - } - } - cpuinfo_processors = processors; cpuinfo_processors_count = valid_processors_count; cpuinfo_cores = cores; @@ -852,8 +878,8 @@ void cpuinfo_powerpc_linux_init(void) { cpuinfo_cache[cpuinfo_cache_level_1i] = l1i; cpuinfo_cache[cpuinfo_cache_level_1d] = l1d; - cpuinfo_cache[cpuinfo_cache_level_2] = l2; - cpuinfo_cache[cpuinfo_cache_level_3] = l3; + cpuinfo_cache[cpuinfo_cache_level_2] = l2; + cpuinfo_cache[cpuinfo_cache_level_3] = l3; cpuinfo_linux_cpu_max = valid_processors_count; cpuinfo_linux_cpu_to_processor_map = linux_cpu_to_processor_map; cpuinfo_linux_cpu_to_core_map = linux_cpu_to_core_map; @@ -861,8 +887,8 @@ void cpuinfo_powerpc_linux_init(void) { cpuinfo_cache_count[cpuinfo_cache_level_1i] = cache_count; cpuinfo_cache_count[cpuinfo_cache_level_1d] = cache_count; - cpuinfo_cache_count[cpuinfo_cache_level_2] = cache_count; - cpuinfo_cache_count[cpuinfo_cache_level_3] = cache_count; + cpuinfo_cache_count[cpuinfo_cache_level_2] = cache_count; + cpuinfo_cache_count[cpuinfo_cache_level_3] = cache_count; __sync_synchronize(); cpuinfo_is_initialized = true; @@ -877,7 +903,7 @@ void cpuinfo_powerpc_linux_init(void) { linux_cpu_to_processor_map = NULL; linux_cpu_to_core_map = NULL; linux_cpu_to_uarch_index_map = NULL; - l1i = l1d = l2 = l3 = NULL; + l1i = l1d = l2 = l3 = NULL; cleanup: free(powerpc_linux_processors); free(processors); diff --git a/src/powerpc/linux/ppc64-hw.c b/src/powerpc/linux/ppc64-hw.c index c7f1ddb1..6d7140f0 100644 --- a/src/powerpc/linux/ppc64-hw.c +++ b/src/powerpc/linux/ppc64-hw.c @@ -1,36 +1,35 @@ #include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include #if CPUINFO_MOCK - #include +#include #endif #include -#include #include +#include #include #if CPUINFO_MOCK - static uint32_t mock_hwcap = 0; - void cpuinfo_set_hwcap(uint32_t hwcap) { - mock_hwcap = hwcap; - } +static uint32_t mock_hwcap = 0; +void cpuinfo_set_hwcap(uint32_t hwcap) { + mock_hwcap = hwcap; +} #endif -void cpuinfo_powerpc_linux_hwcap_from_getauxval(uint32_t isa_feature[]) -{ - #if CPUINFO_MOCK - isa_feature[0] = mock_hwcap; - #else - isa_feature[0] = (uint32_t) getauxval(AT_HWCAP); - isa_feature[1] = (uint32_t) getauxval(AT_HWCAP2); - #endif +void cpuinfo_powerpc_linux_hwcap_from_getauxval(uint32_t isa_feature[]) { +#if CPUINFO_MOCK + isa_feature[0] = mock_hwcap; +#else + isa_feature[0] = (uint32_t)getauxval(AT_HWCAP); + isa_feature[1] = (uint32_t)getauxval(AT_HWCAP2); +#endif } diff --git a/src/powerpc/linux/ppc64-isa.c b/src/powerpc/linux/ppc64-isa.c index c86ff244..ecc30723 100644 --- a/src/powerpc/linux/ppc64-isa.c +++ b/src/powerpc/linux/ppc64-isa.c @@ -1,13 +1,13 @@ #include -#include #include +#include void cpuinfo_ppc64_linux_decode_isa_from_hwcap( - uint32_t features, uint32_t features2, - struct cpuinfo_powerpc_isa isa[restrict static 1]) -{ - isa->vsx=!!(features & CPUINFO_POWERPC_LINUX_FEATURE_HAS_VSX); - isa->htm=!!(features2 & CPUINFO_POWERPC_LINUX_FEATURE_HTM); - isa->mma=!!(features2 & CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMA); + uint32_t features, + uint32_t features2, + struct cpuinfo_powerpc_isa isa[restrict static 1]) { + isa->vsx = !!(features & CPUINFO_POWERPC_LINUX_FEATURE_HAS_VSX); + isa->htm = !!(features2 & CPUINFO_POWERPC_LINUX_FEATURE_HTM); + isa->mma = !!(features2 & CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMA); } diff --git a/test/name/power-features.cc b/test/name/power-features.cc index 8f039de0..4cb23a41 100644 --- a/test/name/power-features.cc +++ b/test/name/power-features.cc @@ -7,35 +7,35 @@ extern "C" inline bool cpuinfo_has_powerpc_vsx(void); extern "C" inline bool cpuinfo_has_powerpc_htm(void); extern "C" inline bool cpuinfo_has_powerpc_mma(void); -#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1 UINT32_C(0x00040000) //To check if the architecture is Power10 -#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00 UINT32_C(0x00800000) //To check if the architecture is Power9 -#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07 UINT32_C(0x80000000) //To check if the architecture is Power8 +#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1 UINT32_C(0x00040000) // To check if the architecture is Power10 +#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00 UINT32_C(0x00800000) // To check if the architecture is Power9 +#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07 UINT32_C(0x80000000) // To check if the architecture is Power8 -TEST(PowerFeatures, Power){ +TEST(PowerFeatures, Power) { if (!cpuinfo_initialize()) { fprintf(stderr, "failed to initialize CPU information\n"); exit(1); } - #if CPUINFO_MOCK - int a = mock_hwcap; - #else - int a = (uint32_t) getauxval(AT_HWCAP); - int b = (uint32_t) getauxval(AT_HWCAP2); - #endif //CPUINFO_MOCK // +#if CPUINFO_MOCK + int a = mock_hwcap; +#else + int a = (uint32_t)getauxval(AT_HWCAP); + int b = (uint32_t)getauxval(AT_HWCAP2); +#endif // CPUINFO_MOCK // - #if (b & CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1) - EXPECT_EQ(0, cpuinfo_has_powerpc_htm()); - EXPECT_EQ(1, cpuinfo_has_powerpc_mma()); - EXPECT_EQ(1, cpuinfo_has_powerpc_vsx()); - #elif (b & CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00) - EXPECT_EQ(0, cpuinfo_has_powerpc_htm()); - EXPECT_EQ(0, cpuinfo_has_powerpc_mma()); - EXPECT_EQ(1, cpuinfo_has_powerpc_vsx()); - #elif (b & CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07) - EXPECT_EQ(1, cpuinfo_has_powerpc_htm()); - EXPECT_EQ(0, cpuinfo_has_powerpc_mma()); - EXPECT_EQ(1, cpuinfo_has_powerpc_vsx()); - #endif +#if (b & CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1) + EXPECT_EQ(0, cpuinfo_has_powerpc_htm()); + EXPECT_EQ(1, cpuinfo_has_powerpc_mma()); + EXPECT_EQ(1, cpuinfo_has_powerpc_vsx()); +#elif (b & CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00) + EXPECT_EQ(0, cpuinfo_has_powerpc_htm()); + EXPECT_EQ(0, cpuinfo_has_powerpc_mma()); + EXPECT_EQ(1, cpuinfo_has_powerpc_vsx()); +#elif (b & CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07) + EXPECT_EQ(1, cpuinfo_has_powerpc_htm()); + EXPECT_EQ(0, cpuinfo_has_powerpc_mma()); + EXPECT_EQ(1, cpuinfo_has_powerpc_vsx()); +#endif cpuinfo_deinitialize(); }