Instead of atomically clear TSQ_THROTTLED and atomically set TSQ_QUEUED
bits, use one cmpxchg() to perform a single locked operation.

Since the following patch will also set TCP_TSQ_DEFERRED here,
this cmpxchg() will make this addition free.

Signed-off-by: Eric Dumazet <eduma...@google.com>
---
 net/ipv4/tcp_output.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index ac55aefc881d..76be79437595 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -860,6 +860,7 @@ void tcp_wfree(struct sk_buff *skb)
 {
        struct sock *sk = skb->sk;
        struct tcp_sock *tp = tcp_sk(sk);
+       unsigned long flags, nval, oval;
        int wmem;
 
        /* Keep one reference on sk_wmem_alloc.
@@ -877,11 +878,17 @@ void tcp_wfree(struct sk_buff *skb)
        if (wmem >= SKB_TRUESIZE(1) && this_cpu_ksoftirqd() == current)
                goto out;
 
-       if (test_and_clear_bit(TSQ_THROTTLED, &tp->tsq_flags) &&
-           !test_and_set_bit(TSQ_QUEUED, &tp->tsq_flags)) {
-               unsigned long flags;
+       for (oval = READ_ONCE(tp->tsq_flags);; oval = nval) {
                struct tsq_tasklet *tsq;
 
+               if (!(oval & TSQF_THROTTLED) || (oval & TSQF_QUEUED))
+                       goto out;
+
+               nval = (oval & ~TSQF_THROTTLED) | TSQF_QUEUED;
+               nval = cmpxchg(&tp->tsq_flags, oval, nval);
+               if (nval != oval)
+                       continue;
+
                /* queue this socket to tasklet queue */
                local_irq_save(flags);
                tsq = this_cpu_ptr(&tsq_tasklet);
-- 
2.8.0.rc3.226.g39d4020

Reply via email to