[ovs-dev] [timers 2/2] poll-loop: New function poll_timer_wait_until().

Jesse Gross jesse at nicira.com
Tue May 18 22:33:37 UTC 2010


This set looks good.

On Wed, May 12, 2010 at 11:01 AM, Ben Pfaff <blp at nicira.com> wrote:

> 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.
> ---
>  extras/ezio/ezio-term.c    |   11 ++---------
>  extras/ezio/ovs-switchui.c |    8 ++++----
>  lib/dhcp-client.c          |    9 ++-------
>  lib/learning-switch.c      |    3 +--
>  lib/mac-learning.c         |    2 +-
>  lib/poll-loop.c            |   17 +++++++++++++++++
>  lib/rconn.c                |    5 ++---
>  ofproto/fail-open.c        |    2 +-
>  ofproto/in-band.c          |    9 ++-------
>  ofproto/ofproto-sflow.c    |    2 +-
>  ofproto/ofproto.c          |    4 ++--
>  ovsdb/trigger.c            |    2 +-
>  vswitchd/bridge.c          |    4 ++--
>  xenserver/ovs-xenserverd.c |    2 +-
>  14 files changed, 39 insertions(+), 41 deletions(-)
>
> diff --git a/extras/ezio/ezio-term.c b/extras/ezio/ezio-term.c
> index cedc5c9..d96122b 100644
> --- a/extras/ezio/ezio-term.c
> +++ b/extras/ezio/ezio-term.c
> @@ -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
> diff --git a/extras/ezio/ovs-switchui.c b/extras/ezio/ovs-switchui.c
> index 16a6903..6ebfece 100644
> --- a/extras/ezio/ovs-switchui.c
> +++ b/extras/ezio/ovs-switchui.c
> @@ -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();
> diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c
> index 0abf115..563a415 100644
> --- a/lib/dhcp-client.c
> +++ b/lib/dhcp-client.c
> @@ -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,
> diff --git a/lib/learning-switch.c b/lib/learning-switch.c
> index 91f8f05..64639f2 100644
> --- a/lib/learning-switch.c
> +++ b/lib/learning-switch.c
> @@ -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
> diff --git a/lib/mac-learning.c b/lib/mac-learning.c
> index a9d414d..f9859b6 100644
> --- a/lib/mac-learning.c
> +++ b/lib/mac-learning.c
> @@ -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);
>     }
>  }
> diff --git a/lib/poll-loop.c b/lib/poll-loop.c
> index 29931f7..91034b0 100644
> --- a/lib/poll-loop.c
> +++ b/lib/poll-loop.c
> @@ -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
> diff --git a/lib/rconn.c b/lib/rconn.c
> index ea45134..71198ea 100644
> --- a/lib/rconn.c
> +++ b/lib/rconn.c
> @@ -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) {
> diff --git a/ofproto/fail-open.c b/ofproto/fail-open.c
> index a79c5b2..b028493 100644
> --- a/ofproto/fail-open.c
> +++ b/ofproto/fail-open.c
> @@ -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);
>     }
>  }
>
> diff --git a/ofproto/in-band.c b/ofproto/in-band.c
> index bf90273..e52a0a0 100644
> --- a/ofproto/in-band.c
> +++ b/ofproto/in-band.c
> @@ -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
> diff --git a/ofproto/ofproto-sflow.c b/ofproto/ofproto-sflow.c
> index 22d99eb..20aaac4 100644
> --- a/ofproto/ofproto-sflow.c
> +++ b/ofproto/ofproto-sflow.c
> @@ -609,6 +609,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);
>     }
>  }
> diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
> index 0ee69ef..50812eb 100644
> --- a/ofproto/ofproto.c
> +++ b/ofproto/ofproto.c
> @@ -1133,7 +1133,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) {
> @@ -1150,7 +1150,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]);
> diff --git a/ovsdb/trigger.c b/ovsdb/trigger.c
> index 8f18291..4771969 100644
> --- a/ovsdb/trigger.c
> +++ b/ovsdb/trigger.c
> @@ -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);
>         }
>     }
>  }
> diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
> index 354d4d8..04898f8 100644
> --- a/vswitchd/bridge.c
> +++ b/vswitchd/bridge.c
> @@ -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);
>         }
>     }
>  }
> diff --git a/xenserver/ovs-xenserverd.c b/xenserver/ovs-xenserverd.c
> index a69ca8a..1598b01 100644
> --- a/xenserver/ovs-xenserverd.c
> +++ b/xenserver/ovs-xenserverd.c
> @@ -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);
>         }
>     }
>  }
> --
> 1.7.1
>
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20100518/2f1210c9/attachment-0003.html>


More information about the dev mailing list