Spreading the Load – CPU Affinities and Hyper-Threading
Many users disable Hyper-Threading in an effort to achieve performance consistency. When the technology first emerged, this was good advice for users with real-time application. However, now that CPU architectures have matured, as have operating system CPU schedulers, the question of whether to disable Hyper-Threading is a little more complicated.
Modern desktop and laptop CPUs from AMD and Intel both use paired core methodologies. This is known as Hyper-Threading on Intel CPUs, and Symmetric Multi-Threading (SMT) for AMD. This technology has evolved over the years. At first it was merely a lesser-capable ‘fake’ logical core attached to every real physical core, relying on most of that physical core’s computational units. AMD went in a slightly different direction starting with Bulldozer, sharing computational units equally between a pair of CPU cores. In fact, AMD initially tried to advertise each of these paired logical cores as a full physical CPU core, for which they were eventually subject to a class action lawsuit.
In time, we ended up calling these pairs a single physical CPU core, each having 2 logical CPU cores. Logical cores are also known as ‘threads’, but we don’t use that term to prevent confusion with software threads. Each of the paired logical CPU cores equally shares computational units with its twin. That means that both logical cores in a pair can execute code simultaneously, but will bottleneck when both need use of the same computational units at the same time.
For a dual-core CPU using Hyper-Threading, the four logical cores would be aligned like so:
0, 1 (paired – share computational units)
2, 3 (paired – share computational units)
Thus, it is preferred to ‘stagger’ a load across CPU core pairs. If you have 2 active threads, you do NOT want to put them on the same CPU core pair. Instead, you want to spread them out so that each is on a distinct pair of cores. For instance, instead of cores 0 and 1, you would pick cores 0 and 2. This would let you make full use of the CPU’s hardware.
CPU affinity for a 2 active thread application:
0, 1 – NOT Optimal
0, 2 – Optimal
The Windows CPU Scheduler is well aware of these paired CPU cores, so it makes an effort to assign threads to distinct CPU core pairs. However, if you want to do it yourself, you can use Process Lasso to set a default/persistent CPU affinity for select processes that staggers the cores available. You can use the ‘Hyper-Threaded Core Avoidance’ context menu selection, or just create your own CPU affinity. This is preferable to disabling Hyper-Threading for the entire system, as you can do it selectively where necessary, yet retain the very significant advantage of the technology.