Skip to content

Commit 9b58e97

Browse files
LiHua-ProbeParkerPeter Zijlstra
authored andcommitted
sched/rt: Try to restart rt period timer when rt runtime exceeded
When rt_runtime is modified from -1 to a valid control value, it may cause the task to be throttled all the time. Operations like the following will trigger the bug. E.g: 1. echo -1 > /proc/sys/kernel/sched_rt_runtime_us 2. Run a FIFO task named A that executes while(1) 3. echo 950000 > /proc/sys/kernel/sched_rt_runtime_us When rt_runtime is -1, The rt period timer will not be activated when task A enqueued. And then the task will be throttled after setting rt_runtime to 950,000. The task will always be throttled because the rt period timer is not activated. Fixes: d0b27fa ("sched: rt-group: synchonised bandwidth period") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Li Hua <hucool.lihua@huawei.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20211203033618.11895-1-hucool.lihua@huawei.com
1 parent 2917406 commit 9b58e97

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

kernel/sched/rt.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime)
5252
rt_b->rt_period_timer.function = sched_rt_period_timer;
5353
}
5454

55-
static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
55+
static inline void do_start_rt_bandwidth(struct rt_bandwidth *rt_b)
5656
{
57-
if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
58-
return;
59-
6057
raw_spin_lock(&rt_b->rt_runtime_lock);
6158
if (!rt_b->rt_period_active) {
6259
rt_b->rt_period_active = 1;
@@ -75,6 +72,14 @@ static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
7572
raw_spin_unlock(&rt_b->rt_runtime_lock);
7673
}
7774

75+
static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
76+
{
77+
if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
78+
return;
79+
80+
do_start_rt_bandwidth(rt_b);
81+
}
82+
7883
void init_rt_rq(struct rt_rq *rt_rq)
7984
{
8085
struct rt_prio_array *array;
@@ -1031,13 +1036,17 @@ static void update_curr_rt(struct rq *rq)
10311036

10321037
for_each_sched_rt_entity(rt_se) {
10331038
struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
1039+
int exceeded;
10341040

10351041
if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
10361042
raw_spin_lock(&rt_rq->rt_runtime_lock);
10371043
rt_rq->rt_time += delta_exec;
1038-
if (sched_rt_runtime_exceeded(rt_rq))
1044+
exceeded = sched_rt_runtime_exceeded(rt_rq);
1045+
if (exceeded)
10391046
resched_curr(rq);
10401047
raw_spin_unlock(&rt_rq->rt_runtime_lock);
1048+
if (exceeded)
1049+
do_start_rt_bandwidth(sched_rt_bandwidth(rt_rq));
10411050
}
10421051
}
10431052
}
@@ -2911,8 +2920,12 @@ static int sched_rt_global_validate(void)
29112920

29122921
static void sched_rt_do_global(void)
29132922
{
2923+
unsigned long flags;
2924+
2925+
raw_spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags);
29142926
def_rt_bandwidth.rt_runtime = global_rt_runtime();
29152927
def_rt_bandwidth.rt_period = ns_to_ktime(global_rt_period());
2928+
raw_spin_unlock_irqrestore(&def_rt_bandwidth.rt_runtime_lock, flags);
29162929
}
29172930

29182931
int sched_rt_handler(struct ctl_table *table, int write, void *buffer,

0 commit comments

Comments
 (0)