examples/ptpclient: add signal handler for cleanup

Message ID 20220831064925.2580881-1-rbhansali@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series examples/ptpclient: add signal handler for cleanup |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed

Commit Message

Rahul Bhansali Aug. 31, 2022, 6:49 a.m. UTC
  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(-)
  

Comments

Rahul Bhansali Nov. 2, 2022, 4:51 p.m. UTC | #1
Ping.

> -----Original Message-----
> From: Rahul Bhansali <rbhansali@marvell.com>
> Sent: Wednesday, August 31, 2022 12:19 PM
> To: dev@dpdk.org; Kirill Rybalchenko <kirill.rybalchenko@intel.com>
> Cc: Rahul Bhansali <rbhansali@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 <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
  
Rahul Bhansali Jan. 20, 2023, 5:56 a.m. UTC | #2
Ping.

> -----Original Message-----
> From: Rahul Bhansali
> Sent: Wednesday, November 2, 2022 10:21 PM
> To: dev@dpdk.org; Kirill Rybalchenko <kirill.rybalchenko@intel.com>
> Subject: RE: [PATCH] examples/ptpclient: add signal handler for cleanup
> 
> Ping.
> 
> > -----Original Message-----
> > From: Rahul Bhansali <rbhansali@marvell.com>
> > Sent: Wednesday, August 31, 2022 12:19 PM
> > To: dev@dpdk.org; Kirill Rybalchenko <kirill.rybalchenko@intel.com>
> > Cc: Rahul Bhansali <rbhansali@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 <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
  
Rahul Bhansali May 15, 2023, 10:59 a.m. UTC | #3
Ping.

> -----Original Message-----
> From: Rahul Bhansali
> Sent: Friday, January 20, 2023 11:26 AM
> To: 'dev@dpdk.org' <dev@dpdk.org>; 'Kirill Rybalchenko'
> <kirill.rybalchenko@intel.com>
> Subject: RE: [PATCH] examples/ptpclient: add signal handler for cleanup
> 
> Ping.
> 
> > -----Original Message-----
> > From: Rahul Bhansali
> > Sent: Wednesday, November 2, 2022 10:21 PM
> > To: dev@dpdk.org; Kirill Rybalchenko <kirill.rybalchenko@intel.com>
> > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > cleanup
> >
> > Ping.
> >
> > > -----Original Message-----
> > > From: Rahul Bhansali <rbhansali@marvell.com>
> > > Sent: Wednesday, August 31, 2022 12:19 PM
> > > To: dev@dpdk.org; Kirill Rybalchenko <kirill.rybalchenko@intel.com>
> > > Cc: Rahul Bhansali <rbhansali@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 <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
  
Rahul Bhansali May 30, 2023, 9 a.m. UTC | #4
Hi Kirill,

This patch is pending for review from long time.
Please do let me know if any comments on this patch, else will request to merge it.

Regards,
Rahul

> -----Original Message-----
> From: Rahul Bhansali
> Sent: Monday, May 15, 2023 4:29 PM
> To: 'Kirill Rybalchenko' <kirill.rybalchenko@intel.com>; Thomas Monjalon
> <thomas@monjalon.net>
> Cc: 'dev@dpdk.org' <dev@dpdk.org>
> Subject: RE: [PATCH] examples/ptpclient: add signal handler for cleanup
> 
> Ping.
> 
> > -----Original Message-----
> > From: Rahul Bhansali
> > Sent: Friday, January 20, 2023 11:26 AM
> > To: 'dev@dpdk.org' <dev@dpdk.org>; 'Kirill Rybalchenko'
> > <kirill.rybalchenko@intel.com>
> > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > cleanup
> >
> > Ping.
> >
> > > -----Original Message-----
> > > From: Rahul Bhansali
> > > Sent: Wednesday, November 2, 2022 10:21 PM
> > > To: dev@dpdk.org; Kirill Rybalchenko <kirill.rybalchenko@intel.com>
> > > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > > cleanup
> > >
> > > Ping.
> > >
> > > > -----Original Message-----
> > > > From: Rahul Bhansali <rbhansali@marvell.com>
> > > > Sent: Wednesday, August 31, 2022 12:19 PM
> > > > To: dev@dpdk.org; Kirill Rybalchenko
> > > > <kirill.rybalchenko@intel.com>
> > > > Cc: Rahul Bhansali <rbhansali@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 <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
  
Rahul Bhansali June 16, 2023, 4:58 a.m. UTC | #5
Hi Thomas,

This is pending from long time and no comments so far. Can you please check and accept this ?
Let me know if you have any review comments.

Regard,
Rahul

> -----Original Message-----
> From: Rahul Bhansali
> Sent: Tuesday, May 30, 2023 2:30 PM
> To: 'Kirill Rybalchenko' <kirill.rybalchenko@intel.com>; 'Thomas Monjalon'
> <thomas@monjalon.net>
> Cc: 'dev@dpdk.org' <dev@dpdk.org>
> Subject: RE: [PATCH] examples/ptpclient: add signal handler for cleanup
> 
> Hi Kirill,
> 
> This patch is pending for review from long time.
> Please do let me know if any comments on this patch, else will request to merge
> it.
> 
> Regards,
> Rahul
> 
> > -----Original Message-----
> > From: Rahul Bhansali
> > Sent: Monday, May 15, 2023 4:29 PM
> > To: 'Kirill Rybalchenko' <kirill.rybalchenko@intel.com>; Thomas
> > Monjalon <thomas@monjalon.net>
> > Cc: 'dev@dpdk.org' <dev@dpdk.org>
> > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > cleanup
> >
> > Ping.
> >
> > > -----Original Message-----
> > > From: Rahul Bhansali
> > > Sent: Friday, January 20, 2023 11:26 AM
> > > To: 'dev@dpdk.org' <dev@dpdk.org>; 'Kirill Rybalchenko'
> > > <kirill.rybalchenko@intel.com>
> > > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > > cleanup
> > >
> > > Ping.
> > >
> > > > -----Original Message-----
> > > > From: Rahul Bhansali
> > > > Sent: Wednesday, November 2, 2022 10:21 PM
> > > > To: dev@dpdk.org; Kirill Rybalchenko
> > > > <kirill.rybalchenko@intel.com>
> > > > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > > > cleanup
> > > >
> > > > Ping.
> > > >
> > > > > -----Original Message-----
> > > > > From: Rahul Bhansali <rbhansali@marvell.com>
> > > > > Sent: Wednesday, August 31, 2022 12:19 PM
> > > > > To: dev@dpdk.org; Kirill Rybalchenko
> > > > > <kirill.rybalchenko@intel.com>
> > > > > Cc: Rahul Bhansali <rbhansali@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 <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
  
Rahul Bhansali Sept. 21, 2023, 2:08 p.m. UTC | #6
Hi Thomas,

Can you please check this and merge if no comments as this is waiting from long time ?

Regards,
Rahul

> -----Original Message-----
> From: Rahul Bhansali
> Sent: Friday, June 16, 2023 10:28 AM
> To: 'Thomas Monjalon' <thomas@monjalon.net>
> Cc: 'dev@dpdk.org' <dev@dpdk.org>; 'Kirill Rybalchenko'
> <kirill.rybalchenko@intel.com>
> Subject: RE: [PATCH] examples/ptpclient: add signal handler for cleanup
> 
> Hi Thomas,
> 
> This is pending from long time and no comments so far. Can you please check
> and accept this ?
> Let me know if you have any review comments.
> 
> Regard,
> Rahul
> 
> > -----Original Message-----
> > From: Rahul Bhansali
> > Sent: Tuesday, May 30, 2023 2:30 PM
> > To: 'Kirill Rybalchenko' <kirill.rybalchenko@intel.com>; 'Thomas Monjalon'
> > <thomas@monjalon.net>
> > Cc: 'dev@dpdk.org' <dev@dpdk.org>
> > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > cleanup
> >
> > Hi Kirill,
> >
> > This patch is pending for review from long time.
> > Please do let me know if any comments on this patch, else will request
> > to merge it.
> >
> > Regards,
> > Rahul
> >
> > > -----Original Message-----
> > > From: Rahul Bhansali
> > > Sent: Monday, May 15, 2023 4:29 PM
> > > To: 'Kirill Rybalchenko' <kirill.rybalchenko@intel.com>; Thomas
> > > Monjalon <thomas@monjalon.net>
> > > Cc: 'dev@dpdk.org' <dev@dpdk.org>
> > > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > > cleanup
> > >
> > > Ping.
> > >
> > > > -----Original Message-----
> > > > From: Rahul Bhansali
> > > > Sent: Friday, January 20, 2023 11:26 AM
> > > > To: 'dev@dpdk.org' <dev@dpdk.org>; 'Kirill Rybalchenko'
> > > > <kirill.rybalchenko@intel.com>
> > > > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > > > cleanup
> > > >
> > > > Ping.
> > > >
> > > > > -----Original Message-----
> > > > > From: Rahul Bhansali
> > > > > Sent: Wednesday, November 2, 2022 10:21 PM
> > > > > To: dev@dpdk.org; Kirill Rybalchenko
> > > > > <kirill.rybalchenko@intel.com>
> > > > > Subject: RE: [PATCH] examples/ptpclient: add signal handler for
> > > > > cleanup
> > > > >
> > > > > Ping.
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Rahul Bhansali <rbhansali@marvell.com>
> > > > > > Sent: Wednesday, August 31, 2022 12:19 PM
> > > > > > To: dev@dpdk.org; Kirill Rybalchenko
> > > > > > <kirill.rybalchenko@intel.com>
> > > > > > Cc: Rahul Bhansali <rbhansali@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 <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
  
Thomas Monjalon March 7, 2024, 9:17 a.m. UTC | #7
31/08/2022 08:49, 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>

Was waiting for review for a very long time.

Applied, thanks.

I suppose Kirill is not maintaining this example.
  
Stephen Hemminger March 7, 2024, 4:48 p.m. UTC | #8
On Wed, 31 Aug 2022 12:19:24 +0530
Rahul Bhansali <rbhansali@marvell.com> wrote:

> 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>

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  

Patch

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();