From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932385AbbEHR2G (ORCPT ); Fri, 8 May 2015 13:28:06 -0400 Received: from smtprelay0036.hostedemail.com ([216.40.44.36]:34737 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932264AbbEHR2E (ORCPT ); Fri, 8 May 2015 13:28:04 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 26,1.8,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::,RULES_HIT:2:41:69:355:379:541:599:800:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1593:1594:1605:1606:1730:1747:1777:1792:1801:2194:2199:2393:2505:2553:2559:2562:2892:2894:2895:3138:3139:3140:3141:3142:3150:3165:3622:3865:3866:3867:3868:3870:3871:3872:3873:4117:4250:4321:4605:5007:6261:7794:7875:7903:10004:10848:10967:11026:11232:11233:11658:11914:12043:12296:12517:12519:12555:12663:12683:12740:13255:14096:14097:21067: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: pear97_bf13514db54c X-Filterd-Recvd-Size: 6879 Date: Fri, 8 May 2015 13:28:00 -0400 From: Steven Rostedt To: pang.xunlei@zte.com.cn Cc: Peter Zijlstra , Juri Lelli , linux-kernel@vger.kernel.org, linux-kernel-owner@vger.kernel.org, Ingo Molnar , Xunlei Pang Subject: Re: [PATCH v2 1/2] sched/rt: Check to push task away when its affinity is changed Message-ID: <20150508132800.1202fd8c@gandalf.local.home> In-Reply-To: References: <1430826968-10251-1-git-send-email-xlpang@126.com> <20150505120946.GL21418@twins.programming.kicks-ass.net> 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 Tue, 5 May 2015 23:17:30 +0800 pang.xunlei@zte.com.cn wrote: > > Or just do the p->{nr_,}cpus_allowed assignments in > > set_cpus_allowed_rt() and keep it all in the one callback. > > Ok, thanks. > > How about this? This is something more like I had in mind. > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index d13fc13..c995a02 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -4768,11 +4768,15 @@ static struct rq *move_queued_task(struct > task_struct *p, int new_cpu) > > void do_set_cpus_allowed(struct task_struct *p, const struct cpumask > *new_mask) > { > + bool updated = false; > + > if (p->sched_class->set_cpus_allowed) > - p->sched_class->set_cpus_allowed(p, new_mask); > + updated = p->sched_class->set_cpus_allowed(p, new_mask); > > - cpumask_copy(&p->cpus_allowed, new_mask); > - p->nr_cpus_allowed = cpumask_weight(new_mask); > + if (!updated) { > + cpumask_copy(&p->cpus_allowed, new_mask); > + p->nr_cpus_allowed = cpumask_weight(new_mask); > + } I'm fine with this if Peter is. > } > > /* > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index 5e95145..3baffb2 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -1574,7 +1574,7 @@ static void task_woken_dl(struct rq *rq, struct > task_struct *p) > } > } > > -static void set_cpus_allowed_dl(struct task_struct *p, > +static bool set_cpus_allowed_dl(struct task_struct *p, > const struct cpumask *new_mask) > { > struct rq *rq; > @@ -1610,7 +1610,7 @@ static void set_cpus_allowed_dl(struct task_struct > *p, > * it is on the rq AND it is not throttled). > */ > if (!on_dl_rq(&p->dl)) > - return; > + return false; > I would think DEAD_LINE tasks would need the same "feature". > weight = cpumask_weight(new_mask); > > @@ -1619,7 +1619,7 @@ static void set_cpus_allowed_dl(struct task_struct > *p, > * can migrate or not. > */ > if ((p->nr_cpus_allowed > 1) == (weight > 1)) > - return; > + return false; > > /* > * The process used to be able to migrate OR it can now migrate > @@ -1636,6 +1636,8 @@ static void set_cpus_allowed_dl(struct task_struct > *p, > } > > update_dl_migration(&rq->dl); > + > + return false; > } > > /* Assumes rq->lock is held */ > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c > index 8885b65..9e7a4bb 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -2241,7 +2241,7 @@ static void task_woken_rt(struct rq *rq, struct > task_struct *p) > push_rt_tasks(rq); > } > > -static void set_cpus_allowed_rt(struct task_struct *p, > +static bool set_cpus_allowed_rt(struct task_struct *p, > const struct cpumask *new_mask) > { > struct rq *rq; > @@ -2250,18 +2250,18 @@ static void set_cpus_allowed_rt(struct task_struct > *p, > BUG_ON(!rt_task(p)); > > if (!task_on_rq_queued(p)) > - return; > + return false; > > weight = cpumask_weight(new_mask); > > + rq = task_rq(p); > + > /* > * Only update if the process changes its state from whether it > * can migrate or not. Comment needs updating. > */ > if ((p->nr_cpus_allowed > 1) == (weight > 1)) > - return; > - > - rq = task_rq(p); > + goto check_push; > > /* > * The process used to be able to migrate OR it can now migrate > @@ -2278,6 +2278,18 @@ static void set_cpus_allowed_rt(struct task_struct > *p, > } > > update_rt_migration(&rq->rt); > + > +check_push: > + if (weight > 1 && !task_running(rq, p) && > + !cpumask_subset(new_mask, &p->cpus_allowed)) { > + /* Update new affinity for pushing */ > + cpumask_copy(&p->cpus_allowed, new_mask); > + p->nr_cpus_allowed = weight; > + push_rt_tasks(rq); > + return true; > + } > + > + return false; > } > > /* Assumes rq->lock is held */ > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index e0e1299..75f869b 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -1189,7 +1189,8 @@ struct sched_class { > void (*task_waking) (struct task_struct *task); > void (*task_woken) (struct rq *this_rq, struct task_struct *task); > > - void (*set_cpus_allowed)(struct task_struct *p, > + /* If p's affinity was updated by it, return true. Otherwise false > */ /* Return true if p's affinity was updated, false otherwise */ -- Steve > + bool (*set_cpus_allowed)(struct task_struct *p, > const struct cpumask *newmask); > > void (*rq_online)(struct rq *rq); > > -------------------------------------------------------- > ZTE Information Security Notice: The information contained in this mail (and any attachment transmitted herewith) is privileged and confidential and is intended for the exclusive use of the addressee(s). If you are not an intended recipient, any disclosure, reproduction, distribution or other dissemination or use of the information contained is strictly prohibited. If you have received this mail in error, please delete it and notify us immediately.