From e36e01f980f1a9c6944a138e974848fac9cb3206 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 17 Aug 2020 15:01:54 +0200 Subject: [PATCH] lscpu: sort extra caches Signed-off-by: Karel Zak --- sys-utils/lscpu-cputype.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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; } -- 2.47.3