Commit b548b17a authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

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: default avatarEric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20221110190239.3531280-1-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent fac30731
...@@ -1139,6 +1139,8 @@ void tcp_wfree(struct sk_buff *skb) ...@@ -1139,6 +1139,8 @@ void tcp_wfree(struct sk_buff *skb)
struct sock *sk = skb->sk; struct sock *sk = skb->sk;
struct tcp_sock *tp = tcp_sk(sk); struct tcp_sock *tp = tcp_sk(sk);
unsigned long flags, nval, oval; unsigned long flags, nval, oval;
struct tsq_tasklet *tsq;
bool empty;
/* Keep one reference on sk_wmem_alloc. /* Keep one reference on sk_wmem_alloc.
* Will be released by sk_free() from here or tcp_tasklet_func() * Will be released by sk_free() from here or tcp_tasklet_func()
...@@ -1155,28 +1157,23 @@ void tcp_wfree(struct sk_buff *skb) ...@@ -1155,28 +1157,23 @@ void tcp_wfree(struct sk_buff *skb)
if (refcount_read(&sk->sk_wmem_alloc) >= SKB_TRUESIZE(1) && this_cpu_ksoftirqd() == current) if (refcount_read(&sk->sk_wmem_alloc) >= SKB_TRUESIZE(1) && this_cpu_ksoftirqd() == current)
goto out; goto out;
for (oval = READ_ONCE(sk->sk_tsq_flags);; oval = nval) { oval = smp_load_acquire(&sk->sk_tsq_flags);
struct tsq_tasklet *tsq; do {
bool empty;
if (!(oval & TSQF_THROTTLED) || (oval & TSQF_QUEUED)) if (!(oval & TSQF_THROTTLED) || (oval & TSQF_QUEUED))
goto out; goto out;
nval = (oval & ~TSQF_THROTTLED) | TSQF_QUEUED; nval = (oval & ~TSQF_THROTTLED) | TSQF_QUEUED;
nval = cmpxchg(&sk->sk_tsq_flags, oval, nval); } while (!try_cmpxchg(&sk->sk_tsq_flags, &oval, nval));
if (nval != oval)
continue;
/* queue this socket to tasklet queue */ /* queue this socket to tasklet queue */
local_irq_save(flags); local_irq_save(flags);
tsq = this_cpu_ptr(&tsq_tasklet); tsq = this_cpu_ptr(&tsq_tasklet);
empty = list_empty(&tsq->head); empty = list_empty(&tsq->head);
list_add(&tp->tsq_node, &tsq->head); list_add(&tp->tsq_node, &tsq->head);
if (empty) if (empty)
tasklet_schedule(&tsq->tasklet); tasklet_schedule(&tsq->tasklet);
local_irq_restore(flags); local_irq_restore(flags);
return; return;
}
out: out:
sk_free(sk); sk_free(sk);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment