Re: [PATCH] sched: shorten setting the allowed cpu mask of task

From: Hillf Danton
Date: Tue May 10 2011 - 08:38:30 EST


On Mon, May 9, 2011 at 10:07 PM, Yong Zhang <yong.zhang0@xxxxxxxxx> wrote:
> 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@xxxxxxxxx> wrote:
>> > On Fri, May 6, 2011 at 8:52 PM, Hillf Danton <dhillf@xxxxxxxxx> 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@xxxxxxxxx>

Acked-by: Hillf Danton <dhillf@xxxxxxxxx>

> ---
> Â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
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/