netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: optimize cmpxchg in ip_idents_reserve
@ 2020-01-15  3:23 Shaokun Zhang
  2020-01-16 12:27 ` David Miller
  0 siblings, 1 reply; 19+ messages in thread
From: Shaokun Zhang @ 2020-01-15  3:23 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Yuqi Jin, David S. Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI,
	Eric Dumazet, Yang Guo, Shaokun Zhang

From: Yuqi Jin <jinyuqi@huawei.com>

atomic_try_cmpxchg is called instead of atomic_cmpxchg that can reduce
the access number of the global variable @p_id in the loop. Let's
optimize it for performance.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Yang Guo <guoyang2@huawei.com>
Signed-off-by: Yuqi Jin <jinyuqi@huawei.com>
Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
---
 net/ipv4/route.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 87e979f2b74a..7e28c7121c20 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -496,10 +496,10 @@ u32 ip_idents_reserve(u32 hash, int segs)
 		delta = prandom_u32_max(now - old);
 
 	/* Do not use atomic_add_return() as it makes UBSAN unhappy */
+	old = (u32)atomic_read(p_id);
 	do {
-		old = (u32)atomic_read(p_id);
 		new = old + delta + segs;
-	} while (atomic_cmpxchg(p_id, old, new) != old);
+	} while (!atomic_try_cmpxchg(p_id, &old, new));
 
 	return new - segs;
 }
-- 
2.7.4


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

end of thread, other threads:[~2020-05-07 13:50 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15  3:23 [PATCH] net: optimize cmpxchg in ip_idents_reserve Shaokun Zhang
2020-01-16 12:27 ` David Miller
2020-01-16 14:05   ` Shaokun Zhang
2020-01-16 15:12   ` Eric Dumazet
2020-01-16 15:19     ` Eric Dumazet
2020-01-17  6:54       ` Shaokun Zhang
2020-01-17 12:32         ` Peter Zijlstra
2020-01-17 16:35           ` Eric Dumazet
2020-01-17 18:03             ` Arvind Sankar
2020-01-17 18:16               ` Eric Dumazet
2020-01-17 18:38                 ` Arvind Sankar
2020-01-17 18:48                   ` Eric Dumazet
2020-01-20  8:18                     ` Peter Zijlstra
2020-05-07  9:12                       ` Shaokun Zhang
2020-05-07 13:49                         ` Eric Dumazet
2020-01-19  3:46           ` Shaokun Zhang
2020-01-19  4:12             ` Eric Dumazet
2020-01-21  2:40               ` Shaokun Zhang
2020-01-22  8:49               ` Peter Zijlstra

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