Skip to content

Commit f1a8ed8

Browse files
ldu4tyreld
authored andcommitted
ppc64_cpu/info: fix bad report when non continuous CPU ids
When CPU ids are not continuous, let say that the kernel didn't reuse a set of CPU ids already used on a different nodes, the output of ppc64_cpu --info is not correct. For instance, in the example below the CPU id 48 to 55 haven't been reused by the kernel when a CPU has been added after a LPM operation. Note that the system is running in SMT=4. The numactl -H command is providing the correct set of CPU: ltczep3-lp4:~ # numactl -H available: 2 nodes (0-1) node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 64 65 66 67 68 69 70 71 node 0 size: 7177 MB node 0 free: 4235 MB node 1 cpus: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 node 1 size: 24508 MB node 1 free: 23539 MB node distances: node 0 1 0: 10 40 1: 40 10 But ppc64_cpu --info is reporting the CPUs 48 to 55 offlined while not reporting at all the CPU 65 to 71: ltczep3-lp4:~ # ppc64_cpu --info Core 0: 0* 1* 2* 3* 4* 5* 6* 7* Core 1: 8* 9* 10* 11* 12* 13* 14* 15* Core 2: 16* 17* 18* 19* 20* 21* 22* 23* Core 3: 24* 25* 26* 27* 28* 29* 30* 31* Core 4: 32* 33* 34* 35* 36* 37* 38* 39* Core 5: 40* 41* 42* 43* 44* 45* 46* 47* Core 6: 48 49 50 51 52 53 54 55 This is because it is considering that the CPU id are continuous which is not the case here. To prevent that, when looking for a core, it is now first checking that the physical_id of the first thread in that core is defined (not -1). If that the case this means that CPU/core is present. With that patch applied, ppc64_cpu --info is reporting: ltczep3-lp4:~ # pc64_cpu --info Core 0: 0* 1* 2* 3* 4 5 6 7 Core 1: 8* 9* 10* 11* 12 13 14 15 Core 2: 16* 17* 18* 19* 20 21 22 23 Core 3: 24* 25* 26* 27* 28 29 30 31 Core 4: 32* 33* 34* 35* 36 37 38 39 Core 5: 40* 41* 42* 43* 44 45 46 47 Core 6: 64* 65* 66* 67* 68 69 70 71 Signed-off-by: Laurent Dufour <[email protected]> Signed-off-by: Tyrel Datwyler <[email protected]>
1 parent d604cc7 commit f1a8ed8

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/common/cpu_info_helpers.c

+14
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ int __sysattr_is_writeable(char *attribute, int threads_in_system)
8383
return test_sysattr(attribute, W_OK, threads_in_system);
8484
}
8585

86+
int cpu_physical_id(int thread)
87+
{
88+
char path[SYSFS_PATH_MAX];
89+
int rc, physical_id;
90+
91+
sprintf(path, SYSFS_CPUDIR"/physical_id", thread);
92+
rc = get_attribute(path, "%d", &physical_id);
93+
94+
/* This attribute does not exist in kernels without hotplug enabled */
95+
if (rc && errno == ENOENT)
96+
return -1;
97+
return physical_id;
98+
}
99+
86100
int cpu_online(int thread)
87101
{
88102
char path[SYSFS_PATH_MAX];

src/common/cpu_info_helpers.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
extern int __sysattr_is_readable(char *attribute, int threads_in_system);
3434
extern int __sysattr_is_writeable(char *attribute, int threads_in_system);
35+
extern int cpu_physical_id(int thread);
3536
extern int cpu_online(int thread);
3637
extern int is_subcore_capable(void);
3738
extern int num_subcores(void);

src/ppc64_cpu.c

+17-8
Original file line numberDiff line numberDiff line change
@@ -1251,31 +1251,40 @@ static int do_cores_on(char *state)
12511251
return 0;
12521252
}
12531253

1254+
static bool core_is_online(int core)
1255+
{
1256+
return cpu_physical_id(core * threads_per_cpu) != -1;
1257+
}
1258+
12541259
static int do_info(void)
12551260
{
12561261
int i, j, thread_num;
12571262
char online;
1258-
int subcores = 0;
1263+
int core, subcores = 0;
12591264

12601265
if (is_subcore_capable())
12611266
subcores = num_subcores();
12621267

1263-
for (i = 0; i < cpus_in_system; i++) {
1268+
for (i = 0, core = 0; core < cpus_in_system; i++) {
1269+
1270+
if (!core_is_online(i))
1271+
continue;
12641272

12651273
if (subcores > 1) {
1266-
if (i % subcores == 0)
1267-
printf("Core %3d:\n", i/subcores);
1268-
printf(" Subcore %3d: ", i);
1274+
if (core % subcores == 0)
1275+
printf("Core %3d:\n", core/subcores);
1276+
printf(" Subcore %3d: ", core);
12691277
} else {
1270-
printf("Core %3d: ", i);
1278+
printf("Core %3d: ", core);
12711279
}
12721280

1273-
for (j = 0; j < threads_per_cpu; j++) {
1274-
thread_num = i*threads_per_cpu + j;
1281+
thread_num = i * threads_per_cpu;
1282+
for (j = 0; j < threads_per_cpu; j++, thread_num++) {
12751283
online = cpu_online(thread_num) ? '*' : ' ';
12761284
printf("%4d%c ", thread_num, online);
12771285
}
12781286
printf("\n");
1287+
core++;
12791288
}
12801289
return 0;
12811290
}

0 commit comments

Comments
 (0)