Skip to content

Commit 5a40a9b

Browse files
author
Peter Zijlstra
committed
sched/debug: Fix dl_server (re)start conditions
There are two problems with sched_server_write_common() that can cause the dl_server to malfunction upon attempting to change the parameters: 1) when, after having disabled the dl_server by setting runtime=0, it is enabled again while tasks are already enqueued. In this case is_active would still be 0 and dl_server_start() would not be called. 2) when dl_server_apply_params() would fail, runtime is not applied and does not reflect the new state. Instead have dl_server_start() check its actual dl_runtime, and have sched_server_write_common() unconditionally (re)start the dl_server. It will automatically stop if there isn't anything to do, so spurious activation is harmless -- while failing to start it is a problem. While there, move the printk out of the locked region and make it symmetric, also printing on enable. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20260203103407.GK1282955@noisy.programming.kicks-ass.net
1 parent 76d1213 commit 5a40a9b

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

kernel/sched/deadline.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ void dl_server_start(struct sched_dl_entity *dl_se)
17991799
struct rq *rq = dl_se->rq;
18001800

18011801
dl_se->dl_defer_idle = 0;
1802-
if (!dl_server(dl_se) || dl_se->dl_server_active)
1802+
if (!dl_server(dl_se) || dl_se->dl_server_active || !dl_se->dl_runtime)
18031803
return;
18041804

18051805
/*
@@ -1898,7 +1898,6 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perio
18981898
int cpu = cpu_of(rq);
18991899
struct dl_bw *dl_b;
19001900
unsigned long cap;
1901-
int retval = 0;
19021901
int cpus;
19031902

19041903
dl_b = dl_bw_of(cpu);
@@ -1930,7 +1929,7 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perio
19301929
dl_se->dl_bw = to_ratio(dl_se->dl_period, dl_se->dl_runtime);
19311930
dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime);
19321931

1933-
return retval;
1932+
return 0;
19341933
}
19351934

19361935
/*

kernel/sched/debug.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
338338
void *server)
339339
{
340340
long cpu = (long) ((struct seq_file *) filp->private_data)->private;
341-
struct rq *rq = cpu_rq(cpu);
342341
struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;
343-
u64 runtime, period;
342+
u64 old_runtime, runtime, period;
343+
struct rq *rq = cpu_rq(cpu);
344344
int retval = 0;
345345
size_t err;
346346
u64 value;
@@ -350,9 +350,7 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
350350
return err;
351351

352352
scoped_guard (rq_lock_irqsave, rq) {
353-
bool is_active;
354-
355-
runtime = dl_se->dl_runtime;
353+
old_runtime = runtime = dl_se->dl_runtime;
356354
period = dl_se->dl_period;
357355

358356
switch (param) {
@@ -374,25 +372,23 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
374372
return -EINVAL;
375373
}
376374

377-
is_active = dl_server_active(dl_se);
378-
if (is_active) {
379-
update_rq_clock(rq);
380-
dl_server_stop(dl_se);
381-
}
382-
375+
update_rq_clock(rq);
376+
dl_server_stop(dl_se);
383377
retval = dl_server_apply_params(dl_se, runtime, period, 0);
384-
385-
if (!runtime)
386-
printk_deferred("%s server disabled in CPU %d, system may crash due to starvation.\n",
387-
server == &rq->fair_server ? "Fair" : "Ext", cpu_of(rq));
388-
389-
if (is_active && runtime)
390-
dl_server_start(dl_se);
378+
dl_server_start(dl_se);
391379

392380
if (retval < 0)
393381
return retval;
394382
}
395383

384+
if (!!old_runtime ^ !!runtime) {
385+
pr_info("%s server %sabled on CPU %d%s.\n",
386+
server == &rq->fair_server ? "Fair" : "Ext",
387+
runtime ? "en" : "dis",
388+
cpu_of(rq),
389+
runtime ? "" : ", system may malfunction due to starvation");
390+
}
391+
396392
*ppos += cnt;
397393
return cnt;
398394
}

0 commit comments

Comments
 (0)