All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: Bitterblue Smith <rtl8821cerfe2@gmail.com>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Cc: Sascha Hauer <sha@pengutronix.de>
Subject: RE: [PATCH v2 3/3] wifi: rtw88: usb: Preallocate and reuse the RX skbs
Date: Thu, 19 Dec 2024 07:18:07 +0000	[thread overview]
Message-ID: <bcc4baa8e91445348dfe896cc7d2cae4@realtek.com> (raw)
In-Reply-To: <9cee7a34-c38d-4128-824d-0ec139ca5a4e@gmail.com>

Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> The USB driver uses four USB Request Blocks for RX. Before submitting
> one, it allocates a 32768 byte skb for the RX data. This allocation can
> fail, maybe due to temporary memory fragmentation. When the allocation
> fails, the corresponding URB is never submitted again. After four such
> allocation failures, all RX stops because the driver is not requesting
> data from the device anymore.
> 
> Don't allocate a 32768 byte skb when submitting a USB Request Block
> (which happens very often). Instead preallocate 8 such skbs, and reuse
> them over and over. If all 8 are busy, allocate a new one. This is
> pretty rare. If the allocation fails, use a work to try again later.
> When there are enough free skbs again, free the excess skbs.
> 
> Also, use WQ_BH for the RX workqueue. With a normal or high priority
> workqueue the skbs are processed too slowly when the system is even a
> little busy, like when opening a new page in a browser, and the driver
> runs out of free skbs and allocates a lot of new ones.
> 
> This is more or less what the out-of-tree Realtek drivers do, except
> they use a tasklet instead of a BH workqueue.
> 
> Tested with RTL8723DU, RTL8821AU, RTL8812AU, RTL8812BU, RTL8822CU,
> RTL8811CU.
> 
> Closes: https://lore.kernel.org/linux-wireless/6e7ecb47-7ea0-433a-a19f-05f88a2edf6b@gmail.com/
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>

Acked-by: Ping-Ke Shih <pkshih@realtek.com>


> 
> -       error = usb_submit_urb(rxcb->rx_urb, GFP_ATOMIC);
> +       error = usb_submit_urb(rxcb->rx_urb, gfp);
>         if (error) {
> -               kfree_skb(rxcb->rx_skb);
> +               skb_queue_tail(&rtwusb->rx_free_queue, rxcb->rx_skb);
> +
>                 if (error != -ENODEV)
>                         rtw_err(rtwdev, "Err sending rx data urb %d\n",
>                                 error);

Looking into usb_submit_urb(), I think ENODEV means USB device becomes
unavailable. For this case, it seems well for rxcb missed to attach RX URB
anymore, not 'goto try_later'.

> +
> +               if (error == -ENOMEM)
> +                       goto try_later;
> +       }
> +
> +       return;
> +
> +try_later:
> +       rxcb->rx_skb = NULL;
> +       queue_work(rtwusb->rxwq, &rtwusb->rx_urb_work);
> +}



  reply	other threads:[~2024-12-19  7:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-18 22:33 [PATCH v2 1/3] wifi: rtw88: usb: Copy instead of cloning the RX skb Bitterblue Smith
2024-12-18 22:34 ` [PATCH v2 2/3] wifi: rtw88: Handle C2H_ADAPTIVITY in rtw_fw_c2h_cmd_handle() Bitterblue Smith
2024-12-19  6:19   ` Ping-Ke Shih
2024-12-18 22:35 ` [PATCH v2 3/3] wifi: rtw88: usb: Preallocate and reuse the RX skbs Bitterblue Smith
2024-12-19  7:18   ` Ping-Ke Shih [this message]
2024-12-19  6:17 ` [PATCH v2 1/3] wifi: rtw88: usb: Copy instead of cloning the RX skb Ping-Ke Shih
2024-12-19 11:15   ` Bitterblue Smith
2024-12-20  0:13     ` Ping-Ke Shih
2024-12-23  8:07 ` Ping-Ke Shih

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=bcc4baa8e91445348dfe896cc7d2cae4@realtek.com \
    --to=pkshih@realtek.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rtl8821cerfe2@gmail.com \
    --cc=sha@pengutronix.de \
    /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.