summaryrefslogtreecommitdiffstats
path: root/sys-utils/lscpu.c
diff options
context:
space:
mode:
authorHeiko Carstens2011-09-06 02:52:59 +0200
committerKarel Zak2011-09-09 23:49:22 +0200
commita7e5300c9714db147a3a700b7ebc55e391922d7d (patch)
tree0f181750274ed53510c48d38886b4c739087c652 /sys-utils/lscpu.c
parentlscpu: add configured state to output (diff)
downloadkernel-qcow2-util-linux-a7e5300c9714db147a3a700b7ebc55e391922d7d.tar.gz
kernel-qcow2-util-linux-a7e5300c9714db147a3a700b7ebc55e391922d7d.tar.xz
kernel-qcow2-util-linux-a7e5300c9714db147a3a700b7ebc55e391922d7d.zip
lscpu: add online state to output
lscpu 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. [kzak@redhat.com: - minor changes] Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r--sys-utils/lscpu.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 319412120..490c0f4eb 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -184,9 +184,10 @@ enum {
};
struct lscpu_modifier {
- int mode; /* OUTPUT_* */
- int hex:1; /* print CPU masks rather than CPU lists */
- int compat:1; /* use backwardly compatible format */
+ int mode; /* OUTPUT_* */
+ unsigned int hex:1, /* print CPU masks rather than CPU lists */
+ compat:1, /* use backwardly compatible format */
+ allcpus:1; /* print all CPUs */
};
static size_t sysrootlen;
@@ -221,6 +222,7 @@ enum {
COL_POLARIZATION,
COL_ADDRESS,
COL_CONFIGURED,
+ COL_ONLINE,
};
static const char *colnames[] =
@@ -234,6 +236,7 @@ static const char *colnames[] =
[COL_POLARIZATION] = "Polarization",
[COL_ADDRESS] = "Address",
[COL_CONFIGURED] = "Configured",
+ [COL_ONLINE] = "Online",
};
@@ -977,6 +980,10 @@ get_cell_data(struct lscpu_desc *desc, int cpu, int col,
snprintf(buf, bufsz,
desc->configured[cpu] ? _("Y") : _("N"));
break;
+ case COL_ONLINE:
+ if (desc->online)
+ snprintf(buf, bufsz, is_cpu_online(desc, cpu) ? _("Y") : _("N"));
+ break;
}
return buf;
}
@@ -1072,7 +1079,7 @@ print_parsable(struct lscpu_desc *desc, int cols[], int ncols,
for (i = 0; i < desc->ncpus; i++) {
int c;
- if (desc->online && !is_cpu_online(desc, i))
+ if (!mod->allcpus && desc->online && !is_cpu_online(desc, i))
continue;
for (c = 0; c < ncols; c++) {
if (mod->compat && cols[c] == COL_CACHE) {
@@ -1118,7 +1125,7 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
int c;
struct tt_line *line;
- if (desc->online && !is_cpu_online(desc, i))
+ if (!mod->allcpus && desc->online && !is_cpu_online(desc, i))
continue;
line = tt_add_line(tt, NULL);
@@ -1126,7 +1133,7 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
for (c = 0; c < ncols; c++) {
data = get_cell_data(desc, i, cols[c], mod,
buf, sizeof(buf));
- tt_line_set_data(line, c, xstrdup(data));
+ tt_line_set_data(line, c, data && *data ? xstrdup(data) : "-");
}
}
@@ -1401,6 +1408,7 @@ int main(int argc, char *argv[])
print_parsable(desc, columns, ncolumns, mod);
break;
case OUTPUT_READABLE:
+ mod->allcpus = 1;
if (!ncolumns) {
/* No list was given. Just print whatever is there. */
columns[ncolumns++] = COL_CPU;
@@ -1414,6 +1422,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)