[ovs-dev] [PATCH 2/2] timeval: Recover from failed timer_create() calls.

Ethan Jackson ethan at nicira.com
Fri Oct 5 02:15:43 UTC 2012


The timer_create() system call is not supported in ESX and returns
an error when called.  Aborting when this system call fails seems a
bit extreme. So instead, this patch simply falls back to disabling
the cached time optimization.

Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 lib/timeval.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/lib/timeval.c b/lib/timeval.c
index 9b81cd3..d36271c 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -40,7 +40,12 @@ VLOG_DEFINE_THIS_MODULE(timeval);
  * to CLOCK_REALTIME. */
 static clockid_t monotonic_clock;
 
-/* Has a timer tick occurred? Only relevant if CACHE_TIME is 1.
+/* Has the same meaning as the CACHE_TIME define.  On some systems
+ * timer_create() is not implemented, in which case this variable can be
+ * overwridden. */
+static bool cache_time = CACHE_TIME;
+
+/* Has a timer tick occurred? Only relevant if cache_time is true.
  *
  * We initialize these to true to force time_init() to get called on the first
  * call to time_msec() or another function that queries the current time. */
@@ -93,10 +98,8 @@ time_init(void)
         VLOG_DBG("monotonic timer not available");
     }
 
-    if (CACHE_TIME) {
-        set_up_signal(SA_RESTART);
-        set_up_timer();
-    }
+    set_up_signal(SA_RESTART);
+    set_up_timer();
 
     boot_time = time_msec();
 }
@@ -148,8 +151,15 @@ set_up_timer(void)
     static timer_t timer_id;    /* "static" to avoid apparent memory leak. */
     struct itimerspec itimer;
 
+    if (!cache_time) {
+        return;
+    }
+
     if (timer_create(monotonic_clock, NULL, &timer_id)) {
-        VLOG_FATAL("timer_create failed (%s)", strerror(errno));
+        VLOG_WARN("timer_create failed (%s), disabling cached timing",
+                  strerror(errno));
+        cache_time = false;
+        return;
     }
 
     itimer.it_interval.tv_sec = 0;
@@ -170,10 +180,7 @@ void
 time_postfork(void)
 {
     time_init();
-
-    if (CACHE_TIME) {
-        set_up_timer();
-    }
+    set_up_timer();
 }
 
 static void
@@ -205,7 +212,7 @@ refresh_monotonic(void)
 /* Forces a refresh of the current time from the kernel.  It is not usually
  * necessary to call this function, since the time will be refreshed
  * automatically at least every TIME_UPDATE_INTERVAL milliseconds.  If
- * CACHE_TIME is 0, we will always refresh the current time so this
+ * cache_time is false, we will always refresh the current time so this
  * function has no effect. */
 void
 time_refresh(void)
@@ -367,7 +374,7 @@ sigalrm_handler(int sig_nr OVS_UNUSED)
 static void
 refresh_wall_if_ticked(void)
 {
-    if (!CACHE_TIME || wall_tick) {
+    if (!cache_time || wall_tick) {
         refresh_wall();
     }
 }
@@ -375,7 +382,7 @@ refresh_wall_if_ticked(void)
 static void
 refresh_monotonic_if_ticked(void)
 {
-    if (!CACHE_TIME || monotonic_tick) {
+    if (!cache_time || monotonic_tick) {
         refresh_monotonic();
     }
 }
-- 
1.7.12




More information about the dev mailing list