* get/put_online_cpus documentation wrong?
@ 2012-05-01 0:12 Paul Mackerras
2012-05-01 11:26 ` Gilad Ben-Yossef
0 siblings, 1 reply; 3+ messages in thread
From: Paul Mackerras @ 2012-05-01 0:12 UTC (permalink / raw)
To: linux-kernel; +Cc: Rusty Russell
In Documentation/cpu-hotplug.txt it says:
" #include <linux/cpu.h>
get_online_cpus() and put_online_cpus():
The above calls are used to inhibit cpu hotplug operations. While the
cpu_hotplug.refcount is non zero, the cpu_online_mask will not change.
If you merely need to avoid cpus going away, you could also use
preempt_disable() and preempt_enable() for those sections.
Just remember the critical section cannot call any
function that can sleep or schedule this process away."
That last statement doesn't seem like it can be correct, given that
get_online_cpus and put_online_cpus both do a mutex_lock(), which can
sleep. So, is that statement still correct? What would happen if a
process did sleep after doing get_online_cpus()?
Also, get/put_online_cpus doing mutex_lock() implies that one should
not call them in atomic context, e.g. while holding a spinlock, which
could usefully be mentioned in cpu-hotplug.txt.
I'm happy to do a patch to update cpu-hotplug.txt once it's clear what
the actual constraints are.
Paul.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: get/put_online_cpus documentation wrong?
2012-05-01 0:12 get/put_online_cpus documentation wrong? Paul Mackerras
@ 2012-05-01 11:26 ` Gilad Ben-Yossef
2012-05-01 13:58 ` Srivatsa S. Bhat
0 siblings, 1 reply; 3+ messages in thread
From: Gilad Ben-Yossef @ 2012-05-01 11:26 UTC (permalink / raw)
To: Paul Mackerras; +Cc: linux-kernel, Rusty Russell
On Tue, May 1, 2012 at 3:12 AM, Paul Mackerras <paulus@samba.org> wrote:
>
> In Documentation/cpu-hotplug.txt it says:
>
> " #include <linux/cpu.h>
> get_online_cpus() and put_online_cpus():
>
> The above calls are used to inhibit cpu hotplug operations. While the
> cpu_hotplug.refcount is non zero, the cpu_online_mask will not change.
> If you merely need to avoid cpus going away, you could also use
> preempt_disable() and preempt_enable() for those sections.
> Just remember the critical section cannot call any
> function that can sleep or schedule this process away."
I *think* the critical section remark here is referring to using
preempt_disable/enable(),
rather then the use of get/put_online_cpus().
Gilad
--
Gilad Ben-Yossef
Chief Coffee Drinker
gilad@benyossef.com
Israel Cell: +972-52-8260388
US Cell: +1-973-8260388
http://benyossef.com
"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
-- Jean-Baptiste Queru
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: get/put_online_cpus documentation wrong?
2012-05-01 11:26 ` Gilad Ben-Yossef
@ 2012-05-01 13:58 ` Srivatsa S. Bhat
0 siblings, 0 replies; 3+ messages in thread
From: Srivatsa S. Bhat @ 2012-05-01 13:58 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Gilad Ben-Yossef, linux-kernel, Rusty Russell
On 05/01/2012 04:56 PM, Gilad Ben-Yossef wrote:
> On Tue, May 1, 2012 at 3:12 AM, Paul Mackerras <paulus@samba.org> wrote:
>>
>> In Documentation/cpu-hotplug.txt it says:
>>
>> " #include <linux/cpu.h>
>> get_online_cpus() and put_online_cpus():
>>
>> The above calls are used to inhibit cpu hotplug operations. While the
>> cpu_hotplug.refcount is non zero, the cpu_online_mask will not change.
>> If you merely need to avoid cpus going away, you could also use
>> preempt_disable() and preempt_enable() for those sections.
>> Just remember the critical section cannot call any
>> function that can sleep or schedule this process away."
>
>
> I *think* the critical section remark here is referring to using
> preempt_disable/enable(),
> rather then the use of get/put_online_cpus().
>
Yes, what Gilad said is right.
Using preempt_disable()/preempt_enable() around a piece of code is a
light-weight way of preventing CPUs from going away (CPUs going offline)
while executing that code. (However, they don't prevent new CPUs from
coming online). So, if you are using preempt_disable|enable() to
prevent some CPU from going offline, then the usual rules for using
preempt_disable|enable() apply - that code should not sleep.
But if you want to avoid CPU hotplug entirely (both CPU offlining and
onlining), then you should use get/put_online_cpus(). You can use this
around any piece of code, including those which can sleep.
Regards,
Srivatsa S. Bhat
IBM Linux Technology Center
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-05-01 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-01 0:12 get/put_online_cpus documentation wrong? Paul Mackerras
2012-05-01 11:26 ` Gilad Ben-Yossef
2012-05-01 13:58 ` Srivatsa S. Bhat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox