diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/smp.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/kernel/smp.c b/kernel/smp.c index 8bd618f0364d..a8c76069cf50 100644 --- a/kernel/smp.c +++ b/kernel/smp.c | |||
| @@ -319,6 +319,51 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, | |||
| 319 | } | 319 | } |
| 320 | EXPORT_SYMBOL(smp_call_function_single); | 320 | EXPORT_SYMBOL(smp_call_function_single); |
| 321 | 321 | ||
| 322 | /* | ||
| 323 | * smp_call_function_any - Run a function on any of the given cpus | ||
| 324 | * @mask: The mask of cpus it can run on. | ||
| 325 | * @func: The function to run. This must be fast and non-blocking. | ||
| 326 | * @info: An arbitrary pointer to pass to the function. | ||
| 327 | * @wait: If true, wait until function has completed. | ||
| 328 | * | ||
| 329 | * Returns 0 on success, else a negative status code (if no cpus were online). | ||
| 330 | * Note that @wait will be implicitly turned on in case of allocation failures, | ||
| 331 | * since we fall back to on-stack allocation. | ||
| 332 | * | ||
| 333 | * Selection preference: | ||
| 334 | * 1) current cpu if in @mask | ||
| 335 | * 2) any cpu of current node if in @mask | ||
| 336 | * 3) any other online cpu in @mask | ||
| 337 | */ | ||
| 338 | int smp_call_function_any(const struct cpumask *mask, | ||
| 339 | void (*func)(void *info), void *info, int wait) | ||
| 340 | { | ||
| 341 | unsigned int cpu; | ||
| 342 | const struct cpumask *nodemask; | ||
| 343 | int ret; | ||
| 344 | |||
| 345 | /* Try for same CPU (cheapest) */ | ||
| 346 | cpu = get_cpu(); | ||
| 347 | if (cpumask_test_cpu(cpu, mask)) | ||
| 348 | goto call; | ||
| 349 | |||
| 350 | /* Try for same node. */ | ||
| 351 | nodemask = cpumask_of_node(cpu); | ||
| 352 | for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids; | ||
| 353 | cpu = cpumask_next_and(cpu, nodemask, mask)) { | ||
| 354 | if (cpu_online(cpu)) | ||
| 355 | goto call; | ||
| 356 | } | ||
| 357 | |||
| 358 | /* Any online will do: smp_call_function_single handles nr_cpu_ids. */ | ||
| 359 | cpu = cpumask_any_and(mask, cpu_online_mask); | ||
| 360 | call: | ||
| 361 | ret = smp_call_function_single(cpu, func, info, wait); | ||
| 362 | put_cpu(); | ||
| 363 | return ret; | ||
| 364 | } | ||
| 365 | EXPORT_SYMBOL_GPL(smp_call_function_any); | ||
| 366 | |||
| 322 | /** | 367 | /** |
| 323 | * __smp_call_function_single(): Run a function on another CPU | 368 | * __smp_call_function_single(): Run a function on another CPU |
| 324 | * @cpu: The CPU to run on. | 369 | * @cpu: The CPU to run on. |
