From: Ankit Jain <ankitja@vmware.com>
To: juri.lelli@redhat.com, bristot@redhat.com,
l.stach@pengutronix.de, suhui_kernel@163.com,
msimmons@redhat.com, peterz@infradead.org, glenn@aurora.tech,
stable@vger.kernel.org, linux-kernel@vger.kernel.org,
gregkh@linuxfoundation.org
Cc: srivatsab@vmware.com, srivatsa@csail.mit.edu, akaher@vmware.com,
amakhalov@vmware.com, vsirnapalli@vmware.com,
sturlapati@vmware.com, bordoloih@vmware.com,
keerthanak@vmware.com, Ankit Jain <ankitja@vmware.com>
Subject: [PATCH v5.4.y 1/4] sched/deadline: Unthrottle PI boosted threads while enqueuing
Date: Mon, 22 Aug 2022 13:09:39 +0530 [thread overview]
Message-ID: <20220822073942.218045-2-ankitja@vmware.com> (raw)
In-Reply-To: <20220822073942.218045-1-ankitja@vmware.com>
From: Daniel Bristot de Oliveira <bristot@redhat.com>
commit feff2e65efd8d84cf831668e182b2ce73c604bbb upstream.
stress-ng has a test (stress-ng --cyclic) that creates a set of threads
under SCHED_DEADLINE with the following parameters:
dl_runtime = 10000 (10 us)
dl_deadline = 100000 (100 us)
dl_period = 100000 (100 us)
These parameters are very aggressive. When using a system without HRTICK
set, these threads can easily execute longer than the dl_runtime because
the throttling happens with 1/HZ resolution.
During the main part of the test, the system works just fine because
the workload does not try to run over the 10 us. The problem happens at
the end of the test, on the exit() path. During exit(), the threads need
to do some cleanups that require real-time mutex locks, mainly those
related to memory management, resulting in this scenario:
Note: locks are rt_mutexes...
------------------------------------------------------------------------
TASK A: TASK B: TASK C:
activation
activation
activation
lock(a): OK! lock(b): OK!
<overrun runtime>
lock(a)
-> block (task A owns it)
-> self notice/set throttled
+--< -> arm replenished timer
| switch-out
| lock(b)
| -> <C prio > B prio>
| -> boost TASK B
| unlock(a) switch-out
| -> handle lock a to B
| -> wakeup(B)
| -> B is throttled:
| -> do not enqueue
| switch-out
|
|
+---------------------> replenishment timer
-> TASK B is boosted:
-> do not enqueue
------------------------------------------------------------------------
BOOM: TASK B is runnable but !enqueued, holding TASK C: the system
crashes with hung task C.
This problem is avoided by removing the throttle state from the boosted
thread while boosting it (by TASK A in the example above), allowing it to
be queued and run boosted.
The next replenishment will take care of the runtime overrun, pushing
the deadline further away. See the "while (dl_se->runtime <= 0)" on
replenish_dl_entity() for more information.
Reported-by: Mark Simmons <msimmons@redhat.com>
Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Juri Lelli <juri.lelli@redhat.com>
Tested-by: Mark Simmons <msimmons@redhat.com>
Link: https://lkml.kernel.org/r/5076e003450835ec74e6fa5917d02c4fa41687e6.1600170294.git.bristot@redhat.com
[Ankit: Regenerated the patch for v5.4.y]
Signed-off-by: Ankit Jain <ankitja@vmware.com>
---
kernel/sched/deadline.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 2bda9fdba31c..fdeb2afffc48 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1484,6 +1484,27 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
*/
if (pi_task && dl_prio(pi_task->normal_prio) && p->dl.dl_boosted) {
pi_se = &pi_task->dl;
+ /*
+ * Because of delays in the detection of the overrun of a
+ * thread's runtime, it might be the case that a thread
+ * goes to sleep in a rt mutex with negative runtime. As
+ * a consequence, the thread will be throttled.
+ *
+ * While waiting for the mutex, this thread can also be
+ * boosted via PI, resulting in a thread that is throttled
+ * and boosted at the same time.
+ *
+ * In this case, the boost overrides the throttle.
+ */
+ if (p->dl.dl_throttled) {
+ /*
+ * The replenish timer needs to be canceled. No
+ * problem if it fires concurrently: boosted threads
+ * are ignored in dl_task_timer().
+ */
+ hrtimer_try_to_cancel(&p->dl.dl_timer);
+ p->dl.dl_throttled = 0;
+ }
} else if (!dl_prio(p->normal_prio)) {
/*
* Special case in which we have a !SCHED_DEADLINE task
--
2.34.1
next prev parent reply other threads:[~2022-08-22 7:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 7:39 [PATCH v5.4.y 0/4] sched/deadline: Fix panic due to nested priority inheritance Ankit Jain
2022-08-22 7:39 ` Ankit Jain [this message]
2022-08-22 7:39 ` [PATCH v5.4.y 2/4] sched/deadline: Fix stale throttling on de-/boosted tasks Ankit Jain
2022-08-22 7:39 ` [PATCH v5.4.y 3/4] sched/deadline: Fix priority inheritance with multiple scheduling classes Ankit Jain
2022-08-22 7:39 ` [PATCH v5.4.y 4/4] kernel/sched: Remove dl_boosted flag comment Ankit Jain
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=20220822073942.218045-2-ankitja@vmware.com \
--to=ankitja@vmware.com \
--cc=akaher@vmware.com \
--cc=amakhalov@vmware.com \
--cc=bordoloih@vmware.com \
--cc=bristot@redhat.com \
--cc=glenn@aurora.tech \
--cc=gregkh@linuxfoundation.org \
--cc=juri.lelli@redhat.com \
--cc=keerthanak@vmware.com \
--cc=l.stach@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=msimmons@redhat.com \
--cc=peterz@infradead.org \
--cc=srivatsa@csail.mit.edu \
--cc=srivatsab@vmware.com \
--cc=stable@vger.kernel.org \
--cc=sturlapati@vmware.com \
--cc=suhui_kernel@163.com \
--cc=vsirnapalli@vmware.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