2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

timeval: Add internal timewarp interface.

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>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Frode Nordahl
2024-01-16 22:52:01 +00:00
committed by Ilya Maximets
parent b222593bc6
commit 6ece3d57b2
2 changed files with 27 additions and 4 deletions

View File

@@ -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)
{

View File

@@ -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