summaryrefslogtreecommitdiffstats
path: root/src/vlib/threads.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-02-19 17:05:30 -0500
committerDamjan Marion <dmarion@me.com>2019-02-20 16:27:47 +0000
commita4324a996f34902579338033110d27575a654c8e (patch)
treecdc4a58a8d055053cf8ef90b5ddf7d0fcd1a5af2 /src/vlib/threads.c
parent51a423dc2b0d4aad0bbd8f7e757d2ca49221ff83 (diff)
calculate per-thread time offset
The main thread squirrels away vlib_time_now (&vlib_global_main), worker threads use it to calculate an offset in f64 seconds from their own vlib_time_now(vm) value. We use that offset until the next barrier sync. Thanks to Damjan for the suggestion. Change-Id: If56cdfe68e5ad8ac3b0d0fc885dc3ba556cd1215 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vlib/threads.c')
-rw-r--r--src/vlib/threads.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index cdb4eb082b5..4368a74ac9f 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -1510,6 +1510,14 @@ vlib_worker_thread_barrier_release (vlib_main_t * vm)
deadline = now + BARRIER_SYNC_TIMEOUT;
+ /*
+ * Note when we let go of the barrier.
+ * Workers can use this to derive a reasonably accurate
+ * time offset. See vlib_time_now(...)
+ */
+ vm->time_last_barrier_release = vlib_time_now (vm);
+ CLIB_MEMORY_STORE_BARRIER ();
+
*vlib_worker_threads->wait_at_barrier = 0;
while (*vlib_worker_threads->workers_at_barrier > 0)
@@ -1808,6 +1816,45 @@ threads_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (threads_init);
+
+static clib_error_t *
+show_clock_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ int i;
+ f64 now;
+
+ now = vlib_time_now (vm);
+
+ vlib_cli_output (vm, "Time now %.9f", now);
+
+ if (vec_len (vlib_mains) == 1)
+ return 0;
+
+ vlib_cli_output (vm, "Time last barrier release %.9f",
+ vm->time_last_barrier_release);
+
+ for (i = 1; i < vec_len (vlib_mains); i++)
+ {
+ if (vlib_mains[i] == 0)
+ continue;
+ vlib_cli_output (vm, "Thread %d offset %.9f error %.9f", i,
+ vlib_mains[i]->time_offset,
+ vm->time_last_barrier_release -
+ vlib_mains[i]->time_last_barrier_release);
+ }
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (f_command, static) =
+{
+ .path = "show clock",
+ .short_help = "show clock",
+ .function = show_clock_command_fn,
+};
+/* *INDENT-ON* */
+
/*
* fd.io coding-style-patch-verification: ON
*