From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752508AbbD3RFv (ORCPT ); Thu, 30 Apr 2015 13:05:51 -0400 Received: from smtprelay0130.hostedemail.com ([216.40.44.130]:48034 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752016AbbD3RFu (ORCPT ); Thu, 30 Apr 2015 13:05:50 -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:1534:1543:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3151:3165:3355:3622:3865:3866:3867:3868:3870:3871:3872:4250:4321:4605:5007:6261:7576:7903:8660:10004:10400:10848:10967:11026:11232:11658:11914:12043:12296:12438:12517:12519:12555:12740:13148:13230: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: drug15_4fbbca62b8f1a X-Filterd-Recvd-Size: 4362 Date: Thu, 30 Apr 2015 13:05:46 -0400 From: Steven Rostedt To: Xunlei Pang Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Juri Lelli , Ingo Molnar , Xunlei Pang Subject: Re: [PATCH 1/2] sched/rt: Check to push task away when its affinity is changed Message-ID: <20150430130546.55deae97@gandalf.local.home> In-Reply-To: <1430411598-4904-1-git-send-email-xlpang@126.com> References: <1430411598-4904-1-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 Fri, 1 May 2015 00:33:17 +0800 Xunlei Pang wrote: > From: Xunlei Pang > > We may suffer from extra rt overload rq due to the affinity, > so when the affinity of any runnable rt task is changed, we > should check to trigger balancing, otherwise it will cause > some unnecessary delayed real-time response. Unfortunately, > current RT global scheduler does nothing about this. > > For example: a 2-cpu system with two runnable FIFO tasks(same > rt_priority) bound on CPU0, let's name them rt1(running) and > rt2(runnable) respectively; CPU1 has no RTs. Then, someone sets > the affinity of rt2 to 0x3(i.e. CPU0 and CPU1), but after this, > rt2 still can't be scheduled enters schedule(), this > definitely causes some/big response latency for rt2. > > This patch introduces a new sched_class::post_set_cpus_allowed() > for RT called after set_cpus_allowed_rt(). In this new function, > if the task is runnable but not running, it tries to push it away > once it got migratable. > > Signed-off-by: Xunlei Pang > --- > kernel/sched/core.c | 3 +++ > kernel/sched/rt.c | 17 +++++++++++++++++ > kernel/sched/sched.h | 1 + > 3 files changed, 21 insertions(+) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index d13fc13..64a1603 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -4773,6 +4773,9 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask) > > cpumask_copy(&p->cpus_allowed, new_mask); > p->nr_cpus_allowed = cpumask_weight(new_mask); > + > + if (p->sched_class->post_set_cpus_allowed) > + p->sched_class->post_set_cpus_allowed(p); > } > > /* > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c > index cc49a7c..a9d33a3 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -2281,6 +2281,22 @@ static void set_cpus_allowed_rt(struct task_struct *p, > update_rt_migration(&rq->rt); > } > > +static void post_set_cpus_allowed_rt(struct task_struct *p) > +{ > + struct rq *rq; > + > + if (!task_on_rq_queued(p)) > + return; > + > + rq = task_rq(p); > + if (!task_running(rq, p) && > + p->nr_cpus_allowed > 1 && > + !test_tsk_need_resched(rq->curr) && > + cpupri_find(&rq->rd->cpupri, p, NULL)) { I don't think we need cpupri_find() call here. It's done in push_rt_tasks() and doing it twice is just a wasted effort. > + push_rt_tasks(rq); > + } > +} > + > /* Assumes rq->lock is held */ > static void rq_online_rt(struct rq *rq) > { > @@ -2495,6 +2511,7 @@ const struct sched_class rt_sched_class = { > .select_task_rq = select_task_rq_rt, > > .set_cpus_allowed = set_cpus_allowed_rt, > + .post_set_cpus_allowed = post_set_cpus_allowed_rt, > .rq_online = rq_online_rt, > .rq_offline = rq_offline_rt, > .post_schedule = post_schedule_rt, > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index e0e1299..6f90645 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -1191,6 +1191,7 @@ struct sched_class { > > void (*set_cpus_allowed)(struct task_struct *p, > const struct cpumask *newmask); > + void (*post_set_cpus_allowed)(struct task_struct *p); > > void (*rq_online)(struct rq *rq); > void (*rq_offline)(struct rq *rq);