cdown / rpms / util-linux

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