Multicore system. How are the cores "sorted"

5

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.

asdrubael

Posted 2010-03-24T16:20:38.033

Reputation: 607

8Out of curiosity, why would you want to know what physical core it is? – Bobby – 2010-03-24T16:25:59.673

As long as the labeling is consistent doesn't seem like it would matter. – mindless.panda – 2010-03-24T16:29:24.767

2It may matter if trying to manually control affinity for some reason. A CPU intensive threaded process that shares data between threads running on two or more cores of one CPU will run faster than one using the same number of processing units spread over distinct physical CPUs, and may event perform faster than one that is actively using more cores but spread over multiple CPUs, due to cache sharing/management, CPU<->RAM bandwidth, and related issues. Trying to optimise things this way is unlikely to be best use of your time though. – David Spillett – 2010-03-24T17:25:36.440

The idea is to have a program/thread A which uses all available cores expect of one and another program/thread B which can run on the "last" core on it's own. If the labeling is consistent it doesn't matter how it's done, but I'm curious how it works and if this differs for example between Windows/Linux or different PCs. – asdrubael – 2010-03-24T19:01:35.747

sounds like you're looking for a way to implement LPARs outside of AIX, perhaps? – warren – 2010-04-05T12:12:31.800

Answers

2

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.

knweiss

Posted 2010-03-24T16:20:38.033

Reputation: 1 636

Thanks this is exactly what I was looking for. Again: This is only for "scientific" purposes. – asdrubael – 2010-04-06T13:49:07.937