Message ID | 20221115091101.2234482-3-edumazet@google.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 30189806fbb945c4cb753878aab0aa5af07bc921 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: more try_cmpxchg() conversions | expand |
On 11/15/22 2:10 AM, Eric Dumazet wrote: > Adopt atomic_try_cmpxchg() which is slightly more efficient. > > Signed-off-by: Eric Dumazet <edumazet@google.com> > Cc: David Ahern <dsahern@kernel.org> > --- > net/ipv6/ip6_fib.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c > index 413f66781e50de62d6b20042d84798e7da59165a..2438da5ff6da810d9f612fc66df4d28510f50f10 100644 > --- a/net/ipv6/ip6_fib.c > +++ b/net/ipv6/ip6_fib.c > @@ -91,13 +91,12 @@ static void fib6_walker_unlink(struct net *net, struct fib6_walker *w) > > static int fib6_new_sernum(struct net *net) > { > - int new, old; > + int new, old = atomic_read(&net->ipv6.fib6_sernum); > > do { > - old = atomic_read(&net->ipv6.fib6_sernum); > new = old < INT_MAX ? old + 1 : 1; > - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum, > - old, new) != old); > + } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new)); > + > return new; > } > Reviewed-by: David Ahern <dsahern@kernel.org>
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 413f66781e50de62d6b20042d84798e7da59165a..2438da5ff6da810d9f612fc66df4d28510f50f10 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -91,13 +91,12 @@ static void fib6_walker_unlink(struct net *net, struct fib6_walker *w) static int fib6_new_sernum(struct net *net) { - int new, old; + int new, old = atomic_read(&net->ipv6.fib6_sernum); do { - old = atomic_read(&net->ipv6.fib6_sernum); new = old < INT_MAX ? old + 1 : 1; - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum, - old, new) != old); + } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new)); + return new; }
Adopt atomic_try_cmpxchg() which is slightly more efficient. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: David Ahern <dsahern@kernel.org> --- net/ipv6/ip6_fib.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)