Show which CPU is executing a thread?

John Baldwin jhb at
Tue Jun 2 12:43:01 UTC 2009

On Monday 01 June 2009 10:38:39 am nocturnal wrote:
> I'm more after a programming API for this and when i search the web all i
> find is people saying it cannot be done on FreeBSD in userspace, yet.
> Solaris and Linux can do it but FreeBSD doesn't have this in user space.
> Is anyone working on it, what is the status? Will it be part of SMPng?

First of all, why do you need to know this?  There are APIs to let you bind 
yourself to specific CPUs, but there is not a convenient way to figure out 
which CPU you are on.  Probably because unless you bind yourself to a 
specific CPU, the knowledge is quite useless and racy (you can be preempted 
in userland at any time and be migrated to another CPU unless you have bound 
yourself to a CPU).  If you do bind yourself to a CPU, then you should know 
which one you are bound to. :)  (And you can also query your binding set.)

John Baldwin

More information about the freebsd-smp mailing list