From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3FDD4A00C5; Wed, 31 Aug 2022 08:49:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 23EBB40395; Wed, 31 Aug 2022 08:49:41 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id D518C400D6 for ; Wed, 31 Aug 2022 08:49:38 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27UKj9pM023791; Tue, 30 Aug 2022 23:49:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=iurOZYkAekggymnP1IDtnYm7SZ7HASoQTl5nuon9Sxg=; b=bjq755EUteFTQiM63lP0AOi7x86XQTkS0zLMvkj3rAOvrs0pL+q/CxoL9/UXS0rfqeQr F+6oeuisBI3Eo6ivj/n57qeMYyGigVCY+6HfF99M0s4ZS/1E+bAOxQgdqS8JP+yDJYZf g4eExLuyTMMIP7RC5mHcsQtDUgc1evNij0O2gIbNI5ajg+Ko+ZBR5012/as1gPJF0FOq cIir/hlReGiOOGAOZj+/cQen7Z8/KCMjXyrMHNbu7MfAxHd+fZvHgYvYi2zisiZqAGLv iTAYUD+zGpOG+RKFu7EradRaP8+9yHWlnv0QrFUOeH5M52r4KR/tCPCGukmFA0I9aZP/ jg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3j9sv4a906-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 30 Aug 2022 23:49:36 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 30 Aug 2022 23:49:34 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 30 Aug 2022 23:49:34 -0700 Received: from localhost.localdomain (unknown [10.28.36.158]) by maili.marvell.com (Postfix) with ESMTP id 794473F705B; Tue, 30 Aug 2022 23:49:33 -0700 (PDT) From: Rahul Bhansali To: , Kirill Rybalchenko CC: Rahul Bhansali Subject: [PATCH] examples/ptpclient: add signal handler for cleanup Date: Wed, 31 Aug 2022 12:19:24 +0530 Message-ID: <20220831064925.2580881-1-rbhansali@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: Ss-Kvo3mQ3-wWswtCjZpFpKOPxc3gj2e X-Proofpoint-GUID: Ss-Kvo3mQ3-wWswtCjZpFpKOPxc3gj2e X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-31_03,2022-08-31_01,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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 #include #include +#include + +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