[This text is the updated version of my announcement in linux-kernel]

Out of despair and lack of other good ideas I invented the
"Completely Mad Time (TM)" :)

There's a difference with the timeoffset taken from the timer chip and
the fasttimeoffset taken from the Pentium cycle counter:

If a time interrupt is delayed with the Pentium stuff, the error
accumulates (e.g. when the first is 500µs late and the next is 200µs
late, the total delay is 700µs). Due to the way the fasttimeoffset is
reset in the timer interrupt routine, these delays are lost forever. I
call this "badness 1".

If a timer interrupt is delayed, the current timeoffset is clamped at
one tick. Thus the time would no longer increase until the interrupt
is processed. I call that "badness 2".

If you remove the clamping, the timeoffset can grow beyond one tick,
but on the next timer interrupt only one tick will be added and the
offset will be reset to zero, effectively making the time run
backwards. I call this "badness 3".

I tried to fix these problems with my CMT (Completely Mad Time) patch
on top of 2.0.31-pre9 (The kernel should be tested anyway): The
clamping in the fast timeoffset has been removed, and the "cycles per
microsecond" are available globally.

In the timer interrupt the delay is computed from the cycle counter
and added to the system clock. If the amount is larger than one tick
(very bad), only one tick is corrected. If the delay is smaller, any
remaining correction from previous runs is subtracted from the system
time, but only up to one tick (because the time between the last two
invocations of the time routine was shorter than one tick then).

I haven't dealt with the APM case yet, and maybe some constants need
tuning (border cases). After all it looks not worse than the previous
code.

Finally I have included a histogram of measured time differences in a
tight loop. Time doesn't look too bad. The Program was taken from the
xntp distribution (util/hist.c).

Ulrich Windl

# Histogram: time between calls, number of occurrencies
6 57657736
7 30774536
8 17291
9 19570
10 8644
11 2989
12 1002
13 146
14 20
15 4
16 29
17 169
18 14390
19 21760
20 11093
21 1557
22 650
23 933
24 819
25 556
26 1280
27 1738
28 1395
29 1147
30 986
31 734
32 406
33 128
34 69
35 38
36 22
37 21
38 22
39 29
40 17
41 17
42 18
43 18
44 21
45 11
46 13
47 13
48 29
49 71
50 197
...
150 4
151 7
152 5
153 4
154 2
155 2
157 1
158 2
159 4
160 6
...
1002 2
...
2007 1
...
3006 1
...
4012 1
...
10037 1
10048 1
10054 1
10063 1
10074 1
10109 1
...
20054 1
...
101314 1
...
205473 1
...
248156 1
264129 1
282133 1
284063 1
291814 1
308834 1
332255 1
