2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
13 #include "user_util.h"
14 #include "kern_util.h"
17 #include "kern_constants.h"
19 #include "uml-config.h"
21 int set_interval(int is_virtual)
23 int usec = 1000000/hz();
24 int timer_type = is_virtual ? ITIMER_VIRTUAL : ITIMER_REAL;
25 struct itimerval interval = ((struct itimerval) { { 0, usec },
28 if(setitimer(timer_type, &interval, NULL) == -1)
34 #ifdef UML_CONFIG_MODE_TT
35 void enable_timer(void)
41 void disable_timer(void)
43 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
44 if((setitimer(ITIMER_VIRTUAL, &disable, NULL) < 0) ||
45 (setitimer(ITIMER_REAL, &disable, NULL) < 0))
46 printk("disnable_timer - setitimer failed, errno = %d\n",
48 /* If there are signals already queued, after unblocking ignore them */
49 signal(SIGALRM, SIG_IGN);
50 signal(SIGVTALRM, SIG_IGN);
53 void switch_timers(int to_real)
55 struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }});
56 struct itimerval enable = ((struct itimerval) { { 0, 1000000/hz() },
57 { 0, 1000000/hz() }});
69 if((setitimer(old, &disable, NULL) < 0) ||
70 (setitimer(new, &enable, NULL)))
71 printk("switch_timers - setitimer failed, errno = %d\n",
75 #ifdef UML_CONFIG_MODE_TT
76 void uml_idle_timer(void)
78 if(signal(SIGVTALRM, SIG_IGN) == SIG_ERR)
79 panic("Couldn't unset SIGVTALRM handler");
81 set_handler(SIGALRM, (__sighandler_t) alarm_handler,
82 SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1);
87 unsigned long long os_nsecs(void)
91 gettimeofday(&tv, NULL);
92 return((unsigned long long) tv.tv_sec * BILLION + tv.tv_usec * 1000);
95 void idle_sleep(int secs)
101 nanosleep(&ts, NULL);