various lscpu changes
cover various lscpu changes
Hi Karel,
another set of patches against lscpu. Since you didn't have chance to push out your local tree to kernel.org yet, I simply based them on my old lscpu branch which you applied on your local tree:
git://git.kernel.org/pub/scm/linux/kernel/git/heiko/util-linux.git lscpu
So, in theory there shouldn't be any merge conflicts ;)
Also, due to master.kernel.org being down I didn't set up a new git branch.
Anyway, the most notable change/addition is the new "-e|--extended" option which prints a human readable extended cpu table:
CPU BOOK SOCKET CORE ONLINE CONFIGURED POLARIZATION ADDRESS
0 0 0 0 yes yes vert-medium 0 1 0 0 1 yes yes vert-low 1 2 0 0 2 yes yes vert-low 2 3 0 1 3 yes yes vert-low 3 4 0 1 4 yes yes vert-low 4 5 0 1 5 yes yes vert-low 5 6 1 2 6 yes yes vert-low 6 7 1 2 - no yes vert-low 7 8 1 2 - no yes vert-low 8 9 - - - no no - 9 10 - - - no no - 10 11 1 3 7 yes yes vert-low 11 12 1 3 8 yes yes vert-low 12 13 1 3 9 yes yes vert-low 13 14 1 3 10 yes yes vert-low 14 15 1 4 11 yes yes vert-low 15 16 1 5 12 yes yes vert-low 16 17 1 5 13 yes yes vert-low 17 18 1 5 14 yes yes vert-low 18 19 1 6 15 yes yes vert-low 19
Hopefully the patches don't look too bad. :)
Thanks,
Heiko
PATCH 1/11 lscpu: remove comma operator
Fix typo where the comma operator has been introduced.
Use a semicolon instead so we end up with simple assignment expressions.
--- sys-utils/lscpu.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
sys-utils/lscpu.c +2 -2
@@ -1218,8 +1218,8 @@ int main(int argc, char *argv[]) }else { columns[ncolumns++] =COL_CPU ; columns[ncolumns++] =COL_CORE ; - columns[ncolumns++] =COL_SOCKET , - columns[ncolumns++] =COL_NODE , + columns[ncolumns++] =COL_SOCKET ; + columns[ncolumns++] =COL_NODE ; columns[ncolumns++] =COL_CACHE ; compatible =1 ; }
Signature · 1 line
1.7.5.4
PATCH 2/11 lscpu: fix cache output for extended parsable output
In reply to Heiko CarstensThe extended parsable output prints a colon instead of comma between each item. The case where a CPU doesn't belong to any cache was not converted. Just fix this.
--- sys-utils/lscpu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
sys-utils/lscpu.c +1 -1
@@ -922,7 +922,7 @@ print_parsable_cell(struct lscpu_desc *desc, int i, int col, int compatible) } }if (x == ca->nsharedmaps) -putchar (',' ); +putchar (compatible ?',' :':' ); }break ;case COL_POLARIZATION :
Signature · 1 line
1.7.5.4
PATCH 3/11 lscpu: simplify cache column output function
In reply to Heiko CarstensSimplify the logic to "always print a ',' for each cache except if it is the last one.
This is also a preparation patch for printing the cache column for offline CPUs where it would print one colon too much because of the current logic.
--- sys-utils/lscpu.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
sys-utils/lscpu.c +1 -3
@@ -915,13 +915,11 @@ print_parsable_cell(struct lscpu_desc *desc, int i, int col, int compatible)for (x =0 ; x < ca->nsharedmaps; x++) {if (CPU_ISSET_S (i, setsize, ca->sharedmaps[x])) { -if (j != desc->ncaches -1 ) -putchar (compatible ?',' :':' );printf ("%d" , x);break ; } } -if (x == ca->nsharedmaps) +if (j !=0 )putchar (compatible ?',' :':' ); }break ;
Signature · 1 line
1.7.5.4
PATCH 4/11 lscpu: allow read_cache() to be called for offline cpus
In reply to Heiko CarstensFirst check path before accessing files to be sure they actually exist. This is necessary when also informations for offline CPUs will be printed.
Since we do not necessarily know if "cpu is offline" means the same as "path does not exist" just check for it.
--- sys-utils/lscpu.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
sys-utils/lscpu.c +3 -0
@@ -804,6 +804,9 @@ read_cache(struct lscpu_desc *desc, int num)struct cpu_cache *ca = &desc->caches[i];cpu_set_t *map; +if (!path_exist (_PATH_SYS_SYSTEM"/cpu/cpu%d/cache/index%d" , + num, i)) +continue ;if (!ca->name) {int type, level;
Signature · 1 line
1.7.5.4
PATCH 5/11 lscpu: add --version option
In reply to Heiko CarstensAdd a --version option like most other tools have it.
--- sys-utils/lscpu.1 | 5 ++++- sys-utils/lscpu.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-)
sys-utils/lscpu.1 +4 -1
@@ -6,7 +6,7 @@ lscpu \- CPU architecture information helper .SH SYNOPSIS .B lscpu -.RB [ \-hpx ] +.RB [ \-hpxV ] .RB [ \-s .IR directory ] .SH DESCRIPTION
@@ -47,6 +47,9 @@ a snapshot from a different system. .BR \-x , " \-\-hex" Use hexadecimal masks for CPU sets (e.g. 0x3). The default is to print the sets in list format (e.g. 0,1). +.TP +.BR \-V , " \-\-version" +Output version information and exit. .SH BUGS The basic overview about CPU family, model, etc. is always based on the first CPU only.
sys-utils/lscpu.c +8 -2
@@ -1178,7 +1178,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)" -h, --help print this help\n" " -p, --parse[=LIST] print out a parsable instead of a readable format\n" " -s, --sysroot DIR use directory DIR as system root\n" - " -x, --hex print hexadecimal masks rather than lists of CPUs\n")); +" -x, --hex print hexadecimal masks rather than lists of CPUs\n" + " -V, --version output version information and exit\n"));exit (out == stderr ?EXIT_FAILURE :EXIT_SUCCESS ); }
@@ -1195,6 +1196,7 @@ int main(int argc, char *argv[]) { "parse", optional_argument, 0, 'p' }, { "sysroot", required_argument, 0, 's' }, { "hex", no_argument, 0, 'x' }, + { "version", no_argument, 0, 'V' }, { NULL, 0, 0, 0 } };
@@ -1202,7 +1204,7 @@ int main(int argc, char *argv[])bindtextdomain (PACKAGE ,LOCALEDIR );textdomain (PACKAGE ); -while ((c =getopt_long (argc, argv,"hp::s:x" , longopts,NULL )) !=-1 ) { +while ((c =getopt_long (argc, argv,"hp::s:xV" , longopts,NULL )) !=-1 ) {switch (c) {case 'h' :usage (stdout);
@@ -1233,6 +1235,10 @@ int main(int argc, char *argv[])case 'x' : hex =1 ;break ; +case 'V' : +printf (_ ("%s from %s\n" ), program_invocation_short_name, +PACKAGE_STRING ); +return EXIT_SUCCESS ;default :usage (stderr); }
Signature · 1 line
1.7.5.4
PATCH 6/11 lscpu: add human readable extended cpu table output
In reply to Heiko Carstenslscpu currently only supports a parsable output which contains a row for each cpu and its attributes. This output contains only comas as separators and is hard to read for humans.
Therefore add a new option "-e | --extended" which outputs the rows in a much more readable (and non-parsable) form. Just like for the -p option a list of columns can be specified that shall be included in the output. By default this option will print all columns that contain data.
--- sys-utils/Makefile.am | 5 +- sys-utils/lscpu.1 | 29 +++++-- sys-utils/lscpu.c | 239 +++++++++++++++++++++++++++++++++++++------------ 3 files changed, 206 insertions(+), 67 deletions(-)
sys-utils/Makefile.am +4 -1
@@ -19,7 +19,10 @@ dist_man_MANS += dmesg.1 ctrlaltdel.8 cytune.8 setarch.8 \ if HAVE_CPU_SET_T usrbin_exec_PROGRAMS += lscpu -lscpu_SOURCES = lscpu.c $(top_srcdir)/lib/cpuset.c $(top_srcdir)/lib/strutils.c +lscpu_SOURCES = lscpu.c $(top_srcdir)/lib/cpuset.c \ + $(top_srcdir)/lib/strutils.c \ + $(top_srcdir)/lib/mbsalign.c \ + $(top_srcdir)/lib/tt.c dist_man_MANS += lscpu.1 endif
sys-utils/lscpu.1 +21 -8
@@ -6,7 +6,7 @@ lscpu \- CPU architecture information helper .SH SYNOPSIS .B lscpu -.RB [ \-hpxV ] +.RB [ \-ehpxV ] .RB [ \-s .IR directory ] .SH DESCRIPTION
@@ -18,24 +18,37 @@ a human-readable format. It supports both online and offline CPUs. It can also print out in a parsable format, including how different caches are shared by different CPUs, which can be fed to other programs. + +Some options have a \fIlist\fP argument. The \fIlist\fP argument is a comma +delimited list of the columns. Currently supported are CPU, Core, Node, Socket, +Book, Cache, Polarization and Address columns. +If the \fIlist\fP argument is given then all requested columns are printed in +the defined order. + .SH OPTIONS .TP +.TP +.BR \-e , " \-\-extended " \fI[=list]\fP +Print CPU list out in human-readable format. + +If the \fIlist\fP argument is not given then all columns where data is +available will be printed. + +Note that the optional \fIlist\fP argument cannot be separated from the +option by a space, the correct form is for example '\fB-e=cpu,node\fP' or '\fB--extended=cpu,node\fP'. +.TP .BR \-h , " \-\-help" Print a help message. .TP .BR \-p , " \-\-parse " \fI[=list]\fP -Print out in parsable instead of human-readable format. +Print out in parsable format. If the \fIlist\fP argument is not given then the default backwardly compatible output is printed. The backwardly compatible format uses two commas to separate CPU cache columns. If no CPU caches are identified, then the cache columns are not printed at all. - -The \fIlist\fP argument is comma delimited list of the columns. Currently -supported are CPU, Core, Node, Socket, Book, Cache, Polarization and Address -columns. -If the \fIlist\fP argument is given then always all requested columns are printed in -the defined order. The Cache columns are separated by ':'. +.br +If the \fIlist\fP argument is given then the cache columns are separated by ':'. Note that the optional \fIlist\fP argument cannot be separated from the option by a space, the correct form is for example '\fB-p=cpu,node\fP' or '\fB--parse=cpu,node\fP'.
sys-utils/lscpu.c +181 -58
417 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 7/11 lscpu: add configured state to output
In reply to Heiko CarstensCPUs may be in a configured or deconfigured state depending if the CPU resource may be used by the guest.
If a CPU is in configured state the guest may use it (i.e. set it online). It it is in deconfigured state it cannot use it before changing its state to configured.
Display this CPU attribute as well.
--- sys-utils/lscpu.1 | 2 +- sys-utils/lscpu.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-)
sys-utils/lscpu.1 +1 -1
@@ -21,7 +21,7 @@ which can be fed to other programs. Some options have a \fIlist\fP argument. The \fIlist\fP argument is a comma delimited list of the columns. Currently supported are CPU, Core, Node, Socket, -Book, Cache, Polarization and Address columns. +Book, Cache, Polarization, Address and Configured columns. If the \fIlist\fP argument is given then all requested columns are printed in the defined order.
sys-utils/lscpu.c +26 -2
@@ -175,6 +175,7 @@ struct lscpu_desc {int *polarization;/* cpu polarization */ int *addresses;/* physical cpu addresses */ +int *configured;/* cpu configured */ };struct lscpu_modifier {
@@ -213,7 +214,8 @@ enum {COL_BOOK ,COL_CACHE ,COL_POLARIZATION , -COL_ADDRESS +COL_ADDRESS , + COL_CONFIGURED, }; static const char *colnames[] =
@@ -225,7 +227,8 @@ static const char *colnames[] = [COL_BOOK] = "Book", [COL_CACHE] = "Cache", [COL_POLARIZATION] = "Polarization", - [COL_ADDRESS] = "Address" + [COL_ADDRESS] = "Address", + [COL_CONFIGURED] = "Configured", };
@@ -787,6 +790,16 @@ read_address(struct lscpu_desc *desc, int num) desc->addresses[num] =path_getnum (_PATH_SYS_CPU"/cpu%d/address" , num); } +static void +read_configured (struct lscpu_desc *desc,int num) +{ +if (!path_exist (_PATH_SYS_CPU"/cpu%d/configure" , num)) +return ; +if (!desc->configured) + desc->configured =xcalloc (desc->ncpus,sizeof (int )); + desc->configured[num] =path_getnum (_PATH_SYS_CPU"/cpu%d/configure" , num); +} +static int cachecmp (const void *a,const void *b) {
@@ -977,6 +990,14 @@ print_cell(struct lscpu_desc *desc, int i, int col, int c,if (desc->addresses)asprintfc (&buffer,"%d" , desc->addresses[i]);break ; +case COL_CONFIGURED : +if (!desc->configured) +break ; +if (mod->formatted) +asprintfc (&buffer, desc->configured[i] ?"yes" :"no" ); +else +asprintfc (&buffer,"%d" , desc->configured[i]); +break ; }if (mod->formatted) {if (strlen (buffer) ==0 )
@@ -1358,6 +1379,7 @@ int main(int argc, char *argv[])read_cache (desc, i);read_polarization (desc, i);read_address (desc, i); +read_configured (desc, i); }qsort (desc->caches, desc->ncaches,sizeof (struct cpu_cache ), cachecmp);
@@ -1380,6 +1402,8 @@ int main(int argc, char *argv[]) columns[ncolumns++] =COL_CORE ;if (desc->caches) columns[ncolumns++] =COL_CACHE ; +if (desc->configured) + columns[ncolumns++] =COL_CONFIGURED ;if (desc->polarization) columns[ncolumns++] =COL_POLARIZATION ;if (desc->addresses)
Signature · 1 line
1.7.5.4
PATCH 8/11 lscpu: add online state to output
In reply to Heiko Carstenslscpu only prints lines for online CPUs. At least for the human readable list the offline CPUs are of interest as well. In order to distinguish between online and offline CPUs introduce the "Online" column. By default the human readable output now displays online and offline CPUs. The parsable output is not changed. It will print only lines for online CPUs as it used to do.
--- sys-utils/lscpu.1 | 2 +- sys-utils/lscpu.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-)
sys-utils/lscpu.1 +1 -1
@@ -21,7 +21,7 @@ which can be fed to other programs. Some options have a \fIlist\fP argument. The \fIlist\fP argument is a comma delimited list of the columns. Currently supported are CPU, Core, Node, Socket, -Book, Cache, Polarization, Address and Configured columns. +Book, Cache, Polarization, Address, Configured and Online columns. If the \fIlist\fP argument is given then all requested columns are printed in the defined order.
sys-utils/lscpu.c +16 -2
@@ -182,6 +182,7 @@ struct lscpu_modifier {int compat;int formatted;int hex; +int allcpus; };static size_t sysrootlen;
@@ -216,6 +217,7 @@ enum {COL_POLARIZATION ,COL_ADDRESS ,COL_CONFIGURED , + COL_ONLINE, }; static const char *colnames[] =
@@ -229,6 +231,7 @@ static const char *colnames[] = [COL_POLARIZATION] = "Polarization", [COL_ADDRESS] = "Address", [COL_CONFIGURED] = "Configured", + [COL_ONLINE] = "Online", };
@@ -998,6 +1001,14 @@ print_cell(struct lscpu_desc *desc, int i, int col, int c,else asprintfc (&buffer,"%d" , desc->configured[i]);break ; +case COL_ONLINE : +if (!desc->online) +break ; +if (mod->formatted) +asprintfc (&buffer,is_cpu_online (desc, i) ?"yes" :"no" ); +else +asprintfc (&buffer,"%d" , !!is_cpu_online (desc, i)); +break ; }if (mod->formatted) {if (strlen (buffer) ==0 )
@@ -1094,7 +1105,7 @@ print_table(struct lscpu_desc *desc, int cols[], int ncols, struct lscpu_modifiefor (i =0 ; i < desc->ncpus; i++) {struct tt_line *line; -if (desc->online && !is_cpu_online (desc, i)) +if (!mod->allcpus && desc->online && !is_cpu_online (desc, i))continue ;if (mod->formatted) line =tt_add_line (tt,NULL );
@@ -1321,6 +1332,7 @@ int main(int argc, char *argv[])case 'e' : print_cpu_table =1 ; mod->formatted =1 ; + mod->allcpus =1 ; ncolumns =-1 ;if (optarg) {if (*optarg =='=' )
@@ -1373,7 +1385,7 @@ int main(int argc, char *argv[])read_basicinfo (desc);for (i =0 ; i < desc->ncpus; i++) { -if (desc->online && !is_cpu_online (desc, i)) +if (!mod->allcpus && desc->online && !is_cpu_online (desc, i))continue ;read_topology (desc, i);read_cache (desc, i);
@@ -1402,6 +1414,8 @@ int main(int argc, char *argv[]) columns[ncolumns++] =COL_CORE ;if (desc->caches) columns[ncolumns++] =COL_CACHE ; +if (desc->online) + columns[ncolumns++] =COL_ONLINE ;if (desc->configured) columns[ncolumns++] =COL_CONFIGURED ;if (desc->polarization)
Signature · 1 line
1.7.5.4
PATCH 9/11 lscpu: add --all option
In reply to Heiko CarstensThe parsable output includes only lines of online CPUs. To also include lines for all offline CPUs the "--all" option can be specified.
--- sys-utils/lscpu.1 | 4 +++- sys-utils/lscpu.c | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-)
sys-utils/lscpu.1 +3 -1
@@ -6,7 +6,7 @@ lscpu \- CPU architecture information helper .SH SYNOPSIS .B lscpu -.RB [ \-ehpxV ] +.RB [ \-aehpxV ] .RB [ \-s .IR directory ] .SH DESCRIPTION
@@ -27,6 +27,8 @@ the defined order. .SH OPTIONS .TP +.BR \-a , " \-\-all" +Include online and offline CPUs in output. .TP .BR \-e , " \-\-extended " \fI[=list]\fP Print CPU list out in human-readable format.
sys-utils/lscpu.c +6 -1
@@ -1293,6 +1293,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)" -p, --parse[=LIST] print out a parsable instead of a readable format\n" " -e, --table[=LIST] print out a readable format\n" " -s, --sysroot DIR use directory DIR as system root\n" +" -a, --all print online and offline CPUs\n" " -x, --hex print hexadecimal masks rather than lists of CPUs\n" " -V, --version output version information and exit\n"));
@@ -1308,6 +1309,7 @@ int main(int argc, char *argv[])int print_cpu_table =0 ;static const struct option longopts[] = { + {"all" , no_argument,0 ,'a' }, {"extended" , optional_argument,0 ,'e' }, {"help" , no_argument,0 ,'h' }, {"parse" , optional_argument,0 ,'p' },
@@ -1322,11 +1324,14 @@ int main(int argc, char *argv[])textdomain (PACKAGE );memset (mod,0 ,sizeof (*mod)); -while ((c =getopt_long (argc, argv,"e::hp::s:xV" , longopts,NULL )) !=-1 ) { +while ((c =getopt_long (argc, argv,"ae::hp::s:xV" , longopts,NULL )) !=-1 ) {if (print_cpu_table &&strchr ("ep" , c))errx (EXIT_FAILURE ,_ ("extended and parsable are mutually exclusive" ));switch (c) { +case 'a' : + mod->allcpus =1 ; +break ;case 'h' :usage (stdout);case 'e' :
Signature · 1 line
1.7.5.4
PATCH 10/11 lscpu: add s390 test case
In reply to Heiko Carstens--- tests/expected/lscpu/lscpu-s390-lpar | 35 +++++++++++++++++++++++++++++++++ tests/expected/lscpu/lscpu-s390-zvm | 21 +++++++++++++++++++ tests/ts/lscpu/bla.tar.gz | Bin 0 -> 2573 bytes tests/ts/lscpu/dumps/s390-lpar.tar.gz | Bin 0 -> 6611 bytes tests/ts/lscpu/dumps/s390-zvm.tar.gz | Bin 0 -> 2582 bytes tests/ts/lscpu/mk-input.sh | 4 +++ 6 files changed, 60 insertions(+), 0 deletions(-) create mode 100644 tests/expected/lscpu/lscpu-s390-lpar create mode 100644 tests/expected/lscpu/lscpu-s390-zvm create mode 100644 tests/ts/lscpu/bla.tar.gz create mode 100644 tests/ts/lscpu/dumps/s390-lpar.tar.gz create mode 100644 tests/ts/lscpu/dumps/s390-zvm.tar.gz
tests/expected/lscpu/lscpu-s390-lpar new file +35 -0
@@ -0,0 +1,35 @@ +CPU op-mode(s): 32-bit, 64-bit +CPU(s): 20 +On-line CPU(s) list: 1-5,8-19 +Off-line CPU(s) list: 0,6,7 +Thread(s) per core: 1 +Core(s) per socket: 4 +Socket(s) per book: 6 +Book(s): 4 +Vendor ID: IBM/S390 +BogoMIPS: 14367.00 +Hypervisor vendor: IBM +Virtualization type: full +Dispatching mode: vertical + +# The following is the parsable format, which can be fed to other +# programs. Each different item in every column has an unique ID +# starting from zero. +# CPU,Core,Socket,Node +1,0,0, +2,1,0, +3,2,1, +4,3,1, +5,4,1, +8,5,2, +9,6,2, +10,7,2, +11,8,3, +12,9,3, +13,10,3, +14,11,3, +15,12,4, +16,13,5, +17,14,5, +18,15,5, +19,16,6,
tests/expected/lscpu/lscpu-s390-zvm new file +21 -0
@@ -0,0 +1,21 @@ +CPU op-mode(s): 32-bit, 64-bit +CPU(s): 4 +On-line CPU(s) list: 0-3 +Thread(s) per core: 1 +Core(s) per socket: 1 +Socket(s) per book: 1 +Book(s): 4 +Vendor ID: IBM/S390 +BogoMIPS: 14367.00 +Hypervisor vendor: IBM +Virtualization type: full +Dispatching mode: horizontal + +# The following is the parsable format, which can be fed to other +# programs. Each different item in every column has an unique ID +# starting from zero. +# CPU,Core,Socket,Node +0,0,0, +1,1,1, +2,2,2, +3,3,3,
tests/ts/lscpu/bla.tar.gz new file binary +0 -0
tests/ts/lscpu/dumps/s390-lpar.tar.gz new file binary +0 -0
tests/ts/lscpu/dumps/s390-zvm.tar.gz new file binary +0 -0
tests/ts/lscpu/mk-input.sh +4 -0
@@ -30,6 +30,10 @@ if [ -d "/proc/xen" ]; then fi fi +if [ -e "/proc/sysinfo" ]; then + $CP /proc/sysinfo $TS_DUMP +fi + $CP /sys/devices/system/cpu/* $TS_DUMP $CP /sys/devices/system/node/*/cpumap $TS_DUMP
Signature · 1 line
1.7.5.4
PATCH 11/11 lscpu: add Hypervisor to output
In reply to Heiko CarstensSome vendors have several hypervisors. Therefore it makes sense to not only print out the hypervisor vendor but also the name of the hypervisor.
--- sys-utils/lscpu.c | 20 ++++++++++++++++++++ tests/expected/lscpu/lscpu-s390-lpar | 1 + tests/expected/lscpu/lscpu-s390-zvm | 1 + 3 files changed, 22 insertions(+), 0 deletions(-)
sys-utils/lscpu.c +20 -0
@@ -138,6 +138,7 @@ struct lscpu_desc {char *family;char *model;char *virtflag;/* virtualization flag (vmx, svm) */ +char *hypervisor;/* hypervisor software */ int hyper;/* hypervisor vendor ID */ int virtype;/* VIRT_PARA|FULL|NONE ? */ char *mhz;
@@ -666,14 +667,31 @@ read_hypervisor(struct lscpu_desc *desc)char buf[BUFSIZ ]; desc->hyper =HYPER_IBM ; + desc->hypervisor ="PR/SM" ; desc->virtype =VIRT_FULL ;while (fgets (buf,sizeof (buf), fd) !=NULL ) { +char *str; +if (!strstr (buf,"Control Program:" ))continue ;if (!strstr (buf,"KVM" )) desc->hyper =HYPER_IBM ;else desc->hyper =HYPER_KVM ; + str =strchr (buf,':' ); +if (!str) +continue ; +if (asprintf (&str, str +1 ) ==-1 ) +errx (EXIT_FAILURE ,_ ("failed to allocate memory" )); +/* remove leading, trailing and repeating whitespace */ +while (*str ==' ' ) + str++; + desc->hypervisor = str; + str +=strlen (str) -1 ; +while ((*str =='\n' ) || (*str ==' ' )) + *(str--) ='\0' ; +while (str =strstr (desc->hypervisor," " )) +memmove (str, str +1 ,strlen (str)); }fclose (fd); }
@@ -1259,6 +1277,8 @@ print_readable(struct lscpu_desc *desc, struct lscpu_modifier *mod)else if (!strcmp (desc->virtflag,"vmx" ))print_s (_ ("Virtualization:" ),"VT-x" ); } +if (desc->hypervisor) +print_s (_ ("Hypervisor:" ), desc->hypervisor);if (desc->hyper) {print_s (_ ("Hypervisor vendor:" ), hv_vendors[desc->hyper]);print_s (_ ("Virtualization type:" ), virt_types[desc->virtype]);
tests/expected/lscpu/lscpu-s390-lpar +1 -0
@@ -8,6 +8,7 @@ Socket(s) per book: 6 Book(s): 4 Vendor ID: IBM/S390 BogoMIPS: 14367.00 +Hypervisor: PR/SM Hypervisor vendor: IBM Virtualization type: full Dispatching mode: vertical
tests/expected/lscpu/lscpu-s390-zvm +1 -0
@@ -7,6 +7,7 @@ Socket(s) per book: 1 Book(s): 4 Vendor ID: IBM/S390 BogoMIPS: 14367.00 +Hypervisor: z/VM 6.1.0 Hypervisor vendor: IBM Virtualization type: full Dispatching mode: horizontal
Signature · 1 line
1.7.5.4
Karel Zak
maintainerQuoted 3 lines · Heiko Carstens
another set of patches against lscpu. Since you didn't have chance to push out your local tree to kernel.org yet, I simply based them on my old lscpu branch which you applied on your local tree:
Merged (available on github) with some minor changes. I have also added --online to disable by default enabled --all for -e.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 7 lines · Karel Zak
Quoted 3 lines · Heiko Carstens
another set of patches against lscpu. Since you didn't have chance to push out your local tree to kernel.org yet, I simply based them on my old lscpu branch which you applied on your local tree:
Merged (available on github) with some minor changes. I have also added --online to disable by default enabled --all for -e.
I wouldn't say that were minor changes :) But the result looks much better than my code. Thanks!
However I'd like to see one change if you don't object: printing just "N" or "Y" instead of "No" and "Yes" in the human readable output looks a bit ugly to me:
[root@r35lp37 sys-utils]# ./lscpu -e
CPU BOOK SOCKET CORE ONLINE CONFIGURED POLARIZATION ADDRESS
0 0 0 0 Y Y horizontal 0 1 - - - N N - 1 2 0 0 2 Y Y horizontal 2 3 0 1 3 Y Y horizontal 3 4 0 1 4 Y Y horizontal 4 5 0 1 5 Y Y horizontal 5 6 0 1 6 Y Y horizontal 6 7 0 2 7 Y Y horizontal 7 8 0 2 8 Y Y horizontal 8 9 0 2 9 Y Y horizontal 9 10 0 3 10 Y Y horizontal 10 11 0 3 11 Y Y horizontal 11 12 0 3 12 Y Y horizontal 12 13 0 4 13 Y Y horizontal 13 14 0 4 14 Y Y horizontal 14 15 0 5 15 Y Y horizontal 15 16 1 6 16 Y Y horizontal 16 17 1 7 17 Y Y horizontal 17 18 1 7 18 Y Y horizontal 18 19 1 7 19 Y Y horizontal 19
Comparing that to the long form:
CPU BOOK SOCKET CORE ONLINE CONFIGURED POLARIZATION ADDRESS
0 0 0 0 Yes Yes horizontal 0 1 - - - No No - 1 2 0 0 1 Yes Yes horizontal 2 3 0 1 2 Yes Yes horizontal 3 4 0 1 3 Yes Yes horizontal 4 5 0 1 4 Yes Yes horizontal 5 6 0 1 5 Yes Yes horizontal 6 7 0 2 6 Yes Yes horizontal 7 8 0 2 7 Yes Yes horizontal 8 9 0 2 8 Yes Yes horizontal 9 10 0 3 9 Yes Yes horizontal 10 11 0 3 10 Yes Yes horizontal 11 12 0 3 11 Yes Yes horizontal 12 13 0 4 12 Yes Yes horizontal 13 14 0 4 13 Yes Yes horizontal 14 15 0 5 14 Yes Yes horizontal 15 16 1 6 15 Yes Yes horizontal 16 17 1 7 16 Yes Yes horizontal 17 18 1 7 17 Yes Yes horizontal 18 19 1 7 18 Yes Yes horizontal 19
I'd prefer the long form. What do you think?
sys-utils/lscpu.c +14 -3
@@ -995,13 +995,24 @@ get_cell_data(struct lscpu_desc *desc, int cpu, int col,snprintf (buf, bufsz,"%d" , desc->addresses[cpu]);break ;case COL_CONFIGURED : -if (desc->configured) +if (!desc->configured) +break ; +if (mod->mode ==OUTPUT_PARSABLE )snprintf (buf, bufsz, desc->configured[cpu] ?_ ("Y" ) :_ ("N" )); +else +snprintf (buf, bufsz, + desc->configured[cpu] ?_ ("Yes" ) :_ ("No" ));break ;case COL_ONLINE : -if (desc->online) -snprintf (buf, bufsz,is_cpu_online (desc, cpu) ?_ ("Y" ) :_ ("N" )); +if (!desc->online) +break ; +if (mod->mode ==OUTPUT_PARSABLE ) +snprintf (buf, bufsz, +is_cpu_online (desc, cpu) ?_ ("Y" ) :_ ("N" )); +else +snprintf (buf, bufsz, +is_cpu_online (desc, cpu) ?_ ("Yes" ) :_ ("No" ));break ; }return buf;
Quoted 3 lines · Heiko Carstens
However I'd like to see one change if you don't object: printing just "N" or "Y" instead of "No" and "Yes" in the human readable output looks a bit ugly to me:
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com