DPDK patches and discussions
 help / color / mirror / Atom feed
From: Rahul Bhansali <rbhansali@marvell.com>
To: "dev@dpdk.org" <dev@dpdk.org>,
	Kirill Rybalchenko <kirill.rybalchenko@intel.com>
Subject: RE: [PATCH] examples/ptpclient: add signal handler for cleanup
Date: Wed, 2 Nov 2022 16:51:11 +0000	[thread overview]
Message-ID: <CO6PR18MB384489D699D469E92F92CC24B8399@CO6PR18MB3844.namprd18.prod.outlook.com> (raw)
In-Reply-To: <20220831064925.2580881-1-rbhansali@marvell.com>

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


  reply	other threads:[~2022-11-02 16:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31  6:49 Rahul Bhansali
2022-11-02 16:51 ` Rahul Bhansali [this message]
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

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=CO6PR18MB384489D699D469E92F92CC24B8399@CO6PR18MB3844.namprd18.prod.outlook.com \
    --to=rbhansali@marvell.com \
    --cc=dev@dpdk.org \
    --cc=kirill.rybalchenko@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).