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 E68DA458BC for ; Sat, 31 Aug 2024 19:10:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6321F402E9; Sat, 31 Aug 2024 19:10:50 +0200 (CEST) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mails.dpdk.org (Postfix) with ESMTP id 68246402D6 for ; Sat, 31 Aug 2024 19:10:49 +0200 (CEST) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7cf5e179b68so1867836a12.1 for ; Sat, 31 Aug 2024 10:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1725124248; x=1725729048; darn=dpdk.org; 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=NkdfB5646TbpoVJM73qV+czPEfh08CFGEBvAYE1nYFg=; b=UmCYhv9V+04PyI61mVuiQImNhhndteAbbKwb0fCQolfnY2en8gf5MXHx8GIjnxXxL4 lk6SQhoNoW8Gn4s2XM2cdERUH9kO5u2pA/s7fMZiycAk9F09SklmWJwulA/JHGm9KRlN 9rMcVMf0vLpdM8BvbcrJiGa7p1Jhqr1/P9Ix0R2IAgX0mCLUv5dGO6JaAPL0sCjxqoSL BFmxZzioF14VauuuFo6MrVDF01MkPA/yMbRwpPriilaeYsLGPQqZzqG0v2o/aDjkvMoc sLfbEfNcfgEy5X6YvJEeUWTmRZfSPgqrqjUtskUm2BrJmWvgzTB9mvIhidmHl9fiqWkZ BkjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725124248; x=1725729048; 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=NkdfB5646TbpoVJM73qV+czPEfh08CFGEBvAYE1nYFg=; b=RjD6mbUqagswIby9IzTA7LPSE/7ueW9hctg8POtf9Y/nEGPuOscj9P0MQ+8bSV6dt2 uIlRxEdanP5nszMN/Rbozi2998Va4DYwUbRG3NXeqnfsE79LcmhSaPQo0aZg1LAKruvs Ms6lsYHkSM3D4BJ/IKBaLpJ+1GS9bXOSEuefUInoMXkUuUBYI3Q1QPFM+KHAEkO8V612 UY7srmF3ooms+EPI0F1QaTUkkUEZWTqSSSCnHv3DdnYoVVja1o9jxJNMReAQabTN2KL0 VU9A50wjNJ+l/80UKCLTuLVWlbOQqrJ+FpTCaHhupxe04jFYiys7gE90wibuW6UVF6o/ 394Q== X-Forwarded-Encrypted: i=1; AJvYcCXS5LZ7gSlEcgfGSSsjRndfyi0384zWqjKN18fymtAwGDTCE21bWVfL5qeT9IAVv/uS5AGCeUA=@dpdk.org X-Gm-Message-State: AOJu0Yz2jy2PMfvMYkEIPWbLrNBM7y24rS8lGY3mYgq1XxWac6GOq2A1 KyA6+qKq+09aF/DchpWtonyNvP1DG16rQU1i+aGC/eUMus0PG7sgnxUIGQZlYXA= X-Google-Smtp-Source: AGHT+IFdWA8JEdgWAoz9Vaw+QNc8TE/BqVaGDwnjrJNgBS3CQmuo3ZtoL7PixxujvL7XAo9Wo97XjA== X-Received: by 2002:a17:902:f603:b0:1fa:2b11:657d with SMTP id d9443c01a7336-20527724293mr101317605ad.10.1725124248432; Sat, 31 Aug 2024 10:10:48 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152cf12bsm43141735ad.83.2024.08.31.10.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Aug 2024 10:10:48 -0700 (PDT) From: Stephen Hemminger To: Kevin Traynor Cc: Stephen Hemminger , stable@dpdk.org, Ferruh Yigit Subject: [PATCH 3/5] app/testpmd: cleanup cleanly from signal Date: Sat, 31 Aug 2024 10:09:27 -0700 Message-ID: <20240831171035.27505-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240831171035.27505-1-stephen@networkplumber.org> References: <20240831171035.27505-1-stephen@networkplumber.org> 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 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. (cherry picked from commit 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff) Fixes: d9a191a00e81 ("app/testpmd: fix quitting in container") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger Acked-by: Ferruh Yigit --- app/test-pmd/cmdline.c | 31 +++++++---------- app/test-pmd/testpmd.c | 78 ++++++++++++++++++++---------------------- app/test-pmd/testpmd.h | 3 ++ 3 files changed, 52 insertions(+), 60 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 6e10afeedd..6da5198ac7 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -68,8 +68,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. *** */ @@ -17985,31 +17983,26 @@ 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) - fprintf(stderr, "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 55eb293cc0..40dff96e5c 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 @@ -219,7 +220,8 @@ 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. */ -uint8_t f_quit; +volatile uint8_t f_quit; +uint8_t cl_quit; /* Quit testpmd from cmdline. */ /* * Max Rx frame size, set by '--max-pkt-len' parameter. @@ -4044,13 +4046,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) { @@ -4069,28 +4064,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 @@ -4261,15 +4237,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) { @@ -4292,15 +4262,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 2149ecd93a..33b4f5504f 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -32,6 +32,9 @@ #define RTE_PORT_CLOSED (uint16_t)2 #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. * The hash key size is NIC dependent. -- 2.45.2