DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1] lib/bitratestats: fix integer roundoff
@ 2017-04-19 13:26 Remy Horton
  2017-04-20 23:09 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Remy Horton @ 2017-04-19 13:26 UTC (permalink / raw)
  To: dev

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 <remy.horton@intel.com>
---
 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH v1] lib/bitratestats: fix integer roundoff
  2017-04-19 13:26 [dpdk-dev] [PATCH v1] lib/bitratestats: fix integer roundoff Remy Horton
@ 2017-04-20 23:09 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2017-04-20 23:09 UTC (permalink / raw)
  To: Remy Horton; +Cc: dev

19/04/2017 15:26, Remy Horton:
> 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 <remy.horton@intel.com>

Applied, thanks

PS: please not that the title of this patch does not match
the title of the fixed patch.
Changed to "bitrate: fix integer roundoff"

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-20 23:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-19 13:26 [dpdk-dev] [PATCH v1] lib/bitratestats: fix integer roundoff Remy Horton
2017-04-20 23:09 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).