Re: [PATCH 04/40] sched: implement __set_cpus_allowed()

Tejun Heo
2010-01-20T08:30:28Z

Hello,

On 01/19/2010 05:37 PM, Peter Zijlstra wrote:
> On Tue, 2010-01-19 at 10:07 +0900, Tejun Heo wrote:
>>
>> It's also necessary to guarantee forward progress during CPU_DOWN.
>> The problem with kthread_bind() is that it's not synchronized against
>> CPU hotplug operations. It needs outer synchronization like calling
>> it directly from CPU_DOWN_PREP. I guess it's doable but I think it
>> would be better to simply share the backend implementation between
>> set_cpus_allowed_ptr() and kthread_bind().
>
> OK, so you're saying you need to migrate the rescue thread during
> cpu-down. That thread is guaranteed sleeping right,

No, it's not. It might have been tasked to process works from other
CPUs.

> if it were not it'd not be elegible to run on our dying cpu. Hence
> kthread_bind() ought to just work, no?

Why wouldn't it be elegible?

Commit e2912009fb7b715728311b0d8fe327a1432b3f79 killed the ability to
bind a kthread to a dead CPU which means that the only differences
between kthread_bind() and set_cpus_allowed_ptr() are...

* Whether to use cpu_online_mask or cpu_active_mask.

* Whether to set or check PF_THREAD_BOUND.

Wouldn't it make more sense to share the backend implementation
between kthread_bind() and set_cpus_allowed_ptr() instead of making
kthread_bind() a special case? The goals of the two functions are
basically identical. Why have two separate implementations?
kthread_bind() implementation as it currently stands is pretty fragile
too. Making kthread_bind() backed by set_cpus_allowed_ptr() will make
it more robust and less error-prone and all that's necessary to
achieve that is modifying sanity checks.

Thanks.

--
tejun