Knowing what CPU resources are available is key to making good use of the CPU in any application. Many of today’s CPUs all have more than a single core available, and many are capable of executing multiple threads in parallel on those physical cores. Windows® presents that to you using the concept of physical and logical cores.

Maximising available CPU performance is especially true for games, given the demands they make of the CPU in order to do create a rich, immersive and incredibly interactive game world, and then efficiently drive the GPU to render it all.

This example code correctly detects the physical cores and logical processors of today’s modern processors.

Additional notes:

Many of today’s CPUs all have more than a single core available and may execute multiple threads in parallel. Additionally, high performance cores have gaps in utilization which may be filled by additional hardware threads—this is Simultaneous Multi-Threading (SMT). Although each hardware thread has its own program counter and architectural register set, they share core resources.

This advice is specific to AMD processors and is not general guidance for all processor vendors:

Generally, applications show SMT benefits and use of all logical processors is recommended. However, games often suffer from SMT contention on the main or render threads during gameplay. One strategy to reduce this contention is to create threads based on physical core count rather than logical processor count.

Profile your application or game to determine the ideal thread count:

  • Game initialization – including decompressing assets and compiling/warming shaders – may benefit from logical processors using SMT dual-thread mode.
  • However, game play may prefer physical core count using only SMT single-thread mode.

We recommend adding game options to:

  • Set max thread pool size.
  • Force thread pool size.
  • Force SMT.
  • Force a single NUMA Node, which will implicitly force a Single Processor Group.

And finally: avoid setting the thread pool size as a constant.

V2.0 update (April 2021)

  • Removed Windows XP code sample. Windows 7 or later is required.
  • Clarified guidance for game play and game initialization.
  • Added command line args to the code sample and more processor information including name and vendor.


CPU Core Count Detection on Windows®

Due to architectural differences between Zen and our previous processor architecture, Bulldozer, developers need to take care when using the Windows® APIs for processor and core enumeration.