Retrieving information about CPUs' relationships
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 https://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
CPUs:
0 (Affinity = 1)
2 (Affinity = 4)
Share a single processor core (HT).
CPUs:
1 (Affinity = 2)
3 (Affinity = 8)
Share a single processor core (HT).
CPUs:
0 (Affinity = 1)
1 (Affinity = 2)
2 (Affinity = 4)
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 https://www.sysinternals.com/Utilities/ProcessExplorer.html. System info view will provide you with required information.
I will be glad to answer your questions.
Comments
Anonymous
March 12, 2006
Технология HyperThreading, многоядерность, NUMA... Сходу и не сосчитаешь :-)Anonymous
August 07, 2007
Over the years, I've heard people mention that they wanted a way to determine the physical processorAnonymous
March 19, 2008
PingBack from http://desktopcomputerreviewsblog.info/slava-okss-weblog-retrieving-information-about-cpus-relationships/Anonymous
May 19, 2008
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 haAnonymous
May 19, 2008
PingBack from http://247blogging.info/story.php?title=Slava-Okss-WebLog-Retrieving-information-about-CPUs-relationshipsAnonymous
June 16, 2009
PingBack from http://topalternativedating.info/story.php?id=10121