2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike{addtoit,linux.intel}.com)
3 * Licensed under the GPL
11 #include "kern_constants.h"
15 static int is_real_timer = 0;
17 int set_interval(void)
19 int usec = 1000000/UM_HZ;
20 struct itimerval interval = ((struct itimerval) { { 0, usec },
23 if (setitimer(ITIMER_VIRTUAL, &interval, NULL) == -1)
29 void disable_timer(void)
31 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
33 if ((setitimer(ITIMER_VIRTUAL, &disable, NULL) < 0) ||
34 (setitimer(ITIMER_REAL, &disable, NULL) < 0))
35 printk(UM_KERN_ERR "disable_timer - setitimer failed, "
36 "errno = %d\n", errno);
38 /* If there are signals already queued, after unblocking ignore them */
39 signal(SIGALRM, SIG_IGN);
40 signal(SIGVTALRM, SIG_IGN);
43 int switch_timers(int to_real)
45 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
46 struct itimerval enable;
47 int old, new, old_type = is_real_timer;
49 if(to_real == old_type)
61 if (setitimer(old, &disable, &enable) < 0)
62 printk(UM_KERN_ERR "switch_timers - setitimer disable failed, "
63 "errno = %d\n", errno);
65 if((enable.it_value.tv_sec == 0) && (enable.it_value.tv_usec == 0))
66 enable.it_value = enable.it_interval;
68 if (setitimer(new, &enable, NULL))
69 printk(UM_KERN_ERR "switch_timers - setitimer enable failed, "
70 "errno = %d\n", errno);
72 is_real_timer = to_real;
76 unsigned long long os_nsecs(void)
80 gettimeofday(&tv, NULL);
81 return (unsigned long long) tv.tv_sec * BILLION + tv.tv_usec * 1000;
84 void idle_sleep(int secs)