Commit 4251417484a1775ba5cbfe38c67e6d5af9615de4

Authored by Rusty Russell
1 parent 62ac127950

cpumask: don't recommend set_cpus_allowed hack in Documentation/cpu-hotplug.txt

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Gautham R Shenoy <ego@in.ibm.com>
Cc: Ashok Raj <ashok.raj@intel.com>

Showing 1 changed file with 17 additions and 32 deletions Side-by-side Diff

Documentation/cpu-hotplug.txt
... ... @@ -315,41 +315,26 @@
315 315  
316 316 Q: I need to ensure that a particular cpu is not removed when there is some
317 317 work specific to this cpu is in progress.
318   -A: First switch the current thread context to preferred cpu
  318 +A: There are two ways. If your code can be run in interrupt context, use
  319 + smp_call_function_single(), otherwise use work_on_cpu(). Note that
  320 + work_on_cpu() is slow, and can fail due to out of memory:
319 321  
320 322 int my_func_on_cpu(int cpu)
321 323 {
322   - cpumask_t saved_mask, new_mask = CPU_MASK_NONE;
323   - int curr_cpu, err = 0;
324   -
325   - saved_mask = current->cpus_allowed;
326   - cpu_set(cpu, new_mask);
327   - err = set_cpus_allowed(current, new_mask);
328   -
329   - if (err)
330   - return err;
331   -
332   - /*
333   - * If we got scheduled out just after the return from
334   - * set_cpus_allowed() before running the work, this ensures
335   - * we stay locked.
336   - */
337   - curr_cpu = get_cpu();
338   -
339   - if (curr_cpu != cpu) {
340   - err = -EAGAIN;
341   - goto ret;
342   - } else {
343   - /*
344   - * Do work : But cant sleep, since get_cpu() disables preempt
345   - */
346   - }
347   - ret:
348   - put_cpu();
349   - set_cpus_allowed(current, saved_mask);
350   - return err;
351   - }
352   -
  324 + int err;
  325 + get_online_cpus();
  326 + if (!cpu_online(cpu))
  327 + err = -EINVAL;
  328 + else
  329 +#if NEEDS_BLOCKING
  330 + err = work_on_cpu(cpu, __my_func_on_cpu, NULL);
  331 +#else
  332 + smp_call_function_single(cpu, __my_func_on_cpu, &err,
  333 + true);
  334 +#endif
  335 + put_online_cpus();
  336 + return err;
  337 + }
353 338  
354 339 Q: How do we determine how many CPUs are available for hotplug.
355 340 A: There is no clear spec defined way from ACPI that can give us that