]> git.proxmox.com Git - mirror_ovs.git/commitdiff
poll-loop: New function poll_timer_wait_until().
authorBen Pfaff <blp@nicira.com>
Wed, 12 May 2010 19:53:07 +0000 (12:53 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 26 May 2010 18:46:59 +0000 (11:46 -0700)
Many of poll_timer_wait()'s callers actually want to wait until a specific
time, so it's convenient for them to offer a function that does this.

15 files changed:
extras/ezio/ezio-term.c
extras/ezio/ovs-switchui.c
lib/dhcp-client.c
lib/learning-switch.c
lib/mac-learning.c
lib/poll-loop.c
lib/poll-loop.h
lib/rconn.c
ofproto/fail-open.c
ofproto/in-band.c
ofproto/ofproto-sflow.c
ofproto/ofproto.c
ovsdb/trigger.c
vswitchd/bridge.c
xenserver/ovs-xenserverd.c

index cedc5c96741ae57be03ce98a21d2207f99e8dd1c..d96122bc8d86d343492af4d207d259239529b013 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009 Nicira Networks, Inc.
+/* Copyright (c) 2008, 2009, 2010 Nicira Networks, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -907,14 +907,7 @@ scanner_run(struct scanner *s, struct ezio *ezio)
 static void
 scanner_wait(struct scanner *s)
 {
-    long long int now = time_msec();
-    long long int expires = s->last_move + 750;
-    if (now >= expires) {
-        poll_immediate_wake();
-    } else {
-        poll_timer_wait(expires - now);
-    }
-
+    poll_timer_wait_until(s->last_move + 750);
 }
 
 static void
index 16a6903f5feba3a5983559c53ba9d47e57fdcee4..6ebfecee5e4701957b3c60fea95d20c25d07fd47 100644 (file)
@@ -242,7 +242,7 @@ main(int argc, char *argv[])
             refresh();
 
             poll_fd_wait(STDIN_FILENO, POLLIN);
-            poll_timer_wait(timeout - time_msec());
+            poll_timer_wait_until(timeout);
             poll_block();
         } while (time_msec() < timeout);
         age_messages();
@@ -868,7 +868,7 @@ fetch_status(struct rconn *rconn, struct dict *dict, long long timeout)
 
         rconn_run_wait(rconn);
         rconn_recv_wait(rconn);
-        poll_timer_wait(timeout - time_msec());
+        poll_timer_wait_until(timeout);
         poll_block();
     }
 }
@@ -1714,7 +1714,7 @@ menu_show(const struct menu *menu, int start, bool select)
         refresh();
 
         if (pos < min || pos > max) {
-            poll_timer_wait(adjust - time_msec());
+            poll_timer_wait_until(adjust);
         }
         poll_fd_wait(STDIN_FILENO, POLLIN);
         poll_block();
@@ -1946,7 +1946,7 @@ static void
 block_until(long long timeout)
 {
     while (timeout > time_msec()) {
-        poll_timer_wait(timeout - time_msec());
+        poll_timer_wait_until(timeout);
         poll_block();
     }
     drain_keyboard_buffer();
index 0abf115b025937b3d897582968fe1b6e397469f1..563a415c52f3f0baab53ac3a2902473a84a30dfa 100644 (file)
@@ -806,13 +806,8 @@ void
 dhclient_wait(struct dhclient *cli)
 {
     if (cli->min_timeout != UINT_MAX) {
-        time_t now = time_now();
-        unsigned int wake = sat_add(cli->state_entered, cli->min_timeout);
-        if (wake <= now) {
-            poll_immediate_wake();
-        } else {
-            poll_timer_wait(sat_mul(sat_sub(wake, now), 1000));
-        }
+        long long int wake = sat_add(cli->state_entered, cli->min_timeout);
+        poll_timer_wait_until(wake * 1000);
     }
     /* Reset timeout to 1 second.  This will have no effect ordinarily, because
      * dhclient_run() will typically set it back to a higher value.  If,
index 91f8f0527ce53f7da3a822f87a6b165e242bd305..64639f2c829a38324608113d55438e26bc320035 100644 (file)
@@ -220,8 +220,7 @@ lswitch_run(struct lswitch *sw, struct rconn *rconn)
 static void
 wait_timeout(long long int started)
 {
-    long long int now = time_msec();
-    poll_timer_wait(10000 - (now - started));
+    poll_timer_wait_until(started + 10000);
 }
 
 void
index a9d414d2fa449081a5691af25f7ca65bebdf7360..f9859b6b0eb75d9fc9f41ed784482c8a26a4e046 100644 (file)
@@ -293,6 +293,6 @@ mac_learning_wait(struct mac_learning *ml)
 {
     if (!list_is_empty(&ml->lrus)) {
         struct mac_entry *e = mac_entry_from_lru_node(ml->lrus.next);
-        poll_timer_wait((e->expires - time_now()) * 1000);
+        poll_timer_wait_until(e->expires * 1000LL);
     }
 }
index 29931f7855ae53f0d4e2651443a6dba9b382ab01..91034b04e907fd2456c5658d65e8fb1368887198 100644 (file)
@@ -100,6 +100,23 @@ poll_timer_wait(long long int msec)
                       : msec);
 }
 
+/* Causes the following call to poll_block() to wake up when the current time,
+ * as returned by time_msec(), reaches 'msec' or later.  If 'msec' is earlier
+ * than the current time, the following call to poll_block() will not block at
+ * all.
+ *
+ * The timer registration is one-shot: only the following call to poll_block()
+ * is affected.  The timer will need to be re-registered after poll_block() is
+ * called if it is to persist. */
+void
+poll_timer_wait_until(long long int msec)
+{
+    long long int now = time_msec();
+    poll_timer_wait__(msec <= now ? 0
+                      : msec < now + INT_MAX ? msec - now
+                      : INT_MAX);
+}
+
 /* Causes the following call to poll_block() to wake up immediately, without
  * blocking. */
 void
index eaeca2be55024cbd70266bd4585f5017e289cf3e..a9038ca586a754a178e3cf50f81790325167c590 100644 (file)
@@ -43,6 +43,7 @@ struct poll_waiter;
 /* Schedule events to wake up the following poll_block(). */
 struct poll_waiter *poll_fd_wait(int fd, short int events);
 void poll_timer_wait(long long int msec);
+void poll_timer_wait_until(long long int msec);
 void poll_immediate_wake(void);
 
 /* Wait until an event occurs. */
index ea45134fea3bcaf02ec4a34a12abe104a530b9af..71198ea76e786d5e31a52b44e06302bab539e439 100644 (file)
@@ -500,9 +500,8 @@ rconn_run_wait(struct rconn *rc)
 
     timeo = timeout(rc);
     if (timeo != UINT_MAX) {
-        unsigned int expires = sat_add(rc->state_entered, timeo);
-        unsigned int remaining = sat_sub(expires, time_now());
-        poll_timer_wait(sat_mul(remaining, 1000));
+        long long int expires = sat_add(rc->state_entered, timeo);
+        poll_timer_wait_until(expires * 1000);
     }
 
     if ((rc->state & (S_ACTIVE | S_IDLE)) && rc->txq.n) {
index a79c5b226ac6fed8370599c77707c5087b6a220d..b028493d6b94b58059f43f509d8dadae4d5ae6c5 100644 (file)
@@ -271,7 +271,7 @@ void
 fail_open_wait(struct fail_open *fo)
 {
     if (fo->next_bogus_packet_in != LLONG_MAX) {
-        poll_timer_wait(fo->next_bogus_packet_in - time_msec());
+        poll_timer_wait_until(fo->next_bogus_packet_in);
     }
 }
 
index bf90273e132e4243ada5f0fbef1ff3fd2f8590a1..e52a0a056f0434115253c2f17b3c497b50f1e3f2 100644 (file)
@@ -745,14 +745,9 @@ in_band_run(struct in_band *ib)
 void
 in_band_wait(struct in_band *in_band)
 {
-    time_t now = time_now();
-    time_t wakeup 
+    long long int wakeup
             = MIN(in_band->next_remote_refresh, in_band->next_local_refresh);
-    if (wakeup > now) {
-        poll_timer_wait((wakeup - now) * 1000);
-    } else {
-        poll_immediate_wake();
-    }
+    poll_timer_wait_until(wakeup * 1000);
 }
 
 /* ofproto has flushed all flows from the flow table and it is calling us back
index 60baf0e9e82c2f3bbba1ad351baaca5164c20244..37c1bb7f457a7ec0da1cab05a43bb15dc8cbe94f 100644 (file)
@@ -607,6 +607,6 @@ void
 ofproto_sflow_wait(struct ofproto_sflow *os)
 {
     if (ofproto_sflow_is_enabled(os)) {
-        poll_timer_wait(os->next_tick * 1000 - time_msec());
+        poll_timer_wait_until(os->next_tick * 1000LL);
     }
 }
index 41977874b8a5a9ab4e236000eaf8fb4755319930..1010948357e1c763f23eb3f0a83fd9998f272782 100644 (file)
@@ -1155,7 +1155,7 @@ ofproto_wait(struct ofproto *p)
         ofconn_wait(ofconn);
     }
     if (p->in_band) {
-        poll_timer_wait(p->next_in_band_update - time_msec());
+        poll_timer_wait_until(p->next_in_band_update);
         in_band_wait(p->in_band);
     }
     if (p->fail_open) {
@@ -1172,7 +1172,7 @@ ofproto_wait(struct ofproto *p)
         VLOG_DBG_RL(&rl, "need revalidate in ofproto_wait_cb()");
         poll_immediate_wake();
     } else if (p->next_expiration != LLONG_MAX) {
-        poll_timer_wait(p->next_expiration - time_msec());
+        poll_timer_wait_until(p->next_expiration);
     }
     for (i = 0; i < p->n_listeners; i++) {
         pvconn_wait(p->listeners[i]);
index 8f18291f498e8832d8ba7f7bca20838c15ebb0c9..47719698c18bcca5d88fb66464ea72331da28b0a 100644 (file)
@@ -102,7 +102,7 @@ ovsdb_trigger_wait(struct ovsdb *db, long long int now)
         }
 
         if (deadline < LLONG_MAX) {
-            poll_timer_wait(deadline - now);
+            poll_timer_wait_until(deadline);
         }
     }
 }
index 354d4d89452a46adef4771dbbf478cb6a23d35de..04898f88d9689787c3f344e692b3fc61417668dd 100644 (file)
@@ -1986,11 +1986,11 @@ bond_wait(struct bridge *br)
         for (j = 0; j < port->n_ifaces; j++) {
             struct iface *iface = port->ifaces[j];
             if (iface->delay_expires != LLONG_MAX) {
-                poll_timer_wait(iface->delay_expires - time_msec());
+                poll_timer_wait_until(iface->delay_expires);
             }
         }
         if (port->bond_fake_iface) {
-            poll_timer_wait(port->bond_next_fake_iface_update - time_msec());
+            poll_timer_wait_until(port->bond_next_fake_iface_update);
         }
     }
 }
index a69ca8adb6d3d45b5fbe16c5c3ed40f2c025f8e7..1598b01bfc4534fcee2847f2462c886a9239bc19 100644 (file)
@@ -240,7 +240,7 @@ network_uuid_refresh_wait(void)
             poll_timer_wait(1000);
         }
         if (next_refresh != LLONG_MAX) {
-            poll_timer_wait(next_refresh - time_msec());
+            poll_timer_wait_until(next_refresh);
         }
     }
 }