Skip to content

Commit 408f0a6

Browse files
edumazetdavem330
authored andcommitted
tcp: tsq: remove one locked operation in tcp_wfree()
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 40fc342 commit 408f0a6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

net/ipv4/tcp_output.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ void tcp_wfree(struct sk_buff *skb)
860860
{
861861
struct sock *sk = skb->sk;
862862
struct tcp_sock *tp = tcp_sk(sk);
863+
unsigned long flags, nval, oval;
863864
int wmem;
864865

865866
/* Keep one reference on sk_wmem_alloc.
@@ -877,11 +878,17 @@ void tcp_wfree(struct sk_buff *skb)
877878
if (wmem >= SKB_TRUESIZE(1) && this_cpu_ksoftirqd() == current)
878879
goto out;
879880

880-
if (test_and_clear_bit(TSQ_THROTTLED, &tp->tsq_flags) &&
881-
!test_and_set_bit(TSQ_QUEUED, &tp->tsq_flags)) {
882-
unsigned long flags;
881+
for (oval = READ_ONCE(tp->tsq_flags);; oval = nval) {
883882
struct tsq_tasklet *tsq;
884883

884+
if (!(oval & TSQF_THROTTLED) || (oval & TSQF_QUEUED))
885+
goto out;
886+
887+
nval = (oval & ~TSQF_THROTTLED) | TSQF_QUEUED;
888+
nval = cmpxchg(&tp->tsq_flags, oval, nval);
889+
if (nval != oval)
890+
continue;
891+
885892
/* queue this socket to tasklet queue */
886893
local_irq_save(flags);
887894
tsq = this_cpu_ptr(&tsq_tasklet);

0 commit comments

Comments
 (0)