Skip to content

Commit

Permalink
tcp: adopt try_cmpxchg() in tcp_release_cb()
Browse files Browse the repository at this point in the history
try_cmpxchg() is slighly more efficient (at least on x86),
and smp_load_acquire(&sk->sk_tsq_flags) could avoid a KCSAN report.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20221110174829.3403442-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Eric Dumazet authored and Jakub Kicinski committed Nov 12, 2022
1 parent 3e35f26 commit fac3073
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions net/ipv4/tcp_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,15 +1077,15 @@ static void tcp_tasklet_func(struct tasklet_struct *t)
*/
void tcp_release_cb(struct sock *sk)
{
unsigned long flags, nflags;
unsigned long flags = smp_load_acquire(&sk->sk_tsq_flags);
unsigned long nflags;

/* perform an atomic operation only if at least one flag is set */
do {
flags = sk->sk_tsq_flags;
if (!(flags & TCP_DEFERRED_ALL))
return;
nflags = flags & ~TCP_DEFERRED_ALL;
} while (cmpxchg(&sk->sk_tsq_flags, flags, nflags) != flags);
} while (!try_cmpxchg(&sk->sk_tsq_flags, &flags, nflags));

if (flags & TCPF_TSQ_DEFERRED) {
tcp_tsq_write(sk);
Expand Down

0 comments on commit fac3073

Please sign in to comment.