5

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.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Jeffrey Yasskin
  • 5,171
  • 2
  • 27
  • 39

1 Answers1

2

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.

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265