DCSIMG
.NET Support for More Than 64 Processors - All Your Base Are Belong To Us

All Your Base Are Belong To Us

Mostly .NET internals and other kinds of gory details

.NET Support for More Than 64 Processors

Daniel Moth recently blogged about the sad fact that there are no managed APIs for working with more than 64 logical processors, even though as you probably know, Windows 7 (and of course Windows Server 2008 R2) features support for up to 256 logical processors.

Frankly, these APIs aren’t designed to be very friendly, but sure enough they give you the ability to create threads (within a single process) that will run on different processor groups. As each processor group is limited to 64 processors, by creating 4 threads you can utilize up to 256 processors, which is currently the cap.

I’ve decided to write a C++/CLI wrapper titled Multi-Processor Extensions for .NET (published on CodePlex today) that wraps these native APIs. Among them you’ll find:

  • Logical processor information (GetLogicalProcessorInformationEx), including cache relationships, processors and processor groups, NUMA nodes and everything else
  • NUMA information, including memory available on each node, NUMA node per process allocation etc.
  • Facilities for modifying the processor group affinity of a thread, retrieving the processor group affinity of a process and creating a new process inheriting the parent’s processor group affinity (which is not the default)

Some example use:

foreach (ProcessorGroup group in Processor.ProcessorGroups)

    Console.WriteLine("Processors in group: " + group.Processors);

 

foreach (NumaNodeRelationship numa in Processor.GetNumaNodeRelationships())

    Console.WriteLine("NUMA node number: " + numa.NodeNumber);

 

foreach (CacheRelationship cache in Processor.GetCacheRelationships())

    Console.WriteLine("Cache: " + cache.Type + " " + cache.CacheSize);

 

Console.WriteLine("Memory on NUMA node 0: " + Numa.GetAvailableMemory(0));

Admittedly I haven’t wrapped the API for creating a new thread and assigning it to a processor group that is different from the processor group of its creating process, but I did wrap the API for modifying the processor group of a thread, so you can still do it in two steps. If there’s much demand, I will add it later, or you can do it yourself (you need to use the new API for modifying extended process & thread attributes).

If you’re the lucky owner of dedicated hardware with more than 64 logical processors, please give these wrappers a try and see if they work ;-)

Comments

Dew Drop – Weekend Edition – July 25-26, 2009 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop – Weekend Edition – July 25-26, 2009 | Alvin Ashcraft's Morning Dew

# July 26, 2009 6:27 PM

Reflective Perspective - Chris Alcock » The Morning Brew #398 said:

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #398

# July 27, 2009 10:40 AM

Josh said:

That is awesome!

# July 27, 2009 2:46 PM

All Your Base Are Belong To Us said:

Dana Groff, Senior Program Manager on the ConcRT team is going to talk about the new Concurrency Runtime

# November 19, 2009 7:18 PM

All Your Base Are Belong To Us said:

Pedro Teixeira is going to talk about processes and threads in systems with more than 64 logical processors

# November 19, 2009 9:01 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: