From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755429AbbBPJff (ORCPT ); Mon, 16 Feb 2015 04:35:35 -0500 Received: from m15-113.126.com ([220.181.15.113]:36979 "EHLO m15-113.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755166AbbBPJfd (ORCPT ); Mon, 16 Feb 2015 04:35:33 -0500 From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Andrew Morton , Dan Streetman , Xunlei Pang Subject: [PATCH v4 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Date: Mon, 16 Feb 2015 17:32:23 +0800 Message-Id: <1424079144-5194-2-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424079144-5194-1-git-send-email-xlpang@126.com> References: <1424079144-5194-1-git-send-email-xlpang@126.com> X-CM-TRANSID: DcmowAA3sXVVueFU6xL6AQ--.1340S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFWrZr4kur48Gw4xXF13Jwb_yoW5uF1Upa ykJw4Uta1kJayqgrn7Xr4kZr43G34vq3y7Jrn5t3yrKanYqFy8ZFn5Zry3tFW3Kr1vqF43 KF4DtrsxGr1UZFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jlc_3UUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbimgKiv1GfVJ167QAAsV Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xunlei Pang 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 before any existing task with the same priority in the pushable queue. Signed-off-by: Xunlei Pang --- kernel/sched/rt.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index f4d4b07..65de40e 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -347,11 +347,15 @@ 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) @@ -373,7 +377,8 @@ static void dequeue_pushable_task(struct rq *rq, struct task_struct *p) #else -static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p) +static inline void enqueue_pushable_task(struct rq *rq, + struct task_struct *p, bool head) { } @@ -1248,7 +1253,7 @@ enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags) enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD); if (!task_current(rq, p) && p->nr_cpus_allowed > 1) - enqueue_pushable_task(rq, p); + enqueue_pushable_task(rq, p, 0); } static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags) @@ -1494,8 +1499,12 @@ 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) { + if (task_running(rq, p) && (preempt_count() & PREEMPT_ACTIVE)) + enqueue_pushable_task(rq, p, 1); + else + enqueue_pushable_task(rq, p, 0); + } } #ifdef CONFIG_SMP @@ -1914,7 +1923,7 @@ static void set_cpus_allowed_rt(struct task_struct *p, rq->rt.rt_nr_migratory--; } else { if (!task_current(rq, p)) - enqueue_pushable_task(rq, p); + enqueue_pushable_task(rq, p, 0); rq->rt.rt_nr_migratory++; } -- 1.9.1