Re: too much context switching
On Mon, Jul 04, 2011 at 02:52:18PM -0600, ChadDavis wrote:
> > Does the "context switching" means CPU switches it speed?
> Context switching means that the CPU has switched the process that it
> is executing. The "context" is the process's execution context, I
> believe, which contains it's execution stack, variables, etc.
Yes, that's exactly what the "context" in question is.
I'm not familiar with how the Linux kernel divides up CPU time between
processes, but, if it does it based on clock cycles (X clocks to this
process, then X to that one, etc.) rather than wall-clock time (0.01
seconds to this process...), then we can expect the number of context
switches per second to correlate strongly with CPU speed, since there
will be more "X clocks" slices per second to distribute. If any running
software includes commands to yield CPU early, then a similar (but
weaker) correlation can be expected, since that yield command will be
reached more quickly each time that program runs, leading to more churn
of executing processes.
Perhaps more significantly, I would expect a strong correlation between
context switches per second and the number of CPU cores, since each core
will have its own process context and do its own switching and time
slicing - I would generally expect a system that's running processes on
four cores to have four times as many context switches per second as a
system that's only using one core. It's just a side detail that, in
general, CPUs with more cores also tend to have higher clock speeds.
Anyhow, there are some good answers to the original question at
For a short and sweet answer, I'll turn to Microsoft and their Windows
2000 Server docs
"You can determine whether context switching is excessive by
comparing it with the value of Processor\% Privileged Time. If this
counter is at 40 percent or more and the context-switching rate is
high, then you can investigate the cause for high rates of context
If, as in the OP, your CPU is 90+% idle, then you are *not* having
problems caused by excessive context switching. (The reason they become
problematic is because they suck CPU time away from doing useful things.
If the CPU is idle, then it's obviously not having problems with wasting
too much time on context switches.)