* [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded
@ 2021-12-03 3:36 Li Hua
2021-12-03 7:17 ` Greg KH
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Li Hua @ 2021-12-03 3:36 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, linux-kernel, hucool.lihua, stable
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.
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Li Hua <hucool.lihua@huawei.com>
---
v1->v2:
- call do_start_rt_bandwidth to reduce repetitive code.
- use raw_spin_lock_irqsave to avoid deadlock on a timer context.
---
kernel/sched/rt.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index b48baaba2fc2..7b4f4fbbb404 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -52,11 +52,8 @@ void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime)
rt_b->rt_period_timer.function = sched_rt_period_timer;
}
-static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
+static inline void do_start_rt_bandwidth(struct rt_bandwidth *rt_b)
{
- if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
- return;
-
raw_spin_lock(&rt_b->rt_runtime_lock);
if (!rt_b->rt_period_active) {
rt_b->rt_period_active = 1;
@@ -75,6 +72,14 @@ static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
raw_spin_unlock(&rt_b->rt_runtime_lock);
}
+static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
+{
+ if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
+ return;
+
+ do_start_rt_bandwidth(rt_b);
+}
+
void init_rt_rq(struct rt_rq *rt_rq)
{
struct rt_prio_array *array;
@@ -1031,13 +1036,17 @@ static void update_curr_rt(struct rq *rq)
for_each_sched_rt_entity(rt_se) {
struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
+ int exceeded;
if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
raw_spin_lock(&rt_rq->rt_runtime_lock);
rt_rq->rt_time += delta_exec;
- if (sched_rt_runtime_exceeded(rt_rq))
+ exceeded = sched_rt_runtime_exceeded(rt_rq);
+ if (exceeded)
resched_curr(rq);
raw_spin_unlock(&rt_rq->rt_runtime_lock);
+ if (exceeded)
+ do_start_rt_bandwidth(sched_rt_bandwidth(rt_rq));
}
}
}
@@ -2911,8 +2920,12 @@ static int sched_rt_global_validate(void)
static void sched_rt_do_global(void)
{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags);
def_rt_bandwidth.rt_runtime = global_rt_runtime();
def_rt_bandwidth.rt_period = ns_to_ktime(global_rt_period());
+ raw_spin_unlock_irqrestore(&def_rt_bandwidth.rt_runtime_lock, flags);
}
int sched_rt_handler(struct ctl_table *table, int write, void *buffer,
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded
2021-12-03 3:36 [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded Li Hua
@ 2021-12-03 7:17 ` Greg KH
2021-12-07 1:38 ` Lihua (lihua, ran)
2021-12-04 11:34 ` Peter Zijlstra
2021-12-07 14:22 ` [tip: sched/core] " tip-bot2 for Li Hua
2 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2021-12-03 7:17 UTC (permalink / raw)
To: Li Hua
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, linux-kernel, stable
On Fri, Dec 03, 2021 at 03:36:18AM +0000, Li Hua wrote:
> 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.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Li Hua <hucool.lihua@huawei.com>
> ---
> v1->v2:
> - call do_start_rt_bandwidth to reduce repetitive code.
> - use raw_spin_lock_irqsave to avoid deadlock on a timer context.
> ---
> kernel/sched/rt.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded
2021-12-03 3:36 [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded Li Hua
2021-12-03 7:17 ` Greg KH
@ 2021-12-04 11:34 ` Peter Zijlstra
2021-12-06 1:42 ` Lihua (lihua, ran)
2021-12-07 14:22 ` [tip: sched/core] " tip-bot2 for Li Hua
2 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2021-12-04 11:34 UTC (permalink / raw)
To: Li Hua
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, linux-kernel, stable
On Fri, Dec 03, 2021 at 03:36:18AM +0000, Li Hua wrote:
> 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.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Li Hua <hucool.lihua@huawei.com>
Thanks, do you think you can reply here with a Fixes: tag so I can add
it?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded
2021-12-04 11:34 ` Peter Zijlstra
@ 2021-12-06 1:42 ` Lihua (lihua, ran)
0 siblings, 0 replies; 6+ messages in thread
From: Lihua (lihua, ran) @ 2021-12-06 1:42 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, linux-kernel, stable
Fixes: d0b27fa77854 ("sched: rt-group: synchonised bandwidth period")
---
Thanks for your review~~
在 2021/12/4 19:34, Peter Zijlstra 写道:
> On Fri, Dec 03, 2021 at 03:36:18AM +0000, Li Hua wrote:
>> 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.
>>
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Li Hua <hucool.lihua@huawei.com>
> Thanks, do you think you can reply here with a Fixes: tag so I can add
> it?
> .
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded
2021-12-03 7:17 ` Greg KH
@ 2021-12-07 1:38 ` Lihua (lihua, ran)
0 siblings, 0 replies; 6+ messages in thread
From: Lihua (lihua, ran) @ 2021-12-07 1:38 UTC (permalink / raw)
To: Greg KH
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, linux-kernel, stable
在 2021/12/3 15:17, Greg KH 写道:
> On Fri, Dec 03, 2021 at 03:36:18AM +0000, Li Hua wrote:
>> 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.
>>
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Li Hua <hucool.lihua@huawei.com>
>> ---
>> v1->v2:
>> - call do_start_rt_bandwidth to reduce repetitive code.
>> - use raw_spin_lock_irqsave to avoid deadlock on a timer context.
>> ---
>> kernel/sched/rt.c | 23 ++++++++++++++++++-----
>> 1 file changed, 18 insertions(+), 5 deletions(-)
> <formletter>
>
> This is not the correct way to submit patches for inclusion in the
> stable kernel tree. Please read:
> https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
> for how to do this properly.
I did not CC: stable in the signed-off region,Is that so?
> </formletter>
> .
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip: sched/core] sched/rt: Try to restart rt period timer when rt runtime exceeded
2021-12-03 3:36 [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded Li Hua
2021-12-03 7:17 ` Greg KH
2021-12-04 11:34 ` Peter Zijlstra
@ 2021-12-07 14:22 ` tip-bot2 for Li Hua
2 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Li Hua @ 2021-12-07 14:22 UTC (permalink / raw)
To: linux-tip-commits
Cc: Hulk Robot, Li Hua, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 9b58e976b3b391c0cf02e038d53dd0478ed3013c
Gitweb: https://git.kernel.org/tip/9b58e976b3b391c0cf02e038d53dd0478ed3013c
Author: Li Hua <hucool.lihua@huawei.com>
AuthorDate: Fri, 03 Dec 2021 03:36:18
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 07 Dec 2021 15:14:10 +01:00
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: d0b27fa77854 ("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
---
kernel/sched/rt.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index b48baab..7b4f4fb 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -52,11 +52,8 @@ void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime)
rt_b->rt_period_timer.function = sched_rt_period_timer;
}
-static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
+static inline void do_start_rt_bandwidth(struct rt_bandwidth *rt_b)
{
- if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
- return;
-
raw_spin_lock(&rt_b->rt_runtime_lock);
if (!rt_b->rt_period_active) {
rt_b->rt_period_active = 1;
@@ -75,6 +72,14 @@ static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
raw_spin_unlock(&rt_b->rt_runtime_lock);
}
+static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
+{
+ if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
+ return;
+
+ do_start_rt_bandwidth(rt_b);
+}
+
void init_rt_rq(struct rt_rq *rt_rq)
{
struct rt_prio_array *array;
@@ -1031,13 +1036,17 @@ static void update_curr_rt(struct rq *rq)
for_each_sched_rt_entity(rt_se) {
struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
+ int exceeded;
if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
raw_spin_lock(&rt_rq->rt_runtime_lock);
rt_rq->rt_time += delta_exec;
- if (sched_rt_runtime_exceeded(rt_rq))
+ exceeded = sched_rt_runtime_exceeded(rt_rq);
+ if (exceeded)
resched_curr(rq);
raw_spin_unlock(&rt_rq->rt_runtime_lock);
+ if (exceeded)
+ do_start_rt_bandwidth(sched_rt_bandwidth(rt_rq));
}
}
}
@@ -2911,8 +2920,12 @@ static int sched_rt_global_validate(void)
static void sched_rt_do_global(void)
{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags);
def_rt_bandwidth.rt_runtime = global_rt_runtime();
def_rt_bandwidth.rt_period = ns_to_ktime(global_rt_period());
+ raw_spin_unlock_irqrestore(&def_rt_bandwidth.rt_runtime_lock, flags);
}
int sched_rt_handler(struct ctl_table *table, int write, void *buffer,
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-07 14:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 3:36 [PATCH v2, RESEND] sched/rt: Try to restart rt period timer when rt runtime exceeded Li Hua
2021-12-03 7:17 ` Greg KH
2021-12-07 1:38 ` Lihua (lihua, ran)
2021-12-04 11:34 ` Peter Zijlstra
2021-12-06 1:42 ` Lihua (lihua, ran)
2021-12-07 14:22 ` [tip: sched/core] " tip-bot2 for Li Hua
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).