Re: Faster timers for Linux 2.1.22

Keith Owens (
Sun, 26 Jan 1997 14:01:59 +1100

On Sun, 26 Jan 1997 00:20:01 +0100 (MET),
Finn Arne Gangstad <> wrote:
>Since cli() and sti() are quite heavy operations, it could be interesting
>to call sti() before detach_timer only every 32 timers or so.

A suggestion on the subject of rewriting timer handling and reducing
the use of sti/cli.

In some sections of code, disable_bh can serialise bottom half
processing instead of cli/sti but is hardly used (only 4 sources). One
of the problems is that many sources use timers to come back and try
again. The timers run under their own bh, instead of under the local
bh. To use disable_bh then requires

... local code ...

Causes a fairly global lock on TIMER_BH instead of just a lock on
local_BH. Since timer handling is being rewritten, how about adding a
finer interface :-

add_timer_bh(&routine, local_BH);
#define add_timer(x) add_timer_bh(x, TIMER_BH)

Separate timers into global timers (use TIMER_BH) and local timers (use
local_BH). No need for separate queues for each bh, just store the bh
bitmap in the timer structure. run_timer_list ignores expired timers
if the relevant bh is disabled. When local_BH is enabled, the next
run_timer_list will find and run the expired timers. Extra overhead is
fairly small, bh bitmap is only checked for expired timers.

The aim is to replace cli/sti with disable/enable_bh where possible.
Requires a bit more documentation to list the structures that really
need cli/sti because they are hit by hard interrupts, everything else
should be a candidate for bh handling. Comments?