]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: sort extra caches
authorKarel Zak <kzak@redhat.com>
Mon, 17 Aug 2020 13:01:54 +0000 (15:01 +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-cputype.c

index a5abef37c3ab4497713ff0e531de9aa7b9d6eafe..189e0c1af3751719bbf399b61d235bb68eb9d08e 100644 (file)
@@ -279,6 +279,14 @@ static int cmp_pattern(const void *a0, const void *b0)
        return strcmp(a->pattern, b->pattern);
 }
 
+static int cmp_cache(const void *a0, const void *b0)
+{
+       const struct lscpu_cache
+               *a = (const struct lscpu_cache *) a0,
+               *b = (const struct lscpu_cache *) b0;
+       return strcmp(a->name, b->name);
+}
+
 struct cpuinfo_parser {
        struct lscpu_cxt        *cxt;
        struct lscpu_cpu        *curr_cpu;
@@ -535,6 +543,11 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt)
        lscpu_unref_cpu(pr->curr_cpu);
 
        fclose(fp);
+
+       if (cxt->ecaches)
+               qsort(cxt->ecaches, cxt->necaches,
+                               sizeof(struct lscpu_cache), cmp_cache);
+
        return 0;
 }