Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Windows switch processes between processors?

If a single threaded process is busy and uses 100% of a single core it seems like Windows is switching this process between the cores, because in Task Managers core overview all cores are equal used.

Why does Windows do that? Isn't this destroying L1/L2 caches?

like image 288
Verim Avatar asked Mar 07 '15 23:03

Verim


People also ask

How do I make Windows use all my CPU cores?

Check if you can enable all the processors from advanced boot menu. Press Windows Key + x from the keyboard->type msconfig->Click on Boot->Advanced Options->Check on Number of Processors->Now select the Processor that you want to activate->Click on Apply->OK. You can now restart the computer and check.

Does Windows automatically use all cores?

Your operating system and the programs you're running will use as many cores and processing power as they need. So, there's really no need to enable all the cores. For example, Windows 10 is configured to automatically use all the cores if the program you're running has this ability.

Does Windows 10 use multiple cores?

From Microsoft - Windows 10 supports a maximum of two physical CPUs, but the number of logical processors or cores varies based on the processor architecture. A maximum of 32 cores is supported in 32-bit versions of Windows 8, whereas up to 256 cores are supported in the 64-bit versions.


2 Answers

There are advantages to pinning a process to one core, primarily caching which you already mentioned.

There are also disadvantages -- you get unequal heating, which can create mechanical stresses that do not improve the expected lifetime of the silicon die.

To avoid this, OSes tend to keep all cores at equal utilization. When there's only one active thread, it will have to be moved and invalidate caches. As long as this is done infrequently (in CPU time), the impact of the extra cache misses during migration is negligible.

For example, the abstract of "Energy and thermal tradeoffs in hardware-based load balancing for clustered multi-core architectures implementing power gating" explicitly lists this as a design goal of scheduling algorithms (emphasis mine):

In this work, a load-balancing technique for these clustered multi-core architectures is presented that provides both a low overhead in energy and an a smooth temperature distribution across the die, increasing the reliability of the processor by evenly stressing the cores.

Spreading the heat dissipation throughout the die is also essential for techniques such as Turbo Boost, where cores are clocked temporarily at a rate that is unsustainable long term. By moving load to a different core regularly, the average heat dissipation remains sustainable even though the instantaneous power is not.

like image 88
Ben Voigt Avatar answered Nov 15 '22 20:11

Ben Voigt


Your process may be the only one doing a lot of work, but it is not the only thing running. There are lots of other processes that need to run occasionally. When your process gets evicted and eventually re-scheduled, the core on which it was running previously might not be available. It's better to run the waiting process immediately on a free core than to wait for the previous core to be available (and in any case its data will likely have been bumped from the caches by the other thread).

In addition, modern CPUs allow all the cores in a package to share high-level caches. See the "Smart Cache" feature in this Intel Core i5 spec sheet. You still lose the lower-level cache(s) on core switch, but those are small and will probably churn somewhat anyway if you're running more than just a small tight loop.

like image 22
nobody Avatar answered Nov 15 '22 18:11

nobody