简体   繁体   English

我如何在 macOS KEXT 中获取当前处理器 ID

[英]How do i get current processor id in macOS KEXT

I found kern/processor.h files that include current_processor().我找到了包含 current_processor() 的kern/processor.h文件。

But I cannot use current_processor() even i include kern/processor.h file.但是我不能使用current_processor()即使我包含kern/processor.h文件。

Is there any methods to get current processor id?是否有任何方法可以获取当前的处理器 ID?

Add 030420 : I need any methods that get current processor id and methods should be possible to used in KEXT.添加 030420 :我需要任何获取当前处理器 ID 的方法,并且方法应该可以在 KEXT 中使用。 current_processor(), cpu_number() doesn't work on KEXT. current_processor(), cpu_number() 在 KEXT 上不起作用。

The following function is declared in <kern/cpu_number.h> :<kern/cpu_number.h>声明了以下函数:

extern int  cpu_number(void);

and returns the index of the CPU on which the code is currently executing.并返回当前正在执行代码的 CPU 的索引。

Please note that this is in the unsupported KPI however, so you need to link against com.apple.kpi.unsupported .请注意,这是在不受支持的KPI 中,因此您需要链接到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.启用抢占意味着可以随时重新调度正在运行的线程,因此当您的代码使用通过调用上述函数获得的 CPU 编号时,它可能已经被重新调度为在不同的 CPU 上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM