@@ -767,17 +767,22 @@ get_cpu_usage(void)
/* "time/stop" stops the monotonic time returned by e.g. time_msec() from
* advancing, except due to later calls to "time/warp". */
-static void
-timeval_stop_cb(struct unixctl_conn *conn,
- int argc OVS_UNUSED, const char *argv[] OVS_UNUSED,
- void *aux OVS_UNUSED)
+void
+timeval_stop(void)
{
ovs_mutex_lock(&monotonic_clock.mutex);
atomic_store_relaxed(&monotonic_clock.slow_path, true);
monotonic_clock.stopped = true;
xclock_gettime(monotonic_clock.id, &monotonic_clock.cache);
ovs_mutex_unlock(&monotonic_clock.mutex);
+}
+static void
+timeval_stop_cb(struct unixctl_conn *conn,
+ int argc OVS_UNUSED, const char *argv[] OVS_UNUSED,
+ void *aux OVS_UNUSED)
+{
+ timeval_stop();
unixctl_command_reply(conn, NULL);
}
@@ -818,6 +823,21 @@ timeval_warp_cb(struct unixctl_conn *conn,
timewarp_work();
}
+/* Direct monotonic clock into slow path and advance the current monotonic
+ * time by 'msecs' milliseconds directly. This is for use in unit tests. */
+void
+timeval_warp(long long int msecs)
+{
+ struct clock *c = &monotonic_clock;
+ struct timespec warp;
+
+ ovs_mutex_lock(&monotonic_clock.mutex);
+ atomic_store_relaxed(&monotonic_clock.slow_path, true);
+ msec_to_timespec(msecs, &warp);
+ timespec_add(&c->warp, &c->warp, &warp);
+ ovs_mutex_unlock(&monotonic_clock.mutex);
+}
+
void
timeval_dummy_register(void)
{
@@ -81,6 +81,9 @@ long long int time_boot_msec(void);
void timewarp_run(void);
+void timeval_stop(void);
+void timeval_warp(long long int msecs);
+
#ifdef __cplusplus
}
#endif
It may be desirable to make use of time warp functionality in unit tests. Separate logic from time/stop unixctl into timeval_stop() and add a new timeval_warp() interface for directing monotonic clock into slow path and advancing the current monotonic directly. This will be used in a patch that implements unit tests for the cooperative multitasking module. Signed-off-by: Frode Nordahl <frode.nordahl@canonical.com> --- lib/timeval.c | 28 ++++++++++++++++++++++++---- lib/timeval.h | 3 +++ 2 files changed, 27 insertions(+), 4 deletions(-)