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.
*/
ca->type = xstrdup(type);
DBG(GATHER, ul_debugobj(cxt, "add cache %s%d::%d", type, level, id));
-
return ca;
}
}
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;
}
}
}
-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
*/
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;
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);