diff options
| author | Karel Zak <kzak@redhat.com> | 2020-09-03 16:31:59 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2020-11-13 09:19:02 +0100 |
| commit | 6d5699e6b567ad83a0fd16c9b44864ec24f24c28 (patch) | |
| tree | e54df702edfa7ca48714bc2642c609cea679ea61 /sys-utils/lscpu-topology.c | |
| parent | 406b088cb422e36f920a1a976ddccd7a9d5a900c (diff) | |
| download | util-linux-6d5699e6b567ad83a0fd16c9b44864ec24f24c28.tar.gz | |
lscpu: add functions to get CPU freq
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/lscpu-topology.c')
| -rw-r--r-- | sys-utils/lscpu-topology.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sys-utils/lscpu-topology.c b/sys-utils/lscpu-topology.c index d6cef7d20f..8f948b48ce 100644 --- a/sys-utils/lscpu-topology.c +++ b/sys-utils/lscpu-topology.c @@ -436,9 +436,44 @@ static int read_mhz(struct lscpu_cxt *cxt, struct lscpu_cpu *cpu) cpu->mhz_max_freq = (float) mhz / 1000; if (ul_path_readf_s32(sys, &mhz, "cpu%d/cpufreq/cpuinfo_min_freq", num) == 0) cpu->mhz_min_freq = (float) mhz / 1000; + + if (cpu->type && (cpu->mhz_min_freq || cpu->mhz_max_freq)) + cpu->type->has_freq = 1; + return 0; } +float lsblk_cputype_get_maxmhz(struct lscpu_cxt *cxt, struct lscpu_cputype *ct) +{ + size_t i; + float res = 0.0; + + for (i = 0; i < cxt->npossibles; i++) { + struct lscpu_cpu *cpu = cxt->cpus[i]; + + if (!cpu || cpu->type != ct || !is_cpu_present(cxt, cpu)) + continue; + res = max(res, cpu->mhz_max_freq); + } + return res; +} + +float lsblk_cputype_get_minmhz(struct lscpu_cxt *cxt, struct lscpu_cputype *ct) +{ + size_t i; + float res = -1.0; + + for (i = 0; i < cxt->npossibles; i++) { + struct lscpu_cpu *cpu = cxt->cpus[i]; + + if (!cpu || cpu->type != ct || !is_cpu_present(cxt, cpu)) + continue; + if (res < 0.0 || cpu->mhz_min_freq < res) + res = cpu->mhz_min_freq; + } + return res; +} + int lscpu_read_topology(struct lscpu_cxt *cxt) { size_t i; |
