Skip to contentSkip to conversation

musb: Add workqueue for URB giveback

PATCH In review Ajay Kumar Gupta 6 participants 8 messages Feb 26, 2010 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 musb: Add workqueue for URB giveback

Current musb host driver does the giveback of completed urb first and then start the next request. This is significantly affecting the streaming from an USB camera wherein we observe huge delay between the two IN tokens from musb host. This is due to the fact that UVC driver is doing decoding and further processing in giveback context.

The patch tries to defer the giveback part to a workqueue and continues with the start of new request in completion path.

---
Patch created against latest linus's tree and all musb patches in Greg's queue.
Patch is also updated with the comments from Alan on handling URBs which got completed with errors.

 drivers/usb/musb/musb_core.c |   22 +++++++++
 drivers/usb/musb/musb_core.h |   18 +++++++
 drivers/usb/musb/musb_host.c |  107 ++++++++++++++++++++++++++++++++++++++----
 drivers/usb/musb/musb_host.h |    2 +
 4 files changed, 139 insertions(+), 10 deletions(-)
drivers/usb/musb/musb_core.c +22 -0
index 0f13ded..9ce21ec 100644
@@ -1857,6 +1857,9 @@ static void musb_free(struct musb *musb)
 	}
 
 #ifdef CONFIG_USB_MUSB_HDRC_HCD
+	if (musb->gb_queue)
+		destroy_workqueue(musb->gb_queue);
+	free_queue(musb);
 	usb_put_hcd(musb_to_hcd(musb));
 #else
 	kfree(musb);
@@ -1915,6 +1918,9 @@ bad_config:
 		return -ENOMEM;
 
 	spin_lock_init(&musb->lock);
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+	spin_lock_init(&musb->qlock);
+#endif
 	musb->board_mode = plat->mode;
 	musb->board_set_power = plat->set_power;
 	musb->set_clock = plat->set_clock;
@@ -2078,8 +2084,24 @@ bad_config:
 			? "DMA" : "PIO",
 			musb->nIrq);
 
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+	musb->gb_queue = create_singlethread_workqueue(dev_name(dev));
+	if (musb->gb_queue == NULL)
+		goto fail2;
+	/* Init giveback workqueue */
+	INIT_WORK(&musb->gb_work, musb_gb_work);
+
+	/* init queue */
+	init_queue(musb);
+	if (!musb->qhead)
+		goto fail3;
+#endif
 	return 0;
 
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+fail3:
+	destroy_workqueue(musb->gb_queue);
+#endif
 fail2:
 	musb_platform_exit(musb);
 fail:
drivers/usb/musb/musb_core.h +18 -0
index 17e7115..ef93c13 100644
@@ -322,6 +322,16 @@ static inline struct usb_request *next_out_request(struct musb_hw_ep *hw_ep)
 #endif
 }
 
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+/*
+ * struct queue - Queue data structure
+ */
+struct queue {
+	struct urb *urb;
+	struct queue *next;
+};
+#endif
+
 /*
  * struct musb - Driver instance data.
  */
@@ -355,6 +365,11 @@ struct musb {
 	struct list_head	in_bulk;	/* of musb_qh */
 	struct list_head	out_bulk;	/* of musb_qh */
 
+	struct workqueue_struct *gb_queue;
+	struct work_struct      gb_work;
+	spinlock_t		qlock;
+	struct queue		*qhead;
+
 	struct timer_list	otg_timer;
 #endif
 
@@ -610,5 +625,8 @@ extern int musb_platform_get_vbus_status(struct musb *musb);
 
 extern int __init musb_platform_init(struct musb *musb);
 extern int musb_platform_exit(struct musb *musb);
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+extern void musb_gb_work(struct work_struct *data);
+#endif
 
 #endif	/* __MUSB_CORE_H__ */
drivers/usb/musb/musb_host.c +97 -10

160 lines not on this page · raw message

drivers/usb/musb/musb_host.h +2 -0
index 14b0077..a1a01df 100644
@@ -83,6 +83,8 @@ static inline struct musb_qh *first_qh(struct list_head *q)
 
 
 extern void musb_root_disconnect(struct musb *musb);
+extern void init_queue(struct musb *musb);
+extern void free_queue(struct musb *musb);
 
 struct usb_hcd;
 
Signature · 1 line
1.6.2.4
#1 lore raw

Am Freitag, 26. Februar 2010 11:39:06 schrieb Ajay Kumar Gupta:

Quoted 5 lines
drivers/usb/musb/musb_host.c +5 -0
+struct queue *create(void)
+{
+       struct queue *new;
+       new = kmalloc(sizeof(struct queue), GFP_ATOMIC);
+       if (!new)

drivers/usb/musb/musb_host.c line 116

Quoted 10 lines
drivers/usb/musb/musb_host.c +10 -0
+               return NULL;
+       new->next = NULL;
+       return new;
+}
+void push_queue(struct musb *musb, struct urb *urb)
+{
+       struct queue *new, *temp;
+
+       new = create();
+       new->urb = urb;

And you happily follow the NULL pointer in the error case.

drivers/usb/musb/musb_host.c line 125

Quoted 9 lines
drivers/usb/musb/musb_host.c +9 -0
+
+       temp = musb->qhead;
+
+       spin_lock(&musb->qlock);
+       while (temp->next != NULL)
+               temp = temp->next;
+       temp->next = new;
+       spin_unlock(&musb->qlock);
+}

A design allocating memory in giveback is problematic. At least you need to handle a failure to allocate memory. But you'd better handle this by putting the list into the private part of the URB.

Regards
Oliver

A message that is not in the archive (sent off-list or not yet received): 201002261203.27619.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org

#3 lore raw

Hi,

Quoted 18 lines

-----Original Message-----
From: Oliver Neukum [mailto:[email protected]]
Sent: Friday, February 26, 2010 4:33 PM
To: Gupta, Ajay Kumar
Cc: [email protected]; [email protected]; stern-nwvwT67g6+6dFdvTe/[email protected]
Subject: Re: [PATCH] musb: Add workqueue for URB giveback

Am Freitag, 26. Februar 2010 11:39:06 schrieb Ajay Kumar Gupta:

Quoted 9 lines
drivers/usb/musb/musb_host.c +9 -0
+struct queue *create(void)
+{
+       struct queue *new;
+       new = kmalloc(sizeof(struct queue), GFP_ATOMIC);
+       if (!new)
+               return NULL;
+       new->next = NULL;
+       return new;
+}
Quoted 8 lines

drivers/usb/musb/musb_host.c line 116

Quoted 6 lines
drivers/usb/musb/musb_host.c +6 -0
+void push_queue(struct musb *musb, struct urb *urb)
+{
+       struct queue *new, *temp;
+
+       new = create();
+       new->urb = urb;

And you happily follow the NULL pointer in the error case.

I will put the NULL check here and also during push_queue(). In case Of memory allocation failure I can giveback the URB right away.

Quoted 14 lines

drivers/usb/musb/musb_host.c line 125

Quoted 10 lines
drivers/usb/musb/musb_host.c +9 -0
+
+       temp = musb->qhead;
+
+       spin_lock(&musb->qlock);
+       while (temp->next != NULL)
+               temp = temp->next;
+       temp->next = new;
+       spin_unlock(&musb->qlock);
+}

A design allocating memory in giveback is problematic. At least you need to handle a failure to allocate memory. But you'd better handle this by putting the list into the private part of the URB.

This would require a change in urb structure which would face more resistance as it will only be used by MUSB HCD.

Thanks,
Ajay

Quoted 3 lines

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 19F8576C6E063C45BE387C64729E7394044DB7A964-/tLxBxkBPtCIQmiDNMet8wC/[email protected]

#5 lore raw

Am Freitag, 26. Februar 2010 12:20:05 schrieb Gupta, Ajay Kumar:

Hello,

Quoted 27 lines
Quoted 18 lines

-----Original Message-----
From: Oliver Neukum [mailto:[email protected]]
Sent: Friday, February 26, 2010 4:33 PM
To: Gupta, Ajay Kumar
Cc: [email protected]; [email protected]; stern-nwvwT67g6+6dFdvTe/[email protected]
Subject: Re: [PATCH] musb: Add workqueue for URB giveback

Am Freitag, 26. Februar 2010 11:39:06 schrieb Ajay Kumar Gupta:

Quoted 9 lines
drivers/usb/musb/musb_host.c +9 -0
+struct queue *create(void)
+{
+       struct queue *new;
+       new = kmalloc(sizeof(struct queue), GFP_ATOMIC);
+       if (!new)
+               return NULL;
+       new->next = NULL;
+       return new;
+}
Quoted 8 lines

drivers/usb/musb/musb_host.c line 116

Quoted 6 lines
drivers/usb/musb/musb_host.c +6 -0
+void push_queue(struct musb *musb, struct urb *urb)
+{
+       struct queue *new, *temp;
+
+       new = create();
+       new->urb = urb;

And you happily follow the NULL pointer in the error case.

Quoted 2 lines

I will put the NULL check here and also during push_queue(). In case Of memory allocation failure I can giveback the URB right away.

If you do that you'll give back URBs out of order. Now I don't know whether this is defined as something you mustn't do, bad it is not a good idea.

Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Hi,

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Am Freitag, 26. Februar 2010 11:39:06 schrieb Ajay Kumar Gupta:

Quoted 5 lines
drivers/usb/musb/musb_host.c +5 -0
+struct queue *create(void)
+{
+       struct queue *new;
+       new = kmalloc(sizeof(struct queue), GFP_ATOMIC);
+       if (!new)

drivers/usb/musb/musb_host.c line 116

Quoted 10 lines
drivers/usb/musb/musb_host.c +10 -0
+               return NULL;
+       new->next = NULL;
+       return new;
+}
+void push_queue(struct musb *musb, struct urb *urb)
+{
+       struct queue *new, *temp;
+
+       new = create();
+       new->urb = urb;

And you happily follow the NULL pointer in the error case.

Quoted 4 lines
Quoted 2 lines

I will put the NULL check here and also during push_queue(). In case Of memory allocation failure I can giveback the URB right away.

If you do that you'll give back URBs out of order.

Right, this would confuse the class driver and better avoided.

Next option is to add another list_head within URB structure to trace the URBs. (as you suggested earlier)

-Ajay

Quoted 5 lines

Now I don't know whether this is defined as something you mustn't do, bad it is not a good idea.

Regards
Oliver

#7 lore raw
In reply to Ajay Kumar Gupta

Hi Ajay,

Quoted 5 lines · On Friday 26 February 2010 11:39:06 Ajay Kumar Gupta wrote:

Current musb host driver does the giveback of completed urb first and then start the next request. This is significantly affecting the streaming from an USB camera wherein we observe huge delay between the two IN tokens from musb host. This is due to the fact that UVC driver is doing decoding and further processing in giveback context.

I was thinking about adding a workqueue to the UVC driver for URB processing. If you beat my by writing a patch before I find time to do so, I won't complain ;-)

Signature · 3 lines
Regards,

Laurent Pinchart

A message that is not in the archive (sent off-list or not yet received): 201002261233.46872.laurent.pinchart-ryLnwIuWjnjg/[email protected]

#9 lore raw

Hi,

Quoted 16 lines

-----Original Message-----
From: Laurent Pinchart [mailto:laurent.pinchart-ryLnwIuWjnjg/[email protected]]
Sent: Friday, February 26, 2010 5:04 PM
To: Gupta, Ajay Kumar
Cc: [email protected]; [email protected]; stern-nwvwT67g6+6dFdvTe/[email protected]; [email protected]
Subject: Re: [PATCH] musb: Add workqueue for URB giveback

Hi Ajay,

Quoted 2 lines · On Friday 26 February 2010 11:39:06 Ajay Kumar Gupta wrote:

Current musb host driver does the giveback of completed urb first and then start the next request. This is significantly affecting the

streaming

Quoted 1 line

from an USB camera wherein we observe huge delay between the two IN

tokens

Quoted 8 lines
Quoted 1 line

from musb host. This is due to the fact that UVC driver is doing

decoding

Quoted 1 line

and further processing in giveback context.

I was thinking about adding a workqueue to the UVC driver for URB processing.
If you beat my by writing a patch before I find time to do so, I won't complain ;-)

Sure, I will see when I can post a RFC/PATCH for it. Probably after two weeks.

Regards,
Ajay

Quoted 5 lines

--
Regards,

Laurent Pinchart

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw
In reply to Ajay Kumar Gupta
Quoted 8 lines · Ajay Kumar Gupta

Current musb host driver does the giveback of completed urb first and then start the next request. This is significantly affecting the streaming from an USB camera wherein we observe huge delay between the two IN tokens from musb host. This is due to the fact that UVC driver is doing decoding and further processing in giveback context.

The patch tries to defer the giveback part to a workqueue and continues with the start of new request in completion path.

Suggest allocating a per-urb structure when a new URB is enqueued. This structure contains the completion/giveback work item. This avoids having to a) allocate memory on completion; b) create a second queue structure.

David

Signature · 6 lines
David Vrabel, Senior Software Engineer, Drivers
CSR, Churchill House, Cambridge Business Park,  Tel: +44 (0)1223 692562
Cowley Road, Cambridge, CB4 0WZ                 http://www.csr.com/


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom