Merge tag 'gcc-plugins-v4.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / arch / cris / arch-v32 / kernel / fasttimer.c
1 /*
2  * linux/arch/cris/kernel/fasttimer.c
3  *
4  * Fast timers for ETRAX FS
5  *
6  * Copyright (C) 2000-2006 Axis Communications AB, Lund, Sweden
7  */
8
9 #include <linux/errno.h>
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
12 #include <linux/param.h>
13 #include <linux/string.h>
14 #include <linux/vmalloc.h>
15 #include <linux/interrupt.h>
16 #include <linux/time.h>
17 #include <linux/delay.h>
18
19 #include <asm/irq.h>
20
21 #include <hwregs/reg_map.h>
22 #include <hwregs/reg_rdwr.h>
23 #include <hwregs/timer_defs.h>
24 #include <asm/fasttimer.h>
25 #include <linux/proc_fs.h>
26 #include <linux/seq_file.h>
27
28 /*
29  * timer0 is running at 100MHz and generating jiffies timer ticks
30  * at 100 or 1000 HZ.
31  * fasttimer gives an API that gives timers that expire "between" the jiffies
32  * giving microsecond resolution (10 ns).
33  * fasttimer uses reg_timer_rw_trig register to get interrupt when
34  * r_time reaches a certain value.
35  */
36
37
38 #define DEBUG_LOG_INCLUDED
39 #define FAST_TIMER_LOG
40 /* #define FAST_TIMER_TEST */
41
42 #define FAST_TIMER_SANITY_CHECKS
43
44 #ifdef FAST_TIMER_SANITY_CHECKS
45 static int sanity_failed;
46 #endif
47
48 #define D1(x)
49 #define D2(x)
50 #define DP(x)
51
52 static unsigned int fast_timer_running;
53 static unsigned int fast_timers_added;
54 static unsigned int fast_timers_started;
55 static unsigned int fast_timers_expired;
56 static unsigned int fast_timers_deleted;
57 static unsigned int fast_timer_is_init;
58 static unsigned int fast_timer_ints;
59
60 struct fast_timer *fast_timer_list = NULL;
61
62 #ifdef DEBUG_LOG_INCLUDED
63 #define DEBUG_LOG_MAX 128
64 static const char * debug_log_string[DEBUG_LOG_MAX];
65 static unsigned long debug_log_value[DEBUG_LOG_MAX];
66 static unsigned int debug_log_cnt;
67 static unsigned int debug_log_cnt_wrapped;
68
69 #define DEBUG_LOG(string, value) \
70 { \
71   unsigned long log_flags; \
72   local_irq_save(log_flags); \
73   debug_log_string[debug_log_cnt] = (string); \
74   debug_log_value[debug_log_cnt] = (unsigned long)(value); \
75   if (++debug_log_cnt >= DEBUG_LOG_MAX) \
76   { \
77     debug_log_cnt = debug_log_cnt % DEBUG_LOG_MAX; \
78     debug_log_cnt_wrapped = 1; \
79   } \
80   local_irq_restore(log_flags); \
81 }
82 #else
83 #define DEBUG_LOG(string, value)
84 #endif
85
86
87 #define NUM_TIMER_STATS 16
88 #ifdef FAST_TIMER_LOG
89 struct fast_timer timer_added_log[NUM_TIMER_STATS];
90 struct fast_timer timer_started_log[NUM_TIMER_STATS];
91 struct fast_timer timer_expired_log[NUM_TIMER_STATS];
92 #endif
93
94 int timer_div_settings[NUM_TIMER_STATS];
95 int timer_delay_settings[NUM_TIMER_STATS];
96
97 struct work_struct fast_work;
98
99 static void
100 timer_trig_handler(struct work_struct *work);
101
102
103
104 /* Not true gettimeofday, only checks the jiffies (uptime) + useconds */
105 inline void do_gettimeofday_fast(struct fasttime_t *tv)
106 {
107         tv->tv_jiff = jiffies;
108         tv->tv_usec = GET_JIFFIES_USEC();
109 }
110
111 inline int fasttime_cmp(struct fasttime_t *t0, struct fasttime_t *t1)
112 {
113         /* Compare jiffies. Takes care of wrapping */
114         if (time_before(t0->tv_jiff, t1->tv_jiff))
115                 return -1;
116         else if (time_after(t0->tv_jiff, t1->tv_jiff))
117                 return 1;
118
119         /* Compare us */
120         if (t0->tv_usec < t1->tv_usec)
121                 return -1;
122         else if (t0->tv_usec > t1->tv_usec)
123                 return 1;
124         return 0;
125 }
126
127 /* Called with ints off */
128 inline void start_timer_trig(unsigned long delay_us)
129 {
130   reg_timer_rw_ack_intr ack_intr = { 0 };
131   reg_timer_rw_intr_mask intr_mask;
132   reg_timer_rw_trig trig;
133   reg_timer_rw_trig_cfg trig_cfg = { 0 };
134         reg_timer_r_time r_time0;
135         reg_timer_r_time r_time1;
136         unsigned char trig_wrap;
137         unsigned char time_wrap;
138
139         r_time0 = REG_RD(timer, regi_timer0, r_time);
140
141   D1(printk("start_timer_trig : %d us freq: %i div: %i\n",
142             delay_us, freq_index, div));
143   /* Clear trig irq */
144         intr_mask = REG_RD(timer, regi_timer0, rw_intr_mask);
145   intr_mask.trig = 0;
146         REG_WR(timer, regi_timer0, rw_intr_mask, intr_mask);
147
148         /* Set timer values and check if trigger wraps. */
149         /* r_time is 100MHz (10 ns resolution) */
150         trig_wrap = (trig = r_time0 + delay_us*(1000/10)) < r_time0;
151
152   timer_div_settings[fast_timers_started % NUM_TIMER_STATS] = trig;
153   timer_delay_settings[fast_timers_started % NUM_TIMER_STATS] = delay_us;
154
155   /* Ack interrupt */
156   ack_intr.trig = 1;
157         REG_WR(timer, regi_timer0, rw_ack_intr, ack_intr);
158
159   /* Start timer */
160         REG_WR(timer, regi_timer0, rw_trig, trig);
161   trig_cfg.tmr = regk_timer_time;
162         REG_WR(timer, regi_timer0, rw_trig_cfg, trig_cfg);
163
164   /* Check if we have already passed the trig time */
165         r_time1 = REG_RD(timer, regi_timer0, r_time);
166         time_wrap = r_time1 < r_time0;
167
168         if ((trig_wrap && !time_wrap) || (r_time1 < trig)) {
169     /* No, Enable trig irq */
170                 intr_mask = REG_RD(timer, regi_timer0, rw_intr_mask);
171     intr_mask.trig = 1;
172                 REG_WR(timer, regi_timer0, rw_intr_mask, intr_mask);
173     fast_timers_started++;
174     fast_timer_running = 1;
175         } else {
176     /* We have passed the time, disable trig point, ack intr */
177     trig_cfg.tmr = regk_timer_off;
178                 REG_WR(timer, regi_timer0, rw_trig_cfg, trig_cfg);
179                 REG_WR(timer, regi_timer0, rw_ack_intr, ack_intr);
180                 /* call the int routine */
181                 INIT_WORK(&fast_work, timer_trig_handler);
182                 schedule_work(&fast_work);
183   }
184
185 }
186
187 /* In version 1.4 this function takes 27 - 50 us */
188 void start_one_shot_timer(struct fast_timer *t,
189                           fast_timer_function_type *function,
190                           unsigned long data,
191                           unsigned long delay_us,
192                           const char *name)
193 {
194   unsigned long flags;
195   struct fast_timer *tmp;
196
197   D1(printk("sft %s %d us\n", name, delay_us));
198
199   local_irq_save(flags);
200
201   do_gettimeofday_fast(&t->tv_set);
202   tmp = fast_timer_list;
203
204 #ifdef FAST_TIMER_SANITY_CHECKS
205         /* Check so this is not in the list already... */
206         while (tmp != NULL) {
207                 if (tmp == t) {
208                         printk(KERN_DEBUG
209                                 "timer name: %s data: 0x%08lX already "
210                                 "in list!\n", name, data);
211                         sanity_failed++;
212                         goto done;
213                 } else
214                         tmp = tmp->next;
215         }
216         tmp = fast_timer_list;
217 #endif
218
219   t->delay_us = delay_us;
220   t->function = function;
221   t->data = data;
222   t->name = name;
223
224   t->tv_expires.tv_usec = t->tv_set.tv_usec + delay_us % 1000000;
225         t->tv_expires.tv_jiff = t->tv_set.tv_jiff + delay_us / 1000000 / HZ;
226         if (t->tv_expires.tv_usec > 1000000) {
227     t->tv_expires.tv_usec -= 1000000;
228                 t->tv_expires.tv_jiff += HZ;
229   }
230 #ifdef FAST_TIMER_LOG
231   timer_added_log[fast_timers_added % NUM_TIMER_STATS] = *t;
232 #endif
233   fast_timers_added++;
234
235   /* Check if this should timeout before anything else */
236   if (tmp == NULL || fasttime_cmp(&t->tv_expires, &tmp->tv_expires) < 0) {
237     /* Put first in list and modify the timer value */
238     t->prev = NULL;
239     t->next = fast_timer_list;
240     if (fast_timer_list)
241       fast_timer_list->prev = t;
242     fast_timer_list = t;
243 #ifdef FAST_TIMER_LOG
244     timer_started_log[fast_timers_started % NUM_TIMER_STATS] = *t;
245 #endif
246     start_timer_trig(delay_us);
247   } else {
248     /* Put in correct place in list */
249     while (tmp->next &&
250         fasttime_cmp(&t->tv_expires, &tmp->next->tv_expires) > 0)
251       tmp = tmp->next;
252     /* Insert t after tmp */
253     t->prev = tmp;
254     t->next = tmp->next;
255     if (tmp->next)
256     {
257       tmp->next->prev = t;
258     }
259     tmp->next = t;
260   }
261
262   D2(printk("start_one_shot_timer: %d us done\n", delay_us));
263
264 done:
265   local_irq_restore(flags);
266 } /* start_one_shot_timer */
267
268 static inline int fast_timer_pending (const struct fast_timer * t)
269 {
270   return (t->next != NULL) || (t->prev != NULL) || (t == fast_timer_list);
271 }
272
273 static inline int detach_fast_timer (struct fast_timer *t)
274 {
275   struct fast_timer *next, *prev;
276   if (!fast_timer_pending(t))
277     return 0;
278   next = t->next;
279   prev = t->prev;
280   if (next)
281     next->prev = prev;
282   if (prev)
283     prev->next = next;
284   else
285     fast_timer_list = next;
286   fast_timers_deleted++;
287   return 1;
288 }
289
290 int del_fast_timer(struct fast_timer * t)
291 {
292   unsigned long flags;
293   int ret;
294
295   local_irq_save(flags);
296   ret = detach_fast_timer(t);
297   t->next = t->prev = NULL;
298   local_irq_restore(flags);
299   return ret;
300 } /* del_fast_timer */
301
302
303 /* Interrupt routines or functions called in interrupt context */
304
305 /* Timer interrupt handler for trig interrupts */
306
307 static irqreturn_t
308 timer_trig_interrupt(int irq, void *dev_id)
309 {
310   reg_timer_r_masked_intr masked_intr;
311   /* Check if the timer interrupt is for us (a trig int) */
312         masked_intr = REG_RD(timer, regi_timer0, r_masked_intr);
313   if (!masked_intr.trig)
314     return IRQ_NONE;
315         timer_trig_handler(NULL);
316   return IRQ_HANDLED;
317 }
318
319 static void timer_trig_handler(struct work_struct *work)
320 {
321         reg_timer_rw_ack_intr ack_intr = { 0 };
322         reg_timer_rw_intr_mask intr_mask;
323         reg_timer_rw_trig_cfg trig_cfg = { 0 };
324         struct fast_timer *t;
325         fast_timer_function_type *f;
326         unsigned long d;
327         unsigned long flags;
328
329         /* We keep interrupts disabled not only when we modify the
330          * fast timer list, but any time we hold a reference to a
331          * timer in the list, since del_fast_timer may be called
332          * from (another) interrupt context.  Thus, the only time
333          * when interrupts are enabled is when calling the timer
334          * callback function.
335          */
336   local_irq_save(flags);
337
338   /* Clear timer trig interrupt */
339         intr_mask = REG_RD(timer, regi_timer0, rw_intr_mask);
340   intr_mask.trig = 0;
341   REG_WR(timer, regi_timer0, rw_intr_mask, intr_mask);
342
343   /* First stop timer, then ack interrupt */
344   /* Stop timer */
345   trig_cfg.tmr = regk_timer_off;
346         REG_WR(timer, regi_timer0, rw_trig_cfg, trig_cfg);
347
348   /* Ack interrupt */
349   ack_intr.trig = 1;
350         REG_WR(timer, regi_timer0, rw_ack_intr, ack_intr);
351
352   fast_timer_running = 0;
353   fast_timer_ints++;
354
355   t = fast_timer_list;
356         while (t) {
357                 struct fasttime_t tv;
358
359     /* Has it really expired? */
360     do_gettimeofday_fast(&tv);
361                 D1(printk(KERN_DEBUG
362                         "t: %is %06ius\n", tv.tv_jiff, tv.tv_usec));
363
364                 if (fasttime_cmp(&t->tv_expires, &tv) <= 0) {
365       /* Yes it has expired */
366 #ifdef FAST_TIMER_LOG
367       timer_expired_log[fast_timers_expired % NUM_TIMER_STATS] = *t;
368 #endif
369       fast_timers_expired++;
370
371       /* Remove this timer before call, since it may reuse the timer */
372       if (t->prev)
373         t->prev->next = t->next;
374       else
375         fast_timer_list = t->next;
376       if (t->next)
377         t->next->prev = t->prev;
378       t->prev = NULL;
379       t->next = NULL;
380
381                         /* Save function callback data before enabling
382                          * interrupts, since the timer may be removed and we
383                          * don't know how it was allocated (e.g. ->function
384                          * and ->data may become overwritten after deletion
385                          * if the timer was stack-allocated).
386                          */
387                         f = t->function;
388                         d = t->data;
389
390                         if (f != NULL) {
391                                 /* Run the callback function with interrupts
392                                  * enabled. */
393                                 local_irq_restore(flags);
394                                 f(d);
395                                 local_irq_save(flags);
396                         } else
397         DEBUG_LOG("!trimertrig %i function==NULL!\n", fast_timer_ints);
398                 } else {
399       /* Timer is to early, let's set it again using the normal routines */
400       D1(printk(".\n"));
401     }
402
403                 t = fast_timer_list;
404                 if (t != NULL) {
405       /* Start next timer.. */
406                         long us = 0;
407                         struct fasttime_t tv;
408
409       do_gettimeofday_fast(&tv);
410
411                         /* time_after_eq takes care of wrapping */
412                         if (time_after_eq(t->tv_expires.tv_jiff, tv.tv_jiff))
413                                 us = ((t->tv_expires.tv_jiff - tv.tv_jiff) *
414                                         1000000 / HZ + t->tv_expires.tv_usec -
415                                         tv.tv_usec);
416
417                         if (us > 0) {
418                                 if (!fast_timer_running) {
419 #ifdef FAST_TIMER_LOG
420           timer_started_log[fast_timers_started % NUM_TIMER_STATS] = *t;
421 #endif
422           start_timer_trig(us);
423         }
424         break;
425                         } else {
426         /* Timer already expired, let's handle it better late than never.
427          * The normal loop handles it
428          */
429         D1(printk("e! %d\n", us));
430       }
431     }
432   }
433
434         local_irq_restore(flags);
435
436         if (!t)
437     D1(printk("ttrig stop!\n"));
438 }
439
440 static void wake_up_func(unsigned long data)
441 {
442   wait_queue_head_t  *sleep_wait_p = (wait_queue_head_t*)data;
443   wake_up(sleep_wait_p);
444 }
445
446
447 /* Useful API */
448
449 void schedule_usleep(unsigned long us)
450 {
451   struct fast_timer t;
452   wait_queue_head_t sleep_wait;
453   init_waitqueue_head(&sleep_wait);
454
455   D1(printk("schedule_usleep(%d)\n", us));
456   start_one_shot_timer(&t, wake_up_func, (unsigned long)&sleep_wait, us,
457                        "usleep");
458         /* Uninterruptible sleep on the fast timer. (The condition is
459          * somewhat redundant since the timer is what wakes us up.) */
460         wait_event(sleep_wait, !fast_timer_pending(&t));
461
462   D1(printk("done schedule_usleep(%d)\n", us));
463 }
464
465 #ifdef CONFIG_PROC_FS
466 /* This value is very much based on testing */
467 #define BIG_BUF_SIZE (500 + NUM_TIMER_STATS * 300)
468
469 static int proc_fasttimer_show(struct seq_file *m, void *v)
470 {
471         unsigned long flags;
472         int i = 0;
473         int num_to_show;
474         struct fasttime_t tv;
475         struct fast_timer *t, *nextt;
476
477         do_gettimeofday_fast(&tv);
478
479         seq_printf(m, "Fast timers added:     %i\n", fast_timers_added);
480         seq_printf(m, "Fast timers started:   %i\n", fast_timers_started);
481         seq_printf(m, "Fast timer interrupts: %i\n", fast_timer_ints);
482         seq_printf(m, "Fast timers expired:   %i\n", fast_timers_expired);
483         seq_printf(m, "Fast timers deleted:   %i\n", fast_timers_deleted);
484         seq_printf(m, "Fast timer running:    %s\n",
485                    fast_timer_running ? "yes" : "no");
486         seq_printf(m, "Current time:          %lu.%06lu\n",
487                    (unsigned long)tv.tv_jiff,
488                    (unsigned long)tv.tv_usec);
489 #ifdef FAST_TIMER_SANITY_CHECKS
490         seq_printf(m, "Sanity failed:         %i\n", sanity_failed);
491 #endif
492         seq_putc(m, '\n');
493
494 #ifdef DEBUG_LOG_INCLUDED
495         {
496                 int end_i = debug_log_cnt;
497                 i = 0;
498
499                 if (debug_log_cnt_wrapped)
500                         i = debug_log_cnt;
501
502                 while ((i != end_i || debug_log_cnt_wrapped)) {
503                         seq_printf(m, debug_log_string[i], debug_log_value[i]);
504                         if (seq_has_overflowed(m))
505                                 return 0;
506                         i = (i+1) % DEBUG_LOG_MAX;
507                 }
508         }
509         seq_putc(m, '\n');
510 #endif
511
512         num_to_show = (fast_timers_started < NUM_TIMER_STATS ? fast_timers_started:
513                        NUM_TIMER_STATS);
514         seq_printf(m, "Timers started: %i\n", fast_timers_started);
515         for (i = 0; i < num_to_show; i++) {
516                 int cur = (fast_timers_started - i - 1) % NUM_TIMER_STATS;
517
518 #if 1 //ndef FAST_TIMER_LOG
519                 seq_printf(m, "div: %i delay: %i\n",
520                            timer_div_settings[cur],
521                            timer_delay_settings[cur]);
522 #endif
523 #ifdef FAST_TIMER_LOG
524                 t = &timer_started_log[cur];
525                 seq_printf(m, "%-14s s: %6lu.%06lu e: %6lu.%06lu d: %6li us data: 0x%08lX\n",
526                            t->name,
527                            (unsigned long)t->tv_set.tv_jiff,
528                            (unsigned long)t->tv_set.tv_usec,
529                            (unsigned long)t->tv_expires.tv_jiff,
530                            (unsigned long)t->tv_expires.tv_usec,
531                            t->delay_us,
532                            t->data);
533                 if (seq_has_overflowed(m))
534                         return 0;
535 #endif
536         }
537         seq_putc(m, '\n');
538
539 #ifdef FAST_TIMER_LOG
540         num_to_show = (fast_timers_added < NUM_TIMER_STATS ? fast_timers_added:
541                        NUM_TIMER_STATS);
542         seq_printf(m, "Timers added: %i\n", fast_timers_added);
543         for (i = 0; i < num_to_show; i++) {
544                 t = &timer_added_log[(fast_timers_added - i - 1) % NUM_TIMER_STATS];
545                 seq_printf(m, "%-14s s: %6lu.%06lu e: %6lu.%06lu d: %6li us data: 0x%08lX\n",
546                            t->name,
547                            (unsigned long)t->tv_set.tv_jiff,
548                            (unsigned long)t->tv_set.tv_usec,
549                            (unsigned long)t->tv_expires.tv_jiff,
550                            (unsigned long)t->tv_expires.tv_usec,
551                            t->delay_us,
552                            t->data);
553                 if (seq_has_overflowed(m))
554                         return 0;
555         }
556         seq_putc(m, '\n');
557
558         num_to_show = (fast_timers_expired < NUM_TIMER_STATS ? fast_timers_expired:
559                        NUM_TIMER_STATS);
560         seq_printf(m, "Timers expired: %i\n", fast_timers_expired);
561         for (i = 0; i < num_to_show; i++){
562                 t = &timer_expired_log[(fast_timers_expired - i - 1) % NUM_TIMER_STATS];
563                 seq_printf(m, "%-14s s: %6lu.%06lu e: %6lu.%06lu d: %6li us data: 0x%08lX\n",
564                            t->name,
565                            (unsigned long)t->tv_set.tv_jiff,
566                            (unsigned long)t->tv_set.tv_usec,
567                            (unsigned long)t->tv_expires.tv_jiff,
568                            (unsigned long)t->tv_expires.tv_usec,
569                            t->delay_us,
570                            t->data);
571                 if (seq_has_overflowed(m))
572                         return 0;
573         }
574         seq_putc(m, '\n');
575 #endif
576
577         seq_puts(m, "Active timers:\n");
578         local_irq_save(flags);
579         t = fast_timer_list;
580         while (t != NULL){
581                 nextt = t->next;
582                 local_irq_restore(flags);
583                 seq_printf(m, "%-14s s: %6lu.%06lu e: %6lu.%06lu d: %6li us data: 0x%08lX\n",
584                            t->name,
585                            (unsigned long)t->tv_set.tv_jiff,
586                            (unsigned long)t->tv_set.tv_usec,
587                            (unsigned long)t->tv_expires.tv_jiff,
588                            (unsigned long)t->tv_expires.tv_usec,
589                            t->delay_us,
590                            t->data);
591                 if (seq_has_overflowed(m))
592                         return 0;
593                 local_irq_save(flags);
594                 if (t->next != nextt)
595                         printk("timer removed!\n");
596                 t = nextt;
597         }
598         local_irq_restore(flags);
599         return 0;
600 }
601
602 static int proc_fasttimer_open(struct inode *inode, struct file *file)
603 {
604         return single_open_size(file, proc_fasttimer_show, PDE_DATA(inode), BIG_BUF_SIZE);
605 }
606
607 static const struct file_operations proc_fasttimer_fops = {
608         .open           = proc_fasttimer_open,
609         .read           = seq_read,
610         .llseek         = seq_lseek,
611         .release        = single_release,
612 };
613
614 #endif /* PROC_FS */
615
616 #ifdef FAST_TIMER_TEST
617 static volatile unsigned long i = 0;
618 static volatile int num_test_timeout = 0;
619 static struct fast_timer tr[10];
620 static int exp_num[10];
621
622 static struct fasttime_t tv_exp[100];
623
624 static void test_timeout(unsigned long data)
625 {
626   do_gettimeofday_fast(&tv_exp[data]);
627   exp_num[data] = num_test_timeout;
628
629   num_test_timeout++;
630 }
631
632 static void test_timeout1(unsigned long data)
633 {
634   do_gettimeofday_fast(&tv_exp[data]);
635   exp_num[data] = num_test_timeout;
636   if (data < 7)
637   {
638     start_one_shot_timer(&tr[i], test_timeout1, i, 1000, "timeout1");
639     i++;
640   }
641   num_test_timeout++;
642 }
643
644 DP(
645 static char buf0[2000];
646 static char buf1[2000];
647 static char buf2[2000];
648 static char buf3[2000];
649 static char buf4[2000];
650 );
651
652 static char buf5[6000];
653 static int j_u[1000];
654
655 static void fast_timer_test(void)
656 {
657   int prev_num;
658   int j;
659
660         struct fasttime_t tv, tv0, tv1, tv2;
661
662   printk("fast_timer_test() start\n");
663   do_gettimeofday_fast(&tv);
664
665   for (j = 0; j < 1000; j++)
666   {
667     j_u[j] = GET_JIFFIES_USEC();
668   }
669   for (j = 0; j < 100; j++)
670   {
671     do_gettimeofday_fast(&tv_exp[j]);
672   }
673   printk(KERN_DEBUG "fast_timer_test() %is %06i\n", tv.tv_jiff, tv.tv_usec);
674
675   for (j = 0; j < 1000; j++)
676   {
677     printk(KERN_DEBUG "%i %i %i %i %i\n",
678       j_u[j], j_u[j+1], j_u[j+2], j_u[j+3], j_u[j+4]);
679     j += 4;
680   }
681   for (j = 0; j < 100; j++)
682   {
683     printk(KERN_DEBUG "%i.%i %i.%i %i.%i %i.%i %i.%i\n",
684                         tv_exp[j].tv_jiff, tv_exp[j].tv_usec,
685                         tv_exp[j+1].tv_jiff, tv_exp[j+1].tv_usec,
686                         tv_exp[j+2].tv_jiff, tv_exp[j+2].tv_usec,
687                         tv_exp[j+3].tv_jiff, tv_exp[j+3].tv_usec,
688                         tv_exp[j+4].tv_jiff, tv_exp[j+4].tv_usec);
689     j += 4;
690   }
691   do_gettimeofday_fast(&tv0);
692   start_one_shot_timer(&tr[i], test_timeout, i, 50000, "test0");
693   DP(proc_fasttimer_read(buf0, NULL, 0, 0, 0));
694   i++;
695   start_one_shot_timer(&tr[i], test_timeout, i, 70000, "test1");
696   DP(proc_fasttimer_read(buf1, NULL, 0, 0, 0));
697   i++;
698   start_one_shot_timer(&tr[i], test_timeout, i, 40000, "test2");
699   DP(proc_fasttimer_read(buf2, NULL, 0, 0, 0));
700   i++;
701   start_one_shot_timer(&tr[i], test_timeout, i, 60000, "test3");
702   DP(proc_fasttimer_read(buf3, NULL, 0, 0, 0));
703   i++;
704   start_one_shot_timer(&tr[i], test_timeout1, i, 55000, "test4xx");
705   DP(proc_fasttimer_read(buf4, NULL, 0, 0, 0));
706   i++;
707   do_gettimeofday_fast(&tv1);
708
709   proc_fasttimer_read(buf5, NULL, 0, 0, 0);
710
711   prev_num = num_test_timeout;
712   while (num_test_timeout < i)
713   {
714     if (num_test_timeout != prev_num)
715       prev_num = num_test_timeout;
716   }
717   do_gettimeofday_fast(&tv2);
718         printk(KERN_INFO "Timers started    %is %06i\n",
719                 tv0.tv_jiff, tv0.tv_usec);
720         printk(KERN_INFO "Timers started at %is %06i\n",
721                 tv1.tv_jiff, tv1.tv_usec);
722         printk(KERN_INFO "Timers done       %is %06i\n",
723                 tv2.tv_jiff, tv2.tv_usec);
724   DP(printk("buf0:\n");
725      printk(buf0);
726      printk("buf1:\n");
727      printk(buf1);
728      printk("buf2:\n");
729      printk(buf2);
730      printk("buf3:\n");
731      printk(buf3);
732      printk("buf4:\n");
733      printk(buf4);
734   );
735   printk("buf5:\n");
736   printk(buf5);
737
738   printk("timers set:\n");
739   for(j = 0; j<i; j++)
740   {
741     struct fast_timer *t = &tr[j];
742     printk("%-10s set: %6is %06ius exp: %6is %06ius "
743            "data: 0x%08X func: 0x%08X\n",
744            t->name,
745                         t->tv_set.tv_jiff,
746            t->tv_set.tv_usec,
747                         t->tv_expires.tv_jiff,
748            t->tv_expires.tv_usec,
749            t->data,
750            t->function
751            );
752
753     printk("           del: %6ius     did exp: %6is %06ius as #%i error: %6li\n",
754            t->delay_us,
755                         tv_exp[j].tv_jiff,
756            tv_exp[j].tv_usec,
757            exp_num[j],
758                         (tv_exp[j].tv_jiff - t->tv_expires.tv_jiff) *
759                                 1000000 + tv_exp[j].tv_usec -
760                                 t->tv_expires.tv_usec);
761   }
762   proc_fasttimer_read(buf5, NULL, 0, 0, 0);
763   printk("buf5 after all done:\n");
764   printk(buf5);
765   printk("fast_timer_test() done\n");
766 }
767 #endif
768
769
770 int fast_timer_init(void)
771 {
772   /* For some reason, request_irq() hangs when called froom time_init() */
773   if (!fast_timer_is_init)
774   {
775     printk("fast_timer_init()\n");
776
777 #ifdef CONFIG_PROC_FS
778     proc_create("fasttimer", 0, NULL, &proc_fasttimer_fops);
779 #endif /* PROC_FS */
780                 if (request_irq(TIMER0_INTR_VECT, timer_trig_interrupt,
781                                 IRQF_SHARED,
782                                 "fast timer int", &fast_timer_list))
783                         printk(KERN_ERR "err: fasttimer irq\n");
784     fast_timer_is_init = 1;
785 #ifdef FAST_TIMER_TEST
786     printk("do test\n");
787     fast_timer_test();
788 #endif
789   }
790         return 0;
791 }
792 __initcall(fast_timer_init);