From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753176AbbC0P2K (ORCPT ); Fri, 27 Mar 2015 11:28:10 -0400 Received: from smtprelay0091.hostedemail.com ([216.40.44.91]:42331 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752778AbbC0P2H (ORCPT ); Fri, 27 Mar 2015 11:28:07 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2895:3138:3139:3140:3141:3142:3151:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:5007:6119:6120:6261:7576:7875:7901:7903:7974:9010:10004:10848:10967:11026:11232:11658:11914:12043:12296:12438:12517:12519:12555:12663:12679:12740:13161:13229:13255:14096:14097:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: smile35_c69f17eb4257 X-Filterd-Recvd-Size: 5467 Date: Fri, 27 Mar 2015 11:28:04 -0400 From: Steven Rostedt To: Xunlei Pang Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Juri Lelli , Xunlei Pang Subject: Re: [PATCH RESEND v4 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Message-ID: <20150327112804.048ba405@gandalf.local.home> In-Reply-To: <1425886348-3191-2-git-send-email-xlpang@126.com> References: <1425886348-3191-1-git-send-email-xlpang@126.com> <1425886348-3191-2-git-send-email-xlpang@126.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 9 Mar 2015 15:32:27 +0800 Xunlei Pang wrote: > 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 ahead of 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..86cd79f 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) Nit. static void enqueue_pushable_task(struct rq *rq, struct task_struct *p, bool head) Is a better breaking of the line. > { > 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) Same here. > { > } > > @@ -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, false); > } > > 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)) put_prev_task_rt() is called by put_prev_task() which is called by several functions: rt_mutex_setprio(), __sched_setscheduler(), sched_setnuma(), migrate_tasks(), and sched_move_task(). It's not part of being preempted. Now it is also called by pick_next_task_rt() which I'm assuming is what you want it to affect. The above definitely needs a comment about what it is doing. Also, I'm not so sure we care about testing task_running(). I'm thinking the check for PREEMPT_ACTIVE is good enough, as that would only be set from being called within preempt_schedule(). Also, we could get rid of the if statement and do: enqueue_pushable_task(rq, p, !!(preempt_count() & PREEMPT_ACTIVE)); -- Steve > + enqueue_pushable_task(rq, p, true); > + else > + enqueue_pushable_task(rq, p, false); > + } > } > > #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, false); > rq->rt.rt_nr_migratory++; > } >