1 /* Copyright (c) 2015 Google Inc
2 * Davide Libenzi <dlibenzi@google.com>
3 * See LICENSE for details.
9 #include <arch/topology.h>
10 #include <ros/common.h>
16 unsigned long cpus[DIV_ROUND_UP(MAX_NUM_CORES, BITS_PER_LONG)];
19 static inline void core_set_init(struct core_set *cset)
21 memset(cset, 0, sizeof(*cset));
24 static inline void core_set_setcpu(struct core_set *cset, unsigned int cpuno)
26 __set_bit(cpuno, cset->cpus);
29 static inline void core_set_clearcpu(struct core_set *cset, unsigned int cpuno)
31 __clear_bit(cpuno, cset->cpus);
34 static inline bool core_set_getcpu(const struct core_set *cset,
37 return test_bit(cpuno, cset->cpus);
40 static inline void core_set_fill_available(struct core_set *cset)
42 for (int i = 0; i < num_cores; i++)
43 core_set_setcpu(cset, i);
46 static inline int core_set_count(const struct core_set *cset)
50 for (size_t i = 0; i < ARRAY_SIZE(cset->cpus); i++) {
51 for (unsigned long v = cset->cpus[i]; v; v >>= 1)
52 count += (int) (v & 1);
58 static inline int core_set_remote_count(const struct core_set *cset)
60 int count = core_set_count(cset), cpu = core_id();
62 return core_set_getcpu(cset, cpu) ? count - 1: count;