]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: improve bogomips use
authorKarel Zak <kzak@redhat.com>
Tue, 3 Nov 2020 10:13:26 +0000 (11:13 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 08:19:02 +0000 (09:19 +0100)
* keep global (cputype) bogomips
* add per-CPU bogomips
* use bogomips from the first CPU as global (for cputype) if /proc/cpuinfo does not provide global bogomips
* add BOGOMIPS column for to -e/-p output

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-cputype.c
sys-utils/lscpu.c
sys-utils/lscpu.h

index 38a9a2afab78a98357bf4bb95118999c099bdf0b..706f1c779a46c7003071bcc81e3c04ac2b8f19b6 100644 (file)
@@ -146,7 +146,8 @@ struct cpuinfo_pattern {
 /* field identifiers (field name may be different on different archs) */
 enum {
        PAT_ADDRESS_SIZES,
-       PAT_BOGOMIPS,
+       PAT_BOGOMIPS,           /* global */
+       PAT_BOGOMIPS_CPU,       /* per-cpu */
        PAT_CPU,
        PAT_FAMILY,
        PAT_FEATURES,
@@ -189,7 +190,6 @@ static const struct cpuinfo_pattern type_patterns[] =
        DEF_PAT_CPUTYPE( "CPU variant",         PAT_VARIANT,    stepping),      /* aarch64 */
        DEF_PAT_CPUTYPE( "Features",            PAT_FEATURES,   flags),         /* aarch64 */
        DEF_PAT_CPUTYPE( "address sizes",       PAT_ADDRESS_SIZES,      addrsz),/* x86 */
-       DEF_PAT_CPUTYPE( "bogomips",            PAT_BOGOMIPS,   bogomips),
        DEF_PAT_CPUTYPE( "bogomips per cpu",    PAT_BOGOMIPS,   bogomips),      /* s390 */
        DEF_PAT_CPUTYPE( "cpu",                 PAT_CPU,        modelname),     /* ppc, sparc */
        DEF_PAT_CPUTYPE( "cpu family",          PAT_FAMILY,     family),
@@ -220,11 +220,12 @@ static const struct cpuinfo_pattern type_patterns[] =
 static const struct cpuinfo_pattern cpu_patterns[] =
 {
        /* Sort by fields name! */
-       DEF_PAT_CPU( "cpu MHz",         PAT_MHZ,        mhz),
-       DEF_PAT_CPU( "cpu MHz dynamic", PAT_MHZ_DYNAMIC,dynamic_mhz),   /* s390 */
-       DEF_PAT_CPU( "cpu MHz static",  PAT_MHZ_STATIC, static_mhz),    /* s390 */
-       DEF_PAT_CPU( "cpu number",      PAT_PROCESSOR,  logical_id),    /* s390 */
-        DEF_PAT_CPU( "processor",      PAT_PROCESSOR,  logical_id),
+       DEF_PAT_CPU( "bogomips",        PAT_BOGOMIPS_CPU, bogomips),
+       DEF_PAT_CPU( "cpu MHz dynamic", PAT_MHZ_DYNAMIC,  dynamic_mhz), /* s390 */
+       DEF_PAT_CPU( "cpu MHz static",  PAT_MHZ_STATIC,   static_mhz),  /* s390 */
+       DEF_PAT_CPU( "cpu MHz",         PAT_MHZ,          mhz),
+       DEF_PAT_CPU( "cpu number",      PAT_PROCESSOR,    logical_id),  /* s390 */
+        DEF_PAT_CPU( "processor",      PAT_PROCESSOR,    logical_id),
 
 };
 
@@ -490,6 +491,8 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt)
                                pr->curr_type->dynamic_mhz = xstrdup(value);
                        if (pattern->id == PAT_MHZ_STATIC && pr->curr_type && !pr->curr_type->static_mhz)
                                pr->curr_type->static_mhz = xstrdup(value);
+                       if (pattern->id == PAT_BOGOMIPS_CPU && pr->curr_type && !pr->curr_type->bogomips)
+                               pr->curr_type->bogomips = xstrdup(value);
                        break;
                case CPUINFO_LINE_CPUTYPE:
                        if (pr->curr_type && is_different_cputype(pr->curr_type, pattern->offset, value)) {
index ea374fd59bebc461c8af3d0c23eb8654f02a4cb7..ef655ec42916817509d7ceca48b9716ea5cc0e87 100644 (file)
@@ -91,6 +91,7 @@ static struct polarization_modes polar_modes[] = {
  * IDs
  */
 enum {
+       COL_CPU_BOGOMIPS,
        COL_CPU_CPU,
        COL_CPU_CORE,
        COL_CPU_SOCKET,
@@ -134,6 +135,7 @@ struct lscpu_coldesc {
 
 static struct lscpu_coldesc coldescs_cpu[] =
 {
+       [COL_CPU_BOGOMIPS]     = { "BOGOMIPS", N_("crude measurement of CPU speed"), SCOLS_FL_RIGHT, 1 },
        [COL_CPU_CPU]          = { "CPU", N_("logical CPU number"), SCOLS_FL_RIGHT, 1 },
        [COL_CPU_CORE]         = { "CORE", N_("logical core number"), SCOLS_FL_RIGHT },
        [COL_CPU_SOCKET]       = { "SOCKET", N_("logical socket number"), SCOLS_FL_RIGHT },
@@ -325,6 +327,12 @@ static char *get_cell_data(
        case COL_CPU_CPU:
                snprintf(buf, bufsz, "%d", cpu->logical_id);
                break;
+       case COL_CPU_BOGOMIPS:
+               if (cpu->bogomips)
+                       xstrncpy(buf, cpu->bogomips, bufsz);
+               else if (cpu->type->bogomips)
+                       xstrncpy(buf, cpu->type->bogomips, bufsz);
+               break;
        case COL_CPU_CORE:
                fill_id(cxt, cpu, core, buf, bufsz);
                break;
index d76e1379026ac18ce197e557f09372da2663d4a6..7a8835f8792e04e811c4530ac66c05204c5df934 100644 (file)
@@ -120,6 +120,7 @@ struct lscpu_cpu {
 
        int logical_id;
 
+       char    *bogomips;      /* per-CPU bogomips */
        char    *mhz;           /* max freq from cpuinfo */
        char    *dynamic_mhz;   /* from cpuinf for s390 */
        char    *static_mhz;    /* from cpuinf for s390 */