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: improve scheduler cpu selection #57

Merged
merged 2 commits into from
Dec 30, 2023

Commits on Dec 30, 2023

  1. scx_rustland: improve scheduler's idle CPU selection

    The current CPU selection logic in the scheduler presents some
    inefficiencies.
    
    When a task is drained from the BPF queue, the scheduler immediately
    checks whether the CPU previously assigned to the task is still idle,
    assigning it if it is. Otherwise, it iterates through available CPUs,
    always starting from CPU #0, and selects the first idle one without
    updating its state. This approach is consistently applied to the entire
    batch of tasks drained from the BPF queue, resulting in all of them
    being assigned to the same idle CPU (also with a higher likelihood of
    allocation to lower CPU ids rather than higher ones).
    
    While dispatching a batch of tasks to the same idle CPU is not
    necessarily problematic, a fairer distribution among the list of idle
    CPUs would be preferable.
    
    Therefore change the CPU selection logic to distribute tasks equally
    among the idle CPUs, still maintaining the preference for the previously
    used one. Additionally, apply the CPU selection logic just before tasks
    are dispatched, rather than assigning a CPU when tasks are drained from
    the BPF queue. This adjustment is important, because tasks may linger in
    the scheduler's internal structures for a bit and the idle state of the
    CPUs in the system may change during that period.
    
    Signed-off-by: Andrea Righi <[email protected]>
    Andrea Righi committed Dec 30, 2023
    Configuration menu
    Copy the full SHA
    1a2c9f5 View commit details
    Browse the repository at this point in the history
  2. scx_rustland: check CPU selection validity

    When the scheduler decides to assign a different CPU to the task always
    make sure the assignment is valid according to the task cpumask. If it's
    not valid simply dispatch the task to the global DSQ.
    
    This prevents the scheduler from exiting with errors like this:
    
      09:11:02 [WARN] EXIT: SCX_DSQ_LOCAL[_ON] verdict target cpu 7 not allowed for gcc[440718]
    
    In the future we may want move this check directly into the user-space
    scheduler, but for now let's keep this check in the BPF dispatcher as a
    quick fix.
    
    Signed-off-by: Andrea Righi <[email protected]>
    Andrea Righi committed Dec 30, 2023
    Configuration menu
    Copy the full SHA
    38145f8 View commit details
    Browse the repository at this point in the history