I found kern/processor.h
files that include current_processor().
But I cannot use current_processor()
even i include kern/processor.h
file.
Is there any methods to get current processor id?
Add 030420 : I need any methods that get current processor id and methods should be possible to used in KEXT. current_processor(), cpu_number() doesn't work on KEXT.
The following function is declared in <kern/cpu_number.h>
:
extern int cpu_number(void);
and returns the index of the CPU on which the code is currently executing.
Please note that this is in the unsupported KPI however, so you need to link against com.apple.kpi.unsupported
.
Also note that the result will be meaningless unless preemption is disabled, which is of course normally not the case, only when a spinlock is held, or when running in a primary interrupt handler. Preemption being enabled means that the running thread can be rescheduled at any time, so by the time your code uses the CPU number it obtained by calling the above function, it may already have been rescheduled to run on a different CPU.