linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 14/14] cpumask: don't recommend set_cpus_allowed hack in Documentation/cpu-hotplug.txt
@ 2009-11-03  4:29 Rusty Russell
  2009-11-03  5:57 ` Gautham R Shenoy
  0 siblings, 1 reply; 3+ messages in thread
From: Rusty Russell @ 2009-11-03  4:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Gautham R Shenoy, Ashok Raj, Gautham R Shenoy, Ashok Raj

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Gautham R Shenoy <ego@in.ibm.com>
Cc: Ashok Raj <ashok.raj@intel.com>
---
 Documentation/cpu-hotplug.txt |   49 ++++++++++++++----------------------------
 1 file changed, 17 insertions(+), 32 deletions(-)

diff --git a/Documentation/cpu-hotplug.txt b/Documentation/cpu-hotplug.txt
--- a/Documentation/cpu-hotplug.txt
+++ b/Documentation/cpu-hotplug.txt
@@ -309,41 +309,26 @@ A: The following are what is required fo
 
 Q: I need to ensure that a particular cpu is not removed when there is some
    work specific to this cpu is in progress.
-A: First switch the current thread context to preferred cpu
+A: There are two ways.  If your code can be run in interrupt context, use
+   smp_call_function_single(), otherwise use work_on_cpu().  Note that
+   work_on_cpu() can fail due to out of memory:
 
 	int my_func_on_cpu(int cpu)
 	{
-		cpumask_t saved_mask, new_mask = CPU_MASK_NONE;
-		int curr_cpu, err = 0;
-
-		saved_mask = current->cpus_allowed;
-		cpu_set(cpu, new_mask);
-		err = set_cpus_allowed(current, new_mask);
-
-		if (err)
-			return err;
-
-		/*
-		 * If we got scheduled out just after the return from
-		 * set_cpus_allowed() before running the work, this ensures
-		 * we stay locked.
-		 */
-		curr_cpu = get_cpu();
-
-		if (curr_cpu != cpu) {
-			err = -EAGAIN;
-			goto ret;
-		} else {
-			/*
-			 * Do work : But cant sleep, since get_cpu() disables preempt
-			 */
-		}
-		ret:
-			put_cpu();
-			set_cpus_allowed(current, saved_mask);
-			return err;
-		}
-
+		int err;
+		cpu_hotplug_lock();
+		if (!cpu_online(cpu))
+			err = -EINVAL;
+		else
+#if NEEDS_BLOCKING
+			err = work_on_cpu(cpu, __my_func_on_cpu, NULL);
+#else
+			smp_call_function_single(cpu, __my_func_on_cpu, &err,
+						 true);
+#endif
+		cpu_hotplug_unlock();
+		return err;
+	}
 
 Q: How do we determine how many CPUs are available for hotplug.
 A: There is no clear spec defined way from ACPI that can give us that


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 14/14] cpumask: don't recommend set_cpus_allowed hack in Documentation/cpu-hotplug.txt
  2009-11-03  4:29 [PATCH 14/14] cpumask: don't recommend set_cpus_allowed hack in Documentation/cpu-hotplug.txt Rusty Russell
@ 2009-11-03  5:57 ` Gautham R Shenoy
  2009-11-04  8:02   ` Rusty Russell
  0 siblings, 1 reply; 3+ messages in thread
From: Gautham R Shenoy @ 2009-11-03  5:57 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel, Andrew Morton, Ashok Raj

Hi Rusty,

On Tue, Nov 03, 2009 at 02:59:06PM +1030, Rusty Russell wrote:
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> Cc: Gautham R Shenoy <ego@in.ibm.com>
> Cc: Ashok Raj <ashok.raj@intel.com>
> ---
>  Documentation/cpu-hotplug.txt |   49 ++++++++++++++----------------------------
>  1 file changed, 17 insertions(+), 32 deletions(-)
> 
> diff --git a/Documentation/cpu-hotplug.txt b/Documentation/cpu-hotplug.txt
> --- a/Documentation/cpu-hotplug.txt
> +++ b/Documentation/cpu-hotplug.txt
> @@ -309,41 +309,26 @@ A: The following are what is required fo
> 
>  Q: I need to ensure that a particular cpu is not removed when there is some
>     work specific to this cpu is in progress.
> -A: First switch the current thread context to preferred cpu
> +A: There are two ways.  If your code can be run in interrupt context, use
> +   smp_call_function_single(), otherwise use work_on_cpu().  Note that
> +   work_on_cpu() can fail due to out of memory:
> 
>  	int my_func_on_cpu(int cpu)
>  	{
> +		int err;
> +		cpu_hotplug_lock();
		^^^^^^^^^^^^^^^^^^^
This needs to be get_online_cpus();
> +		if (!cpu_online(cpu))
> +			err = -EINVAL;
> +		else
> +#if NEEDS_BLOCKING
> +			err = work_on_cpu(cpu, __my_func_on_cpu, NULL);
> +#else
> +			smp_call_function_single(cpu, __my_func_on_cpu, &err,
> +						 true);
> +#endif
> +		cpu_hotplug_unlock();
		^^^^^^^^^^^^^^^^^^^^^
And this one should be put_online_cpus();

> +		return err;
> +	}
> 
>  Q: How do we determine how many CPUs are available for hotplug.
>  A: There is no clear spec defined way from ACPI that can give us that

-- 
Thanks and Regards
gautham

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 14/14] cpumask: don't recommend set_cpus_allowed hack in Documentation/cpu-hotplug.txt
  2009-11-03  5:57 ` Gautham R Shenoy
@ 2009-11-04  8:02   ` Rusty Russell
  0 siblings, 0 replies; 3+ messages in thread
From: Rusty Russell @ 2009-11-04  8:02 UTC (permalink / raw)
  To: ego; +Cc: linux-kernel, Andrew Morton, Ashok Raj

On Tue, 3 Nov 2009 04:27:23 pm Gautham R Shenoy wrote:
> Hi Rusty,
> 
> On Tue, Nov 03, 2009 at 02:59:06PM +1030, Rusty Russell wrote:
...
> > +		int err;
> > +		cpu_hotplug_lock();
> 		^^^^^^^^^^^^^^^^^^^
> This needs to be get_online_cpus();

Thanks, both fixed!

Rusty.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-04  8:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-03  4:29 [PATCH 14/14] cpumask: don't recommend set_cpus_allowed hack in Documentation/cpu-hotplug.txt Rusty Russell
2009-11-03  5:57 ` Gautham R Shenoy
2009-11-04  8:02   ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).