17 int usec = UM_USEC_PER_SEC / UM_HZ;
29 unsigned long usec = ticks * UM_USEC_PER_SEC / UM_HZ;
30 unsigned long sec = usec / UM_USEC_PER_SEC;
33 usec %= UM_USEC_PER_SEC;
34 interval = ((
struct itimerval) { { 0, 0 }, {
sec, usec } });
52 static inline long long timeval_to_ns(
const struct timeval *tv)
54 return ((
long long) tv->
tv_sec * UM_NSEC_PER_SEC) +
61 long long remain,
max = UM_NSEC_PER_SEC / UM_HZ;
65 "errno = %d\n",
errno);
67 remain = timeval_to_ns(&time.
it_value);
79 return timeval_to_ns(&tv);
82 #ifdef UML_CONFIG_NO_HZ
83 static int after_sleep_interval(
struct timespec *
ts)
88 static void deliver_alarm(
void)
93 static unsigned long long sleep_time(
unsigned long long nsecs)
102 static void deliver_alarm(
void)
104 unsigned long long this_tick =
os_nsecs();
105 int one_tick = UM_NSEC_PER_SEC / UM_HZ;
108 if ((last_tick != 0) && (this_tick < last_tick))
112 last_tick = this_tick - one_tick;
116 while (skew >= one_tick) {
121 last_tick = this_tick;
124 static unsigned long long sleep_time(
unsigned long long nsecs)
126 return nsecs > skew ? nsecs - skew : 0;
129 static inline long long timespec_to_us(
const struct timespec *
ts)
131 return ((
long long) ts->
tv_sec * UM_USEC_PER_SEC) +
132 ts->
tv_nsec / UM_NSEC_PER_USEC;
135 static int after_sleep_interval(
struct timespec *ts)
137 int usec = UM_USEC_PER_SEC / UM_HZ;
138 long long start_usecs = timespec_to_us(ts);
149 if (start_usecs > usec)
152 start_usecs -= skew / UM_NSEC_PER_USEC;
156 tv = ((
struct timeval) { .tv_sec = start_usecs / UM_USEC_PER_SEC,
157 .tv_usec = start_usecs % UM_USEC_PER_SEC });
177 nsecs = UM_NSEC_PER_SEC / UM_HZ;
179 nsecs = sleep_time(nsecs);
180 ts = ((
struct timespec) { .tv_sec = nsecs / UM_NSEC_PER_SEC,
181 .tv_nsec = nsecs % UM_NSEC_PER_SEC });
183 if (nanosleep(&ts, &ts) == 0)
185 after_sleep_interval(&ts);