SMP primitives

void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func, void *info, bool wait)

Run a function on processors specified by cpumask, which may include the local processor.

Parameters

const struct cpumask *mask

The set of cpus to run on (only runs on online subset).

smp_call_func_t func

The function to run. This must be fast and non-blocking.

void *info

An arbitrary pointer to pass to the function.

bool wait

If true, wait (atomically) until function has completed on other CPUs.

Description

If wait is true, then returns once func has returned.

You must not call this function with disabled interrupts or from a hardware interrupt handler or from a bottom half handler. The exception is that it may be used during early boot while early_boot_irqs_disabled is set.

smp_processor_id

smp_processor_id ()

get the current (stable) CPU id

Description

This is the normal accessor to the CPU id and should be used whenever possible.

The CPU id is stable when:

  • IRQs are disabled;

  • preemption is disabled;

  • the task is CPU affine.

When CONFIG_DEBUG_PREEMPT=y, we verify these assumptions and WARN when smp_processor_id() is used when the CPU id is not stable.

int smp_call_function_single(int cpu, smp_call_func_t func, void *info, int wait)

Run a function on a specific CPU

Parameters

int cpu

Specific target CPU for this function.

smp_call_func_t func

The function to run. This must be fast and non-blocking.

void *info

An arbitrary pointer to pass to the function.

int wait

If true, wait until function has completed on other CPUs.

Return

0 on success, else a negative status code.

int smp_call_function_single_async(int cpu, call_single_data_t *csd)

Run an asynchronous function on a specific CPU.

Parameters

int cpu

The CPU to run on.

call_single_data_t *csd

Pre-allocated and setup data structure

Description

Like smp_call_function_single(), but the call is asynchonous and can thus be done from contexts with disabled interrupts.

The caller passes his own pre-allocated data structure (ie: embedded in an object) and is responsible for synchronizing it such that the IPIs performed on the csd are strictly serialized.

If the function is called with one csd which has not yet been processed by previous call to smp_call_function_single_async(), the function will return immediately with -EBUSY showing that the csd object is still in progress.

NOTE

Be careful, there is unfortunately no current debugging facility to validate the correctness of this serialization.

Return

0 on success or negative errno value on error

int smp_call_function_any(const struct cpumask *mask, smp_call_func_t func, void *info, int wait)

Run a function on any of the given cpus

Parameters

const struct cpumask *mask

The mask of cpus it can run on.

smp_call_func_t func

The function to run. This must be fast and non-blocking.

void *info

An arbitrary pointer to pass to the function.

int wait

If true, wait until function has completed.

Description

Selection preference:
  1. current cpu if in mask

  2. nearest cpu in mask, based on NUMA topology

Return

0 on success, else a negative status code (if no cpus were online).

void smp_call_function_many(const struct cpumask *mask, smp_call_func_t func, void *info, bool wait)

Run a function on a set of CPUs.

Parameters

const struct cpumask *mask

The set of cpus to run on (only runs on online subset).

smp_call_func_t func

The function to run. This must be fast and non-blocking.

void *info

An arbitrary pointer to pass to the function.

bool wait

If true, wait (atomically) until function has completed on other CPUs.

Description

You must not call this function with disabled interrupts or from a hardware interrupt handler or from a bottom half handler. Preemption must be disabled when calling this function.

func is not called on the local CPU even if mask contains it. Consider using on_each_cpu_cond_mask() instead if this is not desirable.

void smp_call_function(smp_call_func_t func, void *info, int wait)

Run a function on all other CPUs.

Parameters

smp_call_func_t func

The function to run. This must be fast and non-blocking.

void *info

An arbitrary pointer to pass to the function.

int wait

If true, wait (atomically) until function has completed on other CPUs.

Description

If wait is true, then returns once func has returned; otherwise it returns just before the target cpu calls func.

You must not call this function with disabled interrupts or from a hardware interrupt handler or from a bottom half handler.

void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func, void *info, bool wait, const struct cpumask *mask)

Call a function on each processor for which the supplied function cond_func returns true, optionally waiting for all the required CPUs to finish. This may include the local processor.

Parameters

smp_cond_func_t cond_func

A callback function that is passed a cpu id and the info parameter. The function is called with preemption disabled. The function should return a boolean value indicating whether to IPI the specified CPU.

smp_call_func_t func

The function to run on all applicable CPUs. This must be fast and non-blocking.

void *info

An arbitrary pointer to pass to both functions.

bool wait

If true, wait (atomically) until function has completed on other CPUs.

const struct cpumask *mask

The set of cpus to run on (only runs on online subset).

Description

Preemption is disabled to protect against CPUs going offline but not online. CPUs going online during the call will not be seen or sent an IPI.

You must not call this function with disabled interrupts or from a hardware interrupt handler or from a bottom half handler.

void kick_all_cpus_sync(void)

Force all cpus out of idle

Parameters

void

no arguments

Description

Used to synchronize the update of pm_idle function pointer. It’s called after the pointer is updated and returns after the dummy callback function has been executed on all cpus. The execution of the function can only happen on the remote cpus after they have left the idle function which had been called via pm_idle function pointer. So it’s guaranteed that nothing uses the previous pointer anymore.

void wake_up_all_idle_cpus(void)

break all cpus out of idle wake_up_all_idle_cpus try to break all cpus which is in idle state even including idle polling cpus, for non-idle cpus, we will do nothing for them.

Parameters

void

no arguments

int smp_call_on_cpu(unsigned int cpu, int (*func)(void*), void *par, bool phys)

Call a function on a specific CPU and wait for it to return.

Parameters

unsigned int cpu

The CPU to run on.

int (*func)(void *)

The function to run

void *par

An arbitrary pointer parameter for func.

bool phys

If true, force to run on physical cpu. See struct smp_call_on_cpu_struct for more info.

Return

-ENXIO if the cpu is invalid; otherwise the return value from func.