All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2]lscpu: Read available CPUs max and min frequencies
@ 2017-04-27 10:22 Mamatha Inamdar
  2017-05-02  9:25 ` Karel Zak
  2017-05-09 10:24 ` Karel Zak
  0 siblings, 2 replies; 4+ messages in thread
From: Mamatha Inamdar @ 2017-04-27 10:22 UTC (permalink / raw)
  To: util-linux

Problem:"lscpu frequency-info" command was always reading CPU0
max and min frequencies. If CPU0 is guarded or offline then it used to
display max and min frequencies as NULL.

This patch will read overall CPU max and min frequencies.

Test Results:

Before Patch:

    #lscpu (CPU0 is guarded/offline)
    Architecture:          ppc64le
    Byte Order:            Little Endian
    CPU(s):                120
    On-line CPU(s) list:   8-127
    Thread(s) per core:    8
    Core(s) per socket:    3
    Socket(s):             4
    NUMA node(s):          4
    Model:                 2.1 (pvr 004b 0201)
    Model name:            POWER8E (raw), altivec supported
    CPU max MHz:           (null)
    CPU min MHz:           (null)
    L1d cache:             64K
    L1i cache:             32K
    L2 cache:              512K
    L3 cache:              8192K
    NUMA node0 CPU(s):     8-31
    NUMA node1 CPU(s):     32-63
    NUMA node16 CPU(s):    64-95
    NUMA node17 CPU(s):    96-127

With Patch:

    # ./lscpu
    Architecture:          ppc64le
    Byte Order:            Little Endian
    CPU(s):                120
    On-line CPU(s) list:   8-127
    Thread(s) per core:    8
    Core(s) per socket:    3
    Socket(s):             4
    NUMA node(s):          4
    Model:                 2.1 (pvr 004b 0201)
    Model name:            POWER8E (raw), altivec supported
    CPU max MHz:           4322.0000
    CPU min MHz:           2061.0000
    L1d cache:             64K
    L1i cache:             32K
    L2 cache:              512K
    L3 cache:              8192K
    NUMA node0 CPU(s):     8-31
    NUMA node1 CPU(s):     32-63
    NUMA node16 CPU(s):    64-95
    NUMA node17 CPU(s):    96-127

Signed-off-by: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
---
 sys-utils/lscpu.c |   45 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 7da441e..86aa875 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -1255,6 +1255,35 @@ read_configured(struct lscpu_desc *desc, int idx)
 	desc->configured[idx] = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", num);
 }
 
+/* Read overall maximum frequency of cpu */
+static void
+cpu_max_mhz(struct lscpu_desc *desc, char *max_freq)
+{
+	int i;
+	float cpu_freq = atof(desc->maxmhz[0]);
+	for (i = 1; i < desc->ncpuspos; i++) {
+		if (desc->present && CPU_ISSET(real_cpu_num(desc, i), desc->present))
+			if(atof(desc->maxmhz[i]) > cpu_freq)
+				cpu_freq = atof(desc->maxmhz[i]);
+	}
+	sprintf(max_freq, "%.4f", cpu_freq);
+}
+
+/* Read overall minimum frequency of cpu */
+static void
+cpu_min_mhz(struct lscpu_desc *desc, char *min_freq)
+{
+        int i;
+        float cpu_freq = atof(desc->minmhz[0]);
+        for (i = 1; i < desc->ncpuspos; i++) {
+                if (desc->present && CPU_ISSET(real_cpu_num(desc, i), desc->present))
+                        if(atof(desc->minmhz[i]) > cpu_freq)
+                                cpu_freq = atof(desc->minmhz[i]);
+        }
+        sprintf(min_freq, "%.4f", cpu_freq);
+}
+
+
 static void
 read_max_mhz(struct lscpu_desc *desc, int idx)
 {
@@ -1809,7 +1838,9 @@ static void
 print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 {
 	char buf[512];
-	int i;
+	int i = 0;
+	char max_freq[32];
+	char min_freq[32];
 	size_t setsize = CPU_ALLOC_SIZE(maxcpus);
 	struct libscols_table *tb;
 
@@ -1947,10 +1978,14 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 		add_summary_s(tb, _("CPU dynamic MHz:"), desc->dynamic_mhz);
 	if (desc->static_mhz)
 		add_summary_s(tb, _("CPU static MHz:"), desc->static_mhz);
-	if (desc->maxmhz)
-		add_summary_s(tb, _("CPU max MHz:"), desc->maxmhz[0]);
-	if (desc->minmhz)
-		add_summary_s(tb, _("CPU min MHz:"), desc->minmhz[0]);
+	if (desc->maxmhz){
+		cpu_max_mhz(desc, max_freq);
+		add_summary_s(tb, _("CPU max MHz:"), max_freq);
+	}
+	if (desc->minmhz){
+		cpu_min_mhz(desc, min_freq);
+		add_summary_s(tb, _("CPU min MHz:"), min_freq);
+	}
 	if (desc->bogomips)
 		add_summary_s(tb, _("BogoMIPS:"), desc->bogomips);
 	if (desc->virtflag) {


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-15 16:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-27 10:22 [PATCH V2]lscpu: Read available CPUs max and min frequencies Mamatha Inamdar
2017-05-02  9:25 ` Karel Zak
2017-05-09 10:24 ` Karel Zak
2017-05-15 16:48   ` Mamatha Inamdar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.