diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2014-01-15 10:25:35 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-16 19:17:11 -0500 |
commit | 87a2fd286adf35a87cf6cb30fa80a0726eb74f76 (patch) | |
tree | 0510e7dda15901deb3f4432f41c48539f40baf8c /net/packet/af_packet.c | |
parent | 902fefb82ef72a50c78cb4a20cc954b037a98d1c (diff) |
packet: don't unconditionally schedule() in case of MSG_DONTWAIT
In tpacket_snd(), when we've discovered a first frame that is
not in status TP_STATUS_SEND_REQUEST, and return a NULL buffer,
we exit the send routine in case of MSG_DONTWAIT, since we've
finished traversing the mmaped send ring buffer and don't care
about pending frames.
While doing so, we still unconditionally call an expensive
schedule() in the packet_current_frame() "error" path, which
is unnecessary in this case since it's enough to just quit
the function.
Also, in case MSG_DONTWAIT is not set, we should rather test
for need_resched() first and do schedule() only if necessary
since meanwhile pending frames could already have finished
processing and called skb destructor.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet/af_packet.c')
-rw-r--r-- | net/packet/af_packet.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 85bb38cb56fd..d5495d87f399 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -2156,6 +2156,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) | |||
2156 | int err, reserve = 0; | 2156 | int err, reserve = 0; |
2157 | void *ph; | 2157 | void *ph; |
2158 | struct sockaddr_ll *saddr = (struct sockaddr_ll *)msg->msg_name; | 2158 | struct sockaddr_ll *saddr = (struct sockaddr_ll *)msg->msg_name; |
2159 | bool need_wait = !(msg->msg_flags & MSG_DONTWAIT); | ||
2159 | int tp_len, size_max; | 2160 | int tp_len, size_max; |
2160 | unsigned char *addr; | 2161 | unsigned char *addr; |
2161 | int len_sum = 0; | 2162 | int len_sum = 0; |
@@ -2198,10 +2199,10 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) | |||
2198 | 2199 | ||
2199 | do { | 2200 | do { |
2200 | ph = packet_current_frame(po, &po->tx_ring, | 2201 | ph = packet_current_frame(po, &po->tx_ring, |
2201 | TP_STATUS_SEND_REQUEST); | 2202 | TP_STATUS_SEND_REQUEST); |
2202 | |||
2203 | if (unlikely(ph == NULL)) { | 2203 | if (unlikely(ph == NULL)) { |
2204 | schedule(); | 2204 | if (need_wait && need_resched()) |
2205 | schedule(); | ||
2205 | continue; | 2206 | continue; |
2206 | } | 2207 | } |
2207 | 2208 | ||
@@ -2255,10 +2256,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) | |||
2255 | } | 2256 | } |
2256 | packet_increment_head(&po->tx_ring); | 2257 | packet_increment_head(&po->tx_ring); |
2257 | len_sum += tp_len; | 2258 | len_sum += tp_len; |
2258 | } while (likely((ph != NULL) || | 2259 | } while (likely((ph != NULL) || (need_wait && |
2259 | ((!(msg->msg_flags & MSG_DONTWAIT)) && | 2260 | atomic_read(&po->tx_ring.pending)))); |
2260 | (atomic_read(&po->tx_ring.pending)))) | ||
2261 | ); | ||
2262 | 2261 | ||
2263 | err = len_sum; | 2262 | err = len_sum; |
2264 | goto out_put; | 2263 | goto out_put; |