This problem was observed on an x86_64 Mobile AMD Sempron 3700+ where kernel_max
returned "0" as the index of the highest CPU.
As a consequence, several variables in lscpu, which relied on maxcpus >= 1 (in
particular the 'len' value) were set to 0, resulting in the following errors:
host>./lscpu
lscpu: failed to read: /sys/devices/system/cpu/online: No such file or directory
host> cat /sys/devices/system/cpu/kernel_max
0
The fix used by this patch is to interpret kernel_max as an index and maxcpus as
a count >= 1, tested to work.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Karel Zak <kzak@redhat.com>
fclose(fp);
if (path_exist(_PATH_SYS_SYSTEM "/cpu/kernel_max"))
- maxcpus = path_getnum(_PATH_SYS_SYSTEM "/cpu/kernel_max");
+ /* note that kernel_max is maximum index [NR_CPUS-1] */
+ maxcpus = path_getnum(_PATH_SYS_SYSTEM "/cpu/kernel_max") + 1;
else if (!sysrootlen)
/* the root is '/' so we are working with data from the current kernel */