Commit Graph

61 Commits

Author SHA1 Message Date
Karel Zak 1d5c14ae1a misc: improve string to number conversions
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-24 16:42:53 +02:00
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
Huang Shijie 4cae2104ec lscpu: add bios_family
In the arm platform, we do not have the "CPU family" as X86.
In the linux kernel, it is hardcode to set the "CPU architecuture:8"
which should be changed for arm v9 in future.

This patch adds "bios_family" field, which we can get from the DMI table.
In the ampere Altra platform, we can get the new lscpu output:
    ----------------------------------------------------------------
	Architecture:                    aarch64
	CPU op-mode(s):                  32-bit, 64-bit
	Byte Order:                      Little Endian
	CPU(s):                          160
	On-line CPU(s) list:             0-159
	Vendor ID:                       ARM
	BIOS Vendor ID:                  Ampere(R)
	Model name:                      Neoverse-N1
	BIOS Model name:                 Ampere(R) Altra(R) Processor Q00-00 CPU @ 3.0GHz
	BIOS CPU family:                 257
	Model:                           1
	Thread(s) per core:              1
    ----------------------------------------------------------------

[kzak@redhat.com: - s/sprintf/snprintf/]

Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-16 11:12:14 +02:00
Georgy Yakovlev 45cd3aa4de
lscpu: fix build on powerpc
fails with error: label at end of compound statement
and fix typo as bonus.

Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
2021-06-02 13:59:26 -07:00
Karel Zak ac55a4130f Merge branch 'next'
* next: (26 commits)
  build-sys: add script to compare config.h from meson and autotools
  meson: add missing header files check
  docs: update TODO
  tests: update lscpu outputs
  lscpu: read MHZ from /sys/.../cpufreq/scaling_cur_freq
  lscpu: use locale-independent strtod() when read from kernel
  lib/c_strtod; add locale independent strtod()
  tests: update lscpu output
  lscpu: use MHZ as number to be locale sensitive
  lscpu: add SCALMHZ% and "CPU scaling MHz:"
  sulogin: fix whitespace error
  sulogin: ignore none-existing console devices
  lsns: fix old error message
  lsns: fix copy & past in man page
  lsns: fill UID and USER columns for interpolated namespaces
  fixup! lsns: interpolate missing namespaces for converting forests to a tree
  lsns: interpolate missing namespaces for converting forests to a tree
  lsns: reorganize members specifying other namespaces in lsns_namespace
  lsns: make namespace having no process printable
  libblkid: support zone reset for wipefs
  ...
2021-06-02 12:33:07 +02:00
Karel Zak 0a0af6161b lscpu: cleanup tab vs. space
Do not mix tab and space in structs initializations.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-26 11:54:47 +02:00
Karel Zak 0b538002da lscpu: use locale-independent strtod() when read from kernel
Reported-by: Thomas Weißschuh
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-25 11:32:51 +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 1c675ebee0 lscpu: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-19 12:00:58 +01:00
Karel Zak d4cb6a0335 lscpu: fix memory leaks
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 10:20:33 +01:00
Karel Zak 60e7ccb8e8 lscpu: Adapt MIPS cpuinfo
Port commit

  commit 6cb8af7be2
  Author: Jiaxun Yang <jiaxun.yang@flygoat.com>
  Date:   Sat Mar 28 12:19:42 2020 +0800

to new lscpu code.

References: 6cb8af7be2
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak ddc92e3993 lscpu: add shared cached info for s390 lscpu -C
Port commit
 commit 318542e060
 Author: Sumanth Korikkar <sumanthk@linux.ibm.com>
 Date:   Fri Jun 5 18:15:10 2020 +0200

to new lscpu code.

References: 318542e060
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Thomas Abraham 80fcd2c802 lscpu: avoid segfault on PowerPC systems with valid hardware configurations
ntypes greater than 1 is valid in some hardware configurations, and an assert()
on the value isn't necessary or very future proof

[kzak@redhat.com: - port this patch to new code]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 05b9c556f6 lscpu: fix MHZ parsing
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak cc94324ebd lscpu: improve bogomips use
* keep global (cputype) bogomips
* add per-CPU bogomips
* use bogomips from the first CPU as global (for cputype) if /proc/cpuinfo does not provide global bogomips
* add BOGOMIPS column for to -e/-p output

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak d4228e9de2 lscpu: fix for sparc64
We do not read CPUs from cpuinfo on sparc.

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 91eef60ca3 lscpu: split output to sections
Let's make it more readable for humans.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 778254d9a2 lscpu: keep static/dynamic MHz in cputype struct
The Dynamic and Static MHz are /proc/cpuinfo s390 per-CPU fields, but
we display it as a single value according the first parsed CPU. For
this purpose we store the values from the first CPU in lscpu_cputype.

For -p and -e outputs we will print per CPU values.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 406b088cb4 lscpu: fix NUMAs reading code
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 4b9cbc38a4 lscpu: use new code to read CPUs info
and remove test program from lscpu-cputype.c.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 27c349f9d1 lscpu: move to main function to init context
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 43715b4ea8 lscpu: move debug initialization to main
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 e36e01f980 lscpu: sort extra caches
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak ff7449d2ea lscpu: improve debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak ffb7fcfbba lscpu: remove unused function
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 25c2a72cd6 lscpu; (cpuinfo) parse caches
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 f495abb799 lscpu: (cpuinfo) fill empty cputype
Don't introduce a new CPU-type if the current is empty.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak f5d1353246 lscpu: new cpuinfo parser
* extendable by new patterns
* simple semantic
* the same code for all pattern types

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 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
Karel Zak 0266f5cbab lscpu: improve topology debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak fa6a21bf63 lscpu: calculate threads number from type specific values
Don't use global CPU masks (like "online" or "present") to
calculate type specific number of threads due systems with
mixed CPU types.

It's also necessary to check all thread_siblings maps to get the
highest number, because some threads (CPUs) may be disables, for
example old lscpu calculates number of threads from the cpu0 and
if you disable cpu0's sibling (cpu4):

	CPU(s):                          8
	On-line CPU(s) list:             0-7
	Thread(s) per core:              2        <---
	Core(s) per socket:              4
	Socket(s):                       1

 # chcpu --disable 4
 CPU 4 disabled

	CPU(s):                          8
	On-line CPU(s) list:             0-3,5-7
	Off-line CPU(s) list:            4
	Thread(s) per core:              1        <--- !
	Core(s) per socket:              4
	Socket(s):                       1

because 'thread_siblings' contains only one thread for cpu0:

 # cat /sys/devices/system/cpu/cpu{0,1,2,3,4,5,6,7}/topology/thread_siblings_list
 0
 1,5
 2,6
 3,7
 cat: /sys/devices/system/cpu/cpu4/topology/thread_siblings_list: No such file or directory
 1,5
 2,6
 3,7

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak b8a319460d lscpu: deallocate maps
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 314aa95fd5 lscpu: add lscpu_read_topolgy_ids()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 9d5f3b4873 lscpu: add lscpu_read_topology()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 9c5b106b01 lscpu: add lscpu_cpus_loopup_by_type(), improve readability
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 504de58512 lscpu: convert ARM decoding to new API
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak a94bb4357e lscpu: cleaup arch freeing
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 909d35758e lscpu: add lscpu_read_virtualization()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 154ee5a992 lscpu: add lscpu_read_numas()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 0796923aa8 lscpu: add lscpu_read_vulnerabilities()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak b152ec5436 lscpu: cleanup lscpu_unref_cputype()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00