[PATCH v2 03/13] examples/vmdq: do not print from signal handler
Stephen Hemminger
stephen at networkplumber.org
Mon Sep 7 19:03:21 CEST 2026
The SIGHUP handler calls printf() which is not async-signal-safe.
Set a flag instead and print the stats from the main lcore in the
forwarding loop.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
examples/vmdq/main.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/examples/vmdq/main.c b/examples/vmdq/main.c
index 8c9d885090..63ac44deba 100644
--- a/examples/vmdq/main.c
+++ b/examples/vmdq/main.c
@@ -465,18 +465,27 @@ update_mac_address(struct rte_mbuf *m, unsigned dst_port)
rte_ether_addr_copy(&vmdq_ports_eth_addr[dst_port], ð->src_addr);
}
-/* When we receive a HUP signal, print out our stats */
+/* Set by the SIGHUP handler, consumed by the main lcore. */
+static volatile sig_atomic_t stats_requested;
+
+static void
+sighup_handler(__rte_unused int signum)
+{
+ stats_requested = 1;
+}
+
static void
-sighup_handler(int signum)
+print_stats(void)
{
unsigned int q = vmdq_queue_base;
+
for (; q < num_queues; q++) {
if ((q - vmdq_queue_base) % (num_vmdq_queues / num_pools) == 0)
printf("\nPool %u: ", (q - vmdq_queue_base) /
(num_vmdq_queues / num_pools));
printf("%lu ", rxPackets[q]);
}
- printf("\nFinished handling signal %d\n", signum);
+ putchar('\n');
}
/*
@@ -534,6 +543,11 @@ lcore_main(__rte_unused void *dummy)
struct rte_mbuf *buf[MAX_PKT_BURST];
const uint16_t buf_size = RTE_DIM(buf);
+ if (stats_requested && lcore_id == rte_get_main_lcore()) {
+ stats_requested = 0;
+ print_stats();
+ }
+
for (p = 0; p < num_ports; p++) {
const uint8_t sport = ports[p];
/* 0 <-> 1, 2 <-> 3 etc */
--
2.53.0
More information about the dev
mailing list