diff options
| author | Karel Zak <kzak@redhat.com> | 2020-08-21 10:34:28 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2020-11-13 09:19:02 +0100 |
| commit | 05abf5944e8b21dc7cab5a261d23a84cb0af4972 (patch) | |
| tree | caebbf281f99c6e81d7b1818b123083b636fed67 /sys-utils/lscpu-topology.c | |
| parent | 6fbb53286d8d29d38185d65e5bc429c092142a48 (diff) | |
| download | util-linux-05abf5944e8b21dc7cab5a261d23a84cb0af4972.tar.gz | |
lscpu: add function to count caches size
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/lscpu-topology.c')
| -rw-r--r-- | sys-utils/lscpu-topology.c | 18 |
1 files changed, 17 insertions, 1 deletions
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; } |
