All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>
To: <netdev@vger.kernel.org>
Subject: af_packet / TX_RING not fully non-blocking (w/ MSG_DONTWAIT)
Date: Thu, 2 Apr 2015 12:52:54 +0200	[thread overview]
Message-ID: <551D1F86.8050200@fokus.fraunhofer.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 1306 bytes --]

Dear all,

we have encountered a problem where the send(MSG_DONTWAIT) call on a TX_RING is not 
fully non-blocking in cases where the device's sndBuf is full (i.e. we are trying to 
write faster than the device can handle).

This is on a WLAN radio (so it's not that hard to achieve :).

Comparing the TX_RING send() handler to the regular send() handler, the difference 
seems to be in the sock_alloc_send_skb() call where, the regular handler passes a 
(flags & MSG_DONTWAIT), while the TX_RING handler always passes a 0 (block).

The attached patch changes this behavior by

a) also passing (flags & MSG_DONTWAIT)
b) adjusting the return code so that -ENOBUFS is returned if no frame could be sent 
or to return the number of bytes sent, if frame(s) could be sent within this call.

The proposed modification works fine for us and has been tested extensively with 
WLAN and Ethernet device.

Feel free to apply this patch if you agree with this solution.
Of course, we're also open to other solutions / proposals / ideas.

Cheers,

Mathias

-- 
Dr. Mathias Kretschmer, Head of Competence Center
Fraunhofer FOKUS Network Research
A Schloss Birlinghoven, 53754 Sankt Augustin, Germany
T +49-2241-14-3466, F +49-2241-14-1050
E mathias.kretschmer@fokus.fraunhofer.de
W http://www.fokus.fraunhofer.de/en/net

[-- Attachment #2: 005-af_packet_no_block_tx.patch --]
[-- Type: text/x-patch, Size: 1038 bytes --]

diff -uNpr linux-3.16.7.orig/net/packet/af_packet.c linux-3.16.7/net/packet/af_packet.c
--- linux-3.16.7.orig/net/packet/af_packet.c	2014-10-30 16:41:01.000000000 +0000
+++ linux-3.16.7/net/packet/af_packet.c	2015-04-02 08:43:37.386617712 +0000
@@ -2285,17 +2285,22 @@ static int tpacket_snd(struct packet_soc
 				schedule();
 			continue;
 		}
-
+	
 		status = TP_STATUS_SEND_REQUEST;
 		hlen = LL_RESERVED_SPACE(dev);
 		tlen = dev->needed_tailroom;
 		skb = sock_alloc_send_skb(&po->sk,
 				hlen + tlen + sizeof(struct sockaddr_ll),
-				0, &err);
+				!need_wait, &err);
 
-		if (unlikely(skb == NULL))
+		if (skb == NULL) {
+	                /* we assume the socket was initially writeable ... */
+                        if (likely(len_sum > 0))
+                        	err = len_sum;
+                	else
+                        	err = -ENOBUFS;
 			goto out_status;
-
+                }
 		tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
 					  addr, hlen);
 		if (tp_len > dev->mtu + dev->hard_header_len) {

             reply	other threads:[~2015-04-02 11:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-02 10:52 Mathias Kretschmer [this message]
2015-04-03 22:22 ` af_packet / TX_RING not fully non-blocking (w/ MSG_DONTWAIT) Daniel Borkmann
2015-04-04  8:36   ` Mathias Kretschmer
2015-04-04 10:19     ` Oliver Hartkopp
     [not found] ` <CANfWibMogTn8QSdMAci2RUeE2ROVJ92LjUDhs3nHb7NctwKiVw@mail.gmail.com>
2015-04-05  8:35   ` Mathias Kretschmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=551D1F86.8050200@fokus.fraunhofer.de \
    --to=mathias.kretschmer@fokus.fraunhofer.de \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.