static struct timespec warp_offset; /* Offset added to monotonic_time. */
static bool time_stopped; /* Disables real-time updates, if true. */
-/* Time at which to die with SIGALRM (if not TIME_MIN). */
-static time_t deadline = TIME_MIN;
+/* Time in milliseconds at which to die with SIGALRM (if not LLONG_MAX). */
+static long long int deadline = LLONG_MAX;
static void set_up_timer(void);
static void set_up_signal(int flags);
static void sigalrm_handler(int);
static void refresh_wall_if_ticked(void);
static void refresh_monotonic_if_ticked(void);
-static time_t time_add(time_t, time_t);
static void block_sigalrm(sigset_t *);
static void unblock_sigalrm(const sigset_t *);
static void log_poll_interval(long long int last_wakeup);
if (CACHE_TIME) {
set_up_timer();
- } else {
- /* If we are not caching kernel time, the only reason the timer should
- * exist is if time_alarm() was called and deadline is set */
- if (deadline != TIME_MIN) {
- set_up_timer();
- }
}
}
return monotonic_time.tv_sec;
}
-/* Same as time_now() except does not write to static variables, for use in
- * signal handlers. */
-static time_t
-time_now_sig(void)
-{
- struct timespec cur_time;
-
- clock_gettime(monotonic_clock, &cur_time);
- return cur_time.tv_sec;
-}
-
/* Returns the current time, in seconds. */
time_t
time_wall(void)
void
time_alarm(unsigned int secs)
{
+ long long int now;
+ long long int msecs;
+
sigset_t oldsigs;
time_init();
+ time_refresh();
+
+ now = time_msec();
+ msecs = secs * 1000;
block_sigalrm(&oldsigs);
- deadline = secs ? time_add(time_now(), secs) : TIME_MIN;
+ deadline = now < LLONG_MAX - msecs ? now + msecs : LLONG_MAX;
unblock_sigalrm(&oldsigs);
-
- if (!CACHE_TIME) {
- /* If we aren't timing the gaps between kernel time refreshes we need to
- * to start the timer up now */
- set_up_signal(SA_RESTART);
- set_up_timer();
- }
}
/* Like poll(), except:
coverage_clear();
start = time_msec();
blocked = false;
+
+ timeout_when = MIN(timeout_when, deadline);
+
for (;;) {
long long int now = time_msec();
int time_left;
if (retval < 0) {
retval = -errno;
}
+
time_refresh();
+ if (deadline <= time_msec()) {
+ fatal_signal_handler(SIGALRM);
+ if (retval < 0) {
+ retval = 0;
+ }
+ break;
+ }
+
if (retval != -EINTR) {
break;
}
- if (!blocked && deadline == TIME_MIN) {
+ if (!blocked && !CACHE_TIME) {
block_sigalrm(&oldsigs);
blocked = true;
}
return retval;
}
-/* Returns the sum of 'a' and 'b', with saturation on overflow or underflow. */
-static time_t
-time_add(time_t a, time_t b)
-{
- return (a >= 0
- ? (b > TIME_MAX - a ? TIME_MAX : a + b)
- : (b < TIME_MIN - a ? TIME_MIN : a + b));
-}
-
static void
-sigalrm_handler(int sig_nr)
+sigalrm_handler(int sig_nr OVS_UNUSED)
{
wall_tick = true;
monotonic_tick = true;
- if (deadline != TIME_MIN && time_now_sig() > deadline) {
- fatal_signal_handler(sig_nr);
- }
}
static void