2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
13 #include "user_util.h"
14 #include "kern_util.h"
17 #include "kern_constants.h"
20 static void set_interval(int timer_type)
22 int usec = 1000000/hz();
23 struct itimerval interval = ((struct itimerval) { { 0, usec },
26 if(setitimer(timer_type, &interval, NULL) == -1)
27 panic("setitimer failed - errno = %d\n", errno);
30 void enable_timer(void)
32 set_interval(ITIMER_VIRTUAL);
35 void disable_timer(void)
37 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
38 if((setitimer(ITIMER_VIRTUAL, &disable, NULL) < 0) ||
39 (setitimer(ITIMER_REAL, &disable, NULL) < 0))
40 printk("disnable_timer - setitimer failed, errno = %d\n",
42 /* If there are signals already queued, after unblocking ignore them */
43 set_handler(SIGALRM, SIG_IGN, 0, -1);
44 set_handler(SIGVTALRM, SIG_IGN, 0, -1);
47 void switch_timers(int to_real)
49 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
50 struct itimerval enable = ((struct itimerval) { { 0, 1000000/hz() },
51 { 0, 1000000/hz() }});
63 if((setitimer(old, &disable, NULL) < 0) ||
64 (setitimer(new, &enable, NULL)))
65 printk("switch_timers - setitimer failed, errno = %d\n",
69 #ifdef UML_CONFIG_MODE_TT
70 void uml_idle_timer(void)
72 if(signal(SIGVTALRM, SIG_IGN) == SIG_ERR)
73 panic("Couldn't unset SIGVTALRM handler");
75 set_handler(SIGALRM, (__sighandler_t) alarm_handler,
76 SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1);
77 set_interval(ITIMER_REAL);
81 unsigned long long os_nsecs(void)
85 gettimeofday(&tv, NULL);
86 return((unsigned long long) tv.tv_sec * BILLION + tv.tv_usec * 1000);
89 void idle_sleep(int secs)
98 void user_time_init(void)
100 set_interval(ITIMER_VIRTUAL);