• David Vernet's avatar
    sched_ext: Implement sched_ext_ops.cpu_acquire/release() · 245254f7
    David Vernet authored
    Scheduler classes are strictly ordered and when a higher priority class has
    tasks to run, the lower priority ones lose access to the CPU. Being able to
    monitor and act on these events are necessary for use cases includling
    strict core-scheduling and latency management.
    
    This patch adds two operations ops.cpu_acquire() and .cpu_release(). The
    former is invoked when a CPU becomes available to the BPF scheduler and the
    opposite for the latter. This patch also implements
    scx_bpf_reenqueue_local() which can be called from .cpu_release() to trigger
    requeueing of all tasks in the local dsq of the CPU so that the tasks can be
    reassigned to other available CPUs.
    
    scx_pair is updated to use .cpu_acquire/release() along with
    %SCX_KICK_WAIT to make the pair scheduling guarantee strict even when a CPU
    is preempted by a higher priority scheduler class.
    
    scx_qmap is updated to use .cpu_acquire/release() to empty the local
    dsq of a preempted CPU. A similar approach can be adopted by BPF schedulers
    that want to have a tight control over latency.
    
    v4: Use the new SCX_KICK_IDLE to wake up a CPU after re-enqueueing.
    
    v3: Drop the const qualifier from scx_cpu_release_args.task. BPF enforces
        access control through the verifier, so the qualifier isn't actually
        operative and only gets in the way when interacting with various
        helpers.
    
    v2: Add p->scx.kf_mask annotation to allow calling scx_bpf_reenqueue_local()
        from ops.cpu_release() nested inside ops.init() and other sleepable
        operations.
    Signed-off-by: default avatarDavid Vernet <dvernet@meta.com>
    Reviewed-by: default avatarTejun Heo <tj@kernel.org>
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Acked-by: default avatarJosh Don <joshdon@google.com>
    Acked-by: default avatarHao Luo <haoluo@google.com>
    Acked-by: default avatarBarret Rhoden <brho@google.com>
    245254f7
ext.c 157 KB