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