]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: Print physical cpu information
authorSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Wed, 25 Nov 2015 20:10:39 +0000 (12:10 -0800)
committerKarel Zak <kzak@redhat.com>
Wed, 2 Dec 2015 10:33:58 +0000 (11:33 +0100)
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>
configure.ac
sys-utils/Makemodule.am
sys-utils/lscpu.1
sys-utils/lscpu.c

index 90d08f39eadb3efb407a8b91529801951c8fc8a8..0748fb1c6c1a510eecb4c515bf6b5a454ddb7593 100644 (file)
@@ -386,6 +386,12 @@ AC_CHECK_FUNCS([clock_gettime], [],
 )
 AC_SUBST([REALTIME_LIBS])
 
+AC_CHECK_LIB([rtas], [rtas_get_sysparm], [
+       RTAS_LIBS="-lrtas"
+       AC_DEFINE_UNQUOTED([HAVE_LIBRTAS], [1], [Define if librtas exists]), [],
+])
+AC_SUBST([RTAS_LIBS])
+
 have_timer="no"
 AC_CHECK_FUNCS([timer_createx],
        [have_time="yes"],
index ff7e1ee1280c726e411c3d23932f44ffead8daab..c62d77c7958e8fff4e06da98b8c912d7e974fc50 100644 (file)
@@ -324,7 +324,7 @@ lscpu_SOURCES = \
        sys-utils/lscpu.c \
        sys-utils/lscpu.h \
        sys-utils/lscpu-dmi.c
-lscpu_LDADD = $(LDADD) libcommon.la libsmartcols.la
+lscpu_LDADD = $(LDADD) libcommon.la libsmartcols.la $(RTAS_LIBS)
 lscpu_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
 dist_man_MANS += sys-utils/lscpu.1
 endif
index 5502da3d149f20c86ab73c9092b34675a00846f2..26487d23ff45fbe21e58b31557164b3fa30d11ca 100644 (file)
@@ -9,13 +9,21 @@ lscpu \- display information about the CPU architecture
 .BR \-h | \-V
 .SH DESCRIPTION
 .B lscpu
-gathers CPU architecture information from sysfs and /proc/cpuinfo.  The
+gathers CPU architecture information from sysfs, /proc/cpuinfo and any
+applicable architecture-specific libraries (e.g. librtas on Powerpc). The
 command output can be optimized for parsing or for easy readability by humans.
 The information includes, for example, the number of CPUs, threads, cores,
 sockets, and Non-Uniform Memory Access (NUMA) nodes.  There is also information
 about the CPU caches and cache sharing, family, model, bogoMIPS, byte order,
 and stepping.
 
+In virtualized environments, the CPU architecture information displayed
+reflects the configuration of the guest operating system which is
+typically different from the physical (host) system. On architectures that
+support retreiving physical topology information,
+.B lscpu
+also displays the number of physical sockets, chips, cores in the host system.
+
 Options that result in an output table have a \fIlist\fP argument.  Use this
 argument to customize the command output.  Specify a comma-separated list of
 column labels to limit the output table to only the specified columns, arranged
index 47f690d883708437b3e584877136583898a4c91c..d55502259102292c029fbb97f54b3b303d13cfc0 100644 (file)
 # endif
 #endif
 
+#if defined(HAVE_LIBRTAS)
+#include <librtas.h>
+#endif
+
 #include <libsmartcols.h>
 
 #include "cpuset.h"
@@ -242,6 +246,9 @@ struct lscpu_desc {
        int             *polarization;  /* cpu polarization */
        int             *addresses;     /* physical cpu addresses */
        int             *configured;    /* cpu configured */
+       int             physsockets;    /* Physical sockets (modules) */
+       int             physchips;      /* Physical chips */
+       int             physcoresperchip;       /* Physical cores per chip */
 };
 
 enum {
@@ -400,6 +407,45 @@ init_mode(struct lscpu_modifier *mod)
        return m;
 }
 
+#if defined(HAVE_LIBRTAS)
+#define PROCESSOR_MODULE_INFO  43
+static int strbe16toh(const char *buf, int offset)
+{
+       return (buf[offset] << 8) + buf[offset+1];
+}
+
+static void read_physical_info_powerpc(struct lscpu_desc *desc)
+{
+       char buf[BUFSIZ];
+       int rc, len, ntypes;
+
+       desc->physsockets = desc->physchips = desc->physcoresperchip = 0;
+
+       rc = rtas_get_sysparm(PROCESSOR_MODULE_INFO, sizeof(buf), buf);
+       if (rc < 0)
+               return;
+
+       len = strbe16toh(buf, 0);
+       if (len < 8)
+               return;
+
+       ntypes = strbe16toh(buf, 2);
+
+       assert(ntypes <= 1);
+       if (!ntypes)
+               return;
+
+       desc->physsockets = strbe16toh(buf, 4);
+       desc->physchips = strbe16toh(buf, 6);
+       desc->physcoresperchip = strbe16toh(buf, 8);
+}
+#else
+static void read_physical_info_powerpc(
+               struct lscpu_desc *desc __attribute__((__unused__)))
+{
+}
+#endif
+
 static void
 read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 {
@@ -506,6 +552,9 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                desc->dispatching = path_read_s32(_PATH_SYS_CPU "/dispatching");
        else
                desc->dispatching = -1;
+
+       if (mod->system == SYSTEM_LIVE)
+               read_physical_info_powerpc(desc);
 }
 
 static int
@@ -1636,6 +1685,12 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 
        if (desc->flags)
                print_s(_("Flags:"), desc->flags);
+
+       if (desc->physsockets) {
+               print_n(_("Physical sockets:"), desc->physsockets);
+               print_n(_("Physical chips:"), desc->physchips);
+               print_n(_("Physical cores/chip:"), desc->physcoresperchip);
+       }
 }
 
 static void __attribute__((__noreturn__)) usage(FILE *out)