Commit Graph

42 Commits

Author SHA1 Message Date
Huang Shijie 81d6de9166 lscpu: remove the old code
The file "/sys/firmware/dmi/tables/DMI" always exists.

The dmi_decode_cputype() can provide more information then arm_smbios_decode().
So remove it to tidy the code.

Before this patch, we can get the output from Centos 7.9 who has
"/sys/firmware/dmi/entries/4-0/raw" and "/sys/firmware/dmi/tables/DMI":
  ----------------------------------------------------
  BIOS Vendor ID:                  Ampere(TM)
  Model name:                     Neoverse-N1
    BIOS Model name:               Ampere(TM) Altra(TM) Processor
  ----------------------------------------------------

 After this patch which uses "/sys/firmware/dmi/tables/DMI", in Centos 7.9, we get:
  ----------------------------------------------------
  BIOS Vendor ID:                  Ampere(TM)
  Model name:                     Neoverse-N1
    BIOS Model name:               Ampere(TM) Altra(TM) Processor Q00-00 CPU @ 2.8GHz
    BIOS CPU family:               257
  ----------------------------------------------------

Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
2021-06-30 11:27:26 +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
Huang Shijie a772d7c493 lscpu: get the processor information by DMI
The patch :367c85c47286 ("lscpu: use SMBIOS tables on ARM for lscpu")
relies on the existence of "/sys/firmware/dmi/entries/4-0/raw",
which may not exist in standard linux kernel.

But "/sys/firmware/dmi/tables/DMI" should exist and can provide the required
processor information.

This patch uses "/sys/firmware/dmi/tables/DMI"
to get the processor information:

Before this patch, in Ampere Altra platform, the lscpu output is:
   ---------------------------------------------
	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
	Model name:                      Neoverse-N1
	Model:                           1
	Thread(s) per core:              1
	Core(s) per socket:              80
	Socket(s):                       2
    ........................................
   ---------------------------------------------

After this patch, we can use get the lscpu output
in Ampere Altra platform:
   ---------------------------------------------
	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
	Model:                           1
	Thread(s) per core:              1
	Core(s) per socket:              80
	Socket(s):                       2
    ........................................
   ---------------------------------------------

[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:09:19 +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 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
Masayoshi Mizuma f42f105b07 lscpu: show the number of physical socket on aarch64 machine without ACPI PPTT
Show the number of the number of physical socket even if the sysfs doesn't
have the physical socket information.

Note, lscpu shows the number of physical socket as 'Socket(s):' only if
root user runs it because accessing the DMI table requires root
privilege.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 788f90d69a lscpu: add helper to get physical sockets
Add a helper function, get_number_of_physical_sockets_from_dmi(),
to get physical sockets from DMI table in case of the sysfs for
cpu topology doesn't have the physical socket information.

get_number_of_physical_sockets_from_dmi() parse the DMI table
and counts the number of SMBIOS Processor Information (Type04)
structure.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 3cd676f5ec lscpu-dmi: Move some functions related to DMI to lscpu-dmi
Move some functions related to DMI to lscpu-dmi.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma b04ab8dd8a lscpu-virt: split hypervisor_from_dmi_table()
Split hypervisor_from_dmi_table() to parsing dmi table and checking the
hypervisor vendor.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 73c0a766ff lscpu: use cluster on aarch64 machine which doesn't have ACPI PPTT
lscpu may show the wrong number of sockets if the machine is aarch64 and
doesn't have ACPI PPTT.

That's because lscpu shows the number of sockets by using a sysfs entry
(cpu/cpuX/topology/core_siblings). The sysfs entry is set by MPIDR_EL1
register if the machine doesn't have ACPI PPTT. MPIDR_EL1 doesn't show
the physical socket information directly. It shows the affinity level.

According to linux/arch/arm64/kernel/topology.c:store_cpu_topology(),
the top level of affinity is called as 'Cluster'.

Use Cluster instead of Socket on the machine which doesn't have ACPI PPTT.

This patch is useful for aarch64 machine which is based on ARM
SBBR v1.0 and v1.1, the specs don't require ACPI PPTT. ARM SBBR v1.2
requires ACPI PPTT.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 8014104bea lscpu-arm: Add "BIOS Vendor ID" and "BIOS Model name" to show the SMBIOS information.
After commit: 367c85c47 ("lscpu: use SMBIOS tables on ARM for lscpu"),
Model name for A64FX shows like as:

   Model name:       461F0010

That's because 367c85c47 changes to get the modelname from Processor
Version of SMBIOS.

To fix that, use the hard corded table to show the "Model name" and
add two new lines; "BIOS Vendor ID" and "BIOS Model name" to show the
SMBIOS information.

lscpu shows the SMBIOS information when root user runs it because
accessing the SMBIOS information requires root privilege.

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

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 10:06:26 +01:00
Karel Zak 76b6666c0e lscpu: (arm) reuse parsed vendor ID
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 e07cca6b85 lscpu: fix last caches separator in -e and -p output
Note that cxt->ncaches is number of all instances, but we split
output according to split output according to caches names.

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 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 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 30b912d335 lscpu: add LSCPU_OUTPUT_ enum
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 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 f9ac021032 lscpu: remove obsolete code
This is the first step in conversion from old lscpu to the new code.
The patch removes obsolete code from lscpu.c and lscpu.h. The old
output code in lscpu.c is temporary disabled by #ifdef due to
incompatibility between old and new internal APIs -- this will be
changed later by small steps to make all all the changes review-able.

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 b76b4788be lscpu: don't use smbios when read snapshots
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 14:57:08 +02:00
Jeffrey Bastian 367c85c472 lscpu: use SMBIOS tables on ARM for lscpu
ARM SBBR (Sever Base Boot Requirements) require SMBIOS tables, and
SMBIOS Type 4 describes the CPU manufacturer and model name (among other
details).  If SMBIOS Type 4 is present, use it to extract these strings.

Example output (before and after the patch) on an HP m400, Lenovo HR330A,
and HPE Apollo 70:

[root@hp-m400 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:           APM
Model:               1
Model name:          X-Gene
Stepping:            0x0
[root@hp-m400 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:                       AppliedMicro
Model:                           1
Model name:                      X-Gene
Stepping:                        0x0

[root@lenovo-hr330a ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:           APM
Model:               2
Model name:          X-Gene
Stepping:            0x3
[root@lenovo-hr330a ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:                       Ampere(TM)
Model:                           2
Model name:                      eMAG
Stepping:                        0x3

[root@hpe-apollo-70 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:           Cavium
Model:               1
Model name:          ThunderX2 99xx
Stepping:            0x1
[root@hpe-apollo-70 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:                       Cavium Inc.
Model:                           1
Model name:                      Cavium ThunderX2(R) CPU CN9980 v2.1 @ 2.20GHz
Stepping:                        0x1

[kzak@redhat.com: - move dmi_header to lscpu.h
                  - make arm_cpu_smbios() more robust for failed
		    open() and read()
                  - use original arm_cpu_decode() also on failed
		    arm_cpu_smbios()]

Signed-off-by: Jeffrey Bastian <jbastian@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-29 13:28:16 +02:00
Yuri Chornoivan 311e33afef Fix minor typos 2020-07-09 20:14:32 +03:00
Karel Zak cf3b6b71eb lscpu: add a new columns to --cache
References: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:46:10 +02:00
Karel Zak 639eeb28dd lscpu: report CPU vulnerabilities
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-11 13:45:29 +02:00
Karel Zak 0e86bc8406 lscpu: add --caches
$ lscpu -C
NAME ONE-SIZE ALL-SIZE WAYS TYPE        LEVEL
L3         8M       8M   16 Unified         3
L2       256K       1M    8 Unified         2
L1i       32K     128K    8 Instruction     1
L1d       32K     128K    8 Data            1

The patch also updates extra caches (s390) output in lsblk summary to
be compatible with output about normal caches.

Addresses: https://github.com/karelzak/util-linux/issues/663
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-19 14:11:20 +01:00
Karel Zak 16ca05511b lscpu: add 'Frequency boost'
Show turbo boost status on platforms where is available a file
/sys/devices/system/cpu/cpufreq/boost.

Addresses: https://github.com/karelzak/util-linux/issues/755
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-15 13:37:51 +01:00
Karel Zak 3e48ef72c1 lscpu: add 'Address sizes'
Addresses: https://github.com/karelzak/util-linux/issues/674
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-01 08:33:32 +02:00
Karel Zak 6e509042b8 lscpu: use new ul_path_* API
* use ul_path_* API for /sys/devices/system/cpu paths
* use ul_path_* API for /proc
* rename is_compatible() to is_devtree_compatible() as it works
  with the devices tree only

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak 8229df2093 lscpu: move ARM decoding to lscpu-arm.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-22 13:08:11 +01:00
Karel Zak 7106169441 lscpu: move struct lscpu_desc header file
The lscpu code is growing and it seems better to allow to make code
more structured.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-22 13:04:12 +01:00
Stanislav Brabec 7572fb2b8c lscpu: Detect Windows Subsystem for Linux
Windows 10 implements Windows Subsystem for Linux (WSL).

WSL does not implement support for SIGSEGV handler, which is used inside
is_vmware_platform(). As a result, lscpu crashes there.

Implement WSL detection, and as a side effect, work around the crash.
Note that none of existing virtualization types exactly matches.
But the the closest would be "container".

References:

Provide a way to positively detect WSL from an app compiled on Linux.
https://github.com/Microsoft/BashOnWindows/issues/423

missing support for SIGSEGV handler
https://github.com/Microsoft/BashOnWindows/issues/1637

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-01-31 12:28:32 +01:00
Benjamin Romer 4597b69249 lscpu: add s-Par support
Adds support for the s-Par firmware's hypervisor leaf.

Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
2015-02-11 11:46:19 +01:00
Ruediger Meier 5bd31c6d6e lscpu: detect OS/400 and pHyp hypervisors
This patch comes originally from openSUSE / SLE. Author was probably
Petr Uzel.
Internal SUSE references: fate310255, sr226509

In comparison to the original patch we have slightly corrected iSeries
and pSeries detection according to Alexander Graf's comments on
util-linux@vger.kernel.org. Maybe we would need to add some more code
to detect pSeries emulated by Qemu/KVM.

CC: Stanislav Brabec <sbrabec@suse.cz>
CC: Petr Uzel <petr.uzel@suse.cz>
CC: Alexander Graf <agraf@suse.de>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-29 13:16:32 +02:00
Ruediger Meier 96ce475f96 lscpu: minor cleanup and improve hypervisor detection
- add HYPER_VBOX
- improve HYPER_VMWARE

This patch comes from openSUSE / SLE. Original author was probably
Petr Uzel.
Internal SUSE references: fate310255, sr226509

CC: Stanislav Brabec <sbrabec@suse.cz>
CC: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-29 01:27:25 +02:00
Ondrej Oprala fb2627cec4 lscpu: detect more hypervisor vendors
[kzak@redhat.com: - cleanup coding style,
                  - use path_exist()]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-20 16:30:23 +02:00