side initialization
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 27 Oct 2022 19:55:38 +0000 (15:55 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 27 Oct 2022 19:55:38 +0000 (15:55 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/side.c

index 016f55b1f7b7a23aff103460464ac7ad3c8ae12a..72424ee59d46ee246ae69ce14222e8651dd77107 100644 (file)
@@ -6,11 +6,30 @@
 #include <side/trace.h>
 #include "tracer.h"
 #include "rcu.h"
+#include "smp.h"
 
 #define SIDE_EVENT_ENABLED_KERNEL_USER_EVENT_MASK      0x80000000
 
+struct side_rcu_gp_state rcu_gp = {
+       .percpu_state = NULL,
+       .nr_cpus = 0,
+       .period = 0,
+       .gp_lock = PTHREAD_MUTEX_INITIALIZER,
+};
+
+/*
+ * Lazy initialization for early use within library constructors.
+ */
+static bool initialized;
+
+static
+void side_init(void)
+       __attribute__((constructor));
+
 void side_call(const struct side_event_description *desc, const struct side_arg_vec_description *sav_desc)
 {
+       if (side_unlikely(!initialized))
+               side_init();
        if (side_unlikely(desc->flags & SIDE_EVENT_FLAG_VARIADIC)) {
                printf("ERROR: unexpected variadic event description\n");
                abort();
@@ -26,9 +45,21 @@ void side_call_variadic(const struct side_event_description *desc,
        const struct side_arg_vec_description *sav_desc,
        const struct side_arg_dynamic_event_struct *var_struct)
 {
+       if (side_unlikely(!initialized))
+               side_init();
        if (side_unlikely(*desc->enabled & SIDE_EVENT_ENABLED_KERNEL_USER_EVENT_MASK)) {
                // TODO: call kernel write.
        }
        //TODO: replace tracer_call by rcu iteration on list of registered callbacks
        tracer_call_variadic(desc, sav_desc, var_struct, NULL);
 }
+
+void side_init(void)
+{
+       if (initialized)
+               return;
+       rcu_gp.nr_cpus = get_possible_cpus_array_len();
+       if (!rcu_gp.nr_cpus)
+               abort();
+       initialized = true;
+}
This page took 0.023171 seconds and 4 git commands to generate.