From: Xunlei Pang <xlpang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Juri Lelli <juri.lelli@arm.com>, Ingo Molnar <mingo@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
Xunlei Pang <xlpang@redhat.com>
Subject: [PATCH] rtmutex: Consider deadline tasks in try_to_take_rt_mutex()
Date: Wed, 6 Apr 2016 21:06:55 +0800 [thread overview]
Message-ID: <1459948015-13264-1-git-send-email-xlpang@redhat.com> (raw)
If mutliple tasks contest try_to_take_rt_mutex(), it should
let the high-priority task acquire the lock, but it misses
the deadline tasks in the following condition:
if (task->prio >= rt_mutex_top_waiter(lock)->prio)
return 0;
Deadline tasks all have "-1" prio, so above logic will always
return 0, this is wrong.
To solve this, we added extra deadline comparing, and let the
task with smaller deadline win, or the top waiter win if equal.
Signed-off-by: Xunlei Pang <xlpang@redhat.com>
---
kernel/locking/rtmutex.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 244b9f3..45d2f36 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -778,11 +778,24 @@ static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
*/
if (rt_mutex_has_waiters(lock)) {
/*
- * If @task->prio is greater than or equal to
- * the top waiter priority (kernel view),
+ * If !deadline @task->prio is greater than or
+ * equal to the top waiter priority (kernel view),
* @task lost.
*/
- if (task->prio >= rt_mutex_top_waiter(lock)->prio)
+ if (task->prio >= rt_mutex_top_waiter(lock)->prio &&
+ !dl_prio(task->prio))
+ return 0;
+
+ /*
+ * If the top waiter is deadline, @task must be
+ * deadline, otherwise did return 0 above.
+ *
+ * If @task's deadline is not smaller than the
+ * top waiter's, @task lost.
+ */
+ if (dl_prio(rt_mutex_top_waiter(lock)->prio) &&
+ !dl_time_before(task->dl.deadline,
+ rt_mutex_top_waiter(lock)->task->dl.deadline))
return 0;
/*
--
1.8.3.1
reply other threads:[~2016-04-06 13:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1459948015-13264-1-git-send-email-xlpang@redhat.com \
--to=xlpang@redhat.com \
--cc=juri.lelli@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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