The dispatch loop in main() never terminates, so the
rte_eal_cleanup() after it is unreachable. Clang reports this
with -Wunreachable-code.

This example has two independent dispatch loops: the control
plane loop in main() and the data plane loop in thread_main()
running on every worker lcore. Stopping only the control plane
would tear down the EAL while the workers are still running
pipelines, so force_quit is declared in thread.h and tested by
both loops.

The connectivity poll functions are non blocking, so the control
plane loop notices the flag immediately.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 examples/pipeline/main.c   | 21 ++++++++++++++++++++-
 examples/pipeline/thread.c |  2 +-
 examples/pipeline/thread.h |  6 ++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/examples/pipeline/main.c b/examples/pipeline/main.c
index da5dd2b3f6..57f9584a64 100644
--- a/examples/pipeline/main.c
+++ b/examples/pipeline/main.c
@@ -2,6 +2,8 @@
  * Copyright(c) 2020 Intel Corporation
  */
 
+#include <signal.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -131,6 +133,15 @@ parse_args(int argc, char **argv)
        return 0;
 }
 
+volatile bool force_quit;
+
+static void
+signal_handler(int signum)
+{
+       if (signum == SIGINT || signum == SIGTERM)
+               force_quit = true;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -149,6 +160,9 @@ main(int argc, char **argv)
                return status;
        };
 
+       signal(SIGINT, signal_handler);
+       signal(SIGTERM, signal_handler);
+
        /* Thread */
        status = thread_init();
        if (status) {
@@ -178,12 +192,17 @@ main(int argc, char **argv)
        };
 
        /* Dispatch loop */
-       for ( ; ; ) {
+       while (!force_quit) {
                conn_poll_for_conn(conn);
 
                conn_poll_for_msg(conn);
        }
 
+       /* wait for the data plane threads to stop running the pipelines */
+       rte_eal_mp_wait_lcore();
+
        /* clean up the EAL */
        rte_eal_cleanup();
+
+       return 0;
 }
diff --git a/examples/pipeline/thread.c b/examples/pipeline/thread.c
index cf2af55f68..8cdbd4fade 100644
--- a/examples/pipeline/thread.c
+++ b/examples/pipeline/thread.c
@@ -359,7 +359,7 @@ thread_main(void *arg __rte_unused)
        t = &threads[thread_id];
 
        /* Dispatch loop. */
-       for ( ; ; ) {
+       while (!force_quit) {
                uint32_t i;
 
                /* Pipelines. */
diff --git a/examples/pipeline/thread.h b/examples/pipeline/thread.h
index f2e643def5..ad83b27506 100644
--- a/examples/pipeline/thread.h
+++ b/examples/pipeline/thread.h
@@ -5,10 +5,16 @@
 #ifndef _INCLUDE_THREAD_H_
 #define _INCLUDE_THREAD_H_
 
+#include <stdbool.h>
 #include <stdint.h>
 
 #include <rte_swx_pipeline.h>
 
+/**
+ * Set by the signal handler to stop the control and data plane threads.
+ */
+extern volatile bool force_quit;
+
 /**
  * Control plane (CP) thread.
  */
-- 
2.53.0

Reply via email to