From: Li Hua <hucool.lihua@huawei.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: <yuehaibing@huawei.com>, <weiyongjun1@huawei.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
<linux-kernel@vger.kernel.org>, <w.f@huawei.com>,
<hucool.lihua@huawei.com>, <cj.chengjian@huawei.com>,
<judy.chenhui@huawei.com>
Subject: [PATCH -next 1/1] sched/rt: Try to restart rt period timer when rt runtime exceeded
Date: Mon, 15 Nov 2021 01:46:28 +0000 [thread overview]
Message-ID: <20211115014628.15017-2-hucool.lihua@huawei.com> (raw)
In-Reply-To: <20211115014628.15017-1-hucool.lihua@huawei.com>
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>
---
kernel/sched/rt.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index bb945f8faeca..630f2cbe37d0 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -947,6 +947,23 @@ static inline int rt_se_prio(struct sched_rt_entity *rt_se)
return rt_task_of(rt_se)->prio;
}
+static inline void try_start_rt_bandwidth(struct rt_bandwidth *rt_b)
+{
+ raw_spin_lock(&rt_b->rt_runtime_lock);
+ if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) {
+ raw_spin_unlock(&rt_b->rt_runtime_lock);
+ return;
+ }
+
+ if (!rt_b->rt_period_active) {
+ rt_b->rt_period_active = 1;
+ hrtimer_forward_now(&rt_b->rt_period_timer, rt_b->rt_period);
+ hrtimer_start_expires(&rt_b->rt_period_timer,
+ HRTIMER_MODE_ABS_PINNED_HARD);
+ }
+ raw_spin_unlock(&rt_b->rt_runtime_lock);
+}
+
static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)
{
u64 runtime = sched_rt_runtime(rt_rq);
@@ -1027,11 +1044,16 @@ static void update_curr_rt(struct rq *rq)
struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
+ int exceeded;
+
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)
+ try_start_rt_bandwidth(sched_rt_bandwidth(rt_rq));
}
}
}
@@ -2905,8 +2927,10 @@ static int sched_rt_global_validate(void)
static void sched_rt_do_global(void)
{
+ raw_spin_lock(&def_rt_bandwidth.rt_runtime_lock);
def_rt_bandwidth.rt_runtime = global_rt_runtime();
def_rt_bandwidth.rt_period = ns_to_ktime(global_rt_period());
+ raw_spin_unlock(&def_rt_bandwidth.rt_runtime_lock);
}
int sched_rt_handler(struct ctl_table *table, int write, void *buffer,
--
2.17.1
next prev parent reply other threads:[~2021-11-15 1:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-15 1:46 [PATCH -next 0/1] Restart " Li Hua
2021-11-15 1:46 ` Li Hua [this message]
2021-11-18 15:20 ` [PATCH -next 1/1] sched/rt: Try to restart " Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211115014628.15017-2-hucool.lihua@huawei.com \
--to=hucool.lihua@huawei.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=cj.chengjian@huawei.com \
--cc=dietmar.eggemann@arm.com \
--cc=judy.chenhui@huawei.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=w.f@huawei.com \
--cc=weiyongjun1@huawei.com \
--cc=yuehaibing@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®