From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755515AbbDTQG4 (ORCPT ); Mon, 20 Apr 2015 12:06:56 -0400 Received: from smtprelay0033.hostedemail.com ([216.40.44.33]:57908 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752466AbbDTQGy (ORCPT ); Mon, 20 Apr 2015 12:06:54 -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:1605:1711:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2895:3138:3139:3140:3141:3142:3151:3165:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:5007:6119:6261:7875:7903:7904:7974:9010:10004:10400:10848:10967:11026:11232:11658:11914:12043:12295:12296:12438:12517:12519:12663:12740:13172:13229: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: basin98_1bee9f85af5c X-Filterd-Recvd-Size: 4239 Date: Mon, 20 Apr 2015 12:06:50 -0400 From: Steven Rostedt To: Xunlei Pang Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Juri Lelli , Xunlei Pang Subject: Re: [PATCH v6 3/3] sched/rt: Check to push the task when changing its affinity Message-ID: <20150420120650.338120f9@gandalf.local.home> In-Reply-To: <1429518168-7965-3-git-send-email-xlpang@126.com> References: <1429518168-7965-1-git-send-email-xlpang@126.com> <1429518168-7965-3-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, 20 Apr 2015 16:22:48 +0800 Xunlei Pang wrote: > + rq = task_rq(p); > + > + if (new_weight > 1 && > + rt_task(rq->curr) && > + rq->rt.rt_nr_total > 1 && > + !test_tsk_need_resched(rq->curr)) { > + /* > + * We own p->pi_lock and rq->lock. rq->lock might > + * get released when doing direct pushing, however > + * p->pi_lock is always held, so it's safe to assign > + * new_mask and new_weight to p below. > + */ > + if (!task_running(rq, p)) { > + cpumask_copy(&p->cpus_allowed, new_mask); > + p->nr_cpus_allowed = new_weight; > + direct_push = 1; > + } else if (cpumask_test_cpu(task_cpu(p), new_mask)) { > + struct task_struct *next; > + > + cpumask_copy(&p->cpus_allowed, new_mask); > + p->nr_cpus_allowed = new_weight; > + if (!cpupri_find(&rq->rd->cpupri, p, NULL)) > + goto update; > + > + /* > + * At this point, current task gets migratable most > + * likely due to the change of its affinity, let's > + * figure out if we can migrate it. > + * > + * Can we find any task with the same priority as > + * current? To accomplish this, firstly we requeue > + * current to the tail and peek next, then restore > + * current to the head. "current"? Don't you mean 'p'? > + */ > + requeue_task_rt(rq, p, 0); > + next = peek_next_task_rt(rq); > + requeue_task_rt(rq, p, 1); Actually, I'm totally confused by all this. Why are you looking at next? The running task (current) should not be in the next_task_rt() list to begin with. If p can not preempt current, and cpupri_find() finds something for p to run on, then move it there, and be done with it. I also looked at set_cpus_allowed_ptr() and think we should probably add a p->sched_class->pick_cpu() and do: if (p->sched_class->pick_cpu) dest_cpu = p->sched_class->pick_cpu(p, cpu_active_mask, new_mask); else dest_cpu = cpumask_any_and(cpu_active_mask, new_mask); Hmm, maybe all this work should be done there, or have do_set_cpus_allowed() return a value that states that the sched_class->set_cpus_allowed() did all the work for us. -- Steve > + if (next != p && next->prio == p->prio) { > + /* > + * Target found, so let's reschedule to try > + * and push current away. > + */ > + requeue_task_rt(rq, next, 1); > + preempt_push = 1; > + } > + } > + } > + > +update: > /* > * Only update if the process changes its state from whether it > * can migrate or not. > */ > - if ((p->nr_cpus_allowed > 1) == (weight > 1)) > - return; > - > - rq = task_rq(p); > + if ((old_weight > 1) == (new_weight > 1)) > + goto out; > > /* > * The process used to be able to migrate OR it can now migrate > */ > - if (weight <= 1) { > + if (new_weight <= 1) { > if (!task_current(rq, p)) > dequeue_pushable_task(rq, p); > BUG_ON(!rq->rt.rt_nr_migratory); > @@ -2129,6 +2184,12 @@ static void set_cpus_allowed_rt(struct task_struct *p, > } > > update_rt_migration(&rq->rt); > + > +out: > + if (direct_push) > + push_rt_tasks(rq); > + else if (preempt_push) > + resched_curr(rq); > } > > /* Assumes rq->lock is held */