]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: reorg dataplane pthread start
authorMark Stapp <mjs@voltanet.io>
Fri, 7 Sep 2018 19:46:13 +0000 (15:46 -0400)
committerMark Stapp <mjs@voltanet.io>
Wed, 21 Nov 2018 15:38:08 +0000 (10:38 -0500)
Move dataplane pthread start later in the zebra startup; make
the 'test' dplane provider conditional

Signed-off-by: Mark Stapp <mjs@voltanet.io>
zebra/main.c
zebra/zebra_dplane.c
zebra/zebra_dplane.h

index 20a2185b1b61fbebf87a43147dc5b8a8377c523f..e5160c1a51aa64021950cf2340dd715073fb3b19 100644 (file)
@@ -448,6 +448,9 @@ int main(int argc, char **argv)
        /* Needed for BSD routing socket. */
        pid = getpid();
 
+       /* Start dataplane system */
+       zebra_dplane_start();
+
        /* Start Zebra API server */
        zserv_start(zserv_path);
 
index c859bdaf6e229b3630b66ce6bfe66c4591ae9da6..34de6a956e02374367cb259ff663ec52bf82f0ed 100644 (file)
@@ -38,10 +38,12 @@ DEFINE_MTYPE(ZEBRA, DP_PROV, "Zebra DPlane Provider")
 #  define AOK 0
 #endif
 
+/* Enable test dataplane provider */
+/*#define DPLANE_TEST_PROVIDER 1 */
+
 /* Default value for max queued incoming updates */
 const uint32_t DPLANE_DEFAULT_MAX_QUEUED = 200;
 
-
 /* Default value for new work per cycle */
 const uint32_t DPLANE_DEFAULT_NEW_WORK = 100;
 
@@ -1135,9 +1137,16 @@ bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov)
  */
 int dplane_provider_work_ready(void)
 {
-       thread_add_event(zdplane_info.dg_master,
-                        dplane_thread_loop, NULL, 0,
-                        &zdplane_info.dg_t_update);
+       /* Note that during zebra startup, we may be offered work before
+        * the dataplane pthread (and thread-master) are ready. We want to
+        * enqueue the work, but the event-scheduling machinery may not be
+        * available.
+        */
+       if (zdplane_info.dg_run) {
+               thread_add_event(zdplane_info.dg_master,
+                                dplane_thread_loop, NULL, 0,
+                                &zdplane_info.dg_t_update);
+       }
 
        return AOK;
 }
@@ -1217,6 +1226,8 @@ static int kernel_dplane_process_func(struct zebra_dplane_provider *prov)
        return 0;
 }
 
+#if DPLANE_TEST_PROVIDER
+
 /*
  * Test dataplane provider plugin
  */
@@ -1270,6 +1281,7 @@ static int test_dplane_shutdown_func(struct zebra_dplane_provider *prov,
 
        return 0;
 }
+#endif /* DPLANE_TEST_PROVIDER */
 
 /*
  * Register default kernel provider
@@ -1289,7 +1301,8 @@ static void dplane_provider_init(void)
                zlog_err("Unable to register kernel dplane provider: %d",
                         ret);
 
-       /* TODO -- make the test provider optional... */
+#if DPLANE_TEST_PROVIDER
+       /* Optional test provider ... */
        ret = dplane_provider_register("Test",
                                       DPLANE_PRIO_PRE_KERNEL,
                                       DPLANE_PROV_FLAGS_DEFAULT,
@@ -1300,6 +1313,7 @@ static void dplane_provider_init(void)
        if (ret != AOK)
                zlog_err("Unable to register test dplane provider: %d",
                         ret);
+#endif /* DPLANE_TEST_PROVIDER */
 }
 
 /* Indicates zebra shutdown/exit is in progress. Some operations may be
@@ -1623,11 +1637,16 @@ static void zebra_dplane_init_internal(struct zebra_t *zebra)
 
        /* Register default kernel 'provider' during init */
        dplane_provider_init();
+}
 
+/*
+ * Start the dataplane pthread. This step needs to be run later than the
+ * 'init' step, in case zebra has fork-ed.
+ */
+void zebra_dplane_start(void)
+{
        /* Start dataplane pthread */
 
-       zdplane_info.dg_run = true;
-
        struct frr_pthread_attr pattr = {
                .start = frr_pthread_attr_default.start,
                .stop = frr_pthread_attr_default.stop
@@ -1638,6 +1657,8 @@ static void zebra_dplane_init_internal(struct zebra_t *zebra)
 
        zdplane_info.dg_master = zdplane_info.dg_pthread->master;
 
+       zdplane_info.dg_run = true;
+
        /* Enqueue an initial event for the dataplane pthread */
        thread_add_event(zdplane_info.dg_master, dplane_thread_loop, NULL, 0,
                         &zdplane_info.dg_t_update);
index 844fd59600920c5f3b23cac3e662c600d685dd1a..6f471e65a13eae9df52f16b58e19416d62df9fb0 100644 (file)
@@ -324,6 +324,12 @@ int dplane_results_register(dplane_results_fp fp);
  */
 void zebra_dplane_init(void);
 
+/*
+ * Start the dataplane pthread. This step needs to be run later than the
+ * 'init' step, in case zebra has fork-ed.
+ */
+void zebra_dplane_start(void);
+
 /* Finalize/cleanup apis, one called early as shutdown is starting,
  * one called late at the end of zebra shutdown, and then one called
  * from the zebra main pthread to stop the dplane pthread and