* [PATCH] lscpu: report cpu min mhz
@ 2013-09-22 3:43 Davidlohr Bueso
2013-09-22 9:39 ` Sami Kerola
2013-09-25 9:23 ` Karel Zak
0 siblings, 2 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2013-09-22 3:43 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <davidlohr@hp.com>
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 <davidlohr@hp.com>
---
sys-utils/lscpu.c | 50 +++++++++++++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 13 deletions(-)
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 98cee16..71ee84a 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;
@@ -1291,8 +1310,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) {
@@ -1461,6 +1482,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)
@@ -1507,8 +1529,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;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] lscpu: report cpu min mhz
2013-09-22 3:43 [PATCH] lscpu: report cpu min mhz Davidlohr Bueso
@ 2013-09-22 9:39 ` Sami Kerola
2013-09-23 19:00 ` Davidlohr Bueso
2013-09-25 9:23 ` Karel Zak
1 sibling, 1 reply; 4+ messages in thread
From: Sami Kerola @ 2013-09-22 9:39 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: Karel Zak, util-linux
On 22 September 2013 04:43, Davidlohr Bueso <davidlohr@hp.com> wrote:
> 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.
Hi Davidlohr,
The patch seems to work as one might expect. Only small thing seems to require
attention, tests broke again. Could you run in util-linux source directory
./tests/run.sh lscpu
and adjust expected outputs accordingly?
Tested-by: Sami Kerola <kerolasa@iki.fi>
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lscpu: report cpu min mhz
2013-09-22 9:39 ` Sami Kerola
@ 2013-09-23 19:00 ` Davidlohr Bueso
0 siblings, 0 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2013-09-23 19:00 UTC (permalink / raw)
To: kerolasa; +Cc: Karel Zak, util-linux
On Sun, 2013-09-22 at 10:39 +0100, Sami Kerola wrote:
> On 22 September 2013 04:43, Davidlohr Bueso <davidlohr@hp.com> wrote:
> > 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.
>
> Hi Davidlohr,
>
> The patch seems to work as one might expect. Only small thing seems to require
> attention, tests broke again. Could you run in util-linux source directory
>
> ./tests/run.sh lscpu
>
> and adjust expected outputs accordingly?
This actually don't break for me, I get the following with or without
this patch:
-------------------- util-linux regression tests --------------------
For development purpose only.
Don't execute on production system!
lscpu: ...
: armv7 ... FAILED (lscpu/lscpu-armv7)
: ppc64-POWER7-64cpu ... OK
: ppc64-POWER7 ... OK
: s390-kvm ... OK
: s390-lpar ... OK
: s390-zvm ... OK
: x86_64-64cpu ... FAILED (lscpu/lscpu-x86_64-64cpu)
: x86_64-dell_e4310 ... FAILED (lscpu/lscpu-x86_64-dell_e4310)
... FAILED (3 from 8 sub-tests)
---------------------------------------------------------------------
1 tests of 1 FAILED
---------------------------------------------------------------------
Also, these tests seem to bee arch-specific, so not sure how valuable
updating them would be.
Thanks,
Davidlohr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lscpu: report cpu min mhz
2013-09-22 3:43 [PATCH] lscpu: report cpu min mhz Davidlohr Bueso
2013-09-22 9:39 ` Sami Kerola
@ 2013-09-25 9:23 ` Karel Zak
1 sibling, 0 replies; 4+ messages in thread
From: Karel Zak @ 2013-09-25 9:23 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
On Sat, Sep 21, 2013 at 08:43:40PM -0700, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <davidlohr@hp.com>
>
> 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 <davidlohr@hp.com>
> ---
> sys-utils/lscpu.c | 50 +++++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 37 insertions(+), 13 deletions(-)
Applied, thanks. (I'll update tests if necessary).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-25 9:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-22 3:43 [PATCH] lscpu: report cpu min mhz Davidlohr Bueso
2013-09-22 9:39 ` Sami Kerola
2013-09-23 19:00 ` Davidlohr Bueso
2013-09-25 9:23 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox