Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42514174 authored by Rusty Russell's avatar Rusty Russell
Browse files

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



Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Cc: Gautham R Shenoy <ego@in.ibm.com>
Cc: Ashok Raj <ashok.raj@intel.com>
parent 62ac1279
Loading
Loading
Loading
Loading
+17 −32
Original line number Original line Diff line number Diff line
@@ -315,42 +315,27 @@ A: The following are what is required for CPU hotplug infrastructure to work


Q: I need to ensure that a particular cpu is not removed when there is some
Q: I need to ensure that a particular cpu is not removed when there is some
   work specific to this cpu is in progress.
   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() is slow, and can fail due to out of memory:


	int my_func_on_cpu(int cpu)
	int my_func_on_cpu(int cpu)
	{
	{
		cpumask_t saved_mask, new_mask = CPU_MASK_NONE;
		int err;
		int curr_cpu, err = 0;
		get_online_cpus();

		if (!cpu_online(cpu))
		saved_mask = current->cpus_allowed;
			err = -EINVAL;
		cpu_set(cpu, new_mask);
		else
		err = set_cpus_allowed(current, new_mask);
#if NEEDS_BLOCKING

			err = work_on_cpu(cpu, __my_func_on_cpu, NULL);
		if (err)
#else
			return err;
			smp_call_function_single(cpu, __my_func_on_cpu, &err,

						 true);
		/*
#endif
		 * If we got scheduled out just after the return from
		put_online_cpus();
		 * 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;
		return err;
	}
	}



Q: How do we determine how many CPUs are available for hotplug.
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
A: There is no clear spec defined way from ACPI that can give us that
   information today. Based on some input from Natalie of Unisys,
   information today. Based on some input from Natalie of Unisys,