简体   繁体   English

对于Mac和BSD,我如何找到当前线程运行的cpu?

[英]How do I find the cpu the current thread is running on, for Mac and BSD?

I'm looking for a function on Mac OS and BSD that's equivalent to Linux's sched_getcpu() , and Windows' GetCurrentProcessorNumberEx() in order to implement a library for cpu-local storage. 我正在寻找Mac OS和BSD上的一个功能,它相当于Linux的sched_getcpu()和Windows的GetCurrentProcessorNumberEx() ,以便为cpu本地存储实现一个库。 It's clearly possible to emulate this with the cpuid or rdtscp instructions, but it's possible to do better with kernel cooperation: https://lkml.org/lkml/2007/1/6/190 . 显然可以使用cpuid或rdtscp指令来模拟它,但是可以通过内核协作做得更好: https ://lkml.org/lkml/2007/1/6/190。

I already know that the thread's current CPU may change by the time I use the information. 我已经知道线程的当前CPU可能会在我使用信息时发生变化。

There are one or two questions which cover queue tracking for OSX, as well as a dispatch_get_global_queue wiki page which covers the equivalent for BSD. 一个两个问题涵盖了OSX的队列跟踪,以及一个dispatch_get_global_queue wiki页面,它涵盖了BSD的等价物。 I don't know if you can map a queue to a CPU, but if so, that would seem to be the closest equivalent. 我不知道你是否可以将队列映射到CPU,但如果是这样,那似乎是最接近的等价物。

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

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