2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include "linux/module.h"
13 #include "user_util.h"
14 #include "kern_util.h"
17 #include "signal_user.h"
18 #include "time_user.h"
20 extern struct timeval xtime;
24 gettimeofday(&xtime, NULL);
27 void set_interval(int timer_type)
29 int usec = 1000000/hz();
30 struct itimerval interval = ((struct itimerval) { { 0, usec },
33 if(setitimer(timer_type, &interval, NULL) == -1)
34 panic("setitimer failed - errno = %d\n", errno);
37 void enable_timer(void)
39 int usec = 1000000/hz();
40 struct itimerval enable = ((struct itimerval) { { 0, usec },
42 if(setitimer(ITIMER_VIRTUAL, &enable, NULL))
43 printk("enable_timer - setitimer failed, errno = %d\n",
47 void switch_timers(int to_real)
49 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
50 struct itimerval enable = ((struct itimerval) { { 0, 1000000/hz() },
51 { 0, 1000000/hz() }});
63 if((setitimer(old, &disable, NULL) < 0) ||
64 (setitimer(new, &enable, NULL)))
65 printk("switch_timers - setitimer failed, errno = %d\n",
71 if(signal(SIGVTALRM, SIG_IGN) == SIG_ERR)
72 panic("Couldn't unset SIGVTALRM handler");
74 set_handler(SIGALRM, (__sighandler_t) alarm_handler,
75 SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1);
76 set_interval(ITIMER_REAL);
81 if(signal(SIGVTALRM, boot_timer_handler) == SIG_ERR)
82 panic("Couldn't set SIGVTALRM handler");
83 set_interval(ITIMER_VIRTUAL);
86 struct timeval local_offset = { 0, 0 };
88 void do_gettimeofday(struct timeval *tv)
93 gettimeofday(tv, NULL);
94 timeradd(tv, &local_offset, tv);
99 EXPORT_SYMBOL(do_gettimeofday);
101 int do_settimeofday(struct timespec *tv)
105 struct timeval tv_in;
107 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
110 tv_in.tv_sec = tv->tv_sec;
111 tv_in.tv_usec = tv->tv_nsec / 1000;
114 gettimeofday(&now, NULL);
115 timersub(&tv_in, &now, &local_offset);
119 EXPORT_SYMBOL(do_settimeofday);
121 void idle_sleep(int secs)
127 nanosleep(&ts, NULL);
131 * Overrides for Emacs so that we follow Linus's tabbing style.
132 * Emacs will notice this stuff at the end of the file and automatically
133 * adjust the settings for this buffer only. This must remain at the end
135 * ---------------------------------------------------------------------------
137 * c-file-style: "linux"