Reputation: 43
I want to execute function on each processors.
Is OS X have any kernel function similar to on_each_cpu()
in linux?
Upvotes: 0
Views: 143
Reputation: 2383
You want the function mp_cpus_call
:
/*
* mp_cpus_call() runs a given function on cpus specified in a given cpu mask.
* Possible modes are:
* SYNC: function is called serially on target cpus in logical cpu order
* waiting for each call to be acknowledged before proceeding
* ASYNC: function call is queued to the specified cpus
* waiting for all calls to complete in parallel before returning
* NOSYNC: function calls are queued
* but we return before confirmation of calls completing.
* The action function may be NULL.
* The cpu mask may include the local cpu. Offline cpus are ignored.
* The return value is the number of cpus on which the call was made or queued.
*/
cpu_t
mp_cpus_call(
cpumask_t cpus,
mp_sync_t mode,
void (*action_func)(void *),
void *arg)
Note that it is not exported to kexts (or at least non-Apple ones) since it's gated behind com.apple.kpi.apple
which is reserved for Apple kexts. You can still call this either by attempting to resolve the symbol at runtime or by trying to make your kext look like an Apple one (hard on macOS 11). I personlly use dynamic resolution but if this is a kext you want to ship you're mostly out of luck.
Upvotes: 0