From: Karel Zak Date: Tue, 3 Nov 2020 10:13:26 +0000 (+0100) Subject: lscpu: improve bogomips use X-Git-Tag: v2.37-rc1~302 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc94324ebd5edf197342144a42fbf5308b250fbc;p=thirdparty%2Futil-linux.git lscpu: improve bogomips use * 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 --- diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index 38a9a2afab..706f1c779a 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -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)) { diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index ea374fd59b..ef655ec429 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -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; diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h index d76e137902..7a8835f879 100644 --- a/sys-utils/lscpu.h +++ b/sys-utils/lscpu.h @@ -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 */