In order for server side applications to run efficiently on modern hardware they have to understand hardware layout. As we are moving towards multicore and multi node NUMA systems, understanding relationships amongst cores, logical and physical CPU has become very important. Before we jump into how applications can do it, we need to define what information we are looking for. To keep things simple for this post, lets converge on the following terminology:
CPU Socket (CPU Slot) - actual holder of physical CPU, can hold a package consisting of multiple physical CPUs, multi core.
CPU Core (Core) - a single physical CPU, can be part of a package placed in a given socket. Dual or multiple cores depending on packaging might or might not share L2 cache.
Logical CPU (Logical thread, Hyper thread) - a single logical CPU that has its own set of dedicated components on physical CPU but shares the rest of physical CPU, Core, with another logical CPUs.
NUMA Node - a set of CPU Sockets packaged together with a block of dedicated memory. A Node might consists of one CPU Socket.
Above definitions imply following: NUMA Node contains Sockets, Sockets contain Cores, and Cores contain Logical CPUs. For example, the number of CPUs output by Windows in Task Manager or perfmon can be calculated by Nodes*Sockets*Cores*LogicalCPUs. For example for single node system with two sockets, two cores per socket, and two logical CPUs, OS will show 1*2*2*2 = 8 CPUs.
Windows exposes a way for developers to retrieve information about hardware hierarchy http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getlogicalprocessorinformation.asp. See attached source file to this post. It shows GetLogicalProcessorInformation API in action. Below is an example output produced from the machine with a single Node, two Sockets, single Core, and two Logical CPUs.
API GetLogicalProcessorInformation is available
0 (Affinity = 1)
2 (Affinity = 4)
Share a single processor core (HT).
1 (Affinity = 2)
3 (Affinity = 8)
Share a NUMA node.
The node Id is 0
If you need to understand hardware layout and don't want to write code, there are several publicly available tools that you can use. Please take a look at ProcessExplorer.exe from http://www.sysinternals.com/Utilities/ProcessExplorer.html. System info view will provide you with required information.
I will be glad to answer your questions.