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 0F447A0542; Thu, 10 Nov 2022 17:54:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFDB540151; Thu, 10 Nov 2022 17:54:05 +0100 (CET) Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by mails.dpdk.org (Postfix) with ESMTP id D85EF40150 for ; Thu, 10 Nov 2022 17:54:03 +0100 (CET) Received: by mail-pj1-f42.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso5189464pjg.5 for ; Thu, 10 Nov 2022 08:54:03 -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=uQpW+v/2HTN/tpefU36tGkIHEZ5WSpn7Ml1KQhwoapA=; b=IKVoBiJC/A4sDDGHNfFTSOmv26QZDLSkdgj8/pIQzlkbGOm9FPxD/2Y9rdrIfaLTmi zQjhahbPr2BMWHCcI6T1sm7epuY8bXH6MolLscVBatIIH74ifUFtC6zS+jFtvKlczRAu vnqov6HeBSYRBr5pG1EpjawqN/tnMizWQOnuC3ZpenB5ohqy3m35us0yB2vVzPn1jwMl 8ei+VncbefNTIfMzB2VgwG54n8YeTLFmRJl6VeqjXQ/lTyqpuxExETxPmr8oTPYQ5MBe 4RPAjXq3th3YNrTxKmbTOwEMsMS86JfmlmHWGtFjJ+DVUFAZK+9pajR3sUgWk8nnlrWx wbsQ== 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=uQpW+v/2HTN/tpefU36tGkIHEZ5WSpn7Ml1KQhwoapA=; b=rFRNhUz12ca94Cb+bqg+duRtah7jdPATDkU2FptVclR3KadUijKdnsRu9kbqbHnawQ cda0cd6h1DjA9DE1tS+Dmvk4w5BE2OxgSLY6wLcep0grapjnc+ZLodS1+nUHkvBY+mOL 2b/65Z6FKkH+M4WLJlYbqmAVvK2n8Or0QAJ1qwVm9QcVXguU4Yg2mf3wQlVMrjpuWXGL i2aP0E5RvyUDMWKGqoEmVMSQKGtbxAeE95s21Dgdz/jsurVrzv7OLDRzcDO5Jdu/Tc8N UZDUphkWJjV9cbPX0SeTEHSF1Oi12NwnPYQPHTz8ObNJiiyj1eYTEcDx+kGihafqm+bf cQxQ== X-Gm-Message-State: ACrzQf1T+ZkQJp9RahJ4LPDnAZ/EBzcM9MaQGravYC6THHPAy9TvLvJi 9MTiPWEcQEAYMWU5xoi0RSCmd43KcCz73A== X-Google-Smtp-Source: AMsMyM41lHI9R9h7Dgxn90vPhhXKaaS+jo1KmvAme8iUf6R60SXP39JiVMgoMXsRVLQHkN7Ec3g7nQ== X-Received: by 2002:a17:902:e00c:b0:186:f9d4:3ff8 with SMTP id o12-20020a170902e00c00b00186f9d43ff8mr1527939plo.47.1668099242711; Thu, 10 Nov 2022 08:54:02 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id b16-20020a170902d51000b0017a0f40fa19sm11537839plg.191.2022.11.10.08.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 08:54:01 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh , Yuying Zhang , Phil Yang , Jianbo Liu Subject: [PATCH v6] testpmd: cleanup cleanly from signal Date: Thu, 10 Nov 2022 08:53:59 -0800 Message-Id: <20221110165359.343010-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 - drop unnecessary print in signal handler. don't cleanup twice don't print message when select() is interrupted. app/test-pmd/testpmd.c | 72 ++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index cf5942d0c422..62d87f758ac8 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,41 @@ main(int argc, char** argv) prev_time = cur_time; rte_delay_us_sleep(US_PER_S); } - } + } else { + char c; + fd_set fds; + int rc; - printf("Press enter to exit\n"); - rc = read(0, &c, 1); - pmd_test_exit(); - if (rc < 0) - return 1; + printf("Press enter to exit\n"); + + FD_ZERO(&fds); + FD_SET(0, &fds); + + rc = select(1, &fds, NULL, NULL, NULL); + if (rc < 0 && errno != EINTR) { + fprintf(stderr, "Select failed: %s\n", + strerror(errno)); + return 1; + } + if (rc > 0) + rc = read(0, &c, 1); + + pmd_test_exit(); + if (rc < 0) + return 1; + prompt_exit(); + } } +#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