diff --git a/include/linux/sched.h b/include/linux/sched.h index 05dc5bae4dfdde73cad9ddacde384196d94f15c7..0115d4d23bd73dc270509d4486dd633ab5dc8a5e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -665,6 +665,7 @@ struct sched_dl_entity { unsigned int dl_yielded : 1; unsigned int dl_non_contending : 1; unsigned int dl_overrun : 1; + unsigned int dl_server : 1; /* * Bandwidth enforcement timer. Each -deadline task has its diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index e811fdbefdd3cb0ff06566d055a1748ea87af019..f35ca451778db14abccad3343295397c0c9470ad 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -45,6 +45,11 @@ static inline int on_dl_rq(struct sched_dl_entity *dl_se) return !RB_EMPTY_NODE(&dl_se->rb_node); } +static bool dl_server(struct sched_dl_entity *dl_se) +{ + return dl_se->dl_server; +} + #ifdef CONFIG_RT_MUTEXES static inline struct sched_dl_entity *pi_of(struct sched_dl_entity *dl_se) { @@ -1552,8 +1557,13 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) * The replenish timer needs to be canceled. No * problem if it fires concurrently: boosted threads * are ignored in dl_task_timer(). + * + * If the timer callback was running (hrtimer_try_to_cancel == -1), + * it will eventually call put_task_struct(). */ - hrtimer_try_to_cancel(&p->dl.dl_timer); + if (hrtimer_try_to_cancel(&p->dl.dl_timer) == 1 && + !dl_server(&p->dl)) + put_task_struct(p); p->dl.dl_throttled = 0; } } else if (!dl_prio(p->normal_prio)) { @@ -2828,6 +2838,7 @@ void __dl_clear_params(struct task_struct *p) dl_se->dl_yielded = 0; dl_se->dl_non_contending = 0; dl_se->dl_overrun = 0; + dl_se->dl_server = 0; #ifdef CONFIG_RT_MUTEXES dl_se->pi_se = dl_se;