From patchwork Wed Jun 17 14:43:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 190862 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp516533ilo; Wed, 17 Jun 2020 07:44:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFnd28uvuAfsfifFxcBh+qZpZiKwIaKVyqls8rA9n+mZjCBZs4VTlj251D4OExmm+tds1R X-Received: by 2002:adf:e9cb:: with SMTP id l11mr8516462wrn.86.1592405046988; Wed, 17 Jun 2020 07:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592405046; cv=none; d=google.com; s=arc-20160816; b=oLNCDdluud0bbECFKEV5dW1J9aUNYJKUvY7iB1orY34zWwQqTaI4FXbQ1fSUXqasK4 anF8NUck4kkdvikgEbCklqdZIOIa9e5VsnzQX4DmOYsuNgHt3yfogmEfUU2Tz9bM3hsO 3CSJm811BcV6s+uNBc//+rsJ7RKMhP9st0Yhxd+WGUn4DARxZVUP1FUR7q8FKbVCsuyK 3RdC/4mh+MjUREPqQeIzpuwfmEmcUD8a30VxKoBk+N3VDrYpxm/4QQ+tG7tJ6PgMy+3o FteBTjzoR2rvNu+5MHkGwsBw1+gBsKKae9OC9YN5hKUZgHOr1ws7G0UfE0EQiOyNimXh DNbg== 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=dJgw6p8waQUMo+TY+ehGKNvqQyLHgojOImabUhssEqM=; b=Ah3cFLwUi/Ct/nu42VZRigThHCG5GeaDbnYYxh+UtLH69R/onvDxFu+QY1q8P6Q6iL lrg3+U+OosdH8/UUa3Nli+AuJv62PkUBq5U9+0LoS3MaYI1h3g+nQoUU5kTTpQ9fTSFT gzWS+7D+8YzBem86hJFYn3bzQAvvsUPmTJKNGQr1P6LqIrqwRb7mOT1StY+lxd1Zb01w CiYjXj21ScDOddLp8BE4zHN67qh2Ej5rQ3LMG8bRyVvLXHyr5HOrzuX3x77TBtKxa4Nn 8rMQH+NOEd0Aj9CtNRncx6KtWFuYOgg+K+1I6DSCnpel8Slt1Fd8LKzJxzkf70QIko2D nwHw== 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 h15si24087414wrc.66.2020.06.17.07.44.06; Wed, 17 Jun 2020 07:44:06 -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 72BA31B3BB; Wed, 17 Jun 2020 16:43:51 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 4EC09AAD5; Wed, 17 Jun 2020 16:43:49 +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 D643131B; Wed, 17 Jun 2020 07:43:48 -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 CB2C43F73C; Wed, 17 Jun 2020 07:43:48 -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 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: Wed, 17 Jun 2020 09:43:06 -0500 Message-Id: <20200617144307.9961-4-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200617144307.9961-1-honnappa.nagarahalli@arm.com> References: <20200617144307.9961-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH 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 --- app/test-pmd/testpmd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.17.1 Tested-by: Phil Yang Tested-by: Ali Alnubani 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]);