From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds) Subject: Re: Kludge-Omatic-Timers in kernel Date: 6 Feb 1992 17:57:39 GMT
In article <1992Feb6.003838.3194@colorado.edu> drew@hazelrah.Colorado.EDU (Drew Eckhardt) writes:
>There is an add_timer routine in the scheduler sched.c. Unfortunately,
>in the real world this is no good, as you can only get your function called
>when the timer EXPIRES. In reality, you want to be able to abort it
>at any time, or even adjust it.
Yeah, it was a bad idea, and it wasn't really useful for anything. 0.13
has a newer timer-type, but use the old cludgy way (adding a timer into
do_timer()) for now. The timer in 0.13 isn't that general: it just has
32 hardcoded timers and a mask-bit for them all, but it's useful for
everything from the beeping, screen blanking, harddisk timeout to serial
lines, so it should be ok for most things.
>So, to work around this, floppy disk, hard disk, console code are alll
>in sched.c. And now I've got scsi code in there too :-(
The floppy is still there: I'll move that over to the timers too, but I
haven't yet. Should be ready for 0.13 - and if you make the scsi-timer
look somewhat like the harddisk timer (no weird frills?), I'll have no
problem adding the code.
>I propose a slight change in the interface : [add-timer change]
I made this simpler (but not quite general) interface, you'll probably
find it adequate for almost all needs. It has the advantage that setting
timers is very easy from machine code: to start up a timer (like the
serial timer) just means setting one bit after you have set up the
addresses etc.
All the complaints were very valid: the add_timer() code stinks. It
wasn't really good even just for the floppy drive, and didn't work for
much else: I make mistakes too :).
The new timer routines (no, I won't post them here: but it's mainly just
an array: timer_table[32] of a function address to be called and the
timeout, with the addition of the bit which controls if the timer is
active) have a clean interface, and are very easy to make atomic (you
don't even need cli-sti, the enable-bit can work as well, but there are
other ways too).
Linus