From patchwork Mon May 18 23:59:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 27383 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id AD242B707D for ; Tue, 19 May 2009 10:00:22 +1000 (EST) Received: by ozlabs.org (Postfix) id 9BE35DE0D4; Tue, 19 May 2009 10:00:22 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 3B82FDE0D1 for ; Tue, 19 May 2009 10:00:22 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753007AbZESAAK (ORCPT ); Mon, 18 May 2009 20:00:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752697AbZESAAK (ORCPT ); Mon, 18 May 2009 20:00:10 -0400 Received: from gw1.cosmosbay.com ([212.99.114.194]:44611 "EHLO gw1.cosmosbay.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752695AbZESAAJ convert rfc822-to-8bit (ORCPT ); Mon, 18 May 2009 20:00:09 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by gw1.cosmosbay.com (8.13.7/8.13.7) with ESMTP id n4INxt0U015283; Tue, 19 May 2009 01:59:56 +0200 Message-ID: <4A11F67B.3050805@cosmosbay.com> Date: Tue, 19 May 2009 01:59:55 +0200 From: Eric Dumazet User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: David Miller CC: jarkao2@gmail.com, vexwek@gmail.com, netdev@vger.kernel.org, kaber@trash.net, devik@cdi.cz Subject: [PATCH] pkt_sched: gen_estimator: use 64 bits intermediate counters for bps References: <20090516141430.GB3013@ami.dom.local> <4A118F98.60101@cosmosbay.com> <20090518172349.GA2755@ami.dom.local> <20090518.145233.212710505.davem@davemloft.net> In-Reply-To: <20090518.145233.212710505.davem@davemloft.net> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (gw1.cosmosbay.com [0.0.0.0]); Tue, 19 May 2009 01:59:57 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org David Miller a écrit : > From: Jarek Poplawski > Date: Mon, 18 May 2009 19:23:49 +0200 > >> On Mon, May 18, 2009 at 06:40:56PM +0200, Eric Dumazet wrote: >>> With a typical estimator "1sec 8sec", ewma_log value is 3 >>> >>> At gigabit speeds, we are very close to overflow yes, since >>> we only have 27 bits available, so 134217728 bytes per second >>> or 1073741824 bits per second. >>> >>> So formula : >>> e->avbps += ((long)rate - (long)e->avbps) >> e->ewma_log; >>> is going to overflow. >>> >>> One way to avoid the overflow would be to use a smaller estimator, like "500ms 4sec" >>> >>> Or use a 64bits rate & avbps, this is needed fo 10Gb speeds I suppose... >> Yes, I considered this too, but because of an overhead I decided to >> fix as designed (according to the comment) for now. But probably you >> are right, and we should go further, so I'm OK with your patch. > > I like this patch too, Eric can you submit this formally with > proper signoffs etc.? > Sure, here it is. We might need a similar patch to get a correct pps value too, since we currently are limited to ~ 2^21 packets per second. [PATCH] pkt_sched: gen_estimator: use 64 bit intermediate counters for bps gen_estimator can overflow bps (bytes per second) with Gb links, while it was designed with a u32 API, with a theorical limit of 34360Mbit (2^32 bytes) Using 64 bit intermediate avbps/brate counters can allow us to reach this theorical limit. Signed-off-by: Eric Dumazet Signed-off-by: Jarek Poplawski --- -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c index 9cc9f95..ea28659 100644 --- a/net/core/gen_estimator.c +++ b/net/core/gen_estimator.c @@ -66,9 +66,9 @@ NOTES. - * The stored value for avbps is scaled by 2^5, so that maximal - rate is ~1Gbit, avpps is scaled by 2^10. - + * avbps is scaled by 2^5, avpps is scaled by 2^10. + * both values are reported as 32 bit unsigned values. bps can + overflow for fast links : max speed being 34360Mbit/sec * Minimal interval is HZ/4=250msec (it is the greatest common divisor for HZ=100 and HZ=1024 8)), maximal interval is (HZ*2^EST_MAX_INTERVAL)/4 = 8sec. Shorter intervals @@ -86,9 +86,9 @@ struct gen_estimator spinlock_t *stats_lock; int ewma_log; u64 last_bytes; + u64 avbps; u32 last_packets; u32 avpps; - u32 avbps; struct rcu_head e_rcu; struct rb_node node; }; @@ -115,6 +115,7 @@ static void est_timer(unsigned long arg) rcu_read_lock(); list_for_each_entry_rcu(e, &elist[idx].list, list) { u64 nbytes; + u64 brate; u32 npackets; u32 rate; @@ -125,9 +126,9 @@ static void est_timer(unsigned long arg) nbytes = e->bstats->bytes; npackets = e->bstats->packets; - rate = (nbytes - e->last_bytes)<<(7 - idx); + brate = (nbytes - e->last_bytes)<<(7 - idx); e->last_bytes = nbytes; - e->avbps += ((long)rate - (long)e->avbps) >> e->ewma_log; + e->avbps += ((s64)(brate - e->avbps)) >> e->ewma_log; e->rate_est->bps = (e->avbps+0xF)>>5; rate = (npackets - e->last_packets)<<(12 - idx);