From: Karel Zak Date: Fri, 21 Aug 2020 08:34:28 +0000 (+0200) Subject: lscpu: add function to count caches size X-Git-Tag: v2.37-rc1~326 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=05abf5944e8b21dc7cab5a261d23a84cb0af4972;p=thirdparty%2Futil-linux.git lscpu: add function to count caches size Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu-topology.c b/sys-utils/lscpu-topology.c index f4c2ff2a31..e24900a4ba 100644 --- a/sys-utils/lscpu-topology.c +++ b/sys-utils/lscpu-topology.c @@ -221,6 +221,19 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct return 0; } +/* count size of all instancess of the "name" */ +size_t lscpu_get_cache_full_size(struct lscpu_cxt *cxt, const char *name) +{ + size_t i, sz = 0; + + for (i = 0; i < cxt->ncaches; i++) { + if (strcmp(cxt->caches[i].name, name) == 0) + sz += cxt->caches[i].size; + } + + return sz; +} + /* * The cache is identifued by type+level+id. */ @@ -256,7 +269,6 @@ static struct lscpu_cache *add_cache(struct lscpu_cxt *cxt, ca->type = xstrdup(type); DBG(GATHER, ul_debugobj(cxt, "add cache %s%d::%d", type, level, id)); - return ca; } @@ -458,6 +470,10 @@ int lscpu_read_topology(struct lscpu_cxt *cxt) } lscpu_sort_caches(cxt->caches, cxt->ncaches); + DBG(GATHER, ul_debugobj(cxt, " L1d: %zu", lscpu_get_cache_full_size(cxt, "L1d"))); + DBG(GATHER, ul_debugobj(cxt, " L1i: %zu", lscpu_get_cache_full_size(cxt, "L1i"))); + DBG(GATHER, ul_debugobj(cxt, " L2: %zu", lscpu_get_cache_full_size(cxt, "L2"))); + DBG(GATHER, ul_debugobj(cxt, " L3: %zu", lscpu_get_cache_full_size(cxt, "L3"))); return rc; } diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index c4c5af9ddd..6dbbee48de 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -790,32 +790,6 @@ print_cpuset(struct libscols_table *tb, } } -static int get_cache_full_size(struct lscpu_desc *desc, - struct cpu_cache *ca, uint64_t *res) -{ - size_t setsize = CPU_ALLOC_SIZE(maxcpus); - int i, nshares = 0; - - /* Count number of CPUs which shares the cache */ - for (i = 0; i < desc->ncpuspos; i++) { - int cpu = real_cpu_num(desc, i); - - if (desc->present && !is_cpu_present(desc, cpu)) - continue; - if (CPU_ISSET_S(cpu, setsize, ca->sharedmaps[0])) - nshares++; - } - - /* Correction for CPU threads */ - if (desc->nthreads > desc->ncores) - nshares /= (desc->nthreads / desc->ncores); - if (nshares < 1) - nshares = 1; - - *res = (desc->ncores / nshares) * ca->size; - return 0; -} - /* * default output */ diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h index d3dd77edea..45ac844417 100644 --- a/sys-utils/lscpu.h +++ b/sys-utils/lscpu.h @@ -209,7 +209,7 @@ struct lscpu_cxt { struct lscpu_vulnerability *vuls; /* array of CPU vulnerabilities */ size_t nvuls; /* number of CPU vulnerabilities */ - struct lscpu_cache *caches; + struct lscpu_cache *caches; /* all instances of the all caches from /sys */ size_t ncaches; struct lscpu_cache *ecaches; @@ -249,6 +249,8 @@ 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); +size_t lscpu_get_cache_full_size(struct lscpu_cxt *cxt, const char *name); + struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt); void lscpu_free_architecture(struct lscpu_arch *ar);