cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
ad9577
From 79866c4b187e9ccf37fe333e9865a8575f4a3a16 Mon Sep 17 00:00:00 2001
ad9577
From: Karel Zak <kzak@redhat.com>
ad9577
Date: Wed, 6 Jun 2018 10:10:20 +0200
ad9577
Subject: [PATCH 169/173] lscpu: fix mzx/min MHz reporting
ad9577
ad9577
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1579439
ad9577
Signed-off-by: Karel Zak <kzak@redhat.com>
ad9577
---
ad9577
 sys-utils/lscpu.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
ad9577
 1 file changed, 48 insertions(+), 2 deletions(-)
ad9577
ad9577
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
ad9577
index 1ee73f34a..4c15de1d4 100644
ad9577
--- a/sys-utils/lscpu.c
ad9577
+++ b/sys-utils/lscpu.c
ad9577
@@ -1251,6 +1251,52 @@ read_configured(struct lscpu_desc *desc, int idx)
ad9577
 	desc->configured[idx] = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", num);
ad9577
 }
ad9577
 
ad9577
+/* Read overall maximum frequency of cpu */
ad9577
+static char *
ad9577
+cpu_max_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
ad9577
+{
ad9577
+	int i;
ad9577
+	float cpu_freq = 0.0;
ad9577
+	size_t setsize = CPU_ALLOC_SIZE(maxcpus);
ad9577
+
ad9577
+	if (desc->present) {
ad9577
+		for (i = 0; i < desc->ncpuspos; i++) {
ad9577
+			if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)
ad9577
+			    && desc->maxmhz[i]) {
ad9577
+				float freq = atof(desc->maxmhz[i]);
ad9577
+
ad9577
+				if (freq > cpu_freq)
ad9577
+					cpu_freq = freq;
ad9577
+			}
ad9577
+		}
ad9577
+	}
ad9577
+	snprintf(buf, bufsz, "%.4f", cpu_freq);
ad9577
+	return buf;
ad9577
+}
ad9577
+
ad9577
+/* Read overall minimum frequency of cpu */
ad9577
+static char *
ad9577
+cpu_min_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
ad9577
+{
ad9577
+	int i;
ad9577
+	float cpu_freq = -1.0;
ad9577
+	size_t setsize = CPU_ALLOC_SIZE(maxcpus);
ad9577
+
ad9577
+	if (desc->present) {
ad9577
+		for (i = 0; i < desc->ncpuspos; i++) {
ad9577
+			if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)
ad9577
+			    && desc->minmhz[i]) {
ad9577
+				float freq = atof(desc->minmhz[i]);
ad9577
+
ad9577
+				if (cpu_freq < 0.0 || freq < cpu_freq)
ad9577
+					cpu_freq = freq;
ad9577
+			}
ad9577
+		}
ad9577
+	}
ad9577
+        snprintf(buf, bufsz, "%.4f", cpu_freq);
ad9577
+	return buf;
ad9577
+}
ad9577
+
ad9577
 static void
ad9577
 read_max_mhz(struct lscpu_desc *desc, int idx)
ad9577
 {
ad9577
@@ -1898,9 +1944,9 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
ad9577
 	if (desc->static_mhz)
ad9577
 		print_s(_("CPU static MHz:"), desc->static_mhz);
ad9577
 	if (desc->maxmhz && desc->maxmhz[0])
ad9577
-		print_s(_("CPU max MHz:"), desc->maxmhz[0]);
ad9577
+		print_s(_("CPU max MHz:"), cpu_max_mhz(desc, buf, sizeof(buf)));
ad9577
 	if (desc->minmhz && desc->minmhz[0])
ad9577
-		print_s(_("CPU min MHz:"), desc->minmhz[0]);
ad9577
+		print_s(_("CPU min MHz:"), cpu_min_mhz(desc, buf, sizeof(buf)));
ad9577
 	if (desc->bogomips)
ad9577
 		print_s(_("BogoMIPS:"), desc->bogomips);
ad9577
 	if (desc->virtflag) {
ad9577
-- 
ad9577
2.14.4
ad9577