Multicore system. How are the cores “sorted”

multi-coreprocessscheduling

If I have a system with let's say two Quadcore CPUs and HyperThreading enabled, how do I know how the phsyical and virtual cores are sorted? For example if I force a process to run on "CPU 0" how to know which Core this really is? I remember a complex drawing about this, but didn't find anything useful.

Update:
After discussing this with a programer I'm convinced that it doesn't make sense to bind a program/thread to a specific core. In most cases it's better to let the operating system decide what core(s) to use. However it would still be interesting how the enumeration works.

Best Answer

Take a look at the hwloc project. It provides an C API to answer these kind of questions and also a tool called lstopo which generates CPU/memory topology maps. See the URL for examples.