3 ms·
> If this is the case then why don't CPU schedulers try to keep single threads running on the CPU instead of context switching? The scheduler in the kernel doe
by exDM69 14y ago
> If this is the case then why don't CPU schedulers try to keep single threads running on the CPU instead of context switching?
The scheduler in the kernel does do this if possible. In order to maximize the chances of a process waking up to warm caches, the scheduler always attempt to wake up the process in the core that was most recently running it. If that core is not available then it tries another core on the same package before it tries other packages (if there are many cpu packages).
However, the kernel has other real world priorities than just trying to keep a single process throughput as high as
possible. It must also be fair to the other processes while keeping the current consumption low and as many cpu cores powered off as possible.
Because the kernel has to work with different workloads ranging from low-end not-so-smart phones with a battery to a supercomputer with it's own nuclear power plant, there are compromises to be made. There's also a lot of compile time and runtime configuration options you can use to tweak the kernel to your particular workload.
- Evbn 14y agoI thought scheduling was one place where the kernel had branches for architecture types.
- robotresearcher 14y agoIt does, but the parent is talking about workload types, not fixed CPU architectures.