public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yong Zhang <yong.zhang0@gmail.com>
To: Hillf Danton <dhillf@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Mike Galbraith <efault@gmx.de>
Subject: Re: [PATCH] sched: shorten setting the allowed cpu mask of task
Date: Mon, 9 May 2011 22:07:05 +0800	[thread overview]
Message-ID: <20110509140705.GA2219@zhy> (raw)
In-Reply-To: <BANLkTimrHnX5BcK5Q6eJgCAzP+j7azAqow@mail.gmail.com>

On Mon, May 09, 2011 at 08:52:53PM +0800, Hillf Danton wrote:
> On Mon, May 9, 2011 at 12:39 PM, Yong Zhang <yong.zhang0@gmail.com> wrote:
> > On Fri, May 6, 2011 at 8:52 PM, Hillf Danton <dhillf@gmail.com> wrote:
> >> When setting the allowed cpu mask for a given task, if the task is
> >> already bound to certain cpu, after checking the validity of the new
> >
> > Maybe we don't need to restrict it only on task bound to certain cpu.
> >
> Hi Yong
> 
> The original code guards, I guess, casual change in the mask of
> allowed CPUs, if bounded,
> for tasks such as the workers of work queue. So the restriction looks necessary.

Yeah, that is true; but I don't think we need to go ahead for
unbounded task if cpu_allowed will not be changed.

My thought is like below:

---
Subject: [PATCH] sched: avoid going ahead if cpu_allowed will not be changed

If cpumask_equal(&p->cpus_allowed, new_mask) is true, seems
there is no reason to prevent set_cpus_allowed_ptr() return
directly.

Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
---
 kernel/sched.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index da93381..56bc1fa 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -5946,13 +5946,15 @@ int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask)
 
 	rq = task_rq_lock(p, &flags);
 
+	if (cpumask_equal(&p->cpus_allowed, new_mask))
+		goto out;
+
 	if (!cpumask_intersects(new_mask, cpu_active_mask)) {
 		ret = -EINVAL;
 		goto out;
 	}
 
-	if (unlikely((p->flags & PF_THREAD_BOUND) && p != current &&
-		     !cpumask_equal(&p->cpus_allowed, new_mask))) {
+	if (unlikely((p->flags & PF_THREAD_BOUND) && p != current)) {
 		ret = -EINVAL;
 		goto out;
 	}
-- 
1.7.1


  reply	other threads:[~2011-05-09 14:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-06 12:52 [PATCH] sched: shorten setting the allowed cpu mask of task Hillf Danton
2011-05-09  4:39 ` Yong Zhang
2011-05-09 12:52   ` Hillf Danton
2011-05-09 14:07     ` Yong Zhang [this message]
2011-05-10 12:38       ` Hillf Danton
2011-05-16 10:37       ` [tip:sched/core] sched: Avoid going ahead if ->cpus_allowed is not changed tip-bot for Yong Zhang

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=20110509140705.GA2219@zhy \
    --to=yong.zhang0@gmail.com \
    --cc=dhillf@gmail.com \
    --cc=efault@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /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