DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH 13/13] examples/eventdev_pipeline: make signal handler safe
Date: Sun,  6 Sep 2026 16:24:48 -0700	[thread overview]
Message-ID: <20260906232716.496546-14-stephen@networkplumber.org> (raw)
In-Reply-To: <20260906232716.496546-1-stephen@networkplumber.org>

The handler called rte_exit(), rte_event_dev_dump() and (before the
previous patch) printf(), none of which are async-signal-safe.
rte_exit() in particular runs rte_eal_cleanup() and exit(), tearing
down the EAL from signal context while the worker lcores are still
running in it.

Set the done flag and let main() do the work:

- The second-signal path becomes _exit(), which is async-signal-safe.
  This keeps the "hit ^C twice to give up on a clean shutdown" escape
  hatch without running exit handlers from the handler.

- The --dump-dev dump on exit moves to main() after
  rte_eal_mp_wait_lcore(), where it also gets the real dev_id instead
  of the hardcoded 0.

- SIGTSTP sets cdata.dump_dev_signal, which schedule_devices() already
  checks and drains on the scheduler lcore. That mechanism was present
  but nothing ever set the flag. Note this makes the SIGTSTP dump
  depend on a scheduler lcore being configured; there is no dump in
  configurations without one.

dump_dev_signal is now written from signal context, so make it
volatile sig_atomic_t.

Unlike the rest of this series this one is not reported by
-fanalyzer: the handler is registered in main() after rte_eal_init(),
and the analyzer does not connect the registration to the handler
body there. Found by inspection while auditing the neighbours.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/eventdev_pipeline/main.c            | 16 +++++++---------
 examples/eventdev_pipeline/pipeline_common.h |  3 ++-
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/examples/eventdev_pipeline/main.c b/examples/eventdev_pipeline/main.c
index 65e0cd437c..80197b7c21 100644
--- a/examples/eventdev_pipeline/main.c
+++ b/examples/eventdev_pipeline/main.c
@@ -314,18 +314,13 @@ do_capability_setup(uint8_t eventdev_id)
 static void
 signal_handler(int signum)
 {
-	static uint8_t once;
-
-	if (fdata->done)
-		rte_exit(1, "Exiting on signal %d\n", signum);
-	if ((signum == SIGINT || signum == SIGTERM) && !once) {
-		if (cdata.dump_dev)
-			rte_event_dev_dump(0, stdout);
-		once = 1;
+	if (signum == SIGINT || signum == SIGTERM) {
+		if (fdata->done)
+			_exit(1);
 		fdata->done = 1;
 	}
 	if (signum == SIGTSTP)
-		rte_event_dev_dump(0, stdout);
+		cdata.dump_dev_signal = 1;
 }
 
 static inline uint64_t
@@ -452,6 +447,9 @@ main(int argc, char **argv)
 
 	rte_eal_mp_wait_lcore();
 
+	if (cdata.dump_dev)
+		rte_event_dev_dump(dev_id, stdout);
+
 	if (!cdata.quiet && (port_stat(dev_id, worker_data[0].port_id) !=
 			(uint64_t)-ENOTSUP)) {
 		printf("\nPort Workload distribution:\n");
diff --git a/examples/eventdev_pipeline/pipeline_common.h b/examples/eventdev_pipeline/pipeline_common.h
index 7b8eb50240..131617cd5b 100644
--- a/examples/eventdev_pipeline/pipeline_common.h
+++ b/examples/eventdev_pipeline/pipeline_common.h
@@ -3,6 +3,7 @@
  * Copyright 2017 Cavium, Inc.
  */
 
+#include <signal.h>
 #include <stdbool.h>
 
 #include <rte_eal.h>
@@ -68,7 +69,7 @@ struct config_data {
 	int enable_queue_priorities;
 	int quiet;
 	int dump_dev;
-	int dump_dev_signal;
+	volatile sig_atomic_t dump_dev_signal;
 	int all_type_queues;
 	unsigned int num_stages;
 	unsigned int worker_cq_depth;
-- 
2.53.0


  parent reply	other threads:[~2026-09-06 23:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-06 23:24 [PATCH 00/13] make signal handlers async-signal-safe Stephen Hemminger
2026-09-06 23:24 ` [PATCH 01/13] graph: do not call printf in signal Stephen Hemminger
2026-09-06 23:24 ` [PATCH 02/13] examples: remove printf from signal handler Stephen Hemminger
2026-09-06 23:24 ` [PATCH 03/13] examples/vmdq: do not print " Stephen Hemminger
2026-09-06 23:24 ` [PATCH 04/13] examples/symmetric_mp: do not print or exit in handler Stephen Hemminger
2026-09-06 23:24 ` [PATCH 05/13] examples/vdpa: make signal handler safe Stephen Hemminger
2026-09-06 23:24 ` [PATCH 06/13] examples/vhost: " Stephen Hemminger
2026-09-06 23:24 ` [PATCH 07/13] examples/vhost_blk: do not tear down from signal handler Stephen Hemminger
2026-09-06 23:24 ` [PATCH 08/13] examples/ntb: do not print and re-raise " Stephen Hemminger
2026-09-06 23:24 ` [PATCH 09/13] examples/ipsecgw: do not print " Stephen Hemminger
2026-09-08 11:19   ` Radu Nicolau
2026-09-06 23:24 ` [PATCH 10/13] examples/l2fwd-macsec: remove print in " Stephen Hemminger
2026-09-06 23:24 ` [PATCH 11/13] examples/ethtool: fix exit flag and unchecked cmdline Stephen Hemminger
2026-09-06 23:24 ` [PATCH 12/13] examples/vmdq_dcb: allow exit on signal Stephen Hemminger
2026-09-06 23:24 ` Stephen Hemminger [this message]
2026-09-07  9:06 ` [PATCH 00/13] make signal handlers async-signal-safe Bruce Richardson
2026-09-07 17:03 ` [PATCH v2 " Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 01/13] graph: do not call printf in signal Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 02/13] examples: remove printf from signal handler Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 03/13] examples/vmdq: do not print " Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 04/13] examples/symmetric_mp: do not print or exit in handler Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 05/13] examples/vdpa: make signal handler safe Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 06/13] examples/vhost: " Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 07/13] examples/vhost_blk: do not tear down from signal handler Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 08/13] examples/ntb: do not print and re-raise " Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 09/13] examples/ipsecgw: do not print " Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 10/13] examples/l2fwd-macsec: remove print in " Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 11/13] examples/ethtool: fix exit flag and unchecked cmdline Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 12/13] examples/vmdq_dcb: allow exit on signal Stephen Hemminger
2026-09-07 17:03   ` [PATCH v2 13/13] examples/eventdev_pipeline: make signal handler safe Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260906232716.496546-14-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox