Commit Graph

26 Commits

Author SHA1 Message Date
Karel Zak 24c17c6294 lscpu: do not use atoi()
Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-22 17:20:49 +02:00
Karel Zak f2d08d4ddc lscpu: read MHZ from /sys/.../cpufreq/scaling_cur_freq
This is more portable and provides more stable results than
/proc/cpuinfo.

Fixes: https://github.com/karelzak/util-linux/pull/1317
Co-Author: Thomas Weißschuh
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-25 13:30:13 +02:00
Karel Zak 9b9e4f5d06 lscpu: add SCALMHZ% and "CPU scaling MHz:"
$ lscpu
...
  Model name:           Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
    CPU family:         6
    Model:              60
    Thread(s) per core: 2
    Core(s) per socket: 4
    Socket(s):          1
    Stepping:           3
    CPU(s) scaling MHz: 61%
    CPU max MHz:        4400.0000
    CPU min MHz:        800.0000
...

$ lscpu -e=CPU,MAXMHZ,MINMHZ,MHZ,SCALMHZ%
CPU    MAXMHZ   MINMHZ      MHZ SCALMHZ%
  0 4400.0000 800.0000 2800.000      64%
  1 4400.0000 800.0000 4000.146      91%
  2 4400.0000 800.0000 2800.000      64%
  3 4400.0000 800.0000 2800.000      64%
  4 4400.0000 800.0000 2800.000      64%
  5 4400.0000 800.0000 4400.000     100%
  6 4400.0000 800.0000  800.000      18%
  7 4400.0000 800.0000 2800.000      64%

Addresses: https://github.com/karelzak/util-linux/issues/1314
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-24 13:39:53 +02:00
Karel Zak 5c09ab260e lscpu: assume L1d, L1i, L2, L3 for sparc
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-03 20:28:30 +02:00
Karel Zak 57fee04c14 lscpu: read Sparc caches files
Fixes: https://github.com/karelzak/util-linux/issues/1296
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-03 16:29:55 +02:00
Karel Zak 9dadd3e60c lscpu: report also number of cache instances
Caches (sum of all):
  L1d:                   128 KiB (4 instances)
  L1i:                   128 KiB (4 instances)
  L2:                    1 MiB (4 instances)
  L3:                    8 MiB (1 instance)

Suggested-by: John Henning <john.henning@oracle.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-01 12:27:05 +02:00
Karel Zak 19ddc05e11 lscpu: improve topology calculation
Let's make it more robust and readable. The sysinfo file on s390 may
contain zeros, so we need to check the values and fallback to data
from shared maps if necessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak ada1a387b1 lscpu: generate cache ID if not available
The file /sys/devices/system/cpu/cpu*/cache/index*/id is not available
in old kernels. This patch add code to generate IDs according to cache
type and level.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 63c5e7f801 lscpu: cleanup -e
* keep one sharedmap per cache instance
* initialize topology IDs to -1
* rewrite -e code to use a new data structs

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 6d5699e6b5 lscpu: add functions to get CPU freq
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak db919abc13 lscpu: use size_t for counters
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak eaf32c65be lscpu: add setsize to lscpu context
Don't recalculate again and again setsize from maxcpus.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 05abf5944e lscpu: add function to count caches size
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 6fbb53286d lscpu: use cache ID, keep caches independent on CPU type
The cache is identified by Type, Level and ID, the ID is unique cache
instance identifier (of the type).

This changes forces lscpu allocate more lscpu_cache instances (than
old version), but now we're ready for arbitrary scenario where
different CPU types share caches and the same cache type uses
different size in different instances, etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 095be2c20e lscpu: merge new API to lscpu.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak eadaf6d758 lscpu: (topology) read caches from /sys
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 9d08a19d54 lscpu: (topology) add read_mhz()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 8c587fad9f lscpu: (topology) add read_configure()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 6d1a2705f7 lscpu: (topology) add read_address()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 2075eb60b5 lscpu: hide all to lscpu_read_topology()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak ee0fabda30 lscpu: (cpuinfo) rewrite parser
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 801b125f8f lscpu: temporary commit
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 6baa4df7ec lscpu: improve topology calculation, use /proc/sysinfo
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak fd5999d9ac lscpu: support s390 cpuinfo processor-pre-line format
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak fd35a1dae6 lsblk: add lscpu_read_topology_polarization()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak f669523ba0 lscpu: move topology stuff to separate file
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00