]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lscpu: Fix issue found on CPU hot-remove
authorToshi Kani <toshi.kani@hp.com>
Tue, 23 Oct 2012 19:49:46 +0000 (13:49 -0600)
committerKarel Zak <kzak@redhat.com>
Mon, 12 Nov 2012 13:47:13 +0000 (14:47 +0100)
commita5cfffff28a4eb10604750b0f1f4e8696af3947c
tree854c3233656e3c7f1f031efa3e6d98a38ed487a3
parent65178cb3f24c02f902869a102cd0456aa917bb03
lscpu: Fix issue found on CPU hot-remove

read_basicinfo() relies on sysfs cpu directories
"/sys/devices/system/cpu/cpu%d" with assumption that cpu
logical number %d is always sequentially assigned for all
CPUs. However, this assumption is not correct with CPU
hot-remove operation since it removes a target sysfs cpu
directory after it is ejected. As a result, lscpu may not
recognize all CPUs.

The issue can be easily reproduced on KVM or VirtualBox,
which supports CPU eject operation, as follows.

1) The system has 4 CPUs
  $ lscpu -a -e
  CPU NODE SOCKET CORE L1d:L1i:L2 ONLINE
  0   0    0      0    0:0:0      yes
  1   0    1      1    1:1:1      yes
  2   0    2      2    2:2:2      yes
  3   0    3      3    3:3:3      yes

2) Eject cpu2
  # echo 1 > /sys/bus/acpi/devices/LNXCPU:02/eject

3) lscpu no longer recognizes cpu3 after cpu2 is ejected
  $ lscpu -a -e
  CPU NODE SOCKET CORE L1d:L1i:L2 ONLINE
  0   0    0      0    0:0:0      yes
  1   0    1      1    1:1:1      yes

The following changes are made to address this issue.
 - Use maxcpus to allocate and parse bitmaps.
 - Set desc->ncpu from cpu/present, which includes both on-line
   and off-line CPUs.
 - Add is_cpu_present() to check if a CPU is present. Ejected
   CPUs are not present.

[kzak@redhat.com: - read also /sys/devices/system/cpu/possible mask to
                    determine maximal number of CPUs,
                  - err() if possible mask is not found in /sys]

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c