In my previous question How does the kernel scheduler know how to pre-empt a process? I was given an answer to how pre-emption occurs.

Now I am wondering, how does the kernel scheduler know that a timeslice has passed? I read up on the hardware timer solution which makes sense to me, but then I read that most current operating systems (e.g. Windows, Linux, etc.) do not use hardware timers, but rather software timers.

How can software timers be used to pre-empt a process once it has taken up its timeslice (e.g. it did not pre-empt itself.) It seems like some hardware timer would be necessary?


It seems like some hardware timer would be necessary?

Yes, the kernel relies on hardware to generate an interrupt at regular intervals. On PCs, this was historically the 8253/8254 programmable interval timer, or an emulation thereof, then the local APIC timer, then the HPET.

Current Linux kernels can be built to run “tickless” when possible: the kernel will program timers to only fire when necessary, and if a given CPU is running a single process, that may well be “never”. In most cases, dynamic ticks are used, so the kernel sets timers up to fire at varying intervals depending on its requirements — fewer interrupts means fewer wake-ups, which means idle CPUs can be kept in low-power modes for longer periods, which saves energy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.