]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/um/os-Linux/time.c
uml: eliminate interrupts in the idle loop
[linux-2.6-omap-h63xx.git] / arch / um / os-Linux / time.c
1 /*
2  * Copyright (C) 2000 - 2007 Jeff Dike (jdike{addtoit,linux.intel}.com)
3  * Licensed under the GPL
4  */
5
6 #include <stddef.h>
7 #include <errno.h>
8 #include <signal.h>
9 #include <time.h>
10 #include <sys/time.h>
11 #include "kern_constants.h"
12 #include "os.h"
13 #include "user.h"
14
15 int set_interval(void)
16 {
17         int usec = 1000000/UM_HZ;
18         struct itimerval interval = ((struct itimerval) { { 0, usec },
19                                                           { 0, usec } });
20
21         if (setitimer(ITIMER_VIRTUAL, &interval, NULL) == -1)
22                 return -errno;
23
24         return 0;
25 }
26
27 int timer_one_shot(int ticks)
28 {
29         unsigned long usec = ticks * 1000000 / UM_HZ;
30         unsigned long sec = usec / 1000000;
31         struct itimerval interval;
32
33         usec %= 1000000;
34         interval = ((struct itimerval) { { 0, 0 }, { sec, usec } });
35
36         if (setitimer(ITIMER_VIRTUAL, &interval, NULL) == -1)
37                 return -errno;
38
39         return 0;
40 }
41
42 unsigned long long disable_timer(void)
43 {
44         struct itimerval time = ((struct itimerval) { { 0, 0 }, { 0, 0 } });
45
46         if(setitimer(ITIMER_VIRTUAL, &time, &time) < 0)
47                 printk(UM_KERN_ERR "disable_timer - setitimer failed, "
48                        "errno = %d\n", errno);
49
50         return tv_to_nsec(&time.it_value);
51 }
52
53 unsigned long long os_nsecs(void)
54 {
55         struct timeval tv;
56
57         gettimeofday(&tv, NULL);
58         return timeval_to_ns(&tv);
59 }
60
61 extern void alarm_handler(int sig, struct sigcontext *sc);
62
63 void idle_sleep(unsigned long long nsecs)
64 {
65         struct timespec ts = { .tv_sec  = nsecs / BILLION,
66                                .tv_nsec = nsecs % BILLION };
67
68         if (nanosleep(&ts, &ts) == 0)
69                 alarm_handler(SIGVTALRM, NULL);
70 }