uml: style fixes pass 1
[linux-2.6/kvm.git] / arch / um / os-Linux / time.c
blobf22fcdfd42505513d2ac38951b5496d40574762f
1 /*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <stddef.h>
7 #include <errno.h>
8 #include <signal.h>
9 #include <time.h>
10 #include <sys/time.h>
11 #include "kern_util.h"
12 #include "kern_constants.h"
13 #include "os.h"
14 #include "user.h"
16 int set_interval(int is_virtual)
18 int usec = 1000000/hz();
19 int timer_type = is_virtual ? ITIMER_VIRTUAL : ITIMER_REAL;
20 struct itimerval interval = ((struct itimerval) { { 0, usec },
21 { 0, usec } });
23 if (setitimer(timer_type, &interval, NULL) == -1)
24 return -errno;
26 return 0;
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 void switch_timers(int to_real)
45 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
46 struct itimerval enable = ((struct itimerval) { { 0, 1000000/hz() },
47 { 0, 1000000/hz() }});
48 int old, new;
50 if (to_real) {
51 old = ITIMER_VIRTUAL;
52 new = ITIMER_REAL;
54 else {
55 old = ITIMER_REAL;
56 new = ITIMER_VIRTUAL;
59 if ((setitimer(old, &disable, NULL) < 0) ||
60 (setitimer(new, &enable, NULL)))
61 printk(UM_KERN_ERR "switch_timers - setitimer failed, "
62 "errno = %d\n", errno);
65 unsigned long long os_nsecs(void)
67 struct timeval tv;
69 gettimeofday(&tv, NULL);
70 return (unsigned long long) tv.tv_sec * BILLION + tv.tv_usec * 1000;
73 void idle_sleep(int secs)
75 struct timespec ts;
77 ts.tv_sec = secs;
78 ts.tv_nsec = 0;
79 nanosleep(&ts, NULL);