[ovs-dev] [PATCH] timeval: Restore ability to warp time forward when time is not stopped.
Ethan Jackson
ethan at nicira.com
Fri Sep 13 00:46:12 UTC 2013
Assuming we really need this ability. I don't like that we have to
take a readlock every time we get the time. Perhaps we could could
have a global flag which is false unless time has ever been warped.
If it hasn't then we can simply do the xclock_gettime(). I think
that'd add a slight race, but I can't imagine it'd matter.
Ethan
On Thu, Sep 12, 2013 at 5:24 PM, Ben Pfaff <blp at nicira.com> wrote:
> Commit 31ef9f5178dee18 (timeval: Remove CACHE_TIME scheme.) inadvertently
> removed the ability to warp time forward, for use in tests, except when
> time is stopped. This fixes the problem.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> lib/timeval.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/lib/timeval.c b/lib/timeval.c
> index 3262397..7584d58 100644
> --- a/lib/timeval.c
> +++ b/lib/timeval.c
> @@ -105,15 +105,22 @@ time_init(void)
> static void
> time_timespec__(struct clock *c, struct timespec *ts)
> {
> + struct timespec warp;
> + struct timespec cache;
> + bool stopped;
> +
> time_init();
>
> - if (!c->stopped) {
> - xclock_gettime(c->id, ts);
> - } else {
> - ovs_rwlock_rdlock(&c->rwlock);
> - timespec_add(ts, &c->cache, &c->warp);
> - ovs_rwlock_unlock(&c->rwlock);
> + ovs_rwlock_rdlock(&c->rwlock);
> + stopped = c->stopped;
> + warp = c->warp;
> + cache = c->cache;
> + ovs_rwlock_unlock(&c->rwlock);
> +
> + if (!stopped) {
> + xclock_gettime(c->id, &cache);
> }
> + timespec_add(ts, &cache, &warp);
> }
>
> /* Stores a monotonic timer, accurate within TIME_UPDATE_INTERVAL ms, into
> --
> 1.7.10.4
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
More information about the dev
mailing list