Too many context switches in a microkernel?
Posted: Mon Aug 24, 2015 5:04 am
I've added context switch counters to my kernel, and the results got me thinking.
The timer is running at 200 Hz, and in Qemu i get 1000-1500 switches per second.
It's the voluntary preemption.
A driver thread would poll for events, find none and yield.
Services would poll for messages, find none and yield.
A terminal would poll for key press messages, find none and yield.
And so on.
There are flurries of activity when something happens, but most of the time the non-waiting processes just yield to each other, only slowed down by the kernel idle process issuing a hlt instruction.
Without it, i get 5500 switches per second in Qemu - i guess it runs as fast as it can switch.
So, how normal is that?
On one hand, you'd want the system to spend most of the time in idle/low power mode when nothing is happening.
On the other hand, you want fast responses when something does happen.
The scheduler can't really keep track of what would or wouldn't get an event, so i can't quite see a way to improve both things at once.
It's feasible to balance one way or the other - i.e. make the system idle until the next timer interrupt when a process yields.
Any thoughts?
The timer is running at 200 Hz, and in Qemu i get 1000-1500 switches per second.
It's the voluntary preemption.
A driver thread would poll for events, find none and yield.
Services would poll for messages, find none and yield.
A terminal would poll for key press messages, find none and yield.
And so on.
There are flurries of activity when something happens, but most of the time the non-waiting processes just yield to each other, only slowed down by the kernel idle process issuing a hlt instruction.
Without it, i get 5500 switches per second in Qemu - i guess it runs as fast as it can switch.
So, how normal is that?
On one hand, you'd want the system to spend most of the time in idle/low power mode when nothing is happening.
On the other hand, you want fast responses when something does happen.
The scheduler can't really keep track of what would or wouldn't get an event, so i can't quite see a way to improve both things at once.
It's feasible to balance one way or the other - i.e. make the system idle until the next timer interrupt when a process yields.
Any thoughts?