2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike{addtoit,linux.intel}.com)
3 * Licensed under the GPL
11 #include "kern_constants.h"
15 int set_interval(void)
17 int usec = 1000000/UM_HZ;
18 struct itimerval interval = ((struct itimerval) { { 0, usec },
21 if (setitimer(ITIMER_VIRTUAL, &interval, NULL) == -1)
27 int timer_one_shot(int ticks)
29 unsigned long usec = ticks * 1000000 / UM_HZ;
30 unsigned long sec = usec / 1000000;
31 struct itimerval interval;
34 interval = ((struct itimerval) { { 0, 0 }, { sec, usec } });
36 if (setitimer(ITIMER_VIRTUAL, &interval, NULL) == -1)
42 unsigned long long disable_timer(void)
44 struct itimerval time = ((struct itimerval) { { 0, 0 }, { 0, 0 } });
46 if(setitimer(ITIMER_VIRTUAL, &time, &time) < 0)
47 printk(UM_KERN_ERR "disable_timer - setitimer failed, "
48 "errno = %d\n", errno);
50 return tv_to_nsec(&time.it_value);
53 unsigned long long os_nsecs(void)
57 gettimeofday(&tv, NULL);
58 return timeval_to_ns(&tv);
61 extern void alarm_handler(int sig, struct sigcontext *sc);
63 void idle_sleep(unsigned long long nsecs)
65 struct timespec ts = { .tv_sec = nsecs / BILLION,
66 .tv_nsec = nsecs % BILLION };
68 if (nanosleep(&ts, &ts) == 0)
69 alarm_handler(SIGVTALRM, NULL);