Skip to content

Commit 273c798

Browse files
PPC64le:This patch introduces the following updates.
Fixes incorrect processor linux_ids when running in modes other than SMT8. Corrects cache count reporting when SMT is disabled. Removed the cpuinfo_linux_get_processor_online_status and added it in the powerpc specific code and optimized the usage of it. Cleans up the codebase to improve readability and maintainability.
1 parent 33cc865 commit 273c798

File tree

11 files changed

+190
-151
lines changed

11 files changed

+190
-151
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ IF(CPUINFO_SUPPORTED_PLATFORM)
190190
src/powerpc/cache.c
191191
src/powerpc/linux/cpuinfo.c
192192
src/powerpc/linux/ppc64-hw.c
193+
src/powerpc/linux/processors.c
193194
src/powerpc/linux/init.c
194195
src/powerpc/linux/ppc64-isa.c)
195196
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "^Windows" AND CPUINFO_TARGET_PROCESSOR MATCHES "^(ARM64|arm64)$")

configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def main(args):
8181
sources += [
8282
"powerpc/linux/cpuinfo.c"
8383
"powerpc/linux/ppc64-hw.c",
84+
"powerpc/linux/processors.c",
8485
"powerpc/linux/init.c",
8586
"powerpc/linux/ppc64-isa.c",
8687
]

include/cpuinfo.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,12 @@ enum cpuinfo_uarch {
602602
/** HiSilicon TaiShan v110 (Huawei Kunpeng 920 series processors). */
603603
cpuinfo_uarch_taishan_v110 = 0x00C00100,
604604

605-
/** IBM POWER 7. */
606-
cpuinfo_uarch_power7 = 0x00D00100,
607-
/** IBM POWER 7p. */
608-
cpuinfo_uarch_power7p = 0x00D00101,
609-
/** IBM POWER 8. */
610-
cpuinfo_uarch_power8 = 0x00D00200,
611-
/** IBM POWER8E. */
612-
cpuinfo_uarch_power8e = 0x00D00201,
613-
/** IBM POWER8NVL */
614-
cpuinfo_uarch_power8nvl = 0x00D00202,
615605
/** IBM POWER 9. */
616-
cpuinfo_uarch_power9 = 0x00D00303,
606+
cpuinfo_uarch_power9 = 0x00D00100,
617607
/** IBM POWER 10. */
618-
cpuinfo_uarch_power10 = 0x00D00400,
608+
cpuinfo_uarch_power10 = 0x00D00200,
609+
/** IBM POWER11. */
610+
cpuinfo_uarch_power11 = 0x00D00300,
619611
};
620612

621613
struct cpuinfo_processor {

src/linux/api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ CPUINFO_INTERNAL bool cpuinfo_linux_get_processor_package_id(
5151
uint32_t processor,
5252
uint32_t package_id[restrict static 1]);
5353
CPUINFO_INTERNAL bool cpuinfo_linux_get_processor_core_id(uint32_t processor, uint32_t core_id[restrict static 1]);
54-
CPUINFO_INTERNAL bool cpuinfo_linux_get_processor_online_status(uint32_t processor, uint32_t* online_status);
5554

5655
CPUINFO_INTERNAL bool cpuinfo_linux_detect_possible_processors(
5756
uint32_t max_processors_count,

src/linux/processors.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
#define CORE_ID_FILENAME_FORMAT "/sys/devices/system/cpu/cpu%" PRIu32 "/topology/core_id"
3434
#define CORE_ID_FILESIZE 32
3535

36-
#define PROCESSOR_ONLINE_FILENAME_SIZE (sizeof("/sys/devices/system/cpu/cpu" STRINGIFY(UINT32_MAX) "/online"))
37-
#define PROCESSOR_ONLINE_FILENAME_FORMAT "/sys/devices/system/cpu/cpu%" PRIu32 "/online"
38-
#define PROCESSOR_ONLINE_FILESIZE 32
3936
#define CORE_CPUS_FILENAME_SIZE (sizeof("/sys/devices/system/cpu/cpu" STRINGIFY(UINT32_MAX) "/topology/core_cpus_list"))
4037
#define CORE_CPUS_FILENAME_FORMAT "/sys/devices/system/cpu/cpu%" PRIu32 "/topology/core_cpus_list"
4138
#define CORE_SIBLINGS_FILENAME_SIZE \
@@ -283,33 +280,6 @@ bool cpuinfo_linux_get_processor_package_id(uint32_t processor, uint32_t package
283280
}
284281
}
285282

286-
bool cpuinfo_linux_get_processor_online_status(uint32_t processor, uint32_t* online_status_ptr) {
287-
char processor_online_filename[PROCESSOR_ONLINE_FILENAME_SIZE];
288-
const int chars_formatted = snprintf(
289-
processor_online_filename, PROCESSOR_ONLINE_FILENAME_SIZE, PROCESSOR_ONLINE_FILENAME_FORMAT, processor);
290-
if ((unsigned int)chars_formatted >= PROCESSOR_ONLINE_FILENAME_SIZE) {
291-
cpuinfo_log_warning("failed to format filename for online status of processor %" PRIu32, processor);
292-
return 0;
293-
}
294-
uint32_t online_status;
295-
if (cpuinfo_linux_parse_small_file(
296-
processor_online_filename, PROCESSOR_ONLINE_FILESIZE, uint32_parser, &online_status)) {
297-
cpuinfo_log_debug(
298-
"parsed online status value of %" PRIu32 " for logical processor %" PRIu32 " from %s",
299-
online_status,
300-
processor,
301-
processor_online_filename);
302-
*online_status_ptr = online_status;
303-
return true;
304-
} else {
305-
cpuinfo_log_info(
306-
"failed to parse online status for processor %" PRIu32 " from %s",
307-
processor,
308-
processor_online_filename);
309-
return false;
310-
}
311-
}
312-
313283
static bool max_processor_number_parser(uint32_t processor_list_start, uint32_t processor_list_end, void* context) {
314284
uint32_t* processor_number_ptr = (uint32_t*)context;
315285
const uint32_t processor_list_last = processor_list_end - 1;

src/powerpc/linux/api.h

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,19 @@
1-
2-
31
#pragma once
4-
5-
#include <stdbool.h>
6-
#include <stdint.h>
7-
82
#include <cpuinfo.h>
93
#include <cpuinfo/common.h>
104
#include <linux/api.h>
115
#include <powerpc/api.h>
6+
#include <stdbool.h>
7+
#include <stdint.h>
8+
9+
CPUINFO_INTERNAL bool cpuinfo_linux_get_processor_online_status(uint32_t processor, uint32_t* online_status);
1210

1311
/* No hard limit in the kernel, maximum length observed on non-rogue kernels is 64 */
1412
#define CPUINFO_HARDWARE_VALUE_MAX 64
1513

1614
/* from /arch/powerpc/kernel/cputable.c */
17-
#define CPUINFO_POWERPC_LINUX_FEATURE_64 UINT32_C(0x40000000)
18-
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_ALTIVEC UINT32_C(0x10000000)
19-
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_FPU UINT32_C(0x08000000)
20-
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMU UINT32_C(0x04000000)
21-
#define CPUINFO_POWERPC_LINUX_FEATURE_NO_TB UINT32_C(0x00100000)
22-
#define CPUINFO_POWERPC_LINUX_FEATURE_SMT UINT32_C(0x00004000)
23-
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_DFP UINT32_C(0x00000400)
24-
#define CPUINFO_POWERPC_LINUX_FEATURE_POWER6_EXT UINT32_C(0x00000200)
2515
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_VSX UINT32_C(0x00000080)
26-
#define CPUINFO_POWERPC_LINUX_FEATURE_TRUE_LE UINT32_C(0x00000002)
27-
#define CPUINFO_POWERPC_LINUX_FEATURE_PPC_LE UINT32_C(0x00000001
28-
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_2_07 UINT32_C(0x80000000)
2916
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM UINT32_C(0x40000000)
30-
#define CPUINFO_POWERPC_LINUX_FEATURE_DSCR UINT32_C(0x20000000)
31-
#define CPUINFO_POWERPC_LINUX_FEATURE_EBB UINT32_C(0x10000000)
32-
#define CPUINFO_POWERPC_LINUX_FEATURE_ISEL UINT32_C(0x08000000)
33-
#define CPUINFO_POWERPC_LINUX_FEATURE_TAR UINT32_C(0x04000000)
34-
#define CPUINFO_POWERPC_LINUX_FEATURE_VEC_CRYPTO UINT32_C(0x02000000)
35-
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NOSC UINT32_C(0x01000000)
36-
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_00 UINT32_C(0x00800000)
37-
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_IEEE128 UINT32_C(0x00400000)
38-
#define CPUINFO_POWERPC_LINUX_FEATURE_DARN UINT32_C(0x00200000)
39-
#define CPUINFO_POWERPC_LINUX_FEATURE_SCV UINT32_C(0x00100000)
40-
#define CPUINFO_POWERPC_LINUX_FEATURE_HTM_NO_SUSPEND UINT32_C(0x00080000)
41-
#define CPUINFO_POWERPC_LINUX_FEATURE_ARCH_3_1 UINT32_C(0x00040000)
4217
#define CPUINFO_POWERPC_LINUX_FEATURE_HAS_MMA UINT32_C(0x00020000)
4318

4419
#define CPUINFO_POWERPC_LINUX_VALID_ARCHITECTURE UINT32_C(0x00010000)
@@ -90,6 +65,7 @@ struct cpuinfo_powerpc_linux_processor {
9065
* package.
9166
*/
9267
uint32_t package_leader_id;
68+
bool online_status;
9369
};
9470

9571
/**

src/powerpc/linux/cpuinfo.c

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -73,53 +73,26 @@ static void parse_cpu_architecture(
7373
}
7474

7575
switch (arch_version) {
76-
case 7: /* POWER7 */
77-
if (*cpu_arch_ptr == ' ') {
78-
processor->core.uarch = cpuinfo_uarch_power7;
79-
} else if (*cpu_arch_ptr == '+') {
80-
processor->core.uarch = cpuinfo_uarch_power7p;
81-
cpu_arch_ptr++;
82-
} else {
83-
goto unsupported;
84-
}
85-
break;
86-
case 8: /* POWER8 */
87-
if (*cpu_arch_ptr == ' ') {
88-
processor->core.uarch = cpuinfo_uarch_power8;
89-
} else if (*cpu_arch_ptr == 'E') {
90-
processor->core.uarch = cpuinfo_uarch_power8e;
91-
cpu_arch_ptr++;
92-
} else if (*cpu_arch_ptr == 'N') {
93-
cpu_arch_ptr++;
94-
if (*cpu_arch_ptr == 'V') {
95-
cpu_arch_ptr++;
96-
}
97-
if (*cpu_arch_ptr == 'L') {
98-
processor->core.uarch = cpuinfo_uarch_power8nvl;
99-
cpu_arch_ptr++;
100-
}
101-
}
102-
if (*cpu_arch_ptr != ' ') {
103-
goto unsupported;
104-
}
105-
break;
10676
case 9: /* POWER9 */
10777
processor->core.uarch = cpuinfo_uarch_power9;
10878
break;
10979
case 10: /* POWER10 */
11080
processor->core.uarch = cpuinfo_uarch_power10;
11181
break;
82+
case 11: /* POWER11 */
83+
processor->core.uarch = cpuinfo_uarch_power11;
84+
break;
11285
default:
11386
unsupported:
114-
cpuinfo_log_warning(
87+
cpuinfo_log_error(
11588
"CPU architecture %.*s in /proc/cpuinfo is ignored due to a unsupported architecture version",
11689
(int)(cpu_architecture_end - cpu_architecture_start),
11790
cpu_architecture_start);
11891
}
11992
processor->flags |= CPUINFO_POWERPC_LINUX_VALID_PROCESSOR;
12093
} else {
12194
cpuinfo_log_warning(
122-
"processor %.*s in /proc/cpuinfo is ignored due not a Power processor",
95+
"processor %.*s in /proc/cpuinfo is ignored due to not a Power processor",
12396
(int)(cpu_architecture_end - cpu_architecture_start),
12497
cpu_architecture_start);
12598
}
@@ -281,33 +254,36 @@ static bool parse_line(
281254
if (memcmp(line_start, "cpu", key_length) == 0) {
282255
parse_cpu_architecture(value_start, value_end, processor);
283256
} else {
284-
goto unknown;
257+
cpuinfo_log_debug("unknown /proc/cpuinfo key: %.*s", (int)key_length, line_start);
285258
}
286259
break;
287260
case 5:
288261
if (memcmp(line_start, "clock", key_length) == 0) {
289262
parse_cpu_architecture(value_start, value_end, processor);
290263
} else {
291-
goto unknown;
264+
cpuinfo_log_debug("unknown /proc/cpuinfo key: %.*s", (int)key_length, line_start);
292265
}
266+
break;
293267
case 7:
294268
if (memcmp(line_start, "machine", key_length) == 0) {
295269
parse_cpu_architecture(value_start, value_end, processor);
296270
} else {
297-
goto unknown;
271+
cpuinfo_log_debug("unknown /proc/cpuinfo key: %.*s", (int)key_length, line_start);
298272
}
273+
break;
299274
case 8:
300275
if (memcmp(line_start, "revision", key_length) == 0) {
301276
parse_cpu_pvr(value_start, value_end, processor);
302277
} else {
303-
goto unknown;
278+
cpuinfo_log_debug("unknown /proc/cpuinfo key: %.*s", (int)key_length, line_start);
304279
}
280+
break;
305281
case 9:
306282
if (memcmp(line_start, "processor", key_length) == 0) {
307283
state->processor_index = parse_processor_number(value_start, value_end);
308284
return true;
309285
} else {
310-
goto unknown;
286+
cpuinfo_log_debug("unknown /proc/cpuinfo key: %.*s", (int)key_length, line_start);
311287
}
312288
break;
313289
default:

0 commit comments

Comments
 (0)