[NETLINK]: w1_int.c: fix default netlink group
[linux-2.6/verdex.git] / arch / um / kernel / time.c
blobc40b611e3d936dbcd120f65961e18a65ec8a4c87
1 /*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <time.h>
10 #include <sys/time.h>
11 #include <signal.h>
12 #include <errno.h>
13 #include "user_util.h"
14 #include "kern_util.h"
15 #include "user.h"
16 #include "process.h"
17 #include "signal_user.h"
18 #include "time_user.h"
19 #include "kern_constants.h"
21 /* XXX This really needs to be declared and initialized in a kernel file since
22 * it's in <linux/time.h>
24 extern struct timespec wall_to_monotonic;
26 extern struct timeval xtime;
28 struct timeval local_offset = { 0, 0 };
30 void timer(void)
32 gettimeofday(&xtime, NULL);
33 timeradd(&xtime, &local_offset, &xtime);
36 static void set_interval(int timer_type)
38 int usec = 1000000/hz();
39 struct itimerval interval = ((struct itimerval) { { 0, usec },
40 { 0, usec } });
42 if(setitimer(timer_type, &interval, NULL) == -1)
43 panic("setitimer failed - errno = %d\n", errno);
46 void enable_timer(void)
48 set_interval(ITIMER_VIRTUAL);
51 void prepare_timer(void * ptr)
53 int usec = 1000000/hz();
54 *(struct itimerval *)ptr = ((struct itimerval) { { 0, usec },
55 { 0, usec }});
58 void disable_timer(void)
60 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
61 if((setitimer(ITIMER_VIRTUAL, &disable, NULL) < 0) ||
62 (setitimer(ITIMER_REAL, &disable, NULL) < 0))
63 printk("disnable_timer - setitimer failed, errno = %d\n",
64 errno);
65 /* If there are signals already queued, after unblocking ignore them */
66 set_handler(SIGALRM, SIG_IGN, 0, -1);
67 set_handler(SIGVTALRM, SIG_IGN, 0, -1);
70 void switch_timers(int to_real)
72 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
73 struct itimerval enable = ((struct itimerval) { { 0, 1000000/hz() },
74 { 0, 1000000/hz() }});
75 int old, new;
77 if(to_real){
78 old = ITIMER_VIRTUAL;
79 new = ITIMER_REAL;
81 else {
82 old = ITIMER_REAL;
83 new = ITIMER_VIRTUAL;
86 if((setitimer(old, &disable, NULL) < 0) ||
87 (setitimer(new, &enable, NULL)))
88 printk("switch_timers - setitimer failed, errno = %d\n",
89 errno);
92 void uml_idle_timer(void)
94 if(signal(SIGVTALRM, SIG_IGN) == SIG_ERR)
95 panic("Couldn't unset SIGVTALRM handler");
97 set_handler(SIGALRM, (__sighandler_t) alarm_handler,
98 SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1);
99 set_interval(ITIMER_REAL);
102 extern int do_posix_clock_monotonic_gettime(struct timespec *tp);
104 void time_init(void)
106 struct timespec now;
108 if(signal(SIGVTALRM, boot_timer_handler) == SIG_ERR)
109 panic("Couldn't set SIGVTALRM handler");
110 set_interval(ITIMER_VIRTUAL);
112 do_posix_clock_monotonic_gettime(&now);
113 wall_to_monotonic.tv_sec = -now.tv_sec;
114 wall_to_monotonic.tv_nsec = -now.tv_nsec;
117 /* Declared in linux/time.h, which can't be included here */
118 extern void clock_was_set(void);
120 void do_gettimeofday(struct timeval *tv)
122 unsigned long flags;
124 flags = time_lock();
125 gettimeofday(tv, NULL);
126 timeradd(tv, &local_offset, tv);
127 time_unlock(flags);
128 clock_was_set();
131 int do_settimeofday(struct timespec *tv)
133 struct timeval now;
134 unsigned long flags;
135 struct timeval tv_in;
137 if ((unsigned long) tv->tv_nsec >= UM_NSEC_PER_SEC)
138 return -EINVAL;
140 tv_in.tv_sec = tv->tv_sec;
141 tv_in.tv_usec = tv->tv_nsec / 1000;
143 flags = time_lock();
144 gettimeofday(&now, NULL);
145 timersub(&tv_in, &now, &local_offset);
146 time_unlock(flags);
148 return(0);
151 void idle_sleep(int secs)
153 struct timespec ts;
155 ts.tv_sec = secs;
156 ts.tv_nsec = 0;
157 nanosleep(&ts, NULL);
160 /* XXX This partly duplicates init_irq_signals */
162 void user_time_init(void)
164 set_handler(SIGVTALRM, (__sighandler_t) alarm_handler,
165 SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH,
166 SIGALRM, SIGUSR2, -1);
167 set_handler(SIGALRM, (__sighandler_t) alarm_handler,
168 SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH,
169 SIGVTALRM, SIGUSR2, -1);
170 set_interval(ITIMER_VIRTUAL);