#define CMASK_MAX_WORDS 129
#endif
-#define CMASK_NR_WORDS(nr_bits) (((nr_bits) + 63) / 64 + 1)
+#define CMASK_NR_WORDS(nr_cids) (((nr_cids) + 63) / 64 + 1)
static __always_inline bool __cmask_contains(const struct scx_cmask __arena *m, u32 cid)
{
- return cid >= m->base && cid < m->base + m->nr_bits;
+ return cid >= m->base && cid < m->base + m->nr_cids;
}
static __always_inline u64 __arena *__cmask_word(const struct scx_cmask __arena *m, u32 cid)
return (u64 __arena *)&m->bits[cid / 64 - m->base / 64];
}
-static __always_inline void cmask_init(struct scx_cmask __arena *m, u32 base, u32 nr_bits)
+static __always_inline void cmask_init(struct scx_cmask __arena *m, u32 base, u32 nr_cids)
{
- u32 nr_words = CMASK_NR_WORDS(nr_bits), i;
+ u32 nr_words = CMASK_NR_WORDS(nr_cids), i;
m->base = base;
- m->nr_bits = nr_bits;
+ m->nr_cids = nr_cids;
bpf_for(i, 0, CMASK_MAX_WORDS) {
if (i >= nr_words)
static __always_inline void cmask_zero(struct scx_cmask __arena *m)
{
- u32 nr_words = CMASK_NR_WORDS(m->nr_bits), i;
+ u32 nr_words = CMASK_NR_WORDS(m->nr_cids), i;
bpf_for(i, 0, CMASK_MAX_WORDS) {
if (i >= nr_words)
static __always_inline void cmask_op(struct scx_cmask __arena *dst,
const struct scx_cmask __arena *src, int op)
{
- u32 d_end = dst->base + dst->nr_bits;
- u32 s_end = src->base + src->nr_bits;
+ u32 d_end = dst->base + dst->nr_cids;
+ u32 s_end = src->base + src->nr_cids;
u32 lo = dst->base > src->base ? dst->base : src->base;
u32 hi = d_end < s_end ? d_end : s_end;
u32 d_base = dst->base / 64;
/*
* cmask_and/or/copy only modify @dst bits that lie in the intersection of
- * [@dst->base, @dst->base + @dst->nr_bits) and [@src->base,
- * @src->base + @src->nr_bits). Bits in @dst outside that window
+ * [@dst->base, @dst->base + @dst->nr_cids) and [@src->base,
+ * @src->base + @src->nr_cids). Bits in @dst outside that window
* keep their prior values - in particular, cmask_copy() does NOT zero @dst
* bits that lie outside @src's range.
*/
{
u32 nr_words, i;
- if (a->base != b->base || a->nr_bits != b->nr_bits)
+ if (a->base != b->base || a->nr_cids != b->nr_cids)
return false;
- nr_words = CMASK_NR_WORDS(a->nr_bits);
+ nr_words = CMASK_NR_WORDS(a->nr_cids);
bpf_for(i, 0, CMASK_MAX_WORDS) {
if (i >= nr_words)
static __always_inline bool cmask_subset(const struct scx_cmask __arena *a,
const struct scx_cmask __arena *b)
{
- u32 a_end = a->base + a->nr_bits;
- u32 b_end = b->base + b->nr_bits;
+ u32 a_end = a->base + a->nr_cids;
+ u32 b_end = b->base + b->nr_cids;
u32 a_wbase = a->base / 64;
u32 b_wbase = b->base / 64;
u32 nr_words, i;
if (a->base < b->base || a_end > b_end)
return false;
- nr_words = CMASK_NR_WORDS(a->nr_bits);
+ nr_words = CMASK_NR_WORDS(a->nr_cids);
bpf_for(i, 0, CMASK_MAX_WORDS) {
u32 wi_b;
* @m: cmask to search
* @cid: starting cid (clamped to @m->base if below)
*
- * Returns the smallest set cid in [@cid, @m->base + @m->nr_bits), or
- * @m->base + @m->nr_bits if none (the out-of-range sentinel matches the
+ * Returns the smallest set cid in [@cid, @m->base + @m->nr_cids), or
+ * @m->base + @m->nr_cids if none (the out-of-range sentinel matches the
* termination condition used by cmask_for_each()).
*/
static __always_inline u32 cmask_next_set(const struct scx_cmask __arena *m, u32 cid)
{
- u32 end = m->base + m->nr_bits;
+ u32 end = m->base + m->nr_cids;
u32 base = m->base / 64;
u32 last_wi = (end - 1) / 64 - base;
u32 start_wi, start_bit, i;
#define cmask_for_each(cid, m) \
for ((cid) = cmask_first_set(m); \
- (cid) < (m)->base + (m)->nr_bits; \
+ (cid) < (m)->base + (m)->nr_cids; \
(cid) = cmask_next_set((m), (cid) + 1))
/*
- * Population count over [base, base + nr_bits). Padding bits in the head/tail
+ * Population count over [base, base + nr_cids). Padding bits in the head/tail
* words are guaranteed zero by the mutating helpers, so a flat popcount over
* all words is correct.
*/
static __always_inline u32 cmask_weight(const struct scx_cmask __arena *m)
{
- u32 nr_words = CMASK_NR_WORDS(m->nr_bits), i;
+ u32 nr_words = CMASK_NR_WORDS(m->nr_cids), i;
u32 count = 0;
bpf_for(i, 0, CMASK_MAX_WORDS) {
static __always_inline bool cmask_intersects(const struct scx_cmask __arena *a,
const struct scx_cmask __arena *b)
{
- u32 a_end = a->base + a->nr_bits;
- u32 b_end = b->base + b->nr_bits;
+ u32 a_end = a->base + a->nr_cids;
+ u32 b_end = b->base + b->nr_cids;
u32 lo = a->base > b->base ? a->base : b->base;
u32 hi = a_end < b_end ? a_end : b_end;
u32 a_base = a->base / 64;
/*
* Find the next cid set in both @a and @b at or after @start, bounded by the
- * intersection of the two ranges. Return a->base + a->nr_bits if none found.
+ * intersection of the two ranges. Return a->base + a->nr_cids if none found.
*
* Building block for cmask_next_and_set_wrap(). Callers that want a bounded
* scan without wrap call this directly.
const struct scx_cmask __arena *b,
u32 start)
{
- u32 a_end = a->base + a->nr_bits;
- u32 b_end = b->base + b->nr_bits;
+ u32 a_end = a->base + a->nr_cids;
+ u32 b_end = b->base + b->nr_cids;
u32 a_wbase = a->base / 64;
u32 b_wbase = b->base / 64;
u32 lo = a->base > b->base ? a->base : b->base;
/*
* Find the next set cid in @m at or after @start, wrapping to @m->base if no
- * set bit is found in [start, m->base + m->nr_bits). Return m->base +
- * m->nr_bits if @m is empty.
+ * set bit is found in [start, m->base + m->nr_cids). Return m->base +
+ * m->nr_cids if @m is empty.
*
* Callers do round-robin distribution by passing (last_cid + 1) as @start.
*/
static __always_inline u32 cmask_next_set_wrap(const struct scx_cmask __arena *m,
u32 start)
{
- u32 end = m->base + m->nr_bits;
+ u32 end = m->base + m->nr_cids;
u32 found;
found = cmask_next_set(m, start);
/*
* Find the next cid set in both @a and @b at or after @start, wrapping to
- * @a->base if none found in the forward half. Return a->base + a->nr_bits
+ * @a->base if none found in the forward half. Return a->base + a->nr_cids
* if the intersection is empty.
*
* Callers do round-robin distribution by passing (last_cid + 1) as @start.
const struct scx_cmask __arena *b,
u32 start)
{
- u32 a_end = a->base + a->nr_bits;
+ u32 a_end = a->base + a->nr_cids;
u32 found;
found = cmask_next_and_set(a, b, start);
/**
* cmask_from_cpumask - translate a kernel cpumask to a cid-space cmask
* @m: cmask to fill. Zeroed first; only bits within [@m->base, @m->base +
- * @m->nr_bits) are updated - cpus mapping to cids outside that range
+ * @m->nr_cids) are updated - cpus mapping to cids outside that range
* are ignored.
* @cpumask: kernel cpumask to translate
*
static __always_inline void cmask_copy_from_kernel(struct scx_cmask __arena *dst,
const struct scx_cmask *src)
{
- u32 base = 0, nr_bits = 0, nr_words, wi;
+ u32 base = 0, nr_cids = 0, nr_words, wi;
if (dst->base != 0) {
scx_bpf_error("cmask_copy_from_kernel requires dst->base == 0");
return;
}
- if (bpf_probe_read_kernel(&nr_bits, sizeof(nr_bits), &src->nr_bits)) {
- scx_bpf_error("probe-read cmask->nr_bits failed");
+ if (bpf_probe_read_kernel(&nr_cids, sizeof(nr_cids), &src->nr_cids)) {
+ scx_bpf_error("probe-read cmask->nr_cids failed");
return;
}
- if (nr_bits > dst->nr_bits) {
- scx_bpf_error("src cmask nr_bits=%u exceeds dst nr_bits=%u",
- nr_bits, dst->nr_bits);
+ if (nr_cids > dst->nr_cids) {
+ scx_bpf_error("src cmask nr_cids=%u exceeds dst nr_cids=%u",
+ nr_cids, dst->nr_cids);
return;
}
- nr_words = CMASK_NR_WORDS(nr_bits);
+ nr_words = CMASK_NR_WORDS(nr_cids);
cmask_zero(dst);
bpf_for(wi, 0, CMASK_MAX_WORDS) {
u64 word = 0;