From: Mathieu Desnoyers Date: Thu, 21 Sep 2023 10:54:18 +0000 (+0100) Subject: trace.h: Move back nr_callbacks to event description X-Git-Url: http://git.efficios.com/?p=libside.git;a=commitdiff_plain;h=f8188f94f6e17919ca75063e4d43faca0fd03af8 trace.h: Move back nr_callbacks to event description nr_callbacks is not used on the fast path, therefore move it back to the event description to optimize cache density of the event state enabled flags. Signed-off-by: Mathieu Desnoyers --- diff --git a/include/side/trace.h b/include/side/trace.h index 42efeef..f4b1e0f 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -658,7 +658,6 @@ struct side_tracer_dynamic_struct_visitor_ctx { struct side_event_state { uintptr_t enabled; const struct side_callback *callbacks; - uint32_t nr_callbacks; }; struct side_event_description { @@ -672,6 +671,7 @@ struct side_event_description { side_enum_t(enum side_loglevel, uint32_t) loglevel; uint32_t nr_fields; uint32_t nr_attr; + uint32_t nr_callbacks; } SIDE_PACKED; /* Event and type attributes */ @@ -1808,7 +1808,6 @@ struct side_event_description { side_event_state__##_identifier = { \ .enabled = 0, \ .callbacks = &side_empty_callback, \ - .nr_callbacks = 0, \ }; \ _linkage struct side_event_description __attribute__((section("side_event_description"))) \ _identifier = { \ @@ -1822,6 +1821,7 @@ struct side_event_description { .loglevel = SIDE_ENUM_INIT(_loglevel), \ .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .nr_callbacks = 0, \ }; \ static const struct side_event_description *side_event_ptr__##_identifier \ __attribute__((section("side_event_description_ptr"), used)) = &(_identifier); diff --git a/src/side.c b/src/side.c index 67a5bd4..ec5fdbf 100644 --- a/src/side.c +++ b/src/side.c @@ -148,7 +148,7 @@ int _side_tracer_callback_register(struct side_event_description *desc, side_init(); pthread_mutex_lock(&side_lock); event_state = side_ptr_get(desc->state); - old_nr_cb = event_state->nr_callbacks; + old_nr_cb = desc->nr_callbacks; if (old_nr_cb == UINT32_MAX) { ret = SIDE_ERROR_INVAL; goto unlock; @@ -177,7 +177,7 @@ int _side_tracer_callback_register(struct side_event_description *desc, side_rcu_wait_grace_period(&rcu_gp); if (old_nr_cb) free(old_cb); - event_state->nr_callbacks++; + desc->nr_callbacks++; /* Increment concurrently with kernel setting the top bits. */ if (!old_nr_cb) (void) __atomic_add_fetch(&event_state->enabled, 1, __ATOMIC_RELAXED); @@ -227,7 +227,7 @@ static int _side_tracer_callback_unregister(struct side_event_description *desc, ret = SIDE_ERROR_NOENT; goto unlock; } - old_nr_cb = event_state->nr_callbacks; + old_nr_cb = desc->nr_callbacks; old_cb = (struct side_callback *) event_state->callbacks; if (old_nr_cb == 1) { new_cb = (struct side_callback *) &side_empty_callback; @@ -246,7 +246,7 @@ static int _side_tracer_callback_unregister(struct side_event_description *desc, side_rcu_assign_pointer(event_state->callbacks, new_cb); side_rcu_wait_grace_period(&rcu_gp); free(old_cb); - event_state->nr_callbacks--; + desc->nr_callbacks--; /* Decrement concurrently with kernel setting the top bits. */ if (old_nr_cb == 1) (void) __atomic_add_fetch(&event_state->enabled, -1, __ATOMIC_RELAXED); @@ -304,7 +304,7 @@ static void side_event_remove_callbacks(struct side_event_description *desc) { struct side_event_state *event_state = side_ptr_get(desc->state); - uint32_t nr_cb = event_state->nr_callbacks; + uint32_t nr_cb = desc->nr_callbacks; struct side_callback *old_cb; if (!nr_cb) @@ -316,7 +316,7 @@ void side_event_remove_callbacks(struct side_event_description *desc) * caution. This should not matter because instrumentation is * unreachable. */ - event_state->nr_callbacks = 0; + desc->nr_callbacks = 0; side_rcu_assign_pointer(event_state->callbacks, &side_empty_callback); /* * No need to wait for grace period because instrumentation is