Ping. > -----Original Message----- > From: Rahul Bhansali <rbhans...@marvell.com> > Sent: Wednesday, August 31, 2022 12:19 PM > To: dev@dpdk.org; Kirill Rybalchenko <kirill.rybalche...@intel.com> > Cc: Rahul Bhansali <rbhans...@marvell.com> > Subject: [PATCH] examples/ptpclient: add signal handler for cleanup > > 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 <rbhans...@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