From 79e8b41a4a17763ac8d2dffbe72504783d002ddc Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 7 Jan 2010 17:34:03 +0100 Subject: [PATCH] lscpu: add {32,64}-bit CPU modes detection This patch add "CPU op-mode(s):" field that prints all supported CPU operation modes. The field is based on CPU flags: rm (real mode) 16-bit tm (transparent mode) 32-bit lm (long mode) 64-bit Example: $ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit CPU(s): 2 Thread(s) per core: 1 Core(s) per socket: 2 CPU socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 15 Stepping: 11 CPU MHz: 1600.000 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 4096K Signed-off-by: Karel Zak --- sys-utils/lscpu.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 6b6082fb..c200fb32 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -80,6 +80,12 @@ const char *hv_vendors[] = { [HYPER_MSHV] = "Microsoft" }; +/* CPU modes (bits) */ +enum { + MODE_REAL = (1 << 1), + MODE_TRANSPARENT = (1 << 2), + MODE_LONG = (1 << 3) +}; /* CPU(s) description */ struct cpu_desc { @@ -108,6 +114,8 @@ struct cpu_desc { char *stepping; char *flags; + int mode; /* rm, lm or/and tm */ + /* NUMA */ int *nodecpu; }; @@ -285,6 +293,13 @@ read_basicinfo(struct cpu_desc *cpu) cpu->virtflag = strdup("svm"); else if (strstr(buf, " vmx ")) cpu->virtflag = strdup("vmx"); + + if (strstr(buf, " rm ")) + cpu->mode |= MODE_REAL; + if (strstr(buf, " tm ")) + cpu->mode |= MODE_TRANSPARENT; + if (strstr(buf, " lm ")) + cpu->mode |= MODE_LONG; } fclose(fp); @@ -584,6 +599,26 @@ static void print_readable(struct cpu_desc *cpu) { print_s("Architecture:", cpu->arch); + + if (cpu->mode & (MODE_REAL | MODE_TRANSPARENT | MODE_LONG)) { + char buf[64], *p = buf; + + if (cpu->mode & MODE_REAL) { + strcpy(p, "16-bit, "); + p += 8; + } + if (cpu->mode & MODE_TRANSPARENT) { + strcpy(p, "32-bit, "); + p += 8; + } + if (cpu->mode & MODE_LONG) { + strcpy(p, "64-bit, "); + p += 8; + } + *(p - 2) = '\0'; + print_s(_("CPU op-mode(s):"), buf); + } + print_n("CPU(s):", cpu->ct_cpu); if (have_topology) { -- 2.39.5