From 3cac178007a80c34988ce085937711db804ddf7e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 24 Nov 2023 15:56:47 -0500 Subject: [PATCH] Move nr_callbacks to event state Signed-off-by: Mathieu Desnoyers --- include/side/abi/event-description.h | 3 +-- include/side/instrumentation-c-api.h | 2 +- include/side/trace.h | 1 + src/side.c | 17 +++++++++-------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/side/abi/event-description.h b/include/side/abi/event-description.h index a978436..1c72d4d 100644 --- a/include/side/abi/event-description.h +++ b/include/side/abi/event-description.h @@ -57,8 +57,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; -#define side_event_description_orig_abi_last nr_callbacks +#define side_event_description_orig_abi_last nr_attr /* End of fields supported in the original ABI. */ char end[]; /* End with a flexible array to account for extensibility. */ diff --git a/include/side/instrumentation-c-api.h b/include/side/instrumentation-c-api.h index 5b5e1a3..5b7b40c 100644 --- a/include/side/instrumentation-c-api.h +++ b/include/side/instrumentation-c-api.h @@ -1163,6 +1163,7 @@ .p = { \ .version = SIDE_EVENT_STATE_ABI_VERSION, \ }, \ + .nr_callbacks = 0, \ .enabled = 0, \ .callbacks = &side_empty_callback, \ .desc = &(_identifier), \ @@ -1182,7 +1183,6 @@ .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/include/side/trace.h b/include/side/trace.h index 005d499..d13432b 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -62,6 +62,7 @@ struct side_event_state { struct side_event_state_0 { struct side_event_state p; /* Required first field. */ + uint32_t nr_callbacks; uintptr_t enabled; const struct side_callback *callbacks; struct side_event_description *desc; diff --git a/src/side.c b/src/side.c index 643b273..e338006 100644 --- a/src/side.c +++ b/src/side.c @@ -155,7 +155,7 @@ int _side_tracer_callback_register(struct side_event_description *desc, if (side_unlikely(event_state->version != 0)) abort(); es0 = side_container_of(event_state, struct side_event_state_0, p); - old_nr_cb = desc->nr_callbacks; + old_nr_cb = es0->nr_callbacks; if (old_nr_cb == UINT32_MAX) { ret = SIDE_ERROR_INVAL; goto unlock; @@ -185,7 +185,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); - desc->nr_callbacks++; + es0->nr_callbacks++; /* Increment concurrently with kernel setting the top bits. */ if (!old_nr_cb) (void) __atomic_add_fetch(&es0->enabled, 1, __ATOMIC_RELAXED); @@ -239,7 +239,7 @@ static int _side_tracer_callback_unregister(struct side_event_description *desc, ret = SIDE_ERROR_NOENT; goto unlock; } - old_nr_cb = desc->nr_callbacks; + old_nr_cb = es0->nr_callbacks; old_cb = (struct side_callback *) es0->callbacks; if (old_nr_cb == 1) { new_cb = (struct side_callback *) &side_empty_callback; @@ -259,7 +259,7 @@ static int _side_tracer_callback_unregister(struct side_event_description *desc, side_rcu_assign_pointer(es0->callbacks, new_cb); side_rcu_wait_grace_period(&rcu_gp); free(old_cb); - desc->nr_callbacks--; + es0->nr_callbacks--; /* Decrement concurrently with kernel setting the top bits. */ if (old_nr_cb == 1) (void) __atomic_add_fetch(&es0->enabled, -1, __ATOMIC_RELAXED); @@ -317,15 +317,16 @@ 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 = desc->nr_callbacks; struct side_event_state_0 *es0; struct side_callback *old_cb; + uint32_t nr_cb; - if (!nr_cb) - return; if (side_unlikely(event_state->version != 0)) abort(); es0 = side_container_of(event_state, struct side_event_state_0, p); + nr_cb = es0->nr_callbacks; + if (!nr_cb) + return; old_cb = (struct side_callback *) es0->callbacks; (void) __atomic_add_fetch(&es0->enabled, -1, __ATOMIC_RELAXED); /* @@ -333,7 +334,7 @@ void side_event_remove_callbacks(struct side_event_description *desc) * caution. This should not matter because instrumentation is * unreachable. */ - desc->nr_callbacks = 0; + es0->nr_callbacks = 0; side_rcu_assign_pointer(es0->callbacks, &side_empty_callback); /* * No need to wait for grace period because instrumentation is -- 2.34.1