diff options
author | Mamatha Inamdar | 2017-04-27 12:22:59 +0200 |
---|---|---|
committer | Karel Zak | 2017-05-09 12:23:37 +0200 |
commit | fc07d9f5aba7c58d9793a6c781d569316dfd25f6 (patch) | |
tree | 4d2f945bda861b0f36c7d430f27d3f6fb07acfb7 /sys-utils/lscpu.c | |
parent | sulogin: add missing type (diff) | |
download | kernel-qcow2-util-linux-fc07d9f5aba7c58d9793a6c781d569316dfd25f6.tar.gz kernel-qcow2-util-linux-fc07d9f5aba7c58d9793a6c781d569316dfd25f6.tar.xz kernel-qcow2-util-linux-fc07d9f5aba7c58d9793a6c781d569316dfd25f6.zip |
lscpu: Read available CPUs max and min frequencies
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>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r-- | sys-utils/lscpu.c | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 7da441edd..ce2760a71 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -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) { |