public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] gen_estimator: change the lock order for better perfermance
@ 2013-09-17  8:38 Hong Zhiguo
  2013-09-17 11:11 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Hong Zhiguo @ 2013-09-17  8:38 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, Hong Zhiguo

From: Hong Zhiguo <zhiguohong@tencent.com>

e->stats_lock is usually taken by fast path to update stats.
In the old order, fast path should wait for write_lock(&est_lock).
Even though it's only one line inside the write_lock(&est_lock),
but if there's interrupt or page fault, a lot of spin on
e->stats_lock will be wasted in fast path.

Signed-off-by: Hong Zhiguo <zhiguohong@tencent.com>
---
 net/core/gen_estimator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c
index 6b5b6e7..bad7f5f 100644
--- a/net/core/gen_estimator.c
+++ b/net/core/gen_estimator.c
@@ -120,11 +120,11 @@ static void est_timer(unsigned long arg)
 		u32 npackets;
 		u32 rate;
 
-		spin_lock(e->stats_lock);
 		read_lock(&est_lock);
 		if (e->bstats == NULL)
 			goto skip;
 
+		spin_lock(e->stats_lock);
 		nbytes = e->bstats->bytes;
 		npackets = e->bstats->packets;
 		brate = (nbytes - e->last_bytes)<<(7 - idx);
@@ -136,9 +136,9 @@ static void est_timer(unsigned long arg)
 		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);
 skip:
 		read_unlock(&est_lock);
-		spin_unlock(e->stats_lock);
 	}
 
 	if (!list_empty(&elist[idx].list))
-- 
1.8.1.2

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

end of thread, other threads:[~2013-09-18  5:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-17  8:38 [PATCH net-next] gen_estimator: change the lock order for better perfermance Hong Zhiguo
2013-09-17 11:11 ` Eric Dumazet
2013-09-18  5:41   ` 答复: [PATCH net-next] gen_estimator: change the lock order for better perfermance(Internet mail) zhiguohong(洪志国)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox