Commit Graph

188 Commits

Author SHA1 Message Date
Ruediger Meier e230ae7b68 lib/path: fix crash, pathbuf overflow
Before:

$ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)"
Segmentation fault (core dumped)

After:

$ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)"
lscpu: invalid argument to --sysroot: File name too long

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 21:39:35 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
J William Piggott 6e2d5a4460 include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
* login-utils/lslogins.c: all uses changed
* misc-utils/findmnt.c: likewise
* sys-utils/blkzone.c: likewise
* disk-utils/sfdisk.c: likewise
* sys-utils/lscpu.c: likewise
* sys-utils/lsmem.c: likewise
* sys-utils/wdctl.c: likewise

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-24 13:57:12 -04:00
Karel Zak 0145d84a38 lscpu: make min/max freq arrays usage more robust
The array members may be NULL on some architectures (e.g. AMD). Let's
be paranoid and check for the NULL independently on present/online
masks.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1457744
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-01 12:15:23 +02:00
Karel Zak 780ce22cda misc: consolidate smartcols error messages
... just to keep translators happy

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-18 11:39:34 +02:00
Karel Zak 577d1a663c lscpu: reuse the same buffer
Now we use libsmartcols for the default output and all is allocated in
the smartcols table. So, we can reuse the same buffer for all
sprintf/scanf calls.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 12:31:52 +02:00
Karel Zak 89222b17fc lscpu: make cpu_{max,min}_mhz() usage more elegant
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 12:29:24 +02:00
Mamatha Inamdar fc07d9f5ab lscpu: Read available CPUs max and min frequencies
Problem:"lscpu frequency-info" command was always reading CPU0
max and min frequencies. If CPU0 is guarded or offline then it used to
display max and min frequencies as NULL.

This patch will read overall CPU max and min frequencies.

Test Results:

Before Patch:

    #lscpu (CPU0 is guarded/offline)
    Architecture:          ppc64le
    Byte Order:            Little Endian
    CPU(s):                120
    On-line CPU(s) list:   8-127
    Thread(s) per core:    8
    Core(s) per socket:    3
    Socket(s):             4
    NUMA node(s):          4
    Model:                 2.1 (pvr 004b 0201)
    Model name:            POWER8E (raw), altivec supported
    CPU max MHz:           (null)
    CPU min MHz:           (null)
    L1d cache:             64K
    L1i cache:             32K
    L2 cache:              512K
    L3 cache:              8192K
    NUMA node0 CPU(s):     8-31
    NUMA node1 CPU(s):     32-63
    NUMA node16 CPU(s):    64-95
    NUMA node17 CPU(s):    96-127

With Patch:

    # ./lscpu
    Architecture:          ppc64le
    Byte Order:            Little Endian
    CPU(s):                120
    On-line CPU(s) list:   8-127
    Thread(s) per core:    8
    Core(s) per socket:    3
    Socket(s):             4
    NUMA node(s):          4
    Model:                 2.1 (pvr 004b 0201)
    Model name:            POWER8E (raw), altivec supported
    CPU max MHz:           4322.0000
    CPU min MHz:           2061.0000
    L1d cache:             64K
    L1i cache:             32K
    L2 cache:              512K
    L3 cache:              8192K
    NUMA node0 CPU(s):     8-31
    NUMA node1 CPU(s):     32-63
    NUMA node16 CPU(s):    64-95
    NUMA node17 CPU(s):    96-127

[kzak@redhat.com: - cpu_{max,min}_mhz() refactoring]

Signed-off-by: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 12:23:37 +02:00
Karel Zak c6f6afc164 lscpu: fix mem leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-31 11:05:26 +02:00
Karel Zak bf1eab0731 lscpu: check return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-31 10:58:50 +02:00
Karel Zak 19a5510b96 lscpu: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-14 15:32:53 +01:00
Karel Zak c82b12a0a2 lscpu: use libsmartcols to print summary too
Addresses: https://github.com/karelzak/util-linux/issues/419
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-14 15:19:12 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 904ffe1fd2 lscpu: don't use path_exist() before path_fopen()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-31 20:55:07 +01:00
Karel Zak 4dfc54b6b1 lscpu: make osrelease file optional
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-31 13:44:43 +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
Karel Zak a3c455ac9b lscpu: add aarch64 specific names
It seems that aarch64 uses a different names for some /proc/cpuinfo
fields (e.g. intel: bogomips, flags, and aarch64: BogoMIPS, features, ...)

Addresses: https://github.com/karelzak/util-linux/issues/392
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-09 13:04:41 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Ruediger Meier 223939d95b misc: spelling, always use "cannot" instead of "can not"
Just to be consistent ...

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-11-30 14:56:50 +01:00
Karel Zak b5d61108e4 lscpu: disable is_vmware_platform() for non-root users
References: http://www.spinics.net/lists/util-linux-ng/msg13302.html
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-11-03 10:53:09 +01:00
Heiko Carstens 2c497d3288 lscpu: print correct number of threads per core if possible
lscpu calculates the number of threads per core by dividing the number
of online cpus with the number of cores. This may or may not give the
correct number of threads per core depending on the number of online
CPUs (and which CPUs are online).

At least on s390 there is a new "max thread id" field within
/proc/cpuinfo present which reliably allows us to tell the number of
threads per core. Let's use this instead, like we already have also
special treatment to figure out the number core per socket etc. on
s390.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-08-03 13:35:05 +02:00
Heiko Carstens 0002704ebe lscpu: only try to read sysfs attributes of present CPUs
lscpu can skip all CPUs which are possible but not present. For
configurations where a lot of CPUs are possible but only few CPUs are
present this saves a lot of pointless glibc/system calls.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-08-03 13:35:05 +02:00
Heiko Carstens 0d2b5d2a72 lscpu: add --physical option
With the --physical option lscpu will use the IDs that are reported by
the kernel (e.g. core id for the CORE column) instead of calculating
them on it's own.

This has the advantage that it is possible to tell on which physical
hardware CPUs a Linux instance runs. The logical IDs that lscpu
generates on it own are based on comparing of CPU masks and may or may
not be identical with the physical IDs.

If the kernel was unable to retrieve an ID for a topology element then
the corresponding sysfs file will normally contain "-1". In the
extended and parsable output a dash "-" will be displayed for such
cases.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-08-03 13:35:05 +02:00
Karel Zak 81a307bd4d lscpu: make lookup_cache() more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-24 11:07:00 +02:00
Heiko Carstens 28b1658f8b lscpu: show additional caches (s390)
The Linux kernel exposes the cache topology via sysfs. However on
virtualized machines like s390 the cache topology contains only cpu
private caches.

For shared caches it is not known which cpus share them. The
hypervisor would have to update this information whenever a virtual
cpu would be scheduled on a different physical cpu and make the guest
aware of that change. Given that there is hardly any benefit, if it
all, this isn't done.

However it is still of interest to know about the non-private
caches. Therefore this information is available via /proc/cpuinfo at
least on s390.

This patch adds additional lines to the summary output for all shared
caches for which information can be found in /proc/cpuinfo, since we
know these aren't exposed via sysfs.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-06-24 10:54:09 +02:00
Heiko Carstens 0c28f0c815 lscpu: show machine type (s390)
Show also the machine type within the lscpu output. With the machine
type it is possible to identify the cpu generation and the supported
features.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-06-24 10:54:09 +02:00
Heiko Carstens 4632b28811 lscpu: show static and dynamic MHz (s390)
s390 machines provide static and dynamic cpu mhz information via
/proc/cpuinfo. The static cpu mhz is the normal cpu frequency a cpu is
supposed to run with.

The dynamic cpu mhz is the actual frequency a cpu is running
with. This is usually the same as the static cpu mhz. Note that this
values are different to the min/max mhz values available on other
architecutes. The min/max values are unknown.

This patch adds two new fields to the summary output which display
these two values.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-06-24 10:54:09 +02:00
Heiko Carstens 156740ca37 lscpu: fix typo in summary output
The new drawer support did have a type in the summary output:
it reported Drawers(s) instead of Drawer(s). Fix this.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-06-24 10:54:09 +02:00
Heiko Carstens b3adf6ef66 lscpu: add drawer support
The s390 architecture gained another cpu topology level called
"drawer" which is above the book level.

Add support for this to lscpu.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-06-24 10:52:32 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak b4d1fbda1e lscpu: revert unnecessary path_exist()
The features file is there from 2.6.31 when Xen has been added to
kernel. Sorry.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-22 10:31:16 +01:00
Dongli Zhang 0ebbe9f104 lscpu: correct the Virtualization type on Xen DomU PV guest
Nowadays, most Intel CPUs have "cpuid faulting" available which could trap
the execution of "cpuid" instruction when CPL>0  with GP fault. Thus,
"cpuid" instruction could trap to Xen hypervisor on the paravirtualized PV
guest on most servers today, except on old CPUs prior to 2011. On CPU after
2011, Xen will put "XenVMMXenVMM" on both HVM and PV guests, which could
have lscpu command erroneously classify the guest as type "full".  The
current lscpu command, which is based on "cpuid" instruction, still assumes
that it will not cause the trap to Xen hypervisor on Xen PV guest and uses
/proc/xen to identify whether it's running on PV DomU or not.  To identify
this kind of information under the help of
/sys/hypervisor/properties/features would be more accurate for the CPU
nowadays. The bit 5 (XENFEAT_mmu_pt_update_preserve_ad) of the features
will be set only when it's running on Xen PV domain. The combo of bit 3 and
8 (XENFEAT_supervisor_mode_kernel and XENFEAT_hvm_callback_vector) will be
set simultaneously only when it's running on Xen PVH domain.

[kzak@redhat.com: - add path_exist()]

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-22 10:13:03 +01:00
Ruediger Meier e5fc6d6fb5 lscpu: fix memleak because of ambiguous tags
Now the first one of certain ambiguous tags wins. Alternatively to
this patch we could have called free() before xstrdup().

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-16 14:17:34 +01:00
Ruediger Meier c95e388972 lscpu: use cpu and revision tag if available
Avoid ifdef which does not work with --sysroot. Our existing test
dumps produce even better output now for ppc and sparc.

The logic moved to the printing section.

CC: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-16 14:17:33 +01:00
Ruediger Meier 86c4817e0e Revert "lscpu: keep lscpu usable on snapshots"
This reverts commit 641350fe82.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-16 14:17:33 +01:00
Karel Zak 641350fe82 lscpu: keep lscpu usable on snapshots
This patch reverts 3ac03fe4d2 for
snapshots (--sysroot).

Yeah, poor-man solution. It would be really nice to have runtime
detection to support model overwriting also on snapshots.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-15 14:23:59 +01:00
Vasant Hegde 3ac03fe4d2 lscpu: Fix model and model name on Power Systems
On Power System, lspcu presently displays system model number instead of
processor model name. 'model' tag in cpuinfo contains system model name,
not processor model. Instead it uses 'cpu' tag for processor model name.
Also it uses 'revision' tag for processor model.

Fix lspcu so that it displays processor model number. Also display processor
model name.

cpuinfo output on Power System:
  ...
  ...

  processor	: 127
  cpu		: POWER8E (raw), altivec supported
  clock		: 4322.000000MHz
  revision	: 2.1 (pvr 004b 0201)

  timebase	: 512000000
  platform	: PowerNV
  model		: 8286-42A
  machine	: PowerNV 8286-42A
  firmware	: OPAL

Output without this patch:
  Architecture:          ppc64le
  Byte Order:            Little Endian
  CPU(s):                128
  On-line CPU(s) list:   0-127
  Thread(s) per core:    8
  Core(s) per socket:    4
  Socket(s):             4
  NUMA node(s):          4
  Model:                 8286-42A
  ...
  ...

Output with this patch:
  Architecture:          ppc64le
  Byte Order:            Little Endian
  CPU(s):                128
  On-line CPU(s) list:   0-127
  Thread(s) per core:    8
  Core(s) per socket:    4
  Socket(s):             4
  NUMA node(s):          4
  Model:                 2.1 (pvr 004b 0201)
  Model name:            POWER8E (raw), altivec supported
  ...
  ...

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
2016-03-14 16:17:19 +01:00
Yuriy M. Kaminskiy 06fa581748 misc: safer (and uniform) handling of return value
When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:11:06 +01:00
Yuriy M. Kaminskiy 0c5bbafaf9 lscpu: fix backward buffer size adjustment after adding delimiter
remaining buffer space was increased after adding character, instead
of decreasing

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:10:46 +01:00
Sukadev Bhattiprolu bd9b94d12a lscpu: Print physical cpu information
lscpu currently prints information for CPUs configured in the system.
In case of KVM or other virtualized guest operating systems, this
refers to the virtual system, and bears no relation to the physical
topology of the system.

It would be useful if lscpu could also display the physical topology
info when available:

	$ ./lscpu
	Architecture:          ppc64le
	Byte Order:            Little Endian
	CPU(s):                16
	On-line CPU(s) list:   0-15
	Thread(s) per core:    1
	Core(s) per socket:    1
	Socket(s):             16
	NUMA node(s):          1
	Model:                 IBM pSeries (emulated by qemu)
	Hypervisor vendor:     KVM
	Virtualization type:   para
	L1d cache:             64K
	L1i cache:             32K
	NUMA node0 CPU(s):     0-15
	Physical sockets:      2		<<< New
	Physical chips:        4		<<< New
	Physical cores/chip:   4		<<< New

For now, physical topology information is available on platforms that
support the following RTAS (Real time abstraction service) call provided
by librtas:

	rtas_get_sysparm(PROCESSOR_MODULE_INFO).

Currently this call is available to the PowerVM (pHYP) guests on PowerPC.
With a patch propoosed to PowerKVM, this RTAS call would also be available
to PowerKVM guests.

Based on input from Nishanth Aravamudan and Karel Zak.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
2015-12-02 11:33:58 +01:00
Karel Zak e03b613e8d lscpu: fix read_hypervisor_powerpc() logic
We care about /proc/device-tree/compatible content...

The patch also removes unnecessary path_exist(), it seems good enough
to call open() rather than access() + open().

Addresses: https://github.com/karelzak/util-linux/issues/218
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-01 12:37:18 +02:00
Karel Zak 6d9b1c19ea lscpu: add warning for __SANITIZE_ADDRESS__
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-02 14:55:52 +02:00
Cristian Rodríguez a680b2abe7 sys-utils: lscpu segfaults when built with -fsanitize=address
This is expected and a false positive, exclude the vmware detection
trick when __SANITIZE_ADDRESS__ is defined.
2015-06-02 11:58:53 +02:00
WANG Chao ee1f1057e2 lscpu: add cpu flags entry to summary output
It'd be convenient to have unified cpu "Flags: " entry in the summary
output.

Signed-off-by: WANG Chao <wcwxyz@gmail.com>
2015-05-13 11:27:16 +02: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
Karel Zak d45984bef6 lscpu: fix typos in ppc code
Reported-by: David Gibson <dgibson@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-09 12:03:18 +01:00
Karel Zak 79738105b1 lscpu: cleanup ppc virtualization detection
References: https://bugzilla.redhat.com/show_bug.cgi?id=1151604
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-06 11:23:40 +01:00
Karel Zak f93993b746 lscpu: fix compiler error [-Werror=format-security]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-06 10:31:03 +01:00