Commit graph

3 commits

Author SHA1 Message Date
Daniel Eklöf
62ca06eccb
module/cpu: don’t use core ID from /proc/stat as array index
/proc/stat lists CPU usage, in the form:

  cpu ...
  cpu0 ...
  cpu1 ...
  ...
  cpuN ...

where the first line is a summary line. We’ve been using the CPU
numbers from /proc/stat to index into our internal stats array.

This doesn’t work on systems where the core IDs aren’t
consecutive. Examples of such systems are SMT systems with SMT
disabled. Here, /proc/stat may look like this instead:

  cpu ...
  cpu0 ...
  cpu2 ...
  cpu4 ...
  ...

With this patch, we ignore the CPU ID from /proc/stat. Instead, we use
a simple counter that is incremented for each (valid) cpu line found
in /proc/stat. To protect against corrupt /proc/stat content, stop
parsing /proc/stat if the number of parsed CPU lines exceed what we
consider to the be total number of CPUs in the system.

Closes #172
2022-04-07 13:28:35 +02:00
Daniel Eklöf
fce2787bdf
module/cpu: use get_nprocs() to retrieve the CPU count 2022-04-07 13:21:41 +02:00
Alexandre Acebedo
ae5c7e0fc3 modules: add cpu module 2021-12-21 18:44:36 +01:00