From patchwork Mon Jun 7 14:32:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 54857 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1886CB7D1C for ; Tue, 8 Jun 2010 00:33:01 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751329Ab0FGOc4 (ORCPT ); Mon, 7 Jun 2010 10:32:56 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:35515 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750834Ab0FGOc4 (ORCPT ); Mon, 7 Jun 2010 10:32:56 -0400 Received: by wyi11 with SMTP id 11so2411995wyi.19 for ; Mon, 07 Jun 2010 07:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=B0jV5E5AJPV56MgjD4lvZ7F/XFwMckx8mA2VAyvMaZs=; b=V8O25JpuKeaZiDljCTdANmpmT1utckTUgVESRYmVpYJ3dO/07K4BLyqBObuCQ3d2hi IflDONm1H/SPEet5nbcm9bNuhdnSNmnQvMwfGMk79+ZNMz0g6xPWkhYh9aSEzp6Sbphx d0ufZljzz7OMBZkF8gyRr+o7b/uvQBx1VQ6hI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=F8dOCP9ydHMNQLcrJjkxAq5PlG3Cfn3JoFO+SPjv6qj+3VcKhkj/o2httsp0Na/ZEG 7F0GUnwHCeccAFtHIj2fvgKbEr45XM7maHL82lV4rDzGclnl4F/3EjLrophctlVMfebK pYYW6dMivG8gsFzPyFHpqEsh4NOjxejGM4DmI= Received: by 10.216.166.144 with SMTP id g16mr2416360wel.35.1275921174190; Mon, 07 Jun 2010 07:32:54 -0700 (PDT) Received: from [127.0.0.1] ([85.17.35.125]) by mx.google.com with ESMTPS id d75sm1603039wek.8.2010.06.07.07.32.53 (version=SSLv3 cipher=RC4-MD5); Mon, 07 Jun 2010 07:32:53 -0700 (PDT) Subject: [PATCH net-next-2.6] pkt_sched: gen_estimator: kill est_lock rwlock From: Eric Dumazet To: David Miller Cc: netdev , Stephen Hemminger , Jarek Poplawski Date: Mon, 07 Jun 2010 16:32:51 +0200 Message-ID: <1275921171.2545.102.camel@edumazet-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We can use RCU in est_timer() and kill est_lock rwlock. Signed-off-by: Eric Dumazet --- net/core/gen_estimator.c | 45 ++++++++++++++----------------------- 1 file changed, 18 insertions(+), 27 deletions(-) -- 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 cf8e703..406d880 100644 --- a/net/core/gen_estimator.c +++ b/net/core/gen_estimator.c @@ -102,9 +102,6 @@ struct gen_estimator_head static struct gen_estimator_head elist[EST_MAX_INTERVAL+1]; -/* Protects against NULL dereference */ -static DEFINE_RWLOCK(est_lock); - /* Protects against soft lockup during large deletion */ static struct rb_root est_root = RB_ROOT; @@ -115,29 +112,25 @@ 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; + struct gnet_stats_basic_packed *bstats; spin_lock(e->stats_lock); - read_lock(&est_lock); - if (e->bstats == NULL) - goto skip; - - nbytes = e->bstats->bytes; - npackets = e->bstats->packets; - brate = (nbytes - e->last_bytes)<<(7 - idx); - e->last_bytes = nbytes; - e->avbps += (brate >> e->ewma_log) - (e->avbps >> e->ewma_log); - e->rate_est->bps = (e->avbps+0xF)>>5; - - rate = (npackets - e->last_packets)<<(12 - idx); - e->last_packets = npackets; - e->avpps += (rate >> e->ewma_log) - (e->avpps >> e->ewma_log); - e->rate_est->pps = (e->avpps+0x1FF)>>10; -skip: - read_unlock(&est_lock); + bstats = rcu_dereference(e->bstats); + if (bstats) { + u64 nbytes = ACCESS_ONCE(bstats->bytes); + u32 npackets = ACCESS_ONCE(bstats->packets); + u64 brate = (nbytes - e->last_bytes)<<(7 - idx); + u32 rate; + + e->last_bytes = nbytes; + e->avbps += (brate >> e->ewma_log) - (e->avbps >> e->ewma_log); + e->rate_est->bps = (e->avbps+0xF)>>5; + + rate = (npackets - e->last_packets)<<(12 - idx); + e->last_packets = npackets; + e->avpps += (rate >> e->ewma_log) - (e->avpps >> e->ewma_log); + e->rate_est->pps = (e->avpps+0x1FF)>>10; + } spin_unlock(e->stats_lock); } @@ -271,9 +264,7 @@ void gen_kill_estimator(struct gnet_stats_basic_packed *bstats, while ((e = gen_find_node(bstats, rate_est))) { rb_erase(&e->node, &est_root); - write_lock_bh(&est_lock); - e->bstats = NULL; - write_unlock_bh(&est_lock); + rcu_assign_pointer(e->bstats, NULL); list_del_rcu(&e->list); call_rcu(&e->e_rcu, __gen_kill_estimator);