public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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