Re:How long does it take to make a context switch? (2010)
by otabdeveloper on Wednesday March 22, 2017 @01:24PM
(#13932874)
> Does the CPU interrupt threads running happily on cores even when there are no other threads which want to run or which have affinity that would allow them to run on that core?
Yes. Even if you are careful to ever run only one process (so: no monitoring, no logging, no VM's, no 'middleware', etc.) and limit the number of threads to strictly equal the number of processors, you still have background kernel threads that force your process to context switch.
Re:How long does it take to make a context switch? (2010)
by gpderetta on Wednesday March 22, 2017 @01:33PM
(#13932940)
Tough you can instruct the kernel not to run anything (not even interrupt handlers) on specific cores, except for manually pinned processes.
Re:How long does it take to make a context switch? (2010)
by monocasa on Wednesday March 22, 2017 @02:00PM
(#13933178)
At a minimum you still need timer and TLB IPI shootdown interrupts hitting every core, just to have a working SMP system.
Re:How long does it take to make a context switch? (2010)
by gpderetta on Wednesday March 22, 2017 @02:06PM
(#13933224)
the cpu does need to handle IPI of course but not sure about timers.
Re:How long does it take to make a context switch? (2010)
by marcosdumay on Wednesday March 22, 2017 @03:49PM
(#13934180)
Yes, it does interrupt them, but if the kernel decides to keep the same thread there's no context switch. (In other words, there's a penalty, but it is much smaller.)
Your conclusion is correct. By creating more CPU hungry threads than you have CPUs you will reduce the total throughput of the computer.
But creating more threads will cause each to run slower as their caches are ruined by each context switch aren't they?