mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Kirill Tkhai <tkhai@yandex.ru>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH]sched_rt.c: Avoid unnecessary dequeue and enqueue of pushable tasks in set_cpus_allowed_rt()
Date: Tue, 10 Apr 2012 11:52:07 -0400	[thread overview]
Message-ID: <1334073127.23924.213.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <944171329661049@web81.yandex.ru>

On Sun, 2012-02-19 at 18:17 +0400, Kirill Tkhai wrote:
> ---
> 
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 3640ebb..bf48343 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -1779,43 +1779,36 @@ static void set_cpus_allowed_rt(struct task_struct *p,
>  				const struct cpumask *new_mask)
>  {
>  	int weight = cpumask_weight(new_mask);

Lets move the assignment of weight down. Gcc may optimize, but I don't
want to rely on it.

> +	struct rq *rq;
>  
>  	BUG_ON(!rt_task(p));
>  
>  	/*
> -	 * Update the migration status of the RQ if we have an RT task
> -	 * which is running AND changing its weight value.
> +	 * Just exit if it's not necessary to change migration status

Let's comment this better. Something like:

	Only update if the process changes its state from whether it
	can migrate or not.


>  	 */
> -	if (p->on_rq && (weight != p->rt.nr_cpus_allowed)) {
> -		struct rq *rq = task_rq(p);
> -
> -		if (!task_current(rq, p)) {
> -			/*
> -			 * Make sure we dequeue this task from the pushable list
> -			 * before going further.  It will either remain off of
> -			 * the list because we are no longer pushable, or it
> -			 * will be requeued.
> -			 */
> -			if (p->rt.nr_cpus_allowed > 1)
> -				dequeue_pushable_task(rq, p);
> -
> -			/*
> -			 * Requeue if our weight is changing and still > 1
> -			 */
> -			if (weight > 1)
> -				enqueue_pushable_task(rq, p);
> +	if ((p->rt.nr_cpus_allowed > 1) == (weight > 1))
> +		return;
>  
> -		}
> +	if (!p->on_rq)
> +		return;

Make the on_rq check first, and move the weight calculation below it.
Why calculate the weight if we don't plan on doing anything with it?

>  
> -		if ((p->rt.nr_cpus_allowed <= 1) && (weight > 1)) {
> -			rq->rt.rt_nr_migratory++;
> -		} else if ((p->rt.nr_cpus_allowed > 1) && (weight <= 1)) {
> -			BUG_ON(!rq->rt.rt_nr_migratory);
> -			rq->rt.rt_nr_migratory--;
> -		}
> +	rq = task_rq(p);
>  
> -		update_rt_migration(&rq->rt);
> +	/*
> +	 * Several cpus were allowed but now it's not so OR vice versa

I rather say:

	The process use to be able to migrate OR it can now migrate

Otherwise, the patch looks good.

Thanks,

-- Steve

P.S. I don't have any more trips in the near future, so I should be much
quicker in my responses ;-)



> +	 */
> +	if (weight <= 1) {
> +		if (!task_current(rq, p))
> +			dequeue_pushable_task(rq, p);
> +		BUG_ON(!rq->rt.rt_nr_migratory);
> +		rq->rt.rt_nr_migratory--;
> +	} else {
> +		if (!task_current(rq, p))
> +			enqueue_pushable_task(rq, p);
> +		rq->rt.rt_nr_migratory++;
>  	}
> +
> +	update_rt_migration(&rq->rt);
>  }
>  
>  /* Assumes rq->lock is held */



  parent reply	other threads:[~2012-04-10 15:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-01 21:26 Kirill Tkhai
2011-12-20 17:44 ` Oleg Nesterov
2011-12-20 20:28   ` Tkhai Kirill
2011-12-20 21:09     ` Tkhai Kirill
2012-02-13 17:23 ` Steven Rostedt
2012-02-19 14:17   ` Kirill Tkhai
2012-03-16 23:58     ` Kirill Tkhai
2012-04-10 13:58       ` Steven Rostedt
2012-04-10 15:52     ` Steven Rostedt [this message]
2012-04-11  5:06       ` Kirill Tkhai
2012-04-14 18:22         ` [tip:sched/core] sched_rt: Avoid unnecessary dequeue and enqueue of pushable tasks in set_cpus_allowed_rt () tip-bot for Kirill Tkhai
2012-01-11 19:10 [PATCH] sched_rt.c: Avoid unnecessary dequeue and enqueue of pushable tasks in set_cpus_allowed_rt() Kirill Tkhai

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=1334073127.23924.213.camel@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=tkhai@yandex.ru \
    /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®