Skip to content

Commit 4aa736b

Browse files
committed
tcp: tcp_wfree() refactoring
JIRA: https://issues.redhat.com/browse/RHEL-22708 Upstream Status: linux.git commit b548b17 Author: Eric Dumazet <edumazet@google.com> Date: Thu Nov 10 19:02:39 2022 +0000 tcp: tcp_wfree() refactoring Use try_cmpxchg() (instead of cmpxchg()) in a more readable way. oval = smp_load_acquire(&sk->sk_tsq_flags); do { ... } while (!try_cmpxchg(&sk->sk_tsq_flags, &oval, nval)); Reduce indentation level. Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20221110190239.3531280-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent e074fe3 commit 4aa736b

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

net/ipv4/tcp_output.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ void tcp_wfree(struct sk_buff *skb)
11411141
struct sock *sk = skb->sk;
11421142
struct tcp_sock *tp = tcp_sk(sk);
11431143
unsigned long flags, nval, oval;
1144+
struct tsq_tasklet *tsq;
1145+
bool empty;
11441146

11451147
/* Keep one reference on sk_wmem_alloc.
11461148
* Will be released by sk_free() from here or tcp_tasklet_func()
@@ -1157,28 +1159,23 @@ void tcp_wfree(struct sk_buff *skb)
11571159
if (refcount_read(&sk->sk_wmem_alloc) >= SKB_TRUESIZE(1) && this_cpu_ksoftirqd() == current)
11581160
goto out;
11591161

1160-
for (oval = READ_ONCE(sk->sk_tsq_flags);; oval = nval) {
1161-
struct tsq_tasklet *tsq;
1162-
bool empty;
1163-
1162+
oval = smp_load_acquire(&sk->sk_tsq_flags);
1163+
do {
11641164
if (!(oval & TSQF_THROTTLED) || (oval & TSQF_QUEUED))
11651165
goto out;
11661166

11671167
nval = (oval & ~TSQF_THROTTLED) | TSQF_QUEUED;
1168-
nval = cmpxchg(&sk->sk_tsq_flags, oval, nval);
1169-
if (nval != oval)
1170-
continue;
1168+
} while (!try_cmpxchg(&sk->sk_tsq_flags, &oval, nval));
11711169

1172-
/* queue this socket to tasklet queue */
1173-
local_irq_save(flags);
1174-
tsq = this_cpu_ptr(&tsq_tasklet);
1175-
empty = list_empty(&tsq->head);
1176-
list_add(&tp->tsq_node, &tsq->head);
1177-
if (empty)
1178-
tasklet_schedule(&tsq->tasklet);
1179-
local_irq_restore(flags);
1180-
return;
1181-
}
1170+
/* queue this socket to tasklet queue */
1171+
local_irq_save(flags);
1172+
tsq = this_cpu_ptr(&tsq_tasklet);
1173+
empty = list_empty(&tsq->head);
1174+
list_add(&tp->tsq_node, &tsq->head);
1175+
if (empty)
1176+
tasklet_schedule(&tsq->tasklet);
1177+
local_irq_restore(flags);
1178+
return;
11821179
out:
11831180
sk_free(sk);
11841181
}

0 commit comments

Comments
 (0)