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 1F2F342800 for ; Wed, 22 Mar 2023 01:42:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1769A42B7E; Wed, 22 Mar 2023 01:42:16 +0100 (CET) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by mails.dpdk.org (Postfix) with ESMTP id 91C1F427F2 for ; Wed, 22 Mar 2023 01:42:14 +0100 (CET) Received: by mail-wm1-f45.google.com with SMTP id p13-20020a05600c358d00b003ed346d4522so10479758wmq.2 for ; Tue, 21 Mar 2023 17:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679445734; 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=N3KUGcbH1U5NDP+yhlkw/nssFyKzyLn6EKaWbyBvfQI=; b=gn3E+IDwaBM+Ww8n/W/H6UiPyz1r7skK7VjpYE+KgoIuTLp+/PC2LjB+uDIf2qWyYn l7acvW1VYtZbDOoXADRStWVsMDRAzPWiJdTJLloXQ9jR0csFk8RoJ4tYQWBDMWioPGnR RhOEN1pjcwj/wJzMpzhIkDZ8sfZBo0emA/Fw4wacotFtQCqDaFIuTsxFLHogGVKgF0uZ HIa4of87jGBoPk3jnbEK+Nsq3uLMtNXkuUsiyYzCOA1OuJbY/h8Y6ze46GNFPput/0ZR ZwCzKT2Wz+NP8GPr3XLs44nSX8lYE/+49Hj6lq6o90Y9N9iLukP6tAOXnFdM12V/49DD P70g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679445734; 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=N3KUGcbH1U5NDP+yhlkw/nssFyKzyLn6EKaWbyBvfQI=; b=xLv7/I/WoohMgk6rOKHdhQ6D0cBxq5Xg1ZnUvb7Q8DruO0awG9WRvyyAQr66shFeV4 0j/14QXOZr08zDGNAvnlN3ZMFJMeWoe6DwaD3WbR3IR4RLT9b/PcxmA2bNdFlgwl2q+W sLWMm8I7mYci+5BVRdgMyQTPU9f9uK8DGjFMf5Ayf0EO36C7F6GHJ0DCm3xXFujkJ1rU wSYwtn8bCnOui9ryf3RBisqY+JU3bUb3PgQkupAJNE/ePj/8fvFF86yQpxzcCa1iqr/1 +kNoJiFlg19DGdmJL7NVDGeG9Fh4ST+FENBCW7nu5MKXJl/oMcqIK4dq1R0WNWZFPOkh 7bPQ== X-Gm-Message-State: AO0yUKXDwo5L1f7LcKu4ZS6VKFMNSJT27ojx1SbGsP4G49gnOj8aOMkf K9vvIZgoLH9e83XgtIO4vVs= X-Google-Smtp-Source: AK7set/r9ZBkwkWQpqhAkePbkonE7mcNBrNDuciW8fFYzQkV7wbqPc9fi7fZhM85faReb3yFeV+j3A== X-Received: by 2002:a7b:cd85:0:b0:3e2:1dac:b071 with SMTP id y5-20020a7bcd85000000b003e21dacb071mr255019wmj.13.1679445734057; Tue, 21 Mar 2023 17:42:14 -0700 (PDT) Received: from localhost ([2a01:4b00:d307:1000:f1d3:eb5e:11f4:a7d9]) by smtp.gmail.com with ESMTPSA id bi6-20020a05600c3d8600b003ede178dc52sm8898526wmb.40.2023.03.21.17.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 17:42:13 -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, 22 Mar 2023 00:41:42 +0000 Message-Id: <20230322004155.2333903-6-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230322004155.2333903-1-luca.boccassi@gmail.com> References: <20230315224631.1025649-39-luca.boccassi@gmail.com> <20230322004155.2333903-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/23/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/288b168640441ac2662abc069b462e73db8c59a7 Thanks. Luca Boccassi --- >From 288b168640441ac2662abc069b462e73db8c59a7 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-21 21:56:37.291492843 +0000 +++ 0006-app-testpmd-cleanup-cleanly-from-signal.patch 2023-03-21 21:56:37.036806297 +0000 @@ -1 +1 @@ -From 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff Mon Sep 17 00:00:00 2001 +From 288b168640441ac2662abc069b462e73db8c59a7 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 @@