Commit 9bb6cd65 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net/packet: introduce packet_rcv_try_clear_pressure() helper

There are two places where we want to clear the pressure
if possible, add a helper to make it more obvious.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Suggested-by: default avatarWillem de Bruijn <willemb@google.com>
Acked-by: default avatarVinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3a2bb84e
...@@ -1271,6 +1271,13 @@ static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb) ...@@ -1271,6 +1271,13 @@ static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb)
return ret; return ret;
} }
static void packet_rcv_try_clear_pressure(struct packet_sock *po)
{
if (READ_ONCE(po->pressure) &&
__packet_rcv_has_room(po, NULL) == ROOM_NORMAL)
WRITE_ONCE(po->pressure, 0);
}
static void packet_sock_destruct(struct sock *sk) static void packet_sock_destruct(struct sock *sk)
{ {
skb_queue_purge(&sk->sk_error_queue); skb_queue_purge(&sk->sk_error_queue);
...@@ -3308,8 +3315,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ...@@ -3308,8 +3315,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (skb == NULL) if (skb == NULL)
goto out; goto out;
if (READ_ONCE(pkt_sk(sk)->pressure)) packet_rcv_try_clear_pressure(pkt_sk(sk));
packet_rcv_has_room(pkt_sk(sk), NULL);
if (pkt_sk(sk)->has_vnet_hdr) { if (pkt_sk(sk)->has_vnet_hdr) {
err = packet_rcv_vnet(msg, skb, &len); err = packet_rcv_vnet(msg, skb, &len);
...@@ -4127,8 +4133,7 @@ static __poll_t packet_poll(struct file *file, struct socket *sock, ...@@ -4127,8 +4133,7 @@ static __poll_t packet_poll(struct file *file, struct socket *sock,
TP_STATUS_KERNEL)) TP_STATUS_KERNEL))
mask |= EPOLLIN | EPOLLRDNORM; mask |= EPOLLIN | EPOLLRDNORM;
} }
if (READ_ONCE(po->pressure) && __packet_rcv_has_room(po, NULL) == ROOM_NORMAL) packet_rcv_try_clear_pressure(po);
WRITE_ONCE(po->pressure, 0);
spin_unlock_bh(&sk->sk_receive_queue.lock); spin_unlock_bh(&sk->sk_receive_queue.lock);
spin_lock_bh(&sk->sk_write_queue.lock); spin_lock_bh(&sk->sk_write_queue.lock);
if (po->tx_ring.pg_vec) { if (po->tx_ring.pg_vec) {
......
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