From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id E66AD5587 for ; Wed, 19 Apr 2017 15:26:50 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP; 19 Apr 2017 06:26:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,221,1488873600"; d="scan'208";a="958725127" Received: from rhorton-mobl1.ger.corp.intel.com (HELO FC23.ir.intel.com) ([163.33.230.215]) by orsmga003.jf.intel.com with ESMTP; 19 Apr 2017 06:26:49 -0700 From: Remy Horton To: dev@dpdk.org Date: Wed, 19 Apr 2017 14:26:48 +0100 Message-Id: <1492608408-12084-1-git-send-email-remy.horton@intel.com> X-Mailer: git-send-email 2.5.5 Subject: [dpdk-dev] [PATCH v1] lib/bitratestats: fix integer roundoff 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: , X-List-Received-Date: Wed, 19 Apr 2017 13:26:51 -0000 In the absence of traffic, it is possible for the bitrate moving average to get stuck at a non-zero value, due to the calculated delta being less than what an integer can represent. Fixes: 2ad7ba9a6567 ("bitrate: add bitrate statistics library") Signed-off-by: Remy Horton --- lib/librte_bitratestats/rte_bitrate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/librte_bitratestats/rte_bitrate.c b/lib/librte_bitratestats/rte_bitrate.c index 260750f..193aa69 100644 --- a/lib/librte_bitratestats/rte_bitrate.c +++ b/lib/librte_bitratestats/rte_bitrate.c @@ -118,6 +118,11 @@ rte_stats_bitrate_calc(struct rte_stats_bitrates *bitrate_data, else delta = (delta * alpha_percent - 50) / 100; port_data->ewma_ibits += delta; + /* Integer roundoff prevents EWMA between 0 and (100/alpha_percent) + * ever reaching zero in no-traffic conditions + */ + if (cnt_bits == 0 && delta == 0) + port_data->ewma_ibits = 0; port_data->mean_ibits = cnt_bits; /* Outgoing bitrate (also EWMA) */ @@ -132,6 +137,8 @@ rte_stats_bitrate_calc(struct rte_stats_bitrates *bitrate_data, else delta = (delta * alpha_percent - 50) / 100; port_data->ewma_obits += delta; + if (cnt_bits == 0 && delta == 0) + port_data->ewma_obits = 0; port_data->mean_obits = cnt_bits; values[0] = port_data->ewma_ibits; -- 2.5.5