From e065a597d6d13455e388b44d94f51ac4ba539570 Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Sat, 21 Sep 2013 20:43:40 -0700 Subject: lscpu: report cpu min mhz The lscpu tool only shows the current and max CPU frequencies, however, in many scenarios this is not enough. If there are energy saving situations (like some CPUs being idle, or not fully used) the cpugov can lower this value. Signed-off-by: Davidlohr Bueso --- sys-utils/lscpu.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'sys-utils/lscpu.c') diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 265562217..b266beca0 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -148,7 +148,8 @@ struct lscpu_desc { int hyper; /* hypervisor vendor ID */ int virtype; /* VIRT_PARA|FULL|NONE ? */ char *mhz; - char **mmhz; /* maximum mega hertz */ + char **maxmhz; /* maximum mega hertz */ + char **minmhz; /* minimum mega hertz */ char *stepping; char *bogomips; char *flags; @@ -231,7 +232,8 @@ enum { COL_ADDRESS, COL_CONFIGURED, COL_ONLINE, - COL_MMHZ, + COL_MAXMHZ, + COL_MINMHZ, }; /* column description @@ -255,7 +257,8 @@ static struct lscpu_coldesc coldescs[] = [COL_ADDRESS] = { "ADDRESS", N_("physical address of a CPU") }, [COL_CONFIGURED] = { "CONFIGURED", N_("shows if the hypervisor has allocated the CPU") }, [COL_ONLINE] = { "ONLINE", N_("shows if Linux currently makes use of the CPU") }, - [COL_MMHZ] = { "MMHZ", N_("shows the maximum mhz of the CPU") } + [COL_MAXMHZ] = { "MAXMHZ", N_("shows the maximum mhz of the CPU") }, + [COL_MINMHZ] = { "MINMHZ", N_("shows the minimum mhz of the CPU") } }; static int @@ -785,13 +788,25 @@ read_max_mhz(struct lscpu_desc *desc, int num) { if (!path_exist(_PATH_SYS_CPU "/cpu%d/cpufreq/cpuinfo_max_freq", num)) return; - if (!desc->mmhz) - desc->mmhz = xcalloc(desc->ncpuspos, sizeof(char *)); - xasprintf(&(desc->mmhz[num]), "%.4f", + if (!desc->maxmhz) + desc->maxmhz = xcalloc(desc->ncpuspos, sizeof(char *)); + xasprintf(&(desc->maxmhz[num]), "%.4f", (float)path_read_s32(_PATH_SYS_CPU "/cpu%d/cpufreq/cpuinfo_max_freq", num) / 1000); } +static void +read_min_mhz(struct lscpu_desc *desc, int num) +{ + if (!path_exist(_PATH_SYS_CPU "/cpu%d/cpufreq/cpuinfo_min_freq", num)) + return; + if (!desc->minmhz) + desc->minmhz = xcalloc(desc->ncpuspos, sizeof(char *)); + xasprintf(&(desc->minmhz[num]), "%.4f", + (float)path_read_s32(_PATH_SYS_CPU + "/cpu%d/cpufreq/cpuinfo_min_freq", num) / 1000); +} + static int cachecmp(const void *a, const void *b) { @@ -980,9 +995,13 @@ get_cell_data(struct lscpu_desc *desc, int cpu, int col, snprintf(buf, bufsz, is_cpu_online(desc, cpu) ? _("yes") : _("no")); break; - case COL_MMHZ: - if (desc->mmhz) - xstrncpy(buf, desc->mmhz[cpu], bufsz); + case COL_MAXMHZ: + if (desc->maxmhz) + xstrncpy(buf, desc->maxmhz[cpu], bufsz); + break; + case COL_MINMHZ: + if (desc->minmhz) + xstrncpy(buf, desc->minmhz[cpu], bufsz); break; } return buf; @@ -1293,8 +1312,10 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod) print_s(_("Stepping:"), desc->stepping); if (desc->mhz) print_s(_("CPU MHz:"), desc->mhz); - if (desc->mmhz) - print_s(_("CPU max MHz:"), desc->mmhz[0]); + if (desc->maxmhz) + print_s(_("CPU max MHz:"), desc->maxmhz[0]); + if (desc->minmhz) + print_s(_("CPU min MHz:"), desc->minmhz[0]); if (desc->bogomips) print_s(_("BogoMIPS:"), desc->bogomips); if (desc->virtflag) { @@ -1463,6 +1484,7 @@ int main(int argc, char *argv[]) read_address(desc, i); read_configured(desc, i); read_max_mhz(desc, i); + read_min_mhz(desc, i); } if (desc->caches) @@ -1509,8 +1531,10 @@ int main(int argc, char *argv[]) columns[ncolumns++] = COL_POLARIZATION; if (desc->addresses) columns[ncolumns++] = COL_ADDRESS; - if (desc->mmhz) - columns[ncolumns++] = COL_MMHZ; + if (desc->maxmhz) + columns[ncolumns++] = COL_MAXMHZ; + if (desc->minmhz) + columns[ncolumns++] = COL_MINMHZ; } print_readable(desc, columns, ncolumns, mod); break; -- cgit v1.2.3-55-g7522