int lscpu_read_cpulists(struct lscpu_cxt *cxt)
{
- size_t maxn;
- size_t setsize;
cpu_set_t *cpuset = NULL;
assert(cxt);
* real /sys, let's use any crazy number... */
cxt->maxcpus = 2048;
- maxn = cxt->maxcpus;
- setsize = CPU_ALLOC_SIZE(maxn);
+ cxt->setsize = CPU_ALLOC_SIZE(cxt->maxcpus);
/* create CPUs from possible mask */
- if (ul_path_readf_cpulist(cxt->syscpu, &cpuset, maxn, "possible") == 0) {
- lscpu_create_cpus(cxt, cpuset, setsize);
+ if (ul_path_readf_cpulist(cxt->syscpu, &cpuset, cxt->maxcpus, "possible") == 0) {
+ lscpu_create_cpus(cxt, cpuset, cxt->setsize);
cpuset_free(cpuset);
cpuset = NULL;
} else
/* get mask for present CPUs */
- if (ul_path_readf_cpulist(cxt->syscpu, &cxt->present, maxn, "present") == 0)
- cxt->npresents = CPU_COUNT_S(setsize, cxt->present);
+ if (ul_path_readf_cpulist(cxt->syscpu, &cxt->present, cxt->maxcpus, "present") == 0)
+ cxt->npresents = CPU_COUNT_S(cxt->setsize, cxt->present);
/* get mask for online CPUs */
- if (ul_path_readf_cpulist(cxt->syscpu, &cxt->online, maxn, "online") == 0)
- cxt->nonlines = CPU_COUNT_S(setsize, cxt->online);
+ if (ul_path_readf_cpulist(cxt->syscpu, &cxt->online, cxt->maxcpus, "online") == 0)
+ cxt->nonlines = CPU_COUNT_S(cxt->setsize, cxt->online);
return 0;
}
/* Read topology for specified type */
static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
{
- size_t i, setsize, npos;
+ size_t i, npos;
struct path_cxt *sys;
int nthreads = 0, sw_topo = 0;
FILE *fd;
sys = cxt->syscpu; /* /sys/devices/system/cpu/ */
- setsize = CPU_ALLOC_SIZE(cxt->maxcpus); /* CPU set size */
npos = cxt->npossibles; /* possible CPUs */
DBG(TYPE, ul_debugobj(ct, "reading %s/%s/%s topology",
ul_path_readf_cpuset(sys, &drawer_siblings, cxt->maxcpus,
"cpu%d/topology/drawer_siblings", num);
- n = CPU_COUNT_S(setsize, thread_siblings);
+ n = CPU_COUNT_S(cxt->setsize, thread_siblings);
if (!n)
n = 1;
if (n > nthreads)
ct->drawermaps = xcalloc(npos, sizeof(cpu_set_t *));
/* add to topology maps */
- add_cpuset_to_array(ct->coremaps, &ct->ncores, thread_siblings, setsize);
- add_cpuset_to_array(ct->socketmaps, &ct->nsockets, core_siblings, setsize);
+ add_cpuset_to_array(ct->coremaps, &ct->ncores, thread_siblings, cxt->setsize);
+ add_cpuset_to_array(ct->socketmaps, &ct->nsockets, core_siblings, cxt->setsize);
if (book_siblings)
- add_cpuset_to_array(ct->bookmaps, &ct->nbooks, book_siblings, setsize);
+ add_cpuset_to_array(ct->bookmaps, &ct->nbooks, book_siblings, cxt->setsize);
if (drawer_siblings)
- add_cpuset_to_array(ct->drawermaps, &ct->ndrawers, drawer_siblings, setsize);
+ add_cpuset_to_array(ct->drawermaps, &ct->ndrawers, drawer_siblings, cxt->setsize);
}
char buf[256];
struct path_cxt *sys = cxt->syscpu;
int num = cpu->logical_id;
- size_t i, ncaches, setsize;
+ size_t i, ncaches;
ncaches = cxt->ncaches;
while (ul_path_accessf(sys, F_OK,
num, ncaches) == 0)
ncaches++;
- setsize = CPU_ALLOC_SIZE(cxt->maxcpus);
-
for (i = 0; i < ncaches; i++) {
struct lscpu_cache *ca;
cpu_set_t *map;
if (!ca->sharedmaps)
ca->sharedmaps = xcalloc(cxt->npossibles, sizeof(cpu_set_t *));
- add_cpuset_to_array(ca->sharedmaps, &ca->nsharedmaps, map, setsize);
+ add_cpuset_to_array(ca->sharedmaps, &ca->nsharedmaps, map, cxt->setsize);
}
return 0;
struct lscpu_cxt {
int maxcpus; /* size in bits of kernel cpu mask */
+ size_t setsize;
const char *prefix; /* path to /sys and /proc snapshot or NULL */
struct path_cxt *syscpu; /* _PATH_SYS_CPU path handler */
};
+#define is_cpu_online(_cxt, _cpu) \
+ ((_cxt) && (_cpu) && (_cxt)->online && \
+ CPU_ISSET_S((_cpu)->logical_id, (_cxt)->setsize, (_cxt)->online))
+
+#define is_cpu_present(_cxt, _cpu) \
+ ((_cxt) && (_cpu) && (_cxt)->present && \
+ CPU_ISSET_S((_cpu)->logical_id, (_cxt)->setsize, (_cxt)->present))
+
struct lscpu_cputype *lscpu_new_cputype(void);
void lscpu_ref_cputype(struct lscpu_cputype *ct);
void lscpu_unref_cputype(struct lscpu_cputype *ct);