From patchwork Fri Jun 26 22:09:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 191927 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp879303ilg; Fri, 26 Jun 2020 15:10:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8ycOrB6n22SMan15jAyVPuFijR2y81TZC1Hj6tOY/DR206arxvwjNeX9UnklKJ2z8fjBZ X-Received: by 2002:a17:906:3407:: with SMTP id c7mr4383882ejb.284.1593209428677; Fri, 26 Jun 2020 15:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593209428; cv=none; d=google.com; s=arc-20160816; b=XC7CMWz5YdYE5fEOLDnYgUIx3uILiqcWpWScJzm5RyxUTqvWSyqGiapanYEstFobR/ 7OweM611dBzahYddELzE+Sp6D1Q7rNbvKwAZbHhKE0biy7nsQvE6WioZ6qFsDly81GAM t1AeQYbrNAuZGWwJFEOu25z2E80tNhwVK9RppX6GypTP9exgXWH6RXB+YT4oPbWgpWIU +u0wu1QL9qag2BRetY5sZG7B1cNTzqf6olF2fESi+zpHKaLqBT1rfOdPClQnpSzwP893 dNeMjqeYalWMCmrWHr5HgwTKK44wxE5KJMZBMFnq3lG9kZVTH4+beuNEBrEGsOyhbe8Y FL0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=MzsFSxQkkokR+KG4NBHkPzsqc8ktwpTEVK3I43HQLfE=; b=eo5T2JJl/6brKaDtmgv0sQA4KdelAMesTUM5PvdgNEh/UJu+gNOzcn7NGzeUf+elQt 3KYUiwW+ONKIweILoC+wwoVUR2i9y4uNSNw8FqxqTiTjCVXlJe+s/BUkFxKpBeOy//d3 i47DYkwUr7IDHKV5p886MnndCYAC33P+1pFlpGFXIDnNslmv6oSGoVedDb+pkK/pnpiZ FyCOxTltStmaA3RYUs1bzmMC5Dl6cx72qcFwRqm5z3gWEskEnU4SuxO0IcLMOHtCweB9 drZ1oCzAcsXSqdV+H/z1dDAUW0Zk13FzxPqOCMATXa/qnlRuH+Hfa10fdVmQ+7G+8Tj/ VSiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id c68si11017567edf.428.2020.06.26.15.10.28; Fri, 26 Jun 2020 15:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 003B21BEE6; Sat, 27 Jun 2020 00:10:07 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 5E9281BEB3; Sat, 27 Jun 2020 00:10:01 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D8DC9101E; Fri, 26 Jun 2020 15:10:00 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CE4023F6CF; Fri, 26 Jun 2020 15:10:00 -0700 (PDT) From: Honnappa Nagarahalli To: dev@dpdk.org, honnappa.nagarahalli@arm.com, alialnu@mellanox.com, orgerlitz@mellanox.com, wenzhuo.lu@intel.com, beilei.xing@intel.com, bernard.iremonger@intel.com, ferruh.yigit@intel.com Cc: hemant.agrawal@nxp.com, jerinj@marvell.com, viacheslavo@mellanox.com, thomas@monjalon.net, ruifeng.wang@arm.com, phil.yang@arm.com, nd@arm.com, stable@dpdk.org Date: Fri, 26 Jun 2020 17:09:42 -0500 Message-Id: <20200626220943.22526-4-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626220943.22526-1-honnappa.nagarahalli@arm.com> References: <20200617144307.9961-1-honnappa.nagarahalli@arm.com> <20200626220943.22526-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v2 4/5] app/testpmd: fix burst percentage calculation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The burst % calculation can over flow due to multiplication. Fix the multiplication and increase the size of variables to 64b. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Signed-off-by: Honnappa Nagarahalli Reviewed-by: Phil Yang Reviewed-by: Ruifeng Wang Tested-by: Phil Yang Tested-by: Ali Alnubani --- app/test-pmd/testpmd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Ferruh Yigit diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 4989d22ca..2e1493da2 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1692,9 +1692,9 @@ init_fwd_streams(void) static void pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs) { - unsigned int total_burst; - unsigned int nb_burst; - unsigned int burst_stats[3]; + uint64_t total_burst; + uint64_t nb_burst; + uint64_t burst_stats[3]; uint16_t pktnb_stats[3]; uint16_t nb_pkt; int burst_percent[3]; @@ -1723,8 +1723,8 @@ pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs) } if (total_burst == 0) return; - burst_percent[0] = (burst_stats[0] * 100) / total_burst; - printf(" %s-bursts : %u [%d%% of %d pkts", rx_tx, total_burst, + burst_percent[0] = (double)burst_stats[0] / total_burst * 100; + printf(" %s-bursts : %"PRIu64" [%d%% of %d pkts", rx_tx, total_burst, burst_percent[0], (int) pktnb_stats[0]); if (burst_stats[0] == total_burst) { printf("]\n"); @@ -1735,7 +1735,7 @@ pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs) 100 - burst_percent[0], pktnb_stats[1]); return; } - burst_percent[1] = (burst_stats[1] * 100) / total_burst; + burst_percent[1] = (double)burst_stats[1] / total_burst * 100; burst_percent[2] = 100 - (burst_percent[0] + burst_percent[1]); if ((burst_percent[1] == 0) || (burst_percent[2] == 0)) { printf(" + %d%% of others]\n", 100 - burst_percent[0]);