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 489EB41EA5 for ; Wed, 15 Mar 2023 23:47:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4446542B7E; Wed, 15 Mar 2023 23:47:38 +0100 (CET) Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by mails.dpdk.org (Postfix) with ESMTP id 5150D40FDF for ; Wed, 15 Mar 2023 23:47:37 +0100 (CET) Received: by mail-wm1-f41.google.com with SMTP id m35so15796wms.4 for ; Wed, 15 Mar 2023 15:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678920457; 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=KaZOY3fOevrIhZAbjfeRb2S988XtddcfzRRnKRwTXs0=; b=NdgwUsA/8UllpadRmnUQA4PGLLeTEcU89uH88Sj23aQOsy1vUSJ7cc+124uY3nYkCV vTI2NluufzxzLF9MpHBym+wFDB/rxdF5DPqPWJKH2/HTtKPV94kPrKrwyylC5tCKSyyX FfG/j7izKjKMOsFmcEPCcM3qkkTBb+GzBDPwTHCH7ZiIQb8njs8VJDah2gtZ01sv5BkE oyQDFBO1UXumES1ZHsFJTk/rtfi90wR5w9HFLsCCdXPgUG9X1hWACFEHtYo1zR30cHz3 CACa8TznyEK7pbblhNOVPQoEEeiInZ24Bm6//ghWtjc8VHAjmfx6y8g8mABgvXcMc/Li ibAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678920457; 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=KaZOY3fOevrIhZAbjfeRb2S988XtddcfzRRnKRwTXs0=; b=uGqjls0UwKa7SGvneZ7J+EGxS5nLi0S4PMi/GYqPBA8AKIooD4SKC335It3lf9d5Dn jf+ihh8Kugg1vA8k9kAp5rx9vxLdwbR2bpTEroUGzsZEL/+tFNrYEgWUWSnLwFrqRpua Ca6MwY1zZDrlmYG59iQuRcQ0k7PGPEaMLMM0eOu6NBqc4fP/kKNn5lKILlEPVFuFlKiS dXEFGnMq7LdsQGrlFihBO4gCpD1S9hFMcIv9KEUkCB2+kn6grQHMwFZOxVgYuKRcTBXY eQLKx5Xz6QzFunz+2J0EaG07aS3aekW3PPtIH0aLMoNdSol8FmGnjx4MytenaakI7wsg REgw== X-Gm-Message-State: AO0yUKWAKiRmbE0gbQ+F/x/goTkOVrLY88UnO51FnY2XMI0qrbHLLmZ7 zsKsJgEt9CllwmhYivi9uYrws9ljDwLhmw== X-Google-Smtp-Source: AK7set+qZMpv2Je4uwXKBXGQRqO0MD6A5HEmm4K0T4LaH4W33v5kOfcNRjGqWa+mTD+gB6Z5u9068w== X-Received: by 2002:a05:600c:4453:b0:3eb:389d:156c with SMTP id v19-20020a05600c445300b003eb389d156cmr20262237wmn.37.1678920457019; Wed, 15 Mar 2023 15:47:37 -0700 (PDT) Received: from localhost ([137.220.119.58]) by smtp.gmail.com with ESMTPSA id d12-20020a056000114c00b002c6d0462163sm5686473wrx.100.2023.03.15.15.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 15:47:36 -0700 (PDT) From: luca.boccassi@gmail.com To: Stephen Hemminger Cc: Ferruh Yigit , dpdk stable Subject: patch 'app/testpmd: cleanup cleanly from signal' has been queued to stable release 20.11.8 Date: Wed, 15 Mar 2023 22:46:14 +0000 Message-Id: <20230315224631.1025649-23-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230315224631.1025649-1-luca.boccassi@gmail.com> References: <20230223093715.3926893-71-luca.boccassi@gmail.com> <20230315224631.1025649-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 20.11.8 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 03/17/23. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/c7154a7ed76d661a44b7d7948b4adce6810bfe45 Thanks. Luca Boccassi --- >From c7154a7ed76d661a44b7d7948b4adce6810bfe45 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 3 Feb 2023 11:14:09 -0800 Subject: [PATCH] app/testpmd: cleanup cleanly from signal [ upstream commit 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff ] 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 Acked-by: Ferruh Yigit --- app/test-pmd/cmdline.c | 30 +++++++---------- app/test-pmd/testpmd.c | 75 ++++++++++++++++++++---------------------- app/test-pmd/testpmd.h | 1 + 3 files changed, 48 insertions(+), 58 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 9f46570cc4..8a7300bcf9 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -71,8 +71,6 @@ #include "cmdline_tm.h" #include "bpf_cmd.h" -static struct cmdline *testpmd_cl; - static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); /* *** Help command with introduction. *** */ @@ -17199,31 +17197,25 @@ cmdline_read_from_file(const char *filename) void prompt(void) { - int ret; + struct cmdline *cl; /* initialize non-constant commands */ cmd_set_fwd_mode_init(); cmd_set_fwd_retry_mode_init(); - 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) - printf("Cannot set exit function for cmdline\n"); + /* loop until signal or quit command */ + while (f_quit == 0 && cl_quit == 0) { + int status = cmdline_poll(cl); - cmdline_interact(testpmd_cl); - if (ret != 0) - cmdline_stdin_exit(testpmd_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); } static void diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index f22c05920f..a061e10385 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -216,7 +217,7 @@ uint16_t stats_period; /**< Period to show statistics (disabled by default) */ * 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. */ /* @@ -3826,13 +3827,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) { @@ -3851,26 +3845,9 @@ print_stats(void) } static void -signal_handler(int signum) +signal_handler(int signum __rte_unused) { - if (signum == SIGINT || signum == SIGTERM) { - printf("\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 */ - signal(signum, SIG_DFL); - kill(getpid(), signum); - } + f_quit = 1; } int @@ -4044,15 +4021,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) { @@ -4075,15 +4046,41 @@ main(int argc, char** argv) prev_time = cur_time; sleep(1); } + } else { + char c; + fd_set fds; + + printf("Press enter to exit\n"); + + 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)); } - - printf("Press enter to exit\n"); - rc = read(0, &c, 1); - pmd_test_exit(); - if (rc < 0) - return 1; } + 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 76c2c55981..4ca1d59f09 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -25,6 +25,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.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-03-15 22:44:50.950021147 +0000 +++ 0023-app-testpmd-cleanup-cleanly-from-signal.patch 2023-03-15 22:44:49.615850932 +0000 @@ -1 +1 @@ -From 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff Mon Sep 17 00:00:00 2001 +From c7154a7ed76d661a44b7d7948b4adce6810bfe45 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff ] + @@ -17 +18,0 @@ -Cc: stable@dpdk.org @@ -22,2 +23,2 @@ - app/test-pmd/cmdline.c | 29 ++++++---------- - app/test-pmd/testpmd.c | 77 ++++++++++++++++++++---------------------- + app/test-pmd/cmdline.c | 30 +++++++---------- + app/test-pmd/testpmd.c | 75 ++++++++++++++++++++---------------------- @@ -25 +26 @@ - 3 files changed, 48 insertions(+), 59 deletions(-) + 3 files changed, 48 insertions(+), 58 deletions(-) @@ -28 +29 @@ -index 02c72d06b7..6fa870dc32 100644 +index 9f46570cc4..8a7300bcf9 100644 @@ -31 +32 @@ -@@ -66,7 +66,6 @@ +@@ -71,8 +71,6 @@ @@ -36,4 +37,5 @@ - static cmdline_parse_ctx_t *main_ctx; - static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head = - TAILQ_HEAD_INITIALIZER(driver_commands_head); -@@ -13033,28 +13032,22 @@ cmdline_read_from_file(const char *filename) +- + static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); + + /* *** Help command with introduction. *** */ +@@ -17199,31 +17197,25 @@ cmdline_read_from_file(const char *filename) @@ -44,0 +47,3 @@ + /* initialize non-constant commands */ + cmd_set_fwd_mode_init(); + cmd_set_fwd_retry_mode_init(); @@ -54 +59 @@ -- fprintf(stderr, "Cannot set exit function for cmdline\n"); +- printf("Cannot set exit function for cmdline\n"); @@ -78 +83 @@ - void + static void @@ -80 +85 @@ -index 0032696608..2ce19ed47a 100644 +index f22c05920f..a061e10385 100644 @@ -83 +88,2 @@ -@@ -11,6 +11,7 @@ +@@ -10,6 +10,7 @@ + #include @@ -85 +90,0 @@ - #ifndef RTE_EXEC_ENV_WINDOWS @@ -88 +92,0 @@ - #endif @@ -91 +95,2 @@ -@@ -231,7 +232,7 @@ unsigned int xstats_display_num; /**< Size of extended statistics to show */ + #include +@@ -216,7 +217,7 @@ uint16_t stats_period; /**< Period to show statistics (disabled by default) */ @@ -100 +105 @@ -@@ -4447,13 +4448,6 @@ init_port(void) +@@ -3826,13 +3827,6 @@ init_port(void) @@ -114 +119 @@ -@@ -4472,28 +4466,9 @@ print_stats(void) +@@ -3851,26 +3845,9 @@ print_stats(void) @@ -122,2 +127,2 @@ -- fprintf(stderr, "\nSignal %d received, preparing to exit...\n", -- signum); +- printf("\nSignal %d received, preparing to exit...\n", +- signum); @@ -136 +140,0 @@ --#ifndef RTE_EXEC_ENV_WINDOWS @@ -139 +142,0 @@ --#endif @@ -145 +148 @@ -@@ -4677,15 +4652,9 @@ main(int argc, char** argv) +@@ -4044,15 +4021,9 @@ main(int argc, char** argv) @@ -161 +164 @@ -@@ -4708,15 +4677,41 @@ main(int argc, char** argv) +@@ -4075,15 +4046,41 @@ main(int argc, char** argv) @@ -163 +166 @@ - rte_delay_us_sleep(US_PER_S); + sleep(1); @@ -210 +213 @@ -index b9215720b6..bdfbfd36d3 100644 +index 76c2c55981..4ca1d59f09 100644 @@ -213 +216 @@ -@@ -34,6 +34,7 @@ +@@ -25,6 +25,7 @@