From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH v2 13/13] examples/eventdev_pipeline: make signal handler safe
Date: Mon, 7 Sep 2026 10:03:31 -0700 [thread overview]
Message-ID: <20260907170454.351647-14-stephen@networkplumber.org> (raw)
In-Reply-To: <20260907170454.351647-1-stephen@networkplumber.org>
This example was calling functions like rte_exit and printing from a
signal handler which is not async signal safe.
Revise to spit the two signal actions here:
- The handler for SIGINT and SIGTERM set a flag which causes main
loop to exit and proceed with normal clean shutdown. If a second
SIGINT is received the process will get default signal handler
(i.e process exit).
- The dump flag handler is changed form SIGTSTP (^Z) to use SIGUSR1
since that is more standard practice in Linux.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
examples/eventdev_pipeline/main.c | 39 ++++++++++++--------
examples/eventdev_pipeline/pipeline_common.h | 13 ++++---
2 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/examples/eventdev_pipeline/main.c b/examples/eventdev_pipeline/main.c
index 65e0cd437c..00f409a07b 100644
--- a/examples/eventdev_pipeline/main.c
+++ b/examples/eventdev_pipeline/main.c
@@ -312,20 +312,16 @@ do_capability_setup(uint8_t eventdev_id)
}
static void
-signal_handler(int signum)
+signal_quit(int signum __rte_unused)
{
- 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 (fdata != NULL)
fdata->done = 1;
- }
- if (signum == SIGTSTP)
- rte_event_dev_dump(0, stdout);
+}
+
+static void
+signal_dump(int signum __rte_unused)
+{
+ cdata.dump_dev_signal = 1;
}
static inline uint64_t
@@ -345,9 +341,19 @@ main(int argc, char **argv)
int lcore_id;
int err;
- signal(SIGINT, signal_handler);
- signal(SIGTERM, signal_handler);
- signal(SIGTSTP, signal_handler);
+ /* second SIGINT/SIGTERM takes the default action */
+ struct sigaction sa = {
+ .sa_handler = signal_quit,
+ .sa_flags = SA_RESETHAND,
+ };
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGINT, &sa, NULL);
+ sigaction(SIGTERM, &sa, NULL);
+
+ /* allow repeated dump signals */
+ sa.sa_handler = signal_dump;
+ sa.sa_flags = 0;
+ sigaction(SIGUSR1, &sa, NULL);
err = rte_eal_init(argc, argv);
if (err < 0)
@@ -452,6 +458,9 @@ main(int argc, char **argv)
rte_eal_mp_wait_lcore();
+ if (cdata.dump_dev)
+ rte_event_dev_dump(0, 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..274c6942ca 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>
@@ -43,7 +44,7 @@ struct setup_data {
};
struct __rte_cache_aligned fastpath_data {
- volatile int done;
+ volatile sig_atomic_t done;
uint32_t evdev_service_id;
uint32_t rxadptr_service_id;
uint32_t txadptr_service_id;
@@ -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;
@@ -127,16 +128,16 @@ schedule_devices(unsigned int lcore_id)
if (fdata->sched_core[lcore_id]) {
rte_service_run_iter_on_app_lcore(fdata->evdev_service_id,
!fdata->sched_single);
- if (cdata.dump_dev_signal) {
- rte_event_dev_dump(0, stdout);
- cdata.dump_dev_signal = 0;
- }
}
if (fdata->tx_core[lcore_id]) {
rte_service_run_iter_on_app_lcore(fdata->txadptr_service_id,
!fdata->tx_single);
}
+ if (cdata.dump_dev_signal) {
+ rte_event_dev_dump(0, stdout);
+ cdata.dump_dev_signal = 0;
+ }
}
static void
--
2.53.0
prev parent reply other threads:[~2026-09-07 17:06 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 ` [PATCH 13/13] examples/eventdev_pipeline: make signal handler safe Stephen Hemminger
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 ` Stephen Hemminger [this message]
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=20260907170454.351647-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