Fundamentals of multi core processing

In this post I am making an attempt to explain basic concepts in regards to multi core processing in windows operating system.  Also at the end I will demonstrate how you can find details like logical processors, numa nodes in your system.

Most of the definitions in this blog post are my understanding after going through Intel’s user guides available on web, MSDN docs and by watching videos available on channel 9 website.

Let me start by explaining how computing system has evolved over time:

Personal computing started with one processor capable of running one program at a time, if there was a request to run other program, operating system issued an interrupt and program running on CPU saved its state, suspend its operations and gave to control back to OS.  MS DOS was perfect example of this. 

After multi processing evolved these are some new terns we came to know.

1. HyperThreading

It’s a technology introduced by Intel with the primary purpose of improving support of multi threaded code. Hyperthreading allows more efficient use of CPU by running multiple threads on each core. Architecturally a processor which is hyper threaded will consist of two logical processors.  All new processors Intel Nehalem processors (such as Xeon 55xx, 56xx & 75xx) are hyperthreaded.

2. Logical Processors, Processor Groups and NUMA nodes

I believe most of us will have had this question i.e. what we see in task manager is that a physical processor? and also what is a logical processor.

A logical processor is one logical computing engine from the perspective of OS, application or driver. So what we see in task manager is logical processor, windows OS threads are mapped 1:1 onto logical processors. A logical processor is a unit which can be individually controlled like it can be halted, interrupted or directed to execute a specific thread.

The current supported limited in Windows OS is 256 logical processors. 

Lets try to understand how logical processors relates with cores and CPU.

A core is one processor unit, which can consist of one or more logical processors. A physical processor can consist of one or more cores. A physical processor is the same as a processor package, a socket, or a CPU. [From MSDN]

This is how I can visualize logical processors, cores and CPU.

image

So what you see in task manager is actually logical processors.

image

Surprised by the fact that we see double the number in task manager for hyper threaded CPU?

Lets jump onto how logical processors relates to Processor Groups and NUMA nodes.

Windows operating system supports more then 64 logical processors by grouping them into processor group. The concept of Processor group was introduced to overcome the limitation of 64 logical processorsProcessor groups are numbered starting from 0, system with logical processors less then 64 defaults to group 0. Processor groups are available on recent operating system like 2008 R2, Win 7 and are not available in older systems like XP, 2003.

Windows OS also takes into consideration location of logical processors, it tries to organize in such a way that logical processors in same core are part of same processor group. Windows OS assigns a processor group to NUMA Node. NUMA stands for non uniform memory access, it’s a non-uniform design in which each processor is closed to one part of memory and farther from other parts of memory. The processor is able to access memory closer to it and takes longer to access memory farther from it. In a NUMA systems CPU’s are arranged in smaller system called as nodes, each node has its own processors and memory which are connected through a bus.

If you are a .net developer then point to note is that CLR runs only on processor group zero, what it means is .net can only use first 64 logical processors.

Activity: How to Check Your System:

You need to download a sys internal utility called as CoreInfo and run it to figure out how many processors, logical processors, process groups and numa nodes.

image

As you can see I have two processors which are hyperthreaded, due to which I see four CPU’s in task manager.  Since my box does not have more then 64 processors all my processors is organized into one group i.e. Group 0 which is NumaNode0

The CoreInfo tool works by making a call to GetLogicalProcessorInformation to show the data above.

In this blog I have covered how CPU’s has evolved over a period of time and common definitions, as a developer you should be writing code which can take advantage of multi core systems. Previously we were taking advantage of single processor by making use of  threading however to take advantage of multiple processors we should make use of parallel libraries like System.Threading.Tasks available in .net framework 4.0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s