[2/2] usb: gadget: u_serial: improve performance for large data
diff mbox series

Message ID 1592310884-4307-2-git-send-email-macpaul.lin@mediatek.com
State New
Headers show
Series
  • [1/2] usb: gadget: introduce flag for large request
Related show

Commit Message

Macpaul Lin June 16, 2020, 12:34 p.m. UTC
If the hardware (like DMA engine) could support large usb request exceeds
maximum packet size, use larger buffer when performing Rx/Tx could reduce
request numbers and improve performance.

Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
---
 drivers/usb/gadget/function/u_serial.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Felipe Balbi June 24, 2020, 6:48 a.m. UTC | #1
Hi,

Macpaul Lin <macpaul.lin@mediatek.com> writes:

> If the hardware (like DMA engine) could support large usb request exceeds
> maximum packet size, use larger buffer when performing Rx/Tx could reduce
> request numbers and improve performance.
>
> Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
> ---
>  drivers/usb/gadget/function/u_serial.c |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
> index 3cfc6e2..cdcc070 100644
> --- a/drivers/usb/gadget/function/u_serial.c
> +++ b/drivers/usb/gadget/function/u_serial.c
> @@ -80,6 +80,8 @@
>  #define QUEUE_SIZE		16
>  #define WRITE_BUF_SIZE		8192		/* TX only */
>  #define GS_CONSOLE_BUF_SIZE	8192
> +/* for hardware can do more than max packet */
> +#define REQ_BUF_SIZE		4096
>  
>  /* console info */
>  struct gs_console {
> @@ -247,7 +249,8 @@ static int gs_start_tx(struct gs_port *port)
>  			break;
>  
>  		req = list_entry(pool->next, struct usb_request, list);
> -		len = gs_send_packet(port, req->buf, in->maxpacket);
> +		len = gs_send_packet(port, req->buf, in->can_exceed_maxp ?
> +				REQ_BUF_SIZE : in->maxpacket);

just do this unconditionally.

>  		if (len == 0) {
>  			wake_up_interruptible(&port->drain_wait);
>  			break;
> @@ -514,7 +517,9 @@ static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
>  	 * be as speedy as we might otherwise be.
>  	 */
>  	for (i = 0; i < n; i++) {
> -		req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
> +		req = gs_alloc_req(ep, ep->can_exceed_maxp ?
> +					REQ_BUF_SIZE : ep->maxpacket,
> +					GFP_ATOMIC);

allocating 4kiB in atomic isn't very good. A better idea would be to
preallocate a list of requests and recycle them, rather than allocating
every time you need to do a transfer

Patch
diff mbox series

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 3cfc6e2..cdcc070 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -80,6 +80,8 @@ 
 #define QUEUE_SIZE		16
 #define WRITE_BUF_SIZE		8192		/* TX only */
 #define GS_CONSOLE_BUF_SIZE	8192
+/* for hardware can do more than max packet */
+#define REQ_BUF_SIZE		4096
 
 /* console info */
 struct gs_console {
@@ -247,7 +249,8 @@  static int gs_start_tx(struct gs_port *port)
 			break;
 
 		req = list_entry(pool->next, struct usb_request, list);
-		len = gs_send_packet(port, req->buf, in->maxpacket);
+		len = gs_send_packet(port, req->buf, in->can_exceed_maxp ?
+				REQ_BUF_SIZE : in->maxpacket);
 		if (len == 0) {
 			wake_up_interruptible(&port->drain_wait);
 			break;
@@ -514,7 +517,9 @@  static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
 	 * be as speedy as we might otherwise be.
 	 */
 	for (i = 0; i < n; i++) {
-		req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
+		req = gs_alloc_req(ep, ep->can_exceed_maxp ?
+					REQ_BUF_SIZE : ep->maxpacket,
+					GFP_ATOMIC);
 		if (!req)
 			return list_empty(head) ? -ENOMEM : 0;
 		req->complete = fn;