Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

scx: Implement SCX_KICK_IDLE #138

Merged
merged 3 commits into from
Feb 7, 2024
Merged

scx: Implement SCX_KICK_IDLE #138

merged 3 commits into from
Feb 7, 2024

Conversation

htejun
Copy link
Collaborator

@htejun htejun commented Feb 7, 2024

Implement SCX_KICK_IDLE so that schedulers don't have to worry about causing too much churn with attempts to wake idle CPUs.

@htejun htejun requested review from arighi and Byte-Lab February 7, 2024 00:56
struct rq *rq = cpu_rq(cpu);
unsigned long flags;
/*
* We can skip idle kicking if @cpu is going to go through at least one
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/cpu/rq here and below

if (cpu_online(cpu) || cpu == this_cpu) {
if (cpumask_test_cpu(cpu, this_rq->scx.cpus_to_preempt) &&
rq->curr->sched_class == &ext_sched_class)
if (cpu_online(cpu) || cpu == cpu_of(this_rq)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So even though this functionally isn't a change from what was there before, would you mind please adding a comment explaining that a CPU can be offlined before IRQs are disabled to explain how it's possible that the CPU is offline but cpu == cpu_of(this_rq)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just that CPU on/offlining is a multi-stage operation and cpu hotplug ops themselves depend on scheduling working. I'm not sure how much detail we want to explain here. I'll mention it briefly.

- There's no reason to clear all scx_rq->cpus_* masks each time
  kick_cpus_irq_workfn() is run especially given that other cpumasks won't
  be set if ->cpus_to_kick isn't. Selectively clear bits which are set
  instead.

- Don't access rq->scx.pnt_seq if not needed.

- A bit of restructuring for redability and to avoid scanning ->cpus_to_wait
  unnecessarily.

Signed-off-by: Tejun Heo <[email protected]>
No functional changes intended.

Signed-off-by: Tejun Heo <[email protected]>
Wanting to wake a CPU from idle is not an uncommon operaiton that a BPF
scheduler might want to do. The only way to do it is scx_bpf_kick_cpu();
however, this can lead to unnecessary churns when the target CPU is not idle
and there isn't a good way to synchronize against idle transitions to avoid
spurious kicks.

This patch implements SCX_KICK_IDLE which kicks the target CPU if it's idle.
The flag doesn't guarantee that a CPU will never be kicked unless idle but
it optimizes away spurious kicks in most cases.

Signed-off-by: Tejun Heo <[email protected]>
@htejun htejun merged commit a80615d into sched_ext Feb 7, 2024
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants