]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: Read available CPUs max and min frequencies
authorMamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Thu, 27 Apr 2017 10:22:59 +0000 (15:52 +0530)
committerKarel Zak <kzak@redhat.com>
Tue, 9 May 2017 10:23:37 +0000 (12:23 +0200)
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

[kzak@redhat.com: - cpu_{max,min}_mhz() refactoring]

Signed-off-by: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c

index 7da441edd045bc4ac04d36e698910edb1dc954c8..ce2760a71ad3dfa3c9bbe2a65303e0b7dfeda686 100644 (file)
@@ -1255,6 +1255,47 @@ 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]);
+
+       if (desc->present) {
+               for (i = 1; i < desc->ncpuspos; i++) {
+                       if (CPU_ISSET(real_cpu_num(desc, i), desc->present)) {
+                               float freq = atof(desc->maxmhz[i]);
+
+                               if (freq > cpu_freq)
+                                       cpu_freq = freq;
+                       }
+               }
+       }
+       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]);
+
+       if (desc->present) {
+               for (i = 1; i < desc->ncpuspos; i++) {
+                       if (CPU_ISSET(real_cpu_num(desc, i), desc->present)) {
+                               float freq = atof(desc->minmhz[i]);
+
+                               if (freq < cpu_freq)
+                                       cpu_freq = freq;
+                       }
+               }
+       }
+        sprintf(min_freq, "%.4f", cpu_freq);
+}
+
+
 static void
 read_max_mhz(struct lscpu_desc *desc, int idx)
 {
@@ -1809,7 +1850,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 +1990,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) {