summaryrefslogtreecommitdiffstats
path: root/sys-utils/lscpu.c
diff options
context:
space:
mode:
authorHeiko Carstens2011-09-15 08:52:33 +0200
committerKarel Zak2011-09-27 14:48:33 +0200
commit7afc23874e2d477dd5140167c5320499ab2cc0a0 (patch)
treec2ca98826b02171ab22f3c576d8d1567c93c7f0c /sys-utils/lscpu.c
parentlscpu: fix -e output (diff)
downloadkernel-qcow2-util-linux-7afc23874e2d477dd5140167c5320499ab2cc0a0.tar.gz
kernel-qcow2-util-linux-7afc23874e2d477dd5140167c5320499ab2cc0a0.tar.xz
kernel-qcow2-util-linux-7afc23874e2d477dd5140167c5320499ab2cc0a0.zip
lscpu: add --offline option
Implement "--offline" option which only prints offline cpus. As a side effect we can get rid of the internal "allcpus" flag, since if we want to print informations for online and offline cpus we simply set both flags. When reading sysfs attributes of cpus this is now done for all cpus, since e.g. the topology informations of the online cpus may influence the topology informations of the offline cpus. This mainly because online cpus may contain masks which include offline cpus while offline cpus have a missing topology directory. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r--sys-utils/lscpu.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 340450b10..c636eb7cb 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -195,8 +195,8 @@ struct lscpu_modifier {
int system; /* SYSTEM_* */
unsigned int hex:1, /* print CPU masks rather than CPU lists */
compat:1, /* use backwardly compatible format */
- allcpus:1, /* print all CPUs */
- online:1; /* print online CPUs only */
+ online:1, /* print online CPUs */
+ offline:1; /* print offline CPUs */
};
static int maxcpus; /* size in bits of kernel cpu mask */
@@ -963,7 +963,9 @@ print_parsable(struct lscpu_desc *desc, int cols[], int ncols,
for (i = 0; i < desc->ncpus; i++) {
int c;
- if (!mod->allcpus && desc->online && !is_cpu_online(desc, i))
+ if (!mod->offline && desc->online && !is_cpu_online(desc, i))
+ continue;
+ if (!mod->online && desc->online && is_cpu_online(desc, i))
continue;
for (c = 0; c < ncols; c++) {
if (mod->compat && cols[c] == COL_CACHE) {
@@ -1006,7 +1008,9 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
int c;
struct tt_line *line;
- if (!mod->allcpus && desc->online && !is_cpu_online(desc, i))
+ if (!mod->offline && desc->online && !is_cpu_online(desc, i))
+ continue;
+ if (!mod->online && desc->online && is_cpu_online(desc, i))
continue;
line = tt_add_line(tt, NULL);
@@ -1192,6 +1196,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_OPTIONS, out);
fputs(_(" -a, --all print online and offline CPUs (default for -e)\n"
" -b, --online print online CPUs only (default for -p)\n"
+ " -c, --offline print offline CPUs only\n"
" -e, --extended[=<list>] print out a extended readable format\n"
" -h, --help print this help\n"
" -p, --parse[=<list>] print out a parsable format\n"
@@ -1221,6 +1226,7 @@ int main(int argc, char *argv[])
static const struct option longopts[] = {
{ "all", no_argument, 0, 'a' },
{ "online", no_argument, 0, 'b' },
+ { "offline", no_argument, 0, 'c' },
{ "help", no_argument, 0, 'h' },
{ "extended", optional_argument, 0, 'e' },
{ "parse", optional_argument, 0, 'p' },
@@ -1234,22 +1240,25 @@ int main(int argc, char *argv[])
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- while ((c = getopt_long(argc, argv, "abe::hp::s:xV", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "abce::hp::s:xV", longopts, NULL)) != -1) {
if (mod->mode != OUTPUT_SUMMARY && strchr("ep", c))
errx(EXIT_FAILURE,
_("extended and parsable formats are mutually exclusive"));
- if ((mod->allcpus || mod->online) && strchr("ab", c))
+ if ((mod->online || mod->offline) && strchr("abc", c))
errx(EXIT_FAILURE,
- _("--all and --online options are mutually exclusive"));
+ _("--all, --online and --offline options are mutually exclusive"));
switch (c) {
case 'a':
- mod->allcpus = 1;
+ mod->online = mod->offline = 1;
break;
case 'b':
mod->online = 1;
break;
+ case 'c':
+ mod->offline = 1;
+ break;
case 'h':
usage(stdout);
case 'p':
@@ -1280,14 +1289,15 @@ int main(int argc, char *argv[])
usage(stderr);
}
}
- if (mod->mode == OUTPUT_READABLE && !mod->online)
- mod->allcpus = 1;
+ /* set default cpu display mode if none was specified */
+ if (!mod->online && !mod->offline) {
+ mod->online = 1;
+ mod->offline = mod->mode == OUTPUT_READABLE ? 1 : 0;
+ }
read_basicinfo(desc, mod);
for (i = 0; i < desc->ncpus; i++) {
- if (desc->online && !is_cpu_online(desc, i) && !mod->allcpus)
- continue;
read_topology(desc, i);
read_cache(desc, i);
read_polarization(desc, i);