From patchwork Fri Feb 3 19:14:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 123049 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5F5F941BC0; Fri, 3 Feb 2023 20:14:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CDB5A40DDA; Fri, 3 Feb 2023 20:14:16 +0100 (CET) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id BA55A4067B for ; Fri, 3 Feb 2023 20:14:14 +0100 (CET) Received: by mail-pf1-f176.google.com with SMTP id z1so4419503pfg.12 for ; Fri, 03 Feb 2023 11:14:14 -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=mxazDyPNclTXxkvMqi7qk5HfZgyxnlRe4TkpRj6YJ+I=; b=ZT6ECiRZsorfC+z5cz3rgToODoTDiXes6I+s7b5WHPEydX3nVPPT/vieyTI8Ow+9+W JJ0L3v3wfIdYbZuYr0bO4QVwcXKnJe7JIuMijBepv9ye9zxr5W0s733WEw92KTtw6QUo TFwMEwbJt4b22J6ct7Np5ryyJA44NlJLsL/C/dPo1Bhf00bVtNM0jm2l6C8cOKiarQko Z2mWTUQDJTgXgSTFjC9N+xP2njcpivF7mXJ7/hMVpgSSXt65htOm20SHPv1NYvnhDhKQ ICCNFiNqptyYJ+mPL1Yc3MJYP6vC5w8mD9VOMAn4knjv6hArGB5kchuxaB/lYawVGMRX rgOQ== 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=mxazDyPNclTXxkvMqi7qk5HfZgyxnlRe4TkpRj6YJ+I=; b=3rAj6AdqxvQbVL4Pcga6cw0/mdlF+5qfOSKlUCyaeQQepP3sr5U8fo0TK27xYfYIJF vtJTqDzJ+ikA2pCUU5vi551mr6HLfhWfEo2RT/S69w5qNRWGcnePEl9o2eIk693ZvgFO E32kWfLHJHIcfBqZ1FeUg0uTL7kmkGt5qPaAcoOozJgg001eIIywaFCi09mV0wnf0bYF bRVbM4KuOVkoJuevXQIfiyB6kCQ32to547bE1lRNYQGkQg98ORWs33SXLoB4KEEiNWbM r5zxa9eaAEUnBZ3Z7bKrjR+mVqlGAaZKkGGc6M3SU/dvV8rwoyarRKKv7hPTg0Us3Lw2 hNag== X-Gm-Message-State: AO0yUKWDk7gmdfDBwKdq5RxeVbpVbhyN65NpXZUfcz4BaUC5UCee1mZ7 Sr/CSdXJpfp0ucrlRY677gjGxj7Tb6aCLCG4Xx9j+A== X-Google-Smtp-Source: AK7set/X7veMG99SBmRF7gIUY5vsh2yvaJDb65I6ZxOJXT/6FkzOP6suTCyMHstNbGpPMhu9xw5Lhg== X-Received: by 2002:a05:6a00:1d81:b0:58d:bbf:8bb1 with SMTP id z1-20020a056a001d8100b0058d0bbf8bb1mr9630264pfw.14.1675451653751; Fri, 03 Feb 2023 11:14:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:14:13 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: stable@dpdk.org, Stephen Hemminger , dmitry.kozliuk@gmail.com Subject: [PATCH v11 1/3] cmdline: make rdline status not private Date: Fri, 3 Feb 2023 11:14:07 -0800 Message-Id: <20230203191409.97567-2-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 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 The function cmdline_poll() returns values from rdline_status enum but that was moved to being defined only in cmdline_private.h. For proper use of the API the return value needs to be visible to callers. This was not a problem before because cmdline_poll() was not used anywhere. Fixes: f8f8dc289095 ("cmdline: make struct rdline opaque") Cc: dmitry.kozliuk@gmail.com Signed-off-by: Stephen Hemminger Acked-by: Chengwen Feng --- lib/cmdline/cmdline.h | 6 ++++++ lib/cmdline/cmdline_private.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cmdline/cmdline.h b/lib/cmdline/cmdline.h index 96674dfda224..b14355ef5121 100644 --- a/lib/cmdline/cmdline.h +++ b/lib/cmdline/cmdline.h @@ -23,6 +23,12 @@ extern "C" { #endif +enum rdline_status { + RDLINE_INIT, + RDLINE_RUNNING, + RDLINE_EXITED +}; + struct cmdline; struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out); diff --git a/lib/cmdline/cmdline_private.h b/lib/cmdline/cmdline_private.h index c2e906d8de6d..a3271c76934a 100644 --- a/lib/cmdline/cmdline_private.h +++ b/lib/cmdline/cmdline_private.h @@ -23,12 +23,6 @@ #define RDLINE_HISTORY_BUF_SIZE BUFSIZ #define RDLINE_HISTORY_MAX_LINE 64 -enum rdline_status { - RDLINE_INIT, - RDLINE_RUNNING, - RDLINE_EXITED -}; - struct rdline { enum rdline_status status; /* rdline bufs */ From patchwork Fri Feb 3 19:14:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 123050 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AD5D141BC0; Fri, 3 Feb 2023 20:14:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3330242D49; Fri, 3 Feb 2023 20:14:18 +0100 (CET) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mails.dpdk.org (Postfix) with ESMTP id B61134067B for ; Fri, 3 Feb 2023 20:14:15 +0100 (CET) Received: by mail-pj1-f52.google.com with SMTP id v6-20020a17090ad58600b00229eec90a7fso8765910pju.0 for ; Fri, 03 Feb 2023 11:14:15 -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=oZ73CW2sv1WMVI5SidqFd5zlO8UshcK9PT2qEQBScYQ=; b=eU/HxpMAB4SVoruqG8RINpuhgaS58R89gh4b4p6xTmaoVWEYXfGsyFy0DSa2LoDeyP 4ruyOm3bSApbSg7fOpnzb8o589ybELn+OQw6A4DvpfJWzfw03gE2IXHMDidzBO3JdWT+ 4kWhjFH30pQDKPCDnUkAC34QAmqtO1eU9rdgdNeMr6Ko2umx8DRUanVPA2zRUxVy1j1s 8spDC9g2gk3asyJR3thhPUf0sHOWCpbB8dSc3amsdMDJIeBqrJ3hMwfGFKmD4sIr/N91 Slf2MnluXdeacnmkFziUzmeKAozPcX7wXvdBiks05PjDxI9UUEUjH/LPSiTHSpD6pEya xdCg== 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=oZ73CW2sv1WMVI5SidqFd5zlO8UshcK9PT2qEQBScYQ=; b=eOub30p1HyXE7kUSHuO5uTexH6IgddWkNid/IGk2cmAN/uQ2wQEBAvu6iljHpCoUpO CjWfmK3Whv4eqJAjYEhRV1hJvI05pDX3+nPKAUvCptBZ9MH3t/kh4Fq1z9NGRnu2H7wG F0YES5eaE/ERLmaNImJ5POzPwA12Im31SHZmBGrFACOp4Cih72CeDuLcauK6lujG51tM b/qtDNsuAuAyBOSshPz44Oae7YfknEPvmjzATuRSpo7ckHyRPTXT7U1gIc1ft/yC/8Qa WB/i5QZ367c7RQ+KuLIHBM7X61TP760pylqqZQ4zRfmj/ixtzkr/R9EKB3XUL5EKm4q7 mvdg== X-Gm-Message-State: AO0yUKXVK8b6BmNixybrIfzlxC7iAC3bd8sPcb2jzC35E+X/hD85CMwy NNrEh7FWWCPlaSwVHHRKh4tjV5vpK+S1iYXRX+RHdA== X-Google-Smtp-Source: AK7set+A8j83A5Wz7U/08raGgbns7iPdg0MDB7iA7Bf5XctpLTh0CS8mery/ZZ79awZlgOzflcxprQ== X-Received: by 2002:a05:6a20:e18c:b0:bd:8b67:4e6b with SMTP id ks12-20020a056a20e18c00b000bd8b674e6bmr11566802pzb.19.1675451654691; Fri, 03 Feb 2023 11:14:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:14:14 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: stable@dpdk.org, Stephen Hemminger , pawelx.wodkowski@intel.com Subject: [PATCH v11 2/3] cmdline: handle EOF in cmdline_poll Date: Fri, 3 Feb 2023 11:14:08 -0800 Message-Id: <20230203191409.97567-3-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 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 If end of file is reached on input, then cmdline_poll() will return 1 (ie file has something); and then the cmdline_in() call to read will return 0. With the existing code, caller has no way to tell that end of file has been reached and will retry forever. A good way to handle this is to make end of file equivalent to the quit command. Since no more input is possible at that point. Fixes: 067855e651d6 ("cmdline: add polling mode") Cc: pawelx.wodkowski@intel.com Signed-off-by: Stephen Hemminger --- Note: cmdline_poll() should not have been added back in 2015, looks like there is no users, and no tests for this. lib/cmdline/cmdline.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/cmdline/cmdline.c b/lib/cmdline/cmdline.c index e1009ba4c413..8ad0690d8533 100644 --- a/lib/cmdline/cmdline.c +++ b/lib/cmdline/cmdline.c @@ -197,9 +197,14 @@ cmdline_poll(struct cmdline *cl) if (read_status < 0) return read_status; - status = cmdline_in(cl, &c, 1); - if (status < 0 && cl->rdl.status != RDLINE_EXITED) - return status; + if (read_status == 0) { + /* end of file is implicit quit */ + cmdline_quit(cl); + } else { + status = cmdline_in(cl, &c, 1); + if (status < 0 && cl->rdl.status != RDLINE_EXITED) + return status; + } } return cl->rdl.status; From patchwork Fri Feb 3 19:14:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 123051 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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 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 Acked-by: Ferruh Yigit --- 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.