commit dee15756bcb287ccf39a904be07c90107b13844b Author: Laurent Dufour Date: Wed May 3 10:50:15 2023 +0200 lparstat: Fix offline threads uninitialized entries When some threads are offline, lparstat -E is failing like that: $ ppc64_cpu --info # CPU 20 is offline 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* $ lparstat -E Failed to read /sys/devices/system/cpu/cpu0/spurr The message is complaining about CPU0 but the real issue is that in parse_sysfs_values() the test cpu_sysfs_fds[i].spurr >= 0 is valid even if the entry has not been initialized (cpu_sysfs_fds is alloc cleared). So if the number of threads online seen in assign_cpu_sysfs_fds is lower than threads_in_system, the loop in parse_sysfs_values() will read uninitialized entry, where .cpu=0. To prevent that, unset entries in the cpu_sysfs_fds should have the spurr fd set to -1. Signed-off-by: Laurent Dufour Signed-off-by: Tyrel Datwyler diff --git a/src/lparstat.c b/src/lparstat.c index a9e7bce..d2fdb3f 100644 --- a/src/lparstat.c +++ b/src/lparstat.c @@ -163,6 +163,10 @@ static int assign_cpu_sysfs_fds(int threads_in_system) cpu_idx++; } + /* Mark extra slots for offline threads unset, see parse_sysfs_values */ + for (; cpu_idx < threads_in_system; cpu_idx++) + cpu_sysfs_fds[cpu_idx].spurr = -1; + return 0; error: fprintf(stderr, "Failed to open %s: %s\n",