aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/perfmon/perfmon_periodic.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-05-20 10:28:57 -0400
committerDamjan Marion <dmarion@me.com>2019-05-24 08:25:57 +0000
commit5f2cfb21fdf6eb4a32346809c8cee2550d775b19 (patch)
treee54364d08bd2dc2f851df3f0aa9a0689e9569635 /src/plugins/perfmon/perfmon_periodic.c
parentaea0df3d54d90eac3b8085ab8023c502b96bdbf0 (diff)
Add callback multiplex support
Change-Id: Iddeb3a1b0e20706e72ec8f74dabc60b342f003ba Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/plugins/perfmon/perfmon_periodic.c')
-rw-r--r--src/plugins/perfmon/perfmon_periodic.c62
1 files changed, 47 insertions, 15 deletions
diff --git a/src/plugins/perfmon/perfmon_periodic.c b/src/plugins/perfmon/perfmon_periodic.c
index d21b464b07b..ac68c42c219 100644
--- a/src/plugins/perfmon/perfmon_periodic.c
+++ b/src/plugins/perfmon/perfmon_periodic.c
@@ -52,12 +52,18 @@ read_current_perf_counters (vlib_main_t * vm, u64 * c0, u64 * c1,
else
{
u64 sw_value;
- if (read (pm->pm_fds[i][my_thread_index], &sw_value,
- sizeof (sw_value)) != sizeof (sw_value))
+ int read_result;
+ if ((read_result = read (pm->pm_fds[i][my_thread_index], &sw_value,
+ sizeof (sw_value)) != sizeof (sw_value)))
{
clib_unix_warning
- ("counter read failed, disable collection...");
- vm->vlib_node_runtime_perf_counter_cb = 0;
+ ("counter read returned %d, expected %d",
+ read_result, sizeof (sw_value));
+ clib_callback_enable_disable
+ (vm->vlib_node_runtime_perf_counter_cbs,
+ vm->vlib_node_runtime_perf_counter_cb_tmp,
+ vm->worker_thread_main_loop_callback_lock,
+ read_current_perf_counters, 0 /* enable */ );
return;
}
*cc = sw_value;
@@ -202,7 +208,11 @@ enable_current_events (perfmon_main_t * pm)
pm->n_active = i;
/* Enable the main loop counter snapshot mechanism */
- vm->vlib_node_runtime_perf_counter_cb = read_current_perf_counters;
+ clib_callback_enable_disable
+ (vm->vlib_node_runtime_perf_counter_cbs,
+ vm->vlib_node_runtime_perf_counter_cb_tmp,
+ vm->worker_thread_main_loop_callback_lock,
+ read_current_perf_counters, 1 /* enable */ );
}
static void
@@ -213,7 +223,11 @@ disable_events (perfmon_main_t * pm)
int i;
/* Stop main loop collection */
- vm->vlib_node_runtime_perf_counter_cb = 0;
+ clib_callback_enable_disable
+ (vm->vlib_node_runtime_perf_counter_cbs,
+ vm->vlib_node_runtime_perf_counter_cb_tmp,
+ vm->worker_thread_main_loop_callback_lock,
+ read_current_perf_counters, 0 /* enable */ );
for (i = 0; i < pm->n_active; i++)
{
@@ -239,16 +253,22 @@ worker_thread_start_event (vlib_main_t * vm)
{
perfmon_main_t *pm = &perfmon_main;
+ clib_callback_enable_disable (vm->worker_thread_main_loop_callbacks,
+ vm->worker_thread_main_loop_callback_tmp,
+ vm->worker_thread_main_loop_callback_lock,
+ worker_thread_start_event, 0 /* enable */ );
enable_current_events (pm);
- vm->worker_thread_main_loop_callback = 0;
}
static void
worker_thread_stop_event (vlib_main_t * vm)
{
perfmon_main_t *pm = &perfmon_main;
+ clib_callback_enable_disable (vm->worker_thread_main_loop_callbacks,
+ vm->worker_thread_main_loop_callback_tmp,
+ vm->worker_thread_main_loop_callback_lock,
+ worker_thread_stop_event, 0 /* enable */ );
disable_events (pm);
- vm->worker_thread_main_loop_callback = 0;
}
static void
@@ -285,8 +305,11 @@ start_event (perfmon_main_t * pm, f64 now, uword event_data)
continue;
if (all || clib_bitmap_get (pm->thread_bitmap, i))
- vlib_mains[i]->worker_thread_main_loop_callback = (void *)
- worker_thread_start_event;
+ clib_callback_enable_disable
+ (vlib_mains[i]->worker_thread_main_loop_callbacks,
+ vlib_mains[i]->worker_thread_main_loop_callback_tmp,
+ vlib_mains[i]->worker_thread_main_loop_callback_lock,
+ (void *) worker_thread_start_event, 1 /* enable */ );
}
}
@@ -445,8 +468,11 @@ handle_timeout (vlib_main_t * vm, perfmon_main_t * pm, f64 now)
if (vlib_mains[i] == 0)
continue;
if (all || clib_bitmap_get (pm->thread_bitmap, i))
- vlib_mains[i]->worker_thread_main_loop_callback = (void *)
- worker_thread_stop_event;
+ clib_callback_enable_disable
+ (vlib_mains[i]->worker_thread_main_loop_callbacks,
+ vlib_mains[i]->worker_thread_main_loop_callback_tmp,
+ vlib_mains[i]->worker_thread_main_loop_callback_lock,
+ (void *) worker_thread_stop_event, 1 /* enable */ );
}
/* Make sure workers have stopped collection */
@@ -457,7 +483,10 @@ handle_timeout (vlib_main_t * vm, perfmon_main_t * pm, f64 now)
for (i = 1; i < vec_len (vlib_mains); i++)
{
/* Has the worker actually stopped collecting data? */
- while (vlib_mains[i]->worker_thread_main_loop_callback)
+ while (clib_callback_is_set
+ (vlib_mains[i]->worker_thread_main_loop_callbacks,
+ vlib_mains[i]->worker_thread_main_loop_callback_lock,
+ read_current_perf_counters))
{
if (vlib_time_now (vm) > deadman)
{
@@ -486,8 +515,11 @@ handle_timeout (vlib_main_t * vm, perfmon_main_t * pm, f64 now)
if (vlib_mains[i] == 0)
continue;
if (all || clib_bitmap_get (pm->thread_bitmap, i))
- vlib_mains[i]->worker_thread_main_loop_callback = (void *)
- worker_thread_start_event;
+ clib_callback_enable_disable
+ (vlib_mains[i]->worker_thread_main_loop_callbacks,
+ vlib_mains[i]->worker_thread_main_loop_callback_tmp,
+ vlib_mains[i]->worker_thread_main_loop_callback_lock,
+ worker_thread_start_event, 1 /* enable */ );
}
}