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 6D71CA0547; Fri, 11 Nov 2022 17:51:37 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 231E24014F; Fri, 11 Nov 2022 17:51:37 +0100 (CET) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id CF47440141 for ; Fri, 11 Nov 2022 17:51:35 +0100 (CET) Received: by mail-pf1-f173.google.com with SMTP id k15so5373164pfg.2 for ; Fri, 11 Nov 2022 08:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qJvXkNJTghKQdgQPsRxbkompizGS7vwecocgRYyyEWM=; b=wBLO+Q7Ul0TY3jugPO6/tNqbWrdjWrOzOuxQVa8uoe/FjNE+Wh+qLXGgTwAc6R3eMF 7UIoegHkjv+OkjKuuwqU6aIIGqQVdPo9J8P6KQzzWoLftikbXjPVlGVA+wNeJLHP8wFS vfQ3dCuXQBCCqWCPmlpcpLQo7w5YH901auaHAvMgGo/5Ys0bzI5tY4UoE7M2/MbomSeo GLygok35cf7e0uRChTQAwQawBnxfCT6TTXij0ayY1wwd7hkpW7EGyNsv2Da8yFxUSAnv UkrhJnpAVqzlQFQepJvpiKl1lp6HBCUvMF57LUqitVghsEtMywaGlmQWIrSIrW9nax87 a8sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qJvXkNJTghKQdgQPsRxbkompizGS7vwecocgRYyyEWM=; b=W5GaULWZlz92Bcdt7HAcbeVeilsU9vdRoD/Su0jxbi7+rncx6VY/fFuuA2JyXsCkWd hxN/DRQ056Dnwtz+ihpw3semAxSsC0GoGc+yAnFBkYMUTUT7zmeoylqwdwv/US+r5BXN /HgohE5egdaDE4lD4GkRWYJjutbe7s83jjbfDiF0Ek76oMbG2VQeoUbkCN1Ls+8tfH1t clYXIn0SnKxyDnfORdbd1ghB2r4pF5ONbITPuxBzWZCV81pG9oKMtYPIYeWa+oLxsSsO yzxmboRLmEmLbLZ57LqQtwfGM5U7bpl2u+7G5JLQMht04t50hZfLP6Lv+01w4NiZZC/g lpWA== X-Gm-Message-State: ANoB5pmVaiGX5NeDQ3cdvTx35zvORZ6xyX7UqVZbkibB19DDygEefOkF iG+CJw9lWL3SknFI2W/G/xTUj0lG6sP+QQ== X-Google-Smtp-Source: AA0mqf6Y2hxb+ct+2jQ8RODWcs6cXihi/KL64hO18XrrlP3VFSBT29AU81+nnabYLmOOFMVEdskiFw== X-Received: by 2002:a05:6a00:1bce:b0:56d:dd2a:f6b6 with SMTP id o14-20020a056a001bce00b0056ddd2af6b6mr3460585pfw.30.1668185494692; Fri, 11 Nov 2022 08:51:34 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g10-20020a1709026b4a00b0018853dd8832sm1973654plt.4.2022.11.11.08.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 08:51:33 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh , Yuying Zhang , Jianbo Liu , Phil Yang Subject: [PATCH v7] testpmd: cleanup cleanly from signal Date: Fri, 11 Nov 2022 08:51:31 -0800 Message-Id: <20221111165132.65493-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172328.185219-2-stephen@networkplumber.org> References: <20221014172328.185219-2-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Do a clean shutdown of testpmd when a signal is received; instead of having testpmd kill itself. This fixes the problem where a signal could be received in the middle of a PMD and then the signal handler would call PMD's close routine leading to locking problems. An added benefit is it gets rid of some Windows specific code. Fixes: d9a191a00e81 ("app/testpmd: fix quitting in container") Signed-off-by: Stephen Hemminger --- v5 - fix windows build v6 - drop unneeded prprint in signal handler v7 - cleanup logic around exiting, use rte_exit() for read/select errors app/test-pmd/testpmd.c | 67 +++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index cf5942d0c422..c012f9edbc99 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -11,6 +11,7 @@ #include #ifndef RTE_EXEC_ENV_WINDOWS #include +#include #endif #include #include @@ -4224,13 +4225,6 @@ init_port(void) memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS); } -static void -force_quit(void) -{ - pmd_test_exit(); - prompt_exit(); -} - static void print_stats(void) { @@ -4249,28 +4243,9 @@ print_stats(void) } static void -signal_handler(int signum) +signal_handler(int signum __rte_unused) { - if (signum == SIGINT || signum == SIGTERM) { - fprintf(stderr, "\nSignal %d received, preparing to exit...\n", - signum); -#ifdef RTE_LIB_PDUMP - /* uninitialize packet capture framework */ - rte_pdump_uninit(); -#endif -#ifdef RTE_LIB_LATENCYSTATS - if (latencystats_enabled != 0) - rte_latencystats_uninit(); -#endif - force_quit(); - /* Set flag to indicate the force termination. */ - f_quit = 1; - /* exit with the expected status */ -#ifndef RTE_EXEC_ENV_WINDOWS - signal(signum, SIG_DFL); - kill(getpid(), signum); -#endif - } + f_quit = 1; } int @@ -4449,9 +4424,6 @@ main(int argc, char** argv) } else #endif { - char c; - int rc; - f_quit = 0; printf("No commandline core given, start packet forwarding\n"); @@ -4476,15 +4448,38 @@ main(int argc, char** argv) prev_time = cur_time; rte_delay_us_sleep(US_PER_S); } - } + } else { + char c; + fd_set fds; + + printf("Press enter to exit\n"); + + FD_ZERO(&fds); + FD_SET(STDIN_FILENO, &fds); - printf("Press enter to exit\n"); - rc = read(0, &c, 1); + ret = select(1, &fds, NULL, NULL, NULL); + if (ret < 0 && errno != EINTR) + rte_exit(EXIT_FAILURE, + "Select failed: %s\n", + strerror(errno)); + + if (ret == 1 && read(STDIN_FILENO, &c, 1) < 0) + rte_exit(EXIT_FAILURE, + "Read failed: %s\n", + strerror(errno)); + } pmd_test_exit(); - if (rc < 0) - return 1; } +#ifdef RTE_LIB_PDUMP + /* uninitialize packet capture framework */ + rte_pdump_uninit(); +#endif +#ifdef RTE_LIB_LATENCYSTATS + if (latencystats_enabled != 0) + rte_latencystats_uninit(); +#endif + ret = rte_eal_cleanup(); if (ret != 0) rte_exit(EXIT_FAILURE, -- 2.35.1