From 51d4945d6931e7798790e02e1506c63a2a02a024 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Sat, 16 Nov 2024 05:45:44 -1000 Subject: [PATCH] scx_layered: Don't call scx_bpf_cpuperf_set() unnecessarily layered_running() is calling scx_bpf_cpuperf_set() whenever a task of a layer w/ cpuperf setting starts running which can be every task switch. There's no reason to repeatedly call with the same value. Remember the last value and call iff the new value is different. This reduces the bpftop reported CPU consumption of scx_bpf_cpuperf_set() from ~1.2% to ~0.7% while running rd-hashd at full CPU saturation on Ryzen 3900x. --- scheds/rust/scx_layered/src/bpf/intf.h | 1 + scheds/rust/scx_layered/src/bpf/main.bpf.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scheds/rust/scx_layered/src/bpf/intf.h b/scheds/rust/scx_layered/src/bpf/intf.h index 7ca7be9..927e5c3 100644 --- a/scheds/rust/scx_layered/src/bpf/intf.h +++ b/scheds/rust/scx_layered/src/bpf/intf.h @@ -115,6 +115,7 @@ struct cpu_ctx { u32 layer_idx; u32 cache_idx; u32 node_idx; + u32 perf; }; struct cache_ctx { diff --git a/scheds/rust/scx_layered/src/bpf/main.bpf.c b/scheds/rust/scx_layered/src/bpf/main.bpf.c index 9527918..cab67cf 100644 --- a/scheds/rust/scx_layered/src/bpf/main.bpf.c +++ b/scheds/rust/scx_layered/src/bpf/main.bpf.c @@ -2136,8 +2136,10 @@ void BPF_STRUCT_OPS(layered_running, struct task_struct *p) } } - if (layer->perf > 0) + if (layer->perf > 0 && cctx->perf != layer->perf) { scx_bpf_cpuperf_set(task_cpu, layer->perf); + cctx->perf = layer->perf; + } cctx->maybe_idle = false; }