[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / um / kernel / time.c
blobc40c86a3f918b491b04e1d1f05e235fedf22c599
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 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 int usec = 1000000/hz();
49 struct itimerval enable = ((struct itimerval) { { 0, usec },
50 { 0, usec }});
51 if(setitimer(ITIMER_VIRTUAL, &enable, NULL))
52 printk("enable_timer - setitimer failed, errno = %d\n",
53 errno);
56 void disable_timer(void)
58 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
59 if((setitimer(ITIMER_VIRTUAL, &disable, NULL) < 0) ||
60 (setitimer(ITIMER_REAL, &disable, NULL) < 0))
61 printk("disnable_timer - setitimer failed, errno = %d\n",
62 errno);
63 /* If there are signals already queued, after unblocking ignore them */
64 set_handler(SIGALRM, SIG_IGN, 0, -1);
65 set_handler(SIGVTALRM, SIG_IGN, 0, -1);
68 void switch_timers(int to_real)
70 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
71 struct itimerval enable = ((struct itimerval) { { 0, 1000000/hz() },
72 { 0, 1000000/hz() }});
73 int old, new;
75 if(to_real){
76 old = ITIMER_VIRTUAL;
77 new = ITIMER_REAL;
79 else {
80 old = ITIMER_REAL;
81 new = ITIMER_VIRTUAL;
84 if((setitimer(old, &disable, NULL) < 0) ||
85 (setitimer(new, &enable, NULL)))
86 printk("switch_timers - setitimer failed, errno = %d\n",
87 errno);
90 void uml_idle_timer(void)
92 if(signal(SIGVTALRM, SIG_IGN) == SIG_ERR)
93 panic("Couldn't unset SIGVTALRM handler");
95 set_handler(SIGALRM, (__sighandler_t) alarm_handler,
96 SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1);
97 set_interval(ITIMER_REAL);
100 extern int do_posix_clock_monotonic_gettime(struct timespec *tp);
102 void time_init(void)
104 struct timespec now;
106 if(signal(SIGVTALRM, boot_timer_handler) == SIG_ERR)
107 panic("Couldn't set SIGVTALRM handler");
108 set_interval(ITIMER_VIRTUAL);
110 do_posix_clock_monotonic_gettime(&now);
111 wall_to_monotonic.tv_sec = -now.tv_sec;
112 wall_to_monotonic.tv_nsec = -now.tv_nsec;
115 /* Declared in linux/time.h, which can't be included here */
116 extern void clock_was_set(void);
118 void do_gettimeofday(struct timeval *tv)
120 unsigned long flags;
122 flags = time_lock();
123 gettimeofday(tv, NULL);
124 timeradd(tv, &local_offset, tv);
125 time_unlock(flags);
126 clock_was_set();
129 int do_settimeofday(struct timespec *tv)
131 struct timeval now;
132 unsigned long flags;
133 struct timeval tv_in;
135 if ((unsigned long) tv->tv_nsec >= UM_NSEC_PER_SEC)
136 return -EINVAL;
138 tv_in.tv_sec = tv->tv_sec;
139 tv_in.tv_usec = tv->tv_nsec / 1000;
141 flags = time_lock();
142 gettimeofday(&now, NULL);
143 timersub(&tv_in, &now, &local_offset);
144 time_unlock(flags);
146 return(0);
149 void idle_sleep(int secs)
151 struct timespec ts;
153 ts.tv_sec = secs;
154 ts.tv_nsec = 0;
155 nanosleep(&ts, NULL);
159 * Overrides for Emacs so that we follow Linus's tabbing style.
160 * Emacs will notice this stuff at the end of the file and automatically
161 * adjust the settings for this buffer only. This must remain at the end
162 * of the file.
163 * ---------------------------------------------------------------------------
164 * Local variables:
165 * c-file-style: "linux"
166 * End: