usb: gadget: f_tcm: Handle multiple commands in parallel
authorThinh Nguyen <Thinh.Nguyen@synopsys.com>
Wed, 11 Dec 2024 00:32:49 +0000 (00:32 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Dec 2024 07:56:06 +0000 (08:56 +0100)
Resubmit command on completion to fetch more commands and service them
in parallel. Increase the number of work in a queue. Each work will be
for each command allowing them to be processed concurrently. Also, set
them to be unbounded by cpu to improve performance.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/933cf7191b672bf4cfbea4df19af1b08dc1baca9.1733876548.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_tcm.c

index a3e886294c405448cce601d7c2f08a86be9dbf85..50e6a41aaa829f6d10607fd1838a6d73c9f5529d 100644 (file)
@@ -707,21 +707,16 @@ static int usbg_submit_command(struct f_uas *, struct usb_request *);
 static void uasp_cmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
        struct f_uas *fu = req->context;
-       int ret;
 
-       if (req->status < 0)
+       if (req->status == -ESHUTDOWN)
                return;
 
-       ret = usbg_submit_command(fu, req);
-       /*
-        * Once we tune for performance enqueue the command req here again so
-        * we can receive a second command while we processing this one. Pay
-        * attention to properly sync STAUS endpoint with DATA IN + OUT so you
-        * don't break HS.
-        */
-       if (!ret)
+       if (req->status < 0) {
+               usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC);
                return;
-       usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC);
+       }
+
+       usbg_submit_command(fu, req);
 }
 
 static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream)
@@ -1309,7 +1304,8 @@ static struct se_portal_group *usbg_make_tpg(struct se_wwn *wwn,
                goto unref_dep;
        mutex_init(&tpg->tpg_mutex);
        atomic_set(&tpg->tpg_port_count, 0);
-       tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 0, 1);
+       tpg->workqueue = alloc_workqueue("tcm_usb_gadget",
+                                        WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
        if (!tpg->workqueue)
                goto free_tpg;