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 AD8FC41BC0; Fri, 3 Feb 2023 20:14:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 84C6C42D53; Fri, 3 Feb 2023 20:14:19 +0100 (CET) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mails.dpdk.org (Postfix) with ESMTP id CC24D42D3E for ; Fri, 3 Feb 2023 20:14:16 +0100 (CET) Received: by mail-pf1-f170.google.com with SMTP id g9so4427056pfo.5 for ; Fri, 03 Feb 2023 11:14:16 -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=FSIpXz6ccDOj1KJMDpyNL/FnhxQqTiqUnXdZxwWspoA=; b=puikDrxjbu/Ohgy3+8Cau5eJX3nqYki5mK8BvJyCfTANoz3m3a7gIlYaVujDR0/98f 2K78hBHiUiWahlkQn6jnoVy54fdOpJo33S+0WT3OSzJACwCSiCav52SRsffyT06+2nsg B5hwylyybEa+li9assiRxjmwreP8JMvu6t2MtcxIYui7LFlVr7ZIMjlTaZTh8KxVGpGx mxevVUHNn8W3ytB+Zs58g+OBcAxGdDDFgHYcuYkpb4qE/TS2GyJrkm1X+WMuAFbcwghh ztbYSRN2shrgeOqGldRIaYfgGXhtddX901aaavGWkNCKTgWEU7PdYgjHDLAwPhr+L2VV JbXg== 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=FSIpXz6ccDOj1KJMDpyNL/FnhxQqTiqUnXdZxwWspoA=; b=jT6UDvhGKBQ0z83OMPR+OlvgnvTJvVFQnSiRCYR/yeWKkETLMQQLPM4/e4OU88C8a5 EuF3+tzWiWT0JprhVN5cKKzz147F0pxqpkfh7fK0wAj4IxdV9slV1SL0GgQLG/xfritD gmm4rvjKyqpfg5hVx4t0fXtBCPazrNU6XLnwadNmdvzTRF/IXQNs/zZPIdUCqQebquuN vQkuhBT1rX8nVqKPsBB1poha+4ctBdhTdTt1erT1bS2HYjU8BOEJjYLQYUslyLOWuLxi SYHe6ahIFyk/AKQ1WGvrUp5Hh8E+nqmrEIi9bwfCVr2mJw4EaKLtl1SVwnq1spbuojZr ParQ== X-Gm-Message-State: AO0yUKWgmUeRaLVVlX2Zct6ienXdh0q8/VD+gIllVarxTIyTsMA2ipxh EtvHu0Ctyb5bERMJOsK8W+QdnPIcWOLxYVUreyD3IA== X-Google-Smtp-Source: AK7set+2J4DcOCPsB4zEWNN2bCkex++9Kku9ElQ7vapjzuaqU6L257FHEbpT2Do0lQGcXs/tcTlMZA== X-Received: by 2002:a62:388e:0:b0:590:6a57:9901 with SMTP id f136-20020a62388e000000b005906a579901mr9136820pfa.18.1675451655598; Fri, 03 Feb 2023 11:14:15 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id l9-20020a056a00140900b00593edee1af6sm2200898pfu.67.2023.02.03.11.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:14:15 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: stable@dpdk.org, Stephen Hemminger Subject: [PATCH v11 3/3] testpmd: cleanup cleanly from signal Date: Fri, 3 Feb 2023 11:14:09 -0800 Message-Id: <20230203191409.97567-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230203191409.97567-1-stephen@networkplumber.org> References: <20230130200914.22049-1-stephen@networkplumber.org> <20230203191409.97567-1-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. The cmdline structure no longer needs to be global it can just be local to the prompt() function. 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 --- app/test-pmd/cmdline.c | 29 ++++++---------- app/test-pmd/testpmd.c | 77 ++++++++++++++++++++---------------------- app/test-pmd/testpmd.h | 1 + 3 files changed, 48 insertions(+), 59 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index cb8c174020b0..135c5c439bfc 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -66,7 +66,6 @@ #include "cmdline_tm.h" #include "bpf_cmd.h" -static struct cmdline *testpmd_cl; static cmdline_parse_ctx_t *main_ctx; static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head = TAILQ_HEAD_INITIALIZER(driver_commands_head); @@ -12936,28 +12935,22 @@ cmdline_read_from_file(const char *filename) void prompt(void) { - int ret; + struct cmdline *cl; - testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); - if (testpmd_cl == NULL) + cl = cmdline_stdin_new(main_ctx, "testpmd> "); + if (cl == NULL) return; - ret = atexit(prompt_exit); - if (ret != 0) - fprintf(stderr, "Cannot set exit function for cmdline\n"); - - cmdline_interact(testpmd_cl); - if (ret != 0) - cmdline_stdin_exit(testpmd_cl); -} + /* loop until signal or quit command */ + while (f_quit == 0 && cl_quit == 0) { + int status = cmdline_poll(cl); -void -prompt_exit(void) -{ - if (testpmd_cl != NULL) { - cmdline_quit(testpmd_cl); - cmdline_stdin_exit(testpmd_cl); + if (status < 0 || status == RDLINE_EXITED) + break; } + + cmdline_quit(cl); + cmdline_stdin_exit(cl); } void diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index e366f81a0f46..60eb9579ded1 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 @@ -231,7 +232,7 @@ unsigned int xstats_display_num; /**< Size of extended statistics to show */ * In container, it cannot terminate the process which running with 'stats-period' * option. Set flag to exit stats period loop after received SIGINT/SIGTERM. */ -static volatile uint8_t f_quit; +volatile uint8_t f_quit; uint8_t cl_quit; /* Quit testpmd from cmdline. */ /* @@ -4315,13 +4316,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) { @@ -4340,28 +4334,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 @@ -4541,15 +4516,9 @@ main(int argc, char** argv) start_packet_forwarding(0); } prompt(); - pmd_test_exit(); } else #endif { - char c; - int rc; - - f_quit = 0; - printf("No commandline core given, start packet forwarding\n"); start_packet_forwarding(tx_first); if (stats_period != 0) { @@ -4572,15 +4541,41 @@ 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"); - printf("Press enter to exit\n"); - rc = read(0, &c, 1); - pmd_test_exit(); - if (rc < 0) - return 1; + FD_ZERO(&fds); + FD_SET(0, &fds); + + /* wait for signal or enter */ + ret = select(1, &fds, NULL, NULL, NULL); + if (ret < 0 && errno != EINTR) + rte_exit(EXIT_FAILURE, + "Select failed: %s\n", + strerror(errno)); + + /* if got enter then consume it */ + if (ret == 1 && read(0, &c, 1) < 0) + rte_exit(EXIT_FAILURE, + "Read failed: %s\n", + strerror(errno)); + } } + pmd_test_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, diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 7d24d25970d2..022210a7a964 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -34,6 +34,7 @@ #define RTE_PORT_HANDLING (uint16_t)3 extern uint8_t cl_quit; +extern volatile uint8_t f_quit; /* * It is used to allocate the memory for hash key. -- 2.39.0