From: Xunlei Pang <xlpang@126.com>
To: linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Juri Lelli <juri.lelli@gmail.com>,
Xunlei Pang <pang.xunlei@linaro.org>
Subject: [PATCH v6 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases
Date: Mon, 20 Apr 2015 16:22:47 +0800 [thread overview]
Message-ID: <1429518168-7965-2-git-send-email-xlpang@126.com> (raw)
In-Reply-To: <1429518168-7965-1-git-send-email-xlpang@126.com>
From: Xunlei Pang <pang.xunlei@linaro.org>
Currently, SMP RT scheduler has some trouble in dealing with
equal prio cases.
For example, in check_preempt_equal_prio():
When RT1(current task) gets preempted by RT2, if there is a
migratable RT3 with same prio, RT3 will be pushed away instead
of RT1 afterwards, because RT1 will be enqueued to the tail of
the pushable list when going through succeeding put_prev_task_rt()
triggered by resched. This broke FIFO.
Furthermore, this is also problematic for normal preempted cases
if there're some rt tasks queued with the same prio as current.
Because current will be put behind these tasks in the pushable
queue.
So, if a task is running and gets preempted by a higher priority
task (or even with same priority for migrating), this patch ensures
that it is put ahead of any existing task with the same priority in
the pushable queue.
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
v5->v6:
Add wrapped enqueue_pushable_task_preempted() and enqueue_pushable_task()
for __enqueue_pushable_task() to avoid the "bool head" parameter everywhere.
kernel/sched/rt.c | 41 +++++++++++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 575da76..8679eff 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -359,17 +359,32 @@ static inline void set_post_schedule(struct rq *rq)
rq->post_schedule = has_pushable_tasks(rq);
}
-static void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
+static void
+__enqueue_pushable_task(struct rq *rq, struct task_struct *p, bool head)
{
plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks);
plist_node_init(&p->pushable_tasks, p->prio);
- plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks);
+ if (head)
+ plist_add_head(&p->pushable_tasks, &rq->rt.pushable_tasks);
+ else
+ plist_add_tail(&p->pushable_tasks, &rq->rt.pushable_tasks);
/* Update the highest prio pushable task */
if (p->prio < rq->rt.highest_prio.next)
rq->rt.highest_prio.next = p->prio;
}
+static inline
+void enqueue_pushable_task_preempted(struct rq *rq, struct task_struct *p)
+{
+ __enqueue_pushable_task(rq, p, true);
+}
+
+static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
+{
+ __enqueue_pushable_task(rq, p, false);
+}
+
static void dequeue_pushable_task(struct rq *rq, struct task_struct *p)
{
plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks);
@@ -385,6 +400,11 @@ static void dequeue_pushable_task(struct rq *rq, struct task_struct *p)
#else
+static inline
+void enqueue_pushable_task_preempted(struct rq *rq, struct task_struct *p)
+{
+}
+
static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
{
}
@@ -1506,8 +1526,21 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p)
* The previous task needs to be made eligible for pushing
* if it is still active
*/
- if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1)
- enqueue_pushable_task(rq, p);
+ if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) {
+ /*
+ * put_prev_task_rt() is called by many functions,
+ * pick_next_task_rt() is the only one may have
+ * PREEMPT_ACTIVE set. So if detecting p(current
+ * task) is preempted in such case, we should
+ * enqueue it to the front of the pushable plist,
+ * as there may be multiple tasks with the same
+ * priority as p.
+ */
+ if (preempt_count() & PREEMPT_ACTIVE)
+ enqueue_pushable_task_preempted(rq, p);
+ else
+ enqueue_pushable_task(rq, p);
+ }
}
#ifdef CONFIG_SMP
--
1.9.1
next prev parent reply other threads:[~2015-04-20 8:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-20 8:22 [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Xunlei Pang
2015-04-20 8:22 ` Xunlei Pang [this message]
2015-04-20 14:52 ` [PATCH v6 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Steven Rostedt
2015-04-20 17:20 ` Peter Zijlstra
2015-04-20 17:48 ` Steven Rostedt
2015-04-20 23:45 ` Peter Zijlstra
2015-04-21 13:10 ` Steven Rostedt
[not found] ` <OFB1503F16.1E65406F-ON48257E2E.002B562D-48257E30.0008BFEB@zte.com.cn>
2015-04-23 3:01 ` Steven Rostedt
[not found] ` <OFE3B71874.C9D81693-ON48257E30.0024F69F-48257E30.0025E2D3@zte.com.cn>
2015-04-23 13:10 ` Steven Rostedt
2015-04-24 18:32 ` Peter Zijlstra
[not found] ` <OF0B05B4FE.F40C0BE3-ON48257E32.004EF485-48257E32.00513DB3@zte.com.cn>
2015-04-25 18:23 ` Peter Zijlstra
[not found] ` <OFD410EB1E.5A02675A-ON48257E33.00309252-48257E33.003641FF@zte.com.cn>
2015-04-26 15:58 ` Steven Rostedt
2015-04-28 10:19 ` Peter Zijlstra
2015-04-28 12:48 ` Mike Galbraith
2015-04-20 8:22 ` [PATCH v6 3/3] sched/rt: Check to push the task when changing its affinity Xunlei Pang
2015-04-20 16:06 ` Steven Rostedt
2015-04-20 14:42 ` [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Steven Rostedt
2015-04-20 14:48 ` Steven Rostedt
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=1429518168-7965-2-git-send-email-xlpang@126.com \
--to=xlpang@126.com \
--cc=juri.lelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pang.xunlei@linaro.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/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
Powered by JetHome