DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] examples/ptpclient: add signal handler for cleanup
@ 2022-08-31  6:49 Rahul Bhansali
  2022-11-02 16:51 ` Rahul Bhansali
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Rahul Bhansali @ 2022-08-31  6:49 UTC (permalink / raw)
  To: dev, Kirill Rybalchenko; +Cc: Rahul Bhansali

This adds the signal handler for SIGINT, SIGTERM.
Also, this will come out from infinite loop and do cleanup once it receives
any of the registered signal.

Signed-off-by: Rahul Bhansali <rbhansali@marvell.com>
---
 examples/ptpclient/ptpclient.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
index 1f1c9c9c52..8b69716be1 100644
--- a/examples/ptpclient/ptpclient.c
+++ b/examples/ptpclient/ptpclient.c
@@ -19,6 +19,9 @@
 #include <limits.h>
 #include <sys/time.h>
 #include <getopt.h>
+#include <signal.h>
+
+static volatile bool force_quit;
 
 #define RX_RING_SIZE 1024
 #define TX_RING_SIZE 1024
@@ -609,7 +612,7 @@ parse_ptp_frames(uint16_t portid, struct rte_mbuf *m) {
  * The lcore main. This is the main thread that does the work, reading from an
  * input port and writing to an output port.
  */
-static __rte_noreturn void
+static void
 lcore_main(void)
 {
 	uint16_t portid;
@@ -621,7 +624,7 @@ lcore_main(void)
 
 	/* Run until the application is quit or killed. */
 
-	while (1) {
+	while (!force_quit) {
 		/* Read packet from RX queues. 8< */
 		for (portid = 0; portid < ptp_enabled_port_nb; portid++) {
 
@@ -734,6 +737,13 @@ ptp_parse_args(int argc, char **argv)
 	return 0;
 }
 
+static void
+signal_handler(int signum)
+{
+	if (signum == SIGINT || signum == SIGTERM)
+		force_quit = true;
+}
+
 /*
  * The main function, which does initialization and calls the per-lcore
  * functions.
@@ -758,6 +768,10 @@ main(int argc, char *argv[])
 	argc -= ret;
 	argv += ret;
 
+	force_quit = false;
+	signal(SIGINT, signal_handler);
+	signal(SIGTERM, signal_handler);
+
 	ret = ptp_parse_args(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Error with PTP initialization\n");
@@ -802,6 +816,20 @@ main(int argc, char *argv[])
 	/* Call lcore_main on the main core only. */
 	lcore_main();
 
+	RTE_ETH_FOREACH_DEV(portid) {
+		if ((ptp_enabled_port_mask & (1 << portid)) == 0)
+			continue;
+
+		/* Disable timesync timestamping for the Ethernet device */
+		rte_eth_timesync_disable(portid);
+
+		ret = rte_eth_dev_stop(portid);
+		if (ret != 0)
+			printf("rte_eth_dev_stop: err=%d, port=%d\n", ret, portid);
+
+		rte_eth_dev_close(portid);
+	}
+
 	/* clean up the EAL */
 	rte_eal_cleanup();
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-07 16:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-31  6:49 [PATCH] examples/ptpclient: add signal handler for cleanup Rahul Bhansali
2022-11-02 16:51 ` Rahul Bhansali
2023-01-20  5:56   ` Rahul Bhansali
2023-05-15 10:59     ` Rahul Bhansali
2023-05-30  9:00       ` Rahul Bhansali
2023-06-16  4:58         ` Rahul Bhansali
2023-09-21 14:08           ` Rahul Bhansali
2024-03-07  9:17 ` Thomas Monjalon
2024-03-07 16:48 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).