netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next-2.6] pkt_sched: gen_estimator: kill est_lock rwlock
@ 2010-06-07 14:32 Eric Dumazet
  2010-06-07 14:53 ` Changli Gao
  0 siblings, 1 reply; 35+ messages in thread
From: Eric Dumazet @ 2010-06-07 14:32 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Stephen Hemminger, Jarek Poplawski

We can use RCU in est_timer() and kill est_lock rwlock.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/core/gen_estimator.c |   45 ++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 27 deletions(-)

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);



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

end of thread, other threads:[~2010-06-12  1:38 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-07 14:32 [PATCH net-next-2.6] pkt_sched: gen_estimator: kill est_lock rwlock Eric Dumazet
2010-06-07 14:53 ` Changli Gao
2010-06-07 15:30   ` Eric Dumazet
2010-06-07 15:55     ` Eric Dumazet
2010-06-07 16:56       ` [PATCH net-next-2.6 v2] " Eric Dumazet
2010-06-07 17:18         ` [PATCH net-2.6] pkt_sched: gen_estimator: add a new lock Eric Dumazet
2010-06-08  1:00           ` Changli Gao
2010-06-08  4:30             ` Eric Dumazet
2010-06-08  4:57               ` Changli Gao
2010-06-08  4:58             ` Eric Dumazet
2010-06-08  5:20               ` Changli Gao
2010-06-08  5:39                 ` Eric Dumazet
2010-06-09  9:39           ` [PATCH net-2.6 v2] " Eric Dumazet
2010-06-09 11:33             ` Jarek Poplawski
2010-06-09 11:55               ` Eric Dumazet
2010-06-11  5:54             ` David Miller
2010-06-08 12:15         ` [PATCH net-next-2.6 v2] pkt_sched: gen_estimator: kill est_lock rwlock Jarek Poplawski
2010-06-08 12:27           ` Eric Dumazet
2010-06-08 12:40             ` Jarek Poplawski
2010-06-08 19:29               ` Jarek Poplawski
2010-06-08 19:45                 ` Eric Dumazet
2010-06-08 20:24                   ` Jarek Poplawski
2010-06-08 20:52                     ` Eric Dumazet
2010-06-08 21:18                       ` Jarek Poplawski
2010-06-09  6:13                       ` pkt_sched: gen_estimator: more fuel for Jarek and Changli Eric Dumazet
2010-06-09  6:51                         ` Jarek Poplawski
2010-06-09  7:36                           ` Eric Dumazet
2010-06-09  8:14                             ` Jarek Poplawski
2010-06-09  9:40         ` [PATCH] pkt_sched: gen_kill_estimator() rcu fixes Eric Dumazet
2010-06-09  9:56           ` Eric Dumazet
2010-06-09 10:41             ` Jarek Poplawski
2010-06-09 12:09               ` Eric Dumazet
2010-06-09 12:50                 ` Jarek Poplawski
2010-06-09 13:05                   ` Eric Dumazet
2010-06-12  1:39                 ` David Miller

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).