1 /* $Id: fasttimer.c,v 1.7 2003/04/01 14:12:07 starvik Exp $
2 * linux/arch/cris/kernel/fasttimer.c
4 * Fast timers for ETRAX100/ETRAX100LX
5 * This may be useful in other OS than Linux so use 2 space indentation...
7 * $Log: fasttimer.c,v $
8 * Revision 1.7 2003/04/01 14:12:07 starvik
9 * Added loglevel for lots of printks
11 * Revision 1.6 2003/02/10 17:05:44 pkj
12 * Made fast_timer_pending() public.
14 * Revision 1.5 2002/10/15 06:21:39 starvik
15 * Added call to init_waitqueue_head
17 * Revision 1.4 2002/05/28 17:47:59 johana
18 * Added del_fast_timer()
20 * Revision 1.3 2002/05/28 16:16:07 johana
21 * Handle empty fast_timer_list
23 * Revision 1.2 2002/05/27 15:38:42 johana
24 * Made it compile without warnings on Linux 2.4.
25 * (includes, wait_queue, PROC_FS and snprintf)
27 * Revision 1.1 2002/05/27 15:32:25 johana
28 * arch/etrax100/kernel/fasttimer.c v1.8 from the elinux tree.
30 * Revision 1.8 2001/11/27 13:50:40 pkj
31 * Disable interrupts while stopping the timer and while modifying the
32 * list of active timers in timer1_handler() as it may be interrupted
33 * by other interrupts (e.g., the serial interrupt) which may add fast
36 * Revision 1.7 2001/11/22 11:50:32 pkj
37 * * Only store information about the last 16 timers.
38 * * proc_fasttimer_read() now uses an allocated buffer, since it
39 * requires more space than just a page even for only writing the
40 * last 16 timers. The buffer is only allocated on request, so
41 * unless /proc/fasttimer is read, it is never allocated.
42 * * Renamed fast_timer_started to fast_timers_started to match
43 * fast_timers_added and fast_timers_expired.
46 * Revision 1.6 2000/12/13 14:02:08 johana
47 * Removed volatile for fast_timer_list
49 * Revision 1.5 2000/12/13 13:55:35 johana
50 * Added DEBUG_LOG, added som cli() and cleanup
52 * Revision 1.4 2000/12/05 13:48:50 johana
53 * Added range check when writing proc file, modified timer int handling
55 * Revision 1.3 2000/11/23 10:10:20 johana
56 * More debug/logging possibilities.
57 * Moved GET_JIFFIES_USEC() to timex.h and time.c
59 * Revision 1.2 2000/11/01 13:41:04 johana
60 * Clean up and bugfixes.
61 * Created new do_gettimeofday_fast() that gets a timeval struct
62 * with time based on jiffies and *R_TIMER0_DATA, uses a table
63 * for fast conversion of timer value to microseconds.
64 * (Much faster the standard do_gettimeofday() and we don't really
65 * wan't to use the true time - we wan't the "uptime" so timers don't screw up
66 * when we change the time.
67 * TODO: Add efficient support for continuous timers as well.
69 * Revision 1.1 2000/10/26 15:49:16 johana
70 * Added fasttimer, highresolution timers.
72 * Copyright (C) 2000,2001,2002,2003 Axis Communications AB, Lund, Sweden
75 #include <linux/errno.h>
76 #include <linux/sched.h>
77 #include <linux/kernel.h>
78 #include <linux/param.h>
79 #include <linux/string.h>
81 #include <linux/vmalloc.h>
82 #include <linux/interrupt.h>
83 #include <linux/time.h>
84 #include <linux/delay.h>
86 #include <asm/segment.h>
89 #include <asm/delay.h>
92 #include <linux/config.h>
93 #include <linux/version.h>
95 #include <asm/svinto.h>
96 #include <asm/fasttimer.h>
97 #include <linux/proc_fs.h>
100 #define DEBUG_LOG_INCLUDED
101 #define FAST_TIMER_LOG
102 //#define FAST_TIMER_TEST
104 #define FAST_TIMER_SANITY_CHECKS
106 #ifdef FAST_TIMER_SANITY_CHECKS
107 #define SANITYCHECK(x) x
108 static int sanity_failed = 0;
110 #define SANITYCHECK(x)
117 #define __INLINE__ inline
119 static int fast_timer_running = 0;
120 static int fast_timers_added = 0;
121 static int fast_timers_started = 0;
122 static int fast_timers_expired = 0;
123 static int fast_timers_deleted = 0;
124 static int fast_timer_is_init = 0;
125 static int fast_timer_ints = 0;
127 struct fast_timer *fast_timer_list = NULL;
129 #ifdef DEBUG_LOG_INCLUDED
130 #define DEBUG_LOG_MAX 128
131 static const char * debug_log_string[DEBUG_LOG_MAX];
132 static unsigned long debug_log_value[DEBUG_LOG_MAX];
133 static int debug_log_cnt = 0;
134 static int debug_log_cnt_wrapped = 0;
136 #define DEBUG_LOG(string, value) \
138 unsigned long log_flags; \
139 save_flags(log_flags); \
141 debug_log_string[debug_log_cnt] = (string); \
142 debug_log_value[debug_log_cnt] = (unsigned long)(value); \
143 if (++debug_log_cnt >= DEBUG_LOG_MAX) \
145 debug_log_cnt = debug_log_cnt % DEBUG_LOG_MAX; \
146 debug_log_cnt_wrapped = 1; \
148 restore_flags(log_flags); \
151 #define DEBUG_LOG(string, value)
155 /* The frequencies for index = clkselx number in R_TIMER_CTRL */
156 #define NUM_TIMER_FREQ 15
157 #define MAX_USABLE_TIMER_FREQ 7
158 #define MAX_DELAY_US 853333L
159 const unsigned long timer_freq_100[NUM_TIMER_FREQ] =
161 3, /* 0 3333 - 853333 us */
162 6, /* 1 1666 - 426666 us */
163 12, /* 2 833 - 213333 us */
164 24, /* 3 416 - 106666 us */
165 48, /* 4 208 - 53333 us */
166 96, /* 5 104 - 26666 us */
167 192, /* 6 52 - 13333 us */
168 384, /* 7 26 - 6666 us */
178 #define NUM_TIMER_STATS 16
179 #ifdef FAST_TIMER_LOG
180 struct fast_timer timer_added_log[NUM_TIMER_STATS];
181 struct fast_timer timer_started_log[NUM_TIMER_STATS];
182 struct fast_timer timer_expired_log[NUM_TIMER_STATS];
185 int timer_div_settings[NUM_TIMER_STATS];
186 int timer_freq_settings[NUM_TIMER_STATS];
187 int timer_delay_settings[NUM_TIMER_STATS];
189 /* Not true gettimeofday, only checks the jiffies (uptime) + useconds */
190 void __INLINE__ do_gettimeofday_fast(struct timeval *tv)
192 unsigned long sec = jiffies;
193 unsigned long usec = GET_JIFFIES_USEC();
195 usec += (sec % HZ) * (1000000 / HZ);
207 int __INLINE__ timeval_cmp(struct timeval *t0, struct timeval *t1)
209 if (t0->tv_sec < t1->tv_sec)
213 else if (t0->tv_sec > t1->tv_sec)
217 if (t0->tv_usec < t1->tv_usec)
221 else if (t0->tv_usec > t1->tv_usec)
228 void __INLINE__ start_timer1(unsigned long delay_us)
230 int freq_index = 0; /* This is the lowest resolution */
231 unsigned long upper_limit = MAX_DELAY_US;
234 /* Start/Restart the timer to the new shorter value */
235 /* t = 1/freq = 1/19200 = 53us
236 * T=div*t, div = T/t = delay_us*freq/1000000
238 #if 1 /* Adaptive timer settings */
239 while (delay_us < upper_limit && freq_index < MAX_USABLE_TIMER_FREQ)
242 upper_limit >>= 1; /* Divide by 2 using shift */
251 div = delay_us * timer_freq_100[freq_index]/10000;
254 /* Maybe increase timer freq? */
259 div = 0; /* This means 256, the max the timer takes */
260 /* If a longer timeout than the timer can handle is used,
261 * then we must restart it when it goes off.
265 timer_div_settings[fast_timers_started % NUM_TIMER_STATS] = div;
266 timer_freq_settings[fast_timers_started % NUM_TIMER_STATS] = freq_index;
267 timer_delay_settings[fast_timers_started % NUM_TIMER_STATS] = delay_us;
269 D1(printk("start_timer1 : %d us freq: %i div: %i\n",
270 delay_us, freq_index, div));
271 /* Clear timer1 irq */
272 *R_IRQ_MASK0_CLR = IO_STATE(R_IRQ_MASK0_CLR, timer1, clr);
274 /* Set timer values */
275 *R_TIMER_CTRL = r_timer_ctrl_shadow =
276 (r_timer_ctrl_shadow &
277 ~IO_MASK(R_TIMER_CTRL, timerdiv1) &
278 ~IO_MASK(R_TIMER_CTRL, tm1) &
279 ~IO_MASK(R_TIMER_CTRL, clksel1)) |
280 IO_FIELD(R_TIMER_CTRL, timerdiv1, div) |
281 IO_STATE(R_TIMER_CTRL, tm1, stop_ld) |
282 IO_FIELD(R_TIMER_CTRL, clksel1, freq_index ); /* 6=c19k2Hz */
285 *R_TIMER_CTRL = r_timer_ctrl_shadow |
286 IO_STATE(R_TIMER_CTRL, i1, clr);
289 *R_TIMER_CTRL = r_timer_ctrl_shadow =
290 (r_timer_ctrl_shadow & ~IO_MASK(R_TIMER_CTRL, tm1)) |
291 IO_STATE(R_TIMER_CTRL, tm1, run);
293 /* Enable timer1 irq */
294 *R_IRQ_MASK0_SET = IO_STATE(R_IRQ_MASK0_SET, timer1, set);
295 fast_timers_started++;
296 fast_timer_running = 1;
299 /* In version 1.4 this function takes 27 - 50 us */
300 void start_one_shot_timer(struct fast_timer *t,
301 fast_timer_function_type *function,
303 unsigned long delay_us,
307 struct fast_timer *tmp;
309 D1(printk("sft %s %d us\n", name, delay_us));
314 do_gettimeofday_fast(&t->tv_set);
315 tmp = fast_timer_list;
317 SANITYCHECK({ /* Check so this is not in the list already... */
323 "timer name: %s data: 0x%08lX already in list!\n", name, data);
332 tmp = fast_timer_list;
335 t->delay_us = delay_us;
336 t->function = function;
340 t->tv_expires.tv_usec = t->tv_set.tv_usec + delay_us % 1000000;
341 t->tv_expires.tv_sec = t->tv_set.tv_sec + delay_us / 1000000;
342 if (t->tv_expires.tv_usec > 1000000)
344 t->tv_expires.tv_usec -= 1000000;
345 t->tv_expires.tv_sec++;
347 #ifdef FAST_TIMER_LOG
348 timer_added_log[fast_timers_added % NUM_TIMER_STATS] = *t;
352 /* Check if this should timeout before anything else */
353 if (tmp == NULL || timeval_cmp(&t->tv_expires, &tmp->tv_expires) < 0)
355 /* Put first in list and modify the timer value */
357 t->next = fast_timer_list;
360 fast_timer_list->prev = t;
363 #ifdef FAST_TIMER_LOG
364 timer_started_log[fast_timers_started % NUM_TIMER_STATS] = *t;
366 start_timer1(delay_us);
368 /* Put in correct place in list */
370 timeval_cmp(&t->tv_expires, &tmp->next->tv_expires) > 0)
374 /* Insert t after tmp */
384 D2(printk("start_one_shot_timer: %d us done\n", delay_us));
386 restore_flags(flags);
387 } /* start_one_shot_timer */
389 static inline int detach_fast_timer (struct fast_timer *t)
391 struct fast_timer *next, *prev;
392 if (!fast_timer_pending(t))
401 fast_timer_list = next;
402 fast_timers_deleted++;
406 int del_fast_timer(struct fast_timer * t)
413 ret = detach_fast_timer(t);
414 t->next = t->prev = NULL;
415 restore_flags(flags);
417 } /* del_fast_timer */
420 /* Interrupt routines or functions called in interrupt context */
422 /* Timer 1 interrupt handler */
425 timer1_handler(int irq, void *dev_id, struct pt_regs *regs)
427 struct fast_timer *t;
433 /* Clear timer1 irq */
434 *R_IRQ_MASK0_CLR = IO_STATE(R_IRQ_MASK0_CLR, timer1, clr);
436 /* First stop timer, then ack interrupt */
438 *R_TIMER_CTRL = r_timer_ctrl_shadow =
439 (r_timer_ctrl_shadow & ~IO_MASK(R_TIMER_CTRL, tm1)) |
440 IO_STATE(R_TIMER_CTRL, tm1, stop_ld);
443 *R_TIMER_CTRL = r_timer_ctrl_shadow | IO_STATE(R_TIMER_CTRL, i1, clr);
445 fast_timer_running = 0;
448 restore_flags(flags);
455 /* Has it really expired? */
456 do_gettimeofday_fast(&tv);
457 D1(printk("t: %is %06ius\n", tv.tv_sec, tv.tv_usec));
459 if (timeval_cmp(&t->tv_expires, &tv) <= 0)
461 /* Yes it has expired */
462 #ifdef FAST_TIMER_LOG
463 timer_expired_log[fast_timers_expired % NUM_TIMER_STATS] = *t;
465 fast_timers_expired++;
467 /* Remove this timer before call, since it may reuse the timer */
472 t->prev->next = t->next;
476 fast_timer_list = t->next;
480 t->next->prev = t->prev;
484 restore_flags(flags);
486 if (t->function != NULL)
488 t->function(t->data);
492 DEBUG_LOG("!timer1 %i function==NULL!\n", fast_timer_ints);
497 /* Timer is to early, let's set it again using the normal routines */
503 if ((t = fast_timer_list) != NULL)
505 /* Start next timer.. */
509 do_gettimeofday_fast(&tv);
510 us = ((t->tv_expires.tv_sec - tv.tv_sec) * 1000000 +
511 t->tv_expires.tv_usec - tv.tv_usec);
514 if (!fast_timer_running)
516 #ifdef FAST_TIMER_LOG
517 timer_started_log[fast_timers_started % NUM_TIMER_STATS] = *t;
521 restore_flags(flags);
526 /* Timer already expired, let's handle it better late than never.
527 * The normal loop handles it
529 D1(printk("e! %d\n", us));
532 restore_flags(flags);
537 D1(printk("t1 stop!\n"));
541 static void wake_up_func(unsigned long data)
543 #ifdef DECLARE_WAITQUEUE
544 wait_queue_head_t *sleep_wait_p = (wait_queue_head_t*)data;
546 struct wait_queue **sleep_wait_p = (struct wait_queue **)data;
548 wake_up(sleep_wait_p);
554 void schedule_usleep(unsigned long us)
557 #ifdef DECLARE_WAITQUEUE
558 wait_queue_head_t sleep_wait;
559 init_waitqueue_head(&sleep_wait);
561 DECLARE_WAITQUEUE(wait, current);
563 struct wait_queue *sleep_wait = NULL;
564 struct wait_queue wait = { current, NULL };
567 D1(printk("schedule_usleep(%d)\n", us));
568 add_wait_queue(&sleep_wait, &wait);
569 set_current_state(TASK_INTERRUPTIBLE);
570 start_one_shot_timer(&t, wake_up_func, (unsigned long)&sleep_wait, us,
573 set_current_state(TASK_RUNNING);
574 remove_wait_queue(&sleep_wait, &wait);
575 D1(printk("done schedule_usleep(%d)\n", us));
576 #ifdef DECLARE_WAITQUEUE
581 #ifdef CONFIG_PROC_FS
582 static int proc_fasttimer_read(char *buf, char **start, off_t offset, int len
583 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
584 ,int *eof, void *data_unused
589 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
590 static struct proc_dir_entry *fasttimer_proc_entry;
592 static struct proc_dir_entry fasttimer_proc_entry =
595 S_IFREG | S_IRUGO, 1, 0, 0,
596 0, NULL /* ops -- default to array */,
597 &proc_fasttimer_read /* get_info */,
600 #endif /* CONFIG_PROC_FS */
602 #ifdef CONFIG_PROC_FS
604 /* This value is very much based on testing */
605 #define BIG_BUF_SIZE (500 + NUM_TIMER_STATS * 300)
607 static int proc_fasttimer_read(char *buf, char **start, off_t offset, int len
608 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
609 ,int *eof, void *data_unused
619 struct fast_timer *t, *nextt;
620 static char *bigbuf = NULL;
621 static unsigned long used;
623 if (!bigbuf && !(bigbuf = vmalloc(BIG_BUF_SIZE)))
630 if (!offset || !used)
632 do_gettimeofday_fast(&tv);
635 used += sprintf(bigbuf + used, "Fast timers added: %i\n",
637 used += sprintf(bigbuf + used, "Fast timers started: %i\n",
638 fast_timers_started);
639 used += sprintf(bigbuf + used, "Fast timer interrupts: %i\n",
641 used += sprintf(bigbuf + used, "Fast timers expired: %i\n",
642 fast_timers_expired);
643 used += sprintf(bigbuf + used, "Fast timers deleted: %i\n",
644 fast_timers_deleted);
645 used += sprintf(bigbuf + used, "Fast timer running: %s\n",
646 fast_timer_running ? "yes" : "no");
647 used += sprintf(bigbuf + used, "Current time: %lu.%06lu\n",
648 (unsigned long)tv.tv_sec,
649 (unsigned long)tv.tv_usec);
650 #ifdef FAST_TIMER_SANITY_CHECKS
651 used += sprintf(bigbuf + used, "Sanity failed: %i\n",
654 used += sprintf(bigbuf + used, "\n");
656 #ifdef DEBUG_LOG_INCLUDED
658 int end_i = debug_log_cnt;
661 if (debug_log_cnt_wrapped)
666 while ((i != end_i || (debug_log_cnt_wrapped && !used)) &&
667 used+100 < BIG_BUF_SIZE)
669 used += sprintf(bigbuf + used, debug_log_string[i],
671 i = (i+1) % DEBUG_LOG_MAX;
674 used += sprintf(bigbuf + used, "\n");
677 num_to_show = (fast_timers_started < NUM_TIMER_STATS ? fast_timers_started:
679 used += sprintf(bigbuf + used, "Timers started: %i\n", fast_timers_started);
680 for (i = 0; i < num_to_show && (used+100 < BIG_BUF_SIZE) ; i++)
682 int cur = (fast_timers_started - i - 1) % NUM_TIMER_STATS;
684 #if 1 //ndef FAST_TIMER_LOG
685 used += sprintf(bigbuf + used, "div: %i freq: %i delay: %i"
687 timer_div_settings[cur],
688 timer_freq_settings[cur],
689 timer_delay_settings[cur]
692 #ifdef FAST_TIMER_LOG
693 t = &timer_started_log[cur];
694 used += sprintf(bigbuf + used, "%-14s s: %6lu.%06lu e: %6lu.%06lu "
695 "d: %6li us data: 0x%08lX"
698 (unsigned long)t->tv_set.tv_sec,
699 (unsigned long)t->tv_set.tv_usec,
700 (unsigned long)t->tv_expires.tv_sec,
701 (unsigned long)t->tv_expires.tv_usec,
707 used += sprintf(bigbuf + used, "\n");
709 #ifdef FAST_TIMER_LOG
710 num_to_show = (fast_timers_added < NUM_TIMER_STATS ? fast_timers_added:
712 used += sprintf(bigbuf + used, "Timers added: %i\n", fast_timers_added);
713 for (i = 0; i < num_to_show && (used+100 < BIG_BUF_SIZE); i++)
715 t = &timer_added_log[(fast_timers_added - i - 1) % NUM_TIMER_STATS];
716 used += sprintf(bigbuf + used, "%-14s s: %6lu.%06lu e: %6lu.%06lu "
717 "d: %6li us data: 0x%08lX"
720 (unsigned long)t->tv_set.tv_sec,
721 (unsigned long)t->tv_set.tv_usec,
722 (unsigned long)t->tv_expires.tv_sec,
723 (unsigned long)t->tv_expires.tv_usec,
728 used += sprintf(bigbuf + used, "\n");
730 num_to_show = (fast_timers_expired < NUM_TIMER_STATS ? fast_timers_expired:
732 used += sprintf(bigbuf + used, "Timers expired: %i\n", fast_timers_expired);
733 for (i = 0; i < num_to_show && (used+100 < BIG_BUF_SIZE); i++)
735 t = &timer_expired_log[(fast_timers_expired - i - 1) % NUM_TIMER_STATS];
736 used += sprintf(bigbuf + used, "%-14s s: %6lu.%06lu e: %6lu.%06lu "
737 "d: %6li us data: 0x%08lX"
740 (unsigned long)t->tv_set.tv_sec,
741 (unsigned long)t->tv_set.tv_usec,
742 (unsigned long)t->tv_expires.tv_sec,
743 (unsigned long)t->tv_expires.tv_usec,
748 used += sprintf(bigbuf + used, "\n");
751 used += sprintf(bigbuf + used, "Active timers:\n");
755 while (t != NULL && (used+100 < BIG_BUF_SIZE))
758 restore_flags(flags);
759 used += sprintf(bigbuf + used, "%-14s s: %6lu.%06lu e: %6lu.%06lu "
760 "d: %6li us data: 0x%08lX"
761 /* " func: 0x%08lX" */
764 (unsigned long)t->tv_set.tv_sec,
765 (unsigned long)t->tv_set.tv_usec,
766 (unsigned long)t->tv_expires.tv_sec,
767 (unsigned long)t->tv_expires.tv_usec,
773 if (t->next != nextt)
775 printk(KERN_WARNING "timer removed!\n");
779 restore_flags(flags);
782 if (used - offset < len)
787 memcpy(buf, bigbuf + offset, len);
789 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
797 #ifdef FAST_TIMER_TEST
798 static volatile unsigned long i = 0;
799 static volatile int num_test_timeout = 0;
800 static struct fast_timer tr[10];
801 static int exp_num[10];
803 static struct timeval tv_exp[100];
805 static void test_timeout(unsigned long data)
807 do_gettimeofday_fast(&tv_exp[data]);
808 exp_num[data] = num_test_timeout;
813 static void test_timeout1(unsigned long data)
815 do_gettimeofday_fast(&tv_exp[data]);
816 exp_num[data] = num_test_timeout;
819 start_one_shot_timer(&tr[i], test_timeout1, i, 1000, "timeout1");
826 static char buf0[2000];
827 static char buf1[2000];
828 static char buf2[2000];
829 static char buf3[2000];
830 static char buf4[2000];
833 static char buf5[6000];
834 static int j_u[1000];
836 static void fast_timer_test(void)
841 struct timeval tv, tv0, tv1, tv2;
843 printk("fast_timer_test() start\n");
844 do_gettimeofday_fast(&tv);
846 for (j = 0; j < 1000; j++)
848 j_u[j] = GET_JIFFIES_USEC();
850 for (j = 0; j < 100; j++)
852 do_gettimeofday_fast(&tv_exp[j]);
854 printk("fast_timer_test() %is %06i\n", tv.tv_sec, tv.tv_usec);
856 for (j = 0; j < 1000; j++)
858 printk("%i %i %i %i %i\n",j_u[j], j_u[j+1], j_u[j+2], j_u[j+3], j_u[j+4]);
861 for (j = 0; j < 100; j++)
863 printk("%i.%i %i.%i %i.%i %i.%i %i.%i\n",
864 tv_exp[j].tv_sec,tv_exp[j].tv_usec,
865 tv_exp[j+1].tv_sec,tv_exp[j+1].tv_usec,
866 tv_exp[j+2].tv_sec,tv_exp[j+2].tv_usec,
867 tv_exp[j+3].tv_sec,tv_exp[j+3].tv_usec,
868 tv_exp[j+4].tv_sec,tv_exp[j+4].tv_usec);
871 do_gettimeofday_fast(&tv0);
872 start_one_shot_timer(&tr[i], test_timeout, i, 50000, "test0");
873 DP(proc_fasttimer_read(buf0, NULL, 0, 0, 0));
875 start_one_shot_timer(&tr[i], test_timeout, i, 70000, "test1");
876 DP(proc_fasttimer_read(buf1, NULL, 0, 0, 0));
878 start_one_shot_timer(&tr[i], test_timeout, i, 40000, "test2");
879 DP(proc_fasttimer_read(buf2, NULL, 0, 0, 0));
881 start_one_shot_timer(&tr[i], test_timeout, i, 60000, "test3");
882 DP(proc_fasttimer_read(buf3, NULL, 0, 0, 0));
884 start_one_shot_timer(&tr[i], test_timeout1, i, 55000, "test4xx");
885 DP(proc_fasttimer_read(buf4, NULL, 0, 0, 0));
887 do_gettimeofday_fast(&tv1);
889 proc_fasttimer_read(buf5, NULL, 0, 0, 0);
891 prev_num = num_test_timeout;
892 while (num_test_timeout < i)
894 if (num_test_timeout != prev_num)
896 prev_num = num_test_timeout;
899 do_gettimeofday_fast(&tv2);
900 printk("Timers started %is %06i\n", tv0.tv_sec, tv0.tv_usec);
901 printk("Timers started at %is %06i\n", tv1.tv_sec, tv1.tv_usec);
902 printk("Timers done %is %06i\n", tv2.tv_sec, tv2.tv_usec);
903 DP(printk("buf0:\n");
917 printk("timers set:\n");
920 struct fast_timer *t = &tr[j];
921 printk("%-10s set: %6is %06ius exp: %6is %06ius "
922 "data: 0x%08X func: 0x%08X\n",
926 t->tv_expires.tv_sec,
927 t->tv_expires.tv_usec,
932 printk(" del: %6ius did exp: %6is %06ius as #%i error: %6li\n",
937 (tv_exp[j].tv_sec - t->tv_expires.tv_sec)*1000000 + tv_exp[j].tv_usec - t->tv_expires.tv_usec);
939 proc_fasttimer_read(buf5, NULL, 0, 0, 0);
940 printk("buf5 after all done:\n");
942 printk("fast_timer_test() done\n");
947 void fast_timer_init(void)
949 /* For some reason, request_irq() hangs when called froom time_init() */
950 if (!fast_timer_is_init)
952 #if 0 && defined(FAST_TIMER_TEST)
956 printk(KERN_INFO "fast_timer_init()\n");
958 #if 0 && defined(FAST_TIMER_TEST)
959 for (i = 0; i <= TIMER0_DIV; i++)
961 /* We must be careful not to get overflow... */
962 printk("%3i %6u\n", i, timer0_value_us[i]);
965 #ifdef CONFIG_PROC_FS
966 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
967 if ((fasttimer_proc_entry = create_proc_entry( "fasttimer", 0, 0 )))
968 fasttimer_proc_entry->read_proc = proc_fasttimer_read;
970 proc_register_dynamic(&proc_root, &fasttimer_proc_entry);
973 if(request_irq(TIMER1_IRQ_NBR, timer1_handler, SA_SHIRQ,
974 "fast timer int", NULL))
976 printk(KERN_CRIT "err: timer1 irq\n");
978 fast_timer_is_init = 1;
979 #ifdef FAST_TIMER_TEST