Skip to content

KFunc scx_bpf_online_cmask

v7.3

Return the online cid mask in the arena of the scheduler.

Definition

Return a kernel-maintained struct scx_cmask covering all cids, [0, scx_bpf_nr_cids), in which the bits of online cids are set. The mask lives in the arena of the scheduler.

The mask follows the sched_ext hot-plug notifications: the bit of a cid is updated before the ops.cid_online or ops.cid_offline callback runs for it. So it only lags behind the online CPU mask during a hot-plug transition. Reads are live, not atomic snapshots, so outside of ops.init of the root scheduler, which runs with hot-plug excluded, concurrent updates can be observed.

Returns

A pointer to the online cid mask in the arena of the scheduler. Or NULL if the calling program is not associated with a live cid-form scheduler, or the mask is not allocated yet, such as during ops.init_cids.

The pointer is valid from ops.init until ops.exit, no reference needs to be taken. The memory is writable since it is part of the arena, but should be treated as read-only.

Signature

__arena const void *scx_bpf_online_cmask()

Usage

Schedulers using the default cid mapping can treat [0, scx_bpf_nr_online_cids) as the set of online cids, since the scheduler is restarted on hot-plug. Schedulers that install their own mapping with scx_bpf_cid_override to handle hot-plug without a restart have no such guarantee. They can use this kfunc to get the initial set of online cids, and then track changes via the ops.cid_online and ops.cid_offline callbacks.

The kfunc returns the arena offset as a void pointer, which should be cast to an arena pointer. The scx/common.bpf.h header declares the kfunc with a const void __arena * return type for this purpose.

Program types

The following program types can make use of this kfunc:

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome