Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scx_rustland: reduce scheduler overhead #56

Merged
merged 2 commits into from
Dec 29, 2023

Commits on Dec 29, 2023

  1. scx_rustland: treat the CPU running the user-space scheduler as idle

    Considering the CPU where the user-space scheduler is running as busy
    doesn't really provide any benefit, since the user-space scheduler is
    constantly dispatching an amount of tasks equal to the amount of idle
    CPUs and then yields (therefore its own CPU should be considered idle).
    
    Considering the CPU where the user-space scheduler is running as busy
    doesn't provide any benefit, as the scheduler consistently dispatches
    tasks equal to the number of idle CPUs and then yields (therefore its
    own CPU should be considered idle).
    
    This also allows to reduce the overall user-space scheduler CPU
    utilization, especially when the system is mostly idle, without
    introducing any measurable performance regression.
    
    Measuring the average CPU utilization of a (mostly) idle system over a
    time period of 60 sec:
    
     - wihout this patch: 5.41% avg cpu util
     - with this patch:   2.26% avg cpu util
    
    Signed-off-by: Andrea Righi <[email protected]>
    Andrea Righi committed Dec 29, 2023
    Configuration menu
    Copy the full SHA
    d67dfe5 View commit details
    Browse the repository at this point in the history
  2. scx_rustland: introduce nr_waiting concept

    We want to activate the user-space scheduler only when there are pending
    tasks that require scheduling actions.
    
    To do so we keep track of the queued tasks via nr_queued, that is
    incremented in .enqueue() when a task is sent to the user-space
    scheduler and decremented in .dispatch() when a task is dispatched.
    
    However, we may trigger an unbalance if the same pid is sent to the
    scheduler multiple times (because the scheduler store all the tasks by
    their unique pid).
    
    When this happens nr_queued is never decremented back to 0, leading the
    user-space scheduler to constantly spin, even if there's no activity to
    do.
    
    To prevent this from happening split nr_queued into nr_queued and
    nr_scheduled. The former will be updated by the BPF component every time
    that a task is sent to the scheduler and it's up to the user-space
    scheduler to reset the counter when the queue is fully dreained. The
    latter is maintained by the user-space scheduler and represents the
    amount of tasks that are still processed by the scheduler and are
    waiting to be dispatched.
    
    The sum of nr_queued + nr_scheduled will be called nr_waiting and we can
    rely on this metric to determine if the user-space scheduler has some
    pending work to do or not.
    
    This change makes rust_rustland more reliable and it strongly reduces
    the CPU usage of the user-space scheduler by eliminating a lot of
    unnecessary activations.
    
    Signed-off-by: Andrea Righi <[email protected]>
    Andrea Righi committed Dec 29, 2023
    Configuration menu
    Copy the full SHA
    e90bc92 View commit details
    Browse the repository at this point in the history