From c258199f47f7925bd9582b4d5c511601540d572e Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Tue, 19 Nov 2024 17:10:45 +0000 Subject: [PATCH] replace goto with unrolled loop in antistall_set --- scheds/rust/scx_layered/src/bpf/main.bpf.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/scheds/rust/scx_layered/src/bpf/main.bpf.c b/scheds/rust/scx_layered/src/bpf/main.bpf.c index 5323b25f7..575b556ae 100644 --- a/scheds/rust/scx_layered/src/bpf/main.bpf.c +++ b/scheds/rust/scx_layered/src/bpf/main.bpf.c @@ -2501,7 +2501,7 @@ u64 antistall_set(u64 dsq_id, u64 jiffies_now) struct task_ctx *tctx; s32 cpu; u64 *antistall_dsq, *delay, cur_delay; - bool first_pass; + int pass; u32 zero; zero = 0; @@ -2526,9 +2526,8 @@ u64 antistall_set(u64 dsq_id, u64 jiffies_now) // check head task in dsq goto unlock; - first_pass = true; -look_for_cpu: - bpf_for(cpu, 0, nr_possible_cpus) { + #pragma unroll + for (pass = 0; pass < 2; ++pass) bpf_for(cpu, 0, nr_possible_cpus) { const struct cpumask *cpumask; if (!(cpumask = cast_mask(tctx->layered_mask))) @@ -2549,8 +2548,8 @@ u64 antistall_set(u64 dsq_id, u64 jiffies_now) goto unlock; } - if ((first_pass && *antistall_dsq == SCX_DSQ_INVALID) || - (!first_pass && *delay < cur_delay)) { + if ((pass == 0 && *antistall_dsq == SCX_DSQ_INVALID) || + (pass != 0 && *delay < cur_delay)) { trace("antistall set DSQ[%llu] SELECTED_CPU[%llu] DELAY[%llu]", dsq_id, cpu, cur_delay); *delay = cur_delay; *antistall_dsq = dsq_id; @@ -2558,11 +2557,6 @@ u64 antistall_set(u64 dsq_id, u64 jiffies_now) } } - if (first_pass) { - first_pass = false; - goto look_for_cpu; - } - goto unlock; }