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(int is_virtual)
19 int usec = 1000000/UM_HZ;
20 int timer_type = is_virtual ? ITIMER_VIRTUAL : ITIMER_REAL;
21 struct itimerval interval = ((struct itimerval) { { 0, usec },
24 if (setitimer(timer_type, &interval, NULL) == -1)
30 void disable_timer(void)
32 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
34 if ((setitimer(ITIMER_VIRTUAL, &disable, NULL) < 0) ||
35 (setitimer(ITIMER_REAL, &disable, NULL) < 0))
36 printk(UM_KERN_ERR "disable_timer - setitimer failed, "
37 "errno = %d\n", errno);
39 /* If there are signals already queued, after unblocking ignore them */
40 signal(SIGALRM, SIG_IGN);
41 signal(SIGVTALRM, SIG_IGN);
44 int switch_timers(int to_real)
46 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
47 struct itimerval enable;
48 int old, new, old_type = is_real_timer;
50 if(to_real == old_type)
62 if (setitimer(old, &disable, &enable) < 0)
63 printk(UM_KERN_ERR "switch_timers - setitimer disable failed, "
64 "errno = %d\n", errno);
66 if((enable.it_value.tv_sec == 0) && (enable.it_value.tv_usec == 0))
67 enable.it_value = enable.it_interval;
69 if (setitimer(new, &enable, NULL))
70 printk(UM_KERN_ERR "switch_timers - setitimer enable failed, "
71 "errno = %d\n", errno);
73 is_real_timer = to_real;
77 unsigned long long os_nsecs(void)
81 gettimeofday(&tv, NULL);
82 return (unsigned long long) tv.tv_sec * BILLION + tv.tv_usec * 1000;
85 void idle_sleep(int secs)