Skip to content

Commit

Permalink
Merge pull request #874 from hodgesds/layered-fallback-stall
Browse files Browse the repository at this point in the history
scx_layered: Add additional drain to fallback DSQs
  • Loading branch information
hodgesds authored Nov 1, 2024
2 parents defbf38 + cb5b196 commit 9bba51a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions scheds/rust/scx_layered/src/bpf/cost.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct cost {
u32 idx;
bool overflow;
bool has_parent;
bool drain_fallback;
};


Expand Down Expand Up @@ -217,6 +218,7 @@ static int record_cpu_cost(struct cost *costc, u32 layer_id, s64 amount)
__sync_fetch_and_sub(&costc->budget[layer_id], amount);

if (costc->budget[layer_id] <= 0) {
costc->drain_fallback = true;
if (costc->has_parent) {
s64 budget = acquire_budget(costc, layer_id,
costc->capacity[layer_id] + amount);
Expand Down
14 changes: 13 additions & 1 deletion scheds/rust/scx_layered/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ void BPF_STRUCT_OPS(layered_enqueue, struct task_struct *p, u64 enq_flags)
* usually important for system performance and responsiveness.
*/
if (!layer->preempt &&
(p->flags & PF_KTHREAD) && p->nr_cpus_allowed == 1) {
(p->flags & PF_KTHREAD) && p->nr_cpus_allowed < nr_possible_cpus) {
struct cpumask *layer_cpumask;

if (!layer->open &&
Expand Down Expand Up @@ -1444,6 +1444,18 @@ void BPF_STRUCT_OPS(layered_dispatch, s32 cpu, struct task_struct *prev)
return;
}

/*
* Fallback DSQs don't have cost accounting. When the budget runs out
* for a layer we do an extra consume of the fallback DSQ to ensure
* that it doesn't stall out when the system is being saturated.
*/
if (costc->drain_fallback) {
costc->drain_fallback = false;
dsq_id = cpu_hi_fallback_dsq_id(cpu);
if (scx_bpf_consume(dsq_id))
return;
}

u32 my_llc_id = cpu_to_llc_id(cpu);

/* consume preempting layers first */
Expand Down

0 comments on commit 9bba51a

Please sign in to comment.