mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Xunlei Pang <xlpang@126.com>
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@gmail.com>,
	Xunlei Pang <pang.xunlei@linaro.org>
Subject: Re: [PATCH v6 3/3] sched/rt: Check to push the task when changing its affinity
Date: Mon, 20 Apr 2015 12:06:50 -0400	[thread overview]
Message-ID: <20150420120650.338120f9@gandalf.local.home> (raw)
In-Reply-To: <1429518168-7965-3-git-send-email-xlpang@126.com>

On Mon, 20 Apr 2015 16:22:48 +0800
Xunlei Pang <xlpang@126.com> 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 */


  reply	other threads:[~2015-04-20 16:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-20  8:22 [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Xunlei Pang
2015-04-20  8:22 ` [PATCH v6 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Xunlei Pang
2015-04-20 14:52   ` Steven Rostedt
2015-04-20 17:20     ` Peter Zijlstra
2015-04-20 17:48       ` Steven Rostedt
2015-04-20 23:45         ` Peter Zijlstra
2015-04-21 13:10           ` Steven Rostedt
     [not found]         ` <OFB1503F16.1E65406F-ON48257E2E.002B562D-48257E30.0008BFEB@zte.com.cn>
2015-04-23  3:01           ` Steven Rostedt
     [not found]             ` <OFE3B71874.C9D81693-ON48257E30.0024F69F-48257E30.0025E2D3@zte.com.cn>
2015-04-23 13:10               ` Steven Rostedt
2015-04-24 18:32               ` Peter Zijlstra
     [not found]                 ` <OF0B05B4FE.F40C0BE3-ON48257E32.004EF485-48257E32.00513DB3@zte.com.cn>
2015-04-25 18:23                   ` Peter Zijlstra
     [not found]                     ` <OFD410EB1E.5A02675A-ON48257E33.00309252-48257E33.003641FF@zte.com.cn>
2015-04-26 15:58                       ` Steven Rostedt
2015-04-28 10:19                         ` Peter Zijlstra
2015-04-28 12:48                           ` Mike Galbraith
2015-04-20  8:22 ` [PATCH v6 3/3] sched/rt: Check to push the task when changing its affinity Xunlei Pang
2015-04-20 16:06   ` Steven Rostedt [this message]
2015-04-20 14:42 ` [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Steven Rostedt
2015-04-20 14:48 ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150420120650.338120f9@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=juri.lelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pang.xunlei@linaro.org \
    --cc=peterz@infradead.org \
    --cc=xlpang@126.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®