From: Karel Zak Date: Mon, 17 Aug 2020 13:01:54 +0000 (+0200) Subject: lscpu: sort extra caches X-Git-Tag: v2.37-rc1~338 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e36e01f980f1a9c6944a138e974848fac9cb3206;p=thirdparty%2Futil-linux.git lscpu: sort extra caches Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index a5abef37c3..189e0c1af3 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -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; }