]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: add functions to get CPU freq
authorKarel Zak <kzak@redhat.com>
Thu, 3 Sep 2020 14:31:59 +0000 (16:31 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 08:19:02 +0000 (09:19 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-topology.c
sys-utils/lscpu.h

index d6cef7d20fc924c0ad01498087aceccfe943d9c3..8f948b48ceaa0c407f27f3236574800db1c35dfd 100644 (file)
@@ -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;
index 2ea5cfc5513747897a1ed3ea5d4da89384016199..011444e2f718a9bbcfde31754e091017fa74adbc 100644 (file)
@@ -90,6 +90,8 @@ struct lscpu_cputype {
        cpu_set_t       **bookmaps;
        size_t          ndrawers;
        cpu_set_t       **drawermaps;
+
+       unsigned int    has_freq;
 };
 
 /* dispatching modes */
@@ -258,6 +260,9 @@ void lscpu_sort_caches(struct lscpu_cache *caches, size_t n);
 int lscpu_read_topology(struct lscpu_cxt *cxt);
 void lscpu_cputype_free_topology(struct lscpu_cputype *ct);
 
+float lsblk_cputype_get_maxmhz(struct lscpu_cxt *cxt, struct lscpu_cputype *ct);
+float lsblk_cputype_get_minmhz(struct lscpu_cxt *cxt, struct lscpu_cputype *ct);
+
 size_t lscpu_get_cache_full_size(struct lscpu_cxt *cxt, const char *name);
 
 struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt);