From b22e83d4d58e9c939dfbc3d1de9fc5eed6f0a832 Mon Sep 17 00:00:00 2001 From: Daniel Hodges Date: Thu, 10 Oct 2024 09:56:42 -0700 Subject: [PATCH] scx_layered: Cleanup topology preempt path Signed-off-by: Daniel Hodges --- scheds/rust/scx_layered/src/bpf/main.bpf.c | 42 +++++++++------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/scheds/rust/scx_layered/src/bpf/main.bpf.c b/scheds/rust/scx_layered/src/bpf/main.bpf.c index 8d7231f..96c1415 100644 --- a/scheds/rust/scx_layered/src/bpf/main.bpf.c +++ b/scheds/rust/scx_layered/src/bpf/main.bpf.c @@ -700,14 +700,14 @@ s32 pick_idle_cpu(struct task_struct *p, s32 prev_cpu, return -1; } - pref_idle_cpumask = bpf_cpumask_create(); - if (layer->idle_smt) { idle_cpumask = scx_bpf_get_idle_smtmask(); } else { idle_cpumask = scx_bpf_get_idle_cpumask(); } + pref_idle_cpumask = bpf_cpumask_create(); + if (!pref_idle_cpumask || !idle_cpumask) { cpu = -1; goto out_put; @@ -749,7 +749,6 @@ s32 pick_idle_cpu(struct task_struct *p, s32 prev_cpu, goto out_put; } - /* * Next try a CPU in the current node */ @@ -987,24 +986,21 @@ void try_preempt(s32 task_cpu, struct task_struct *p, struct task_ctx *tctx, } if (!(cachec = lookup_cache_ctx(cctx->cache_idx)) || - !(nodec = lookup_node_ctx(cctx->node_idx))) + !(nodec = lookup_node_ctx(cctx->node_idx)) || + !cachec->cpumask) { + scx_bpf_error("can't happen"); return; + } attempted = bpf_cpumask_create(); - if (!attempted) - goto preempt_fail; + if (!attempted) { + lstat_inc(LSTAT_PREEMPT_FAIL, layer, cctx); + return; + } topo_cpus = bpf_cpumask_create(); - if (!topo_cpus) { - bpf_cpumask_release(attempted); + if (!topo_cpus || !cachec->cpumask) goto preempt_fail; - } - - if (!cachec->cpumask) { - bpf_cpumask_release(attempted); - bpf_cpumask_release(topo_cpus); - goto preempt_fail; - } bpf_cpumask_copy(topo_cpus, cast_mask(cachec->cpumask)); bpf_cpumask_and(topo_cpus, cast_mask(topo_cpus), layer_cpumask); @@ -1029,11 +1025,8 @@ void try_preempt(s32 task_cpu, struct task_struct *p, struct task_ctx *tctx, /* * Next try node local LLCs in the layer cpumask */ - if (!nodec->cpumask) { - bpf_cpumask_release(attempted); - bpf_cpumask_release(topo_cpus); + if (!nodec->cpumask) goto preempt_fail; - } bpf_cpumask_copy(topo_cpus, cast_mask(nodec->cpumask)); bpf_cpumask_xor(topo_cpus, cast_mask(attempted), cast_mask(topo_cpus)); @@ -1058,8 +1051,6 @@ void try_preempt(s32 task_cpu, struct task_struct *p, struct task_ctx *tctx, */ if (xnuma_preemption) { if (!all_cpumask) { - bpf_cpumask_release(attempted); - bpf_cpumask_release(topo_cpus); goto preempt_fail; } bpf_cpumask_copy(topo_cpus, cast_mask(all_cpumask)); @@ -1080,12 +1071,13 @@ void try_preempt(s32 task_cpu, struct task_struct *p, struct task_ctx *tctx, break; } } - bpf_cpumask_release(attempted); - bpf_cpumask_release(topo_cpus); - - lstat_inc(LSTAT_PREEMPT_FAIL, layer, cctx); preempt_fail: + if (attempted) + bpf_cpumask_release(attempted); + if (topo_cpus) + bpf_cpumask_release(topo_cpus); + lstat_inc(LSTAT_PREEMPT_FAIL, layer, cctx); }