Skip to content

Commit 7960e09

Browse files
committed
scx_lavd: Use scx_bpf_cpu_curr()
Use the new scx_bpf_cpu_curr() introduced in v6.18 as a safer way to access rq->curr instead of the deprecated scx_bpf_cpu_rq(). Signed-off-by: Christian Loehle <[email protected]>
1 parent 807135a commit 7960e09

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

scheds/rust/scx_lavd/src/bpf/preempt.bpf.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static struct cpu_ctx *find_victim_cpu(const struct cpumask *cpumask,
186186

187187
static void ask_cpu_yield_after(struct cpu_ctx *victim_cpuc, u64 new_slice)
188188
{
189+
bpf_rcu_read_lock();
189190
/*
190191
* Note that we avoid using scx_bpf_kick_cpu() on purpose.
191192
* While scx_bpf_kick_cpu() can trigger a task preemption immediately,
@@ -196,11 +197,9 @@ static void ask_cpu_yield_after(struct cpu_ctx *victim_cpuc, u64 new_slice)
196197
* set the victim task's time slice to zero so the victim task yields
197198
* the CPU in the next scheduling point.
198199
*/
199-
struct rq *victim_rq;
200-
struct task_struct *victim_p;
200+
struct task_struct *victim_p = __COMPAT_scx_bpf_cpu_curr(victim_cpuc->cpu_id);
201201

202-
victim_rq = scx_bpf_cpu_rq(victim_cpuc->cpu_id);
203-
if (victim_rq && (victim_p = victim_rq->curr)) {
202+
if (victim_p) {
204203
/*
205204
* Finding a victim is racy, but we do not coordinate. Thus,
206205
* two different CPUs can choose the same victim CPU. We do not
@@ -220,8 +219,10 @@ static void ask_cpu_yield_after(struct cpu_ctx *victim_cpuc, u64 new_slice)
220219
* (SCX_SLICE_DFL, 20 msec).
221220
*/
222221
u64 old = victim_cpuc->est_stopping_clk;
223-
if (!old)
222+
if (!old) {
223+
bpf_rcu_read_unlock();
224224
return;
225+
}
225226

226227
/*
227228
* If the new slice is one, this is the last time to be kicked,
@@ -240,6 +241,7 @@ static void ask_cpu_yield_after(struct cpu_ctx *victim_cpuc, u64 new_slice)
240241
WRITE_ONCE(victim_p->scx.slice, new_slice);
241242
}
242243
}
244+
bpf_rcu_read_unlock();
243245
}
244246

245247
__hidden

0 commit comments

Comments
 (0)