Tickless systems

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Tickless systems

Post by JJeronimo »

I'm now reconfiguring the linux kernel for compiling (last version was linux-2.6.20.6), and found the option "Tickless system".

The idea is lowering the IRQ rate by programming the timer only when we need it (I suppose for example if all the processes are sleeping waiting for IO, we don't even need the timer interrupting the idle process every 1/n seconds, we only need to wait for the mouse/kbd/hd/etc IRQ).

Sound very interesting. A question then came to my mind: are there any more OSs supporting this?

JJ
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Post by Korona »

This option only makes sense if you are using the APIC or the HPET timers.
If your using the PIT the I/O port accesses will be way to slow and you will waste a lot of time while adjusting the timer. I'm planning to implement this option when I implement APIC timers.
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Post by JJeronimo »

Korona wrote:This option only makes sense if you are using the APIC or the HPET timers.
If your using the PIT the I/O port accesses will be way to slow and you will waste a lot of time while adjusting the timer.
I haven't played much with the PIT, but I thought you had to reprogram it every time it ticks, even if you always need the same delay.
It's probably because I've been programming a timer with this behavior in computer architecture classes (in my university we use a special processor they invented, P3, which are the initials for "Little Pedagogic Processor", in Portuguese).

JJ
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Post by Stevo14 »

JJeronimo wrote: I haven't played much with the PIT, but I thought you had to reprogram it every time it ticks, even if you always need the same delay.
AFAIK mode 3 allows you to program it once and it will indefinitely continue ticking at the same rate.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Post by Korona »

Yes, it has a periodic interrupt mode.
Reprogramming it on every tick is bad because inb() and outb() calls are _very_ slow on the x86.
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post by xyzzy »

My kernel runs tickless when using the APIC timer and no threads are runnable. It simply doesn't prepare the next tick (I have the timer in one-shot mode) when the idle thread gets scheduled.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

If you count the OUTs, tickless systems are better whenever you get more than 4 interrupts without scheduling the process (4xEOI vs 1xEOI + 1x3 bytes to PIT). There's an older discussion on this you can try finding with a search.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
Combuster wrote:If you count the OUTs, tickless systems are better whenever you get more than 4 interrupts without scheduling the process (4xEOI vs 1xEOI + 1x3 bytes to PIT). There's an older discussion on this you can try finding with a search.
It's not quite that simple...

First, I put the PIT into "hibyte only" mode and leave channel 0 selected, so that a new PIT count can be set with a single I/O port write, and so you get a range from 214.5 us to 54.9 ms (in 214.5 us increments).

Secondly, if the task doesn't use it's entire time slice then the count will be reprogrammed before any IRQ occurs - no EOI necessary.

However, if a task uses a small fraction of it's time slice you'll be doing I/O port writes more often. For e.g. if the PIT is set to 100 Hz and each task runs for 1 ms and blocks, then you get one I/O port access for 10 task switches, but if the PIT is being used in "one-shot" mode you'd get 10 times as many I/O port accesses.

Lastly, if the PIT is being used in "one-shot" mode then you need to keep track of real time somehow. You could read the PIT's remaining count when a task doesn't use it's entire time slice (more I/O port accesses but very precise) or use the CMOS/RTC's periodic IRQ or update IRQ (lots more I/O port accesses), or read the time from the CMOS/RTC's "hour/minute/second" fields (a potentially huge number of I/O port accesses and a complete lack of precision) or use some other way (e.g. RDTSC, which is very hard to get right but is extremely precise).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
de
Posts: 12
Joined: Tue Apr 29, 2008 2:27 pm

Post by de »

I disable the PIT before HLT-ing the CPU when no thread is runnable. If there's work to do again I reenable the timer. That works quite well.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Post by Korona »

What is the advantage of doing that? When no running thread you don't have to save clock cycles.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
Korona wrote:What is the advantage of doing that? When no running thread you don't have to save clock cycles.
It reduces CPU power consumption (less heat, less chance of thermal throttling, less electricity, longer laptop battery life, less fan noise, less "server room" air-conditioning, less global warming, etc).

Taking the CPU out of the HLT state (and out of any other power saving state) for no reason doesn't really help SMP performance either. For e.g. unnecessary bus/memory bandwidth used by one CPU effects the performance of other CPUs trying to use bus/memory bandwidth; and for hyper-threading, unnecessary work done by one logical CPU effects the performance of another logical CPU in the same chip/core.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply