Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

I already know that the thread's current CPU may change by the time I use the information.

like image 768
Jeffrey Yasskin Avatar asked Nov 04 '22 00:11

Jeffrey Yasskin


1 Answers

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. I don't know if you can map a queue to a CPU, but if so, that would seem to be the closest equivalent.

like image 167
Paul Sweatte Avatar answered Nov 12 '22 13:11

Paul Sweatte