media: uvcvideo: handle urb completion in a work queue
Subsystems (2)
PATCH 1/1 media: uvcvideo: handle urb completion in a work queue
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
---
History:
v1:
- Use global work queue instead of creating ordered queue.
- Add completed urbs to a list and process all on the list when work is scheduled
- Save timestamp and sof number in urb completion callback and use in uvc_video_clock_decode() and uvc_video_decode_start()
- Fix race between usb_submit_urb() from uvc_video_complete() and usb_kill_urb() from uvc_uninit_video()
drivers/media/usb/uvc/uvc_isight.c | 3 +- drivers/media/usb/uvc/uvc_video.c | 132 +++++++++++++++++++++++++++---------- drivers/media/usb/uvc/uvcvideo.h | 17 ++++- 3 files changed, 113 insertions(+), 39 deletions(-)
drivers/media/usb/uvc/uvc_isight.c +2 -1
@@ -99,9 +99,10 @@ static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,return 0 ; } -void uvc_video_decode_isight (struct urb *urb,struct uvc_streaming *stream, +void uvc_video_decode_isight (struct uvc_urb *uu,struct uvc_streaming *stream,struct uvc_buffer *buf) { +struct urb *urb = uu->urb;int ret, i;for (i =0 ; i < urb->number_of_packets; ++i) {
drivers/media/usb/uvc/uvc_video.c +97 -35
288 lines not on this page · raw message
drivers/media/usb/uvc/uvcvideo.h +14 -3
@@ -440,6 +440,13 @@ struct uvc_stats_stream {unsigned int max_sof;/* Maximum STC.SOF value */ }; +struct uvc_urb { +struct urb *urb; +struct uvc_streaming *stream; +struct timespec ts; +u16 sof; +}; +struct uvc_streaming {struct list_head list;struct uvc_device *dev;
@@ -470,7 +477,7 @@ struct uvc_streaming {/* Buffers queue. */ unsigned int frozen : 1;struct uvc_video_queue queue; -void (*decode) (struct urb *urb,struct uvc_streaming *video, +void (*decode)(struct uvc_urb *uu,struct uvc_streaming *video,struct uvc_buffer *buf);/* Context data used by the bulk completion handler. */
@@ -482,7 +489,11 @@ struct uvc_streaming {__u32 max_payload_size; } bulk; -struct urb *urb[UVC_URBS ]; +bool stop; +spinlock_t urb_list_lock; +struct list_head urb_complete_list; +struct work_struct urb_work; +struct uvc_urb uvc_urb[UVC_URBS ];char *urb_buffer[UVC_URBS ];dma_addr_t urb_dma[UVC_URBS ];unsigned int urb_size;
@@ -728,7 +739,7 @@ extern struct usb_host_endpoint *uvc_find_endpoint( struct usb_host_interface *alts, __u8 epaddr);/* Quirks support */ -void uvc_video_decode_isight (struct urb *urb,struct uvc_streaming *stream, +void uvc_video_decode_isight (struct uvc_urb *uu,struct uvc_streaming *stream,struct uvc_buffer *buf);/* debugfs and statistics */
Signature · 1 line
2.3.3
Quoted 4 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Quoted 8 lines
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Signed-off-by Mian Yousaf Kaukab <[email protected]>---
History:
v1:
- Use global work queue instead of creating ordered queue.
1. using a common queue for real-time work is probably not nice for picture quality
2. it will deadlock under some conditions
The explanation is a bit long
Suppose we have a device with a camera and a storage device, like an ordinary camera you can use as a video device which also exports its memory card.
Now we assume that the storage part is suspended.
CPU A CPU B
work item scheduled
entering uvc_uninit_video()
work item executed work item allocates memory write to storage interface storage interface being resumedflush_work() - waiting for CPU B
DEADLOCK
If you want to use flush_work() you must use a dedicated queue.
Regards
Oliver
Hi,
Quoted 6 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Erm, I thought that we had already moved to using threaded interrupt handling for the urb completion a while (1-2 years ?) back. Is this then still needed ?
Regards,
Hans
Quoted 398 lines
Signed-off-by Mian Yousaf Kaukab <[email protected]>---
History:
v1:
- Use global work queue instead of creating ordered queue.
- Add completed urbs to a list and process all on the list when work is scheduled
- Save timestamp and sof number in urb completion callback and use inuvc_video_clock_decode()anduvc_video_decode_start()
- Fix race betweenusb_submit_urb()fromuvc_video_complete()andusb_kill_urb()fromuvc_uninit_video()drivers/media/usb/uvc/uvc_isight.c | 3 +- drivers/media/usb/uvc/uvc_video.c | 132 +++++++++++++++++++++++++++---------- drivers/media/usb/uvc/uvcvideo.h | 17 ++++- 3 files changed, 113 insertions(+), 39 deletions(-)drivers/media/usb/uvc/uvc_isight.c +2
-1@@ -99,9 +99,10 @@ static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,return 0 ; } -void uvc_video_decode_isight (struct urb *urb,struct uvc_streaming *stream, +void uvc_video_decode_isight (struct uvc_urb *uu,struct uvc_streaming *stream,struct uvc_buffer *buf) { +struct urb *urb = uu->urb;int ret, i;for (i =0 ; i < urb->number_of_packets; ++i) {drivers/media/usb/uvc/uvc_video.c +97
-35@@ -379,15 +379,14 @@ static inline void uvc_video_get_ts(struct timespec *ts)static void uvc_video_clock_decode (struct uvc_streaming *stream,struct uvc_buffer *buf, -const __u8 *data,int len) +const __u8 *data,int len,u16 host_sof, +struct timespec *ts) {struct uvc_clock_sample *sample;unsigned int header_size;bool has_pts = false;bool has_scr = false;unsigned long flags; -struct timespec ts; -u16 host_sof;u16 dev_sof;switch (data[1 ] & (UVC_STREAM_PTS |UVC_STREAM_SCR )) {@@ -435,9 +434,6 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, stream->clock.last_sof = dev_sof; - host_sof =usb_get_current_frame_number (stream->dev->udev); -uvc_video_get_ts (&ts); -/* The UVC specification allows device implementations that can't obtain * the USB frame number to keep their own frame counters as long as they * match the size and frequency of the frame number associated with USB @@ -473,7 +469,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, sample->dev_stc =get_unaligned_le32 (&data[header_size -6 ]); sample->dev_sof = dev_sof; sample->host_sof = host_sof; - sample->host_ts = ts; + sample->host_ts = *ts;/* Update the sliding window head and count. */ stream->clock.head = (stream->clock.head +1 ) % stream->clock.size;@@ -964,7 +960,8 @@ static void uvc_video_stats_stop(struct uvc_streaming *stream)* uvc_video_decode_end will never be called with a NULL buffer. */ static int uvc_video_decode_start (struct uvc_streaming *stream, -struct uvc_buffer *buf,const __u8 *data,int len) +struct uvc_buffer *buf,const __u8 *data,int len, +u16 host_sof,struct timespec *ts) {__u8 fid;@@ -989,7 +986,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,uvc_video_stats_update (stream); } -uvc_video_clock_decode (stream, buf, data, len); +uvc_video_clock_decode (stream, buf, data, len, host_sof, ts);uvc_video_stats_decode (stream, data, len);/* Store the payload FID bit and return immediately when the buffer is @@ -1016,8 +1013,6 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,* when the EOF bit is set to force synchronisation on the next packet. */ if (buf->state !=UVC_BUF_STATE_ACTIVE ) { -struct timespec ts; -if (fid == stream->last_fid) {uvc_trace (UVC_TRACE_FRAME ,"Dropping payload (out of " "sync).\n" );@@ -1027,13 +1022,11 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,return -ENODATA ; } -uvc_video_get_ts (&ts); - buf->buf.v4l2_buf.field =V4L2_FIELD_NONE ; buf->buf.v4l2_buf.sequence = stream->sequence; - buf->buf.v4l2_buf.timestamp.tv_sec = ts.tv_sec; + buf->buf.v4l2_buf.timestamp.tv_sec = ts->tv_sec; buf->buf.v4l2_buf.timestamp.tv_usec = - ts.tv_nsec /NSEC_PER_USEC ; + ts->tv_nsec /NSEC_PER_USEC ;/* TODO: Handle PTS and SCR. */ buf->state =UVC_BUF_STATE_ACTIVE ;@@ -1160,9 +1153,10 @@ static void uvc_video_validate_buffer(const struct uvc_streaming *stream,/* * Completion handler for video URBs. */ -static void uvc_video_decode_isoc (struct urb *urb,struct uvc_streaming *stream, -struct uvc_buffer *buf) +static void uvc_video_decode_isoc (struct uvc_urb *uu, +struct uvc_streaming *stream,struct uvc_buffer *buf) { +struct urb *urb = uu->urb;u8 *mem;int ret, i;@@ -1180,7 +1174,8 @@ static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream, mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset; do { ret = uvc_video_decode_start(stream, buf, mem, - urb->iso_frame_desc[i].actual_length); + urb->iso_frame_desc[i].actual_length, uu->sof, + &uu->ts); if (ret == -EAGAIN) { uvc_video_validate_buffer(stream, buf); buf = uvc_queue_next_buffer(&stream->queue,@@ -1206,9 +1201,10 @@ static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream, } } -static void uvc_video_decode_bulk (struct urb *urb,struct uvc_streaming *stream, -struct uvc_buffer *buf) +static void uvc_video_decode_bulk (struct uvc_urb *uu, +struct uvc_streaming *stream,struct uvc_buffer *buf) { +struct urb *urb = uu->urb;u8 *mem;int len, ret;@@ -1228,7 +1224,8 @@ static void uvc_video_decode_bulk(struct urb *urb, struct uvc_streaming *stream,*/ if (stream->bulk.header_size ==0 && !stream->bulk.skip_payload) { do { - ret = uvc_video_decode_start(stream, buf, mem, len); + ret = uvc_video_decode_start(stream, buf, mem, len, + uu->sof, &uu->ts); if (ret == -EAGAIN) buf = uvc_queue_next_buffer(&stream->queue, buf);@@ -1274,9 +1271,10 @@ static void uvc_video_decode_bulk(struct urb *urb, struct uvc_streaming *stream, } } -static void uvc_video_encode_bulk (struct urb *urb,struct uvc_streaming *stream, -struct uvc_buffer *buf) +static void uvc_video_encode_bulk (struct uvc_urb *uu, +struct uvc_streaming *stream,struct uvc_buffer *buf) { +struct urb *urb = uu->urb;u8 *mem = urb->transfer_buffer;int len = stream->urb_size, ret;@@ -1317,9 +1315,26 @@ static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream, urb->transfer_buffer_length = stream->urb_size - len; } -static void uvc_video_complete (struct urb *urb) +static void uvc_urb_complete (struct urb *urb) { -struct uvc_streaming *stream = urb->context; +struct uvc_urb *uu = urb->context; +struct uvc_streaming *stream = uu->stream; +unsigned long flags; + + uu->sof =usb_get_current_frame_number (stream->dev->udev); +uvc_video_get_ts (&uu->ts); + +spin_lock_irqsave (&stream->urb_list_lock, flags); +list_add_tail (&urb->urb_list, &stream->urb_complete_list); +spin_unlock_irqrestore (&stream->urb_list_lock, flags); + +schedule_work (&stream->urb_work); +} + +static void uvc_video_complete (struct uvc_urb *uu) +{ +struct urb *urb = uu->urb; +struct uvc_streaming *stream = uu->stream;struct uvc_video_queue *queue = &stream->queue;struct uvc_buffer *buf =NULL ;unsigned long flags;@@ -1349,7 +1364,10 @@ static void uvc_video_complete(struct urb *urb) queue);spin_unlock_irqrestore (&queue->irqlock, flags); - stream->decode (urb, stream, buf); + stream->decode (uu, stream, buf); + +if (stream->stop) +return ;if ((ret =usb_submit_urb (urb,GFP_ATOMIC )) <0 ) { uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n",@@ -1357,6 +1375,29 @@ static void uvc_video_complete(struct urb *urb) } } +static void uvc_video_complete_work (struct work_struct *work) +{ + struct uvc_streaming *stream = container_of(work, struct uvc_streaming, + urb_work); +struct urb *urb; +unsigned long flags; +int i; + +for (i =0 ; i <UVC_URBS ; i++) { +spin_lock_irqsave (&stream->urb_list_lock, flags); +if (list_empty (&stream->urb_complete_list)) { +spin_unlock_irqrestore (&stream->urb_list_lock, flags); +return ; + } + urb =list_first_entry (&stream->urb_complete_list, + struct urb, urb_list); +list_del (&urb->urb_list); +spin_unlock_irqrestore (&stream->urb_list_lock, flags); + +uvc_video_complete (urb->context); + } +} +/* * Free transfer buffers. */ @@ -1448,14 +1489,28 @@ static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers)uvc_video_stats_stop (stream); +/* set stop and make sure no urb is being submitted.*/ + stream->stop = true; +flush_work (&stream->urb_work); +for (i =0 ; i <UVC_URBS ; ++i) { - urb = stream->urb[i]; + urb = stream->uvc_urb[i].urb;if (urb ==NULL )continue ;usb_kill_urb (urb); + } + +/* Finish all kill callbacks */ +flush_work (&stream->urb_work); + +for (i =0 ; i <UVC_URBS ; ++i) { + urb = stream->uvc_urb[i].urb; +if (urb ==NULL ) +continue ; +usb_free_urb (urb); - stream->urb[i] =NULL ; + stream->uvc_urb[i].urb =NULL ; }if (free_buffers)@@ -1514,7 +1569,7 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, } urb->dev = stream->dev->udev; - urb->context = stream; + urb->context = &stream->uvc_urb[i]; urb->pipe =usb_rcvisocpipe (stream->dev->udev, ep->desc.bEndpointAddress);#ifndef CONFIG_DMA_NONCOHERENT @@ -1525,7 +1580,7 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,#endif urb->interval = ep->desc.bInterval; urb->transfer_buffer = stream->urb_buffer[i]; - urb->complete = uvc_video_complete; + urb->complete = uvc_urb_complete; urb->number_of_packets = npackets; urb->transfer_buffer_length = size;@@ -1534,7 +1589,8 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, urb->iso_frame_desc[j].length = psize; } - stream->urb[i] = urb; + stream->uvc_urb[i].urb = urb; + stream->uvc_urb[i].stream = stream; }return 0 ;@@ -1580,14 +1636,15 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream, }usb_fill_bulk_urb (urb, stream->dev->udev, pipe, - stream->urb_buffer[i], size, uvc_video_complete, - stream); + stream->urb_buffer[i], size, uvc_urb_complete, + &stream->uvc_urb[i]);#ifndef CONFIG_DMA_NONCOHERENT urb->transfer_flags =URB_NO_TRANSFER_DMA_MAP ; urb->transfer_dma = stream->urb_dma[i];#endif - stream->urb[i] = urb; + stream->uvc_urb[i].urb = urb; + stream->uvc_urb[i].stream = stream; }return 0 ;@@ -1611,6 +1668,11 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags)uvc_video_stats_start (stream); +INIT_WORK (&stream->urb_work, uvc_video_complete_work); +INIT_LIST_HEAD (&stream->urb_complete_list); +spin_lock_init (&stream->urb_list_lock); + stream->stop = false; +if (intf->num_altsetting >1 ) {struct usb_host_endpoint *best_ep =NULL ;unsigned int best_psize =UINT_MAX ;@@ -1678,7 +1740,7 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags)/* Submit the URBs. */ for (i =0 ; i <UVC_URBS ; ++i) { - ret =usb_submit_urb (stream->urb[i], gfp_flags); + ret =usb_submit_urb (stream->uvc_urb[i].urb, gfp_flags);if (ret <0 ) {uvc_printk (KERN_ERR ,"Failed to submit URB %u " "(%d).\n" , i, ret);drivers/media/usb/uvc/uvcvideo.h +14
-3@@ -440,6 +440,13 @@ struct uvc_stats_stream {unsigned int max_sof;/* Maximum STC.SOF value */ }; +struct uvc_urb { +struct urb *urb; +struct uvc_streaming *stream; +struct timespec ts; +u16 sof; +}; +struct uvc_streaming {struct list_head list;struct uvc_device *dev;@@ -470,7 +477,7 @@ struct uvc_streaming {/* Buffers queue. */ unsigned int frozen : 1;struct uvc_video_queue queue; -void (*decode) (struct urb *urb,struct uvc_streaming *video, +void (*decode)(struct uvc_urb *uu,struct uvc_streaming *video,struct uvc_buffer *buf);/* Context data used by the bulk completion handler. */ @@ -482,7 +489,11 @@ struct uvc_streaming {__u32 max_payload_size; } bulk; -struct urb *urb[UVC_URBS ]; +bool stop; +spinlock_t urb_list_lock; +struct list_head urb_complete_list; +struct work_struct urb_work; +struct uvc_urb uvc_urb[UVC_URBS ];char *urb_buffer[UVC_URBS ];dma_addr_t urb_dma[UVC_URBS ];unsigned int urb_size;@@ -728,7 +739,7 @@ extern struct usb_host_endpoint *uvc_find_endpoint( struct usb_host_interface *alts, __u8 epaddr);/* Quirks support */ -void uvc_video_decode_isight (struct urb *urb,struct uvc_streaming *stream, +void uvc_video_decode_isight (struct uvc_urb *uu,struct uvc_streaming *stream,struct uvc_buffer *buf);/* debugfs and statistics */
Quoted 7 lines · Hans de Goede
Hi,
Quoted 4 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Quoted 6 lines
Quoted 2 lines
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Erm, I thought that we had already moved to using threaded interrupt handling for the urb completion a while (1-2 years ?) back. Is this then still needed ?
We moved to handling URB completions in a tasklet, not a threaded handler. (Similar idea, though.) And the change was made in only one or two HCDs, not in all of them.
Alan Stern
Hi,
Quoted 12 lines · Alan Stern
Quoted 10 lines · Hans de Goede
Hi,
Quoted 6 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Quoted 6 lines
Quoted 3 lines
Erm, I thought that we had already moved to using threaded interrupt handling for the urb completion a while (1-2 years ?) back. Is this then still needed ?
We moved to handling URB completions in a tasklet, not a threaded handler.
Right.
Quoted 2 lines
(Similar idea, though.) And the change was made in only one or two HCDs, not in all of them.
Ah, I was under the impression this was a core change, not a per hcd change.
Regards,
Hans
Laurent Pinchart
maintainerQuoted 17 lines · On Wednesday 09 September 2015 10:30:12 Hans de Goede wrote:
Quoted 9 lines · Alan Stern
Quoted 8 lines · Hans de Goede
Quoted 6 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Quoted 6 lines
Quoted 3 lines
Erm, I thought that we had already moved to using threaded interrupt handling for the urb completion a while (1-2 years ?) back. Is this then still needed ?
We moved to handling URB completions in a tasklet, not a threaded handler.
Quoted 7 lines
Right.
Quoted 2 lines
(Similar idea, though.) And the change was made in only one or two HCDs, not in all of them.
Ah, I was under the impression this was a core change, not a per hcd change.
Instead of fixing the issue in the uvcvideo driver, would it then make more sense to fix it in the remaining hcd drivers ?
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 20 lines · Laurent Pinchart
Quoted 19 lines · On Wednesday 09 September 2015 10:30:12 Hans de Goede wrote:
Quoted 9 lines · Alan Stern
Quoted 8 lines · Hans de Goede
Quoted 6 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Quoted 6 lines
Quoted 3 lines
Erm, I thought that we had already moved to using threaded interrupt handling for the urb completion a while (1-2 years ?) back. Is this then still needed ?
We moved to handling URB completions in a tasklet, not a threaded handler.
Right.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
(Similar idea, though.) And the change was made in only one or two HCDs, not in all of them.
Ah, I was under the impression this was a core change, not a per hcd change.
Instead of fixing the issue in the uvcvideo driver, would it then make more sense to fix it in the remaining hcd drivers ?
Unfortunately that's not so easy. It involves some subtle changes related to the way isochronous endpoints are handled. I wouldn't know what to change in any of the HCDs, except the ones that I maintain.
Alan Stern
Laurent Pinchart
maintainerHi Alan,
Quoted 27 lines · On Wednesday 09 September 2015 11:14:38 Alan Stern wrote:
Quoted 26 lines · Laurent Pinchart
Quoted 24 lines · On Wednesday 09 September 2015 10:30:12 Hans de Goede wrote:
Quoted 9 lines · Alan Stern
Quoted 8 lines · Hans de Goede
Quoted 6 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Quoted 6 lines
Quoted 3 lines
Erm, I thought that we had already moved to using threaded interrupt handling for the urb completion a while (1-2 years ?) back. Is this then still needed ?
We moved to handling URB completions in a tasklet, not a threaded handler.
Right.
Quoted 2 lines
(Similar idea, though.) And the change was made in only one or two HCDs, not in all of them.
Ah, I was under the impression this was a core change, not a per hcd change.
Quoted 6 lines
Quoted 2 lines
Instead of fixing the issue in the uvcvideo driver, would it then make more sense to fix it in the remaining hcd drivers ?
Unfortunately that's not so easy. It involves some subtle changes related to the way isochronous endpoints are handled. I wouldn't know what to change in any of the HCDs, except the ones that I maintain.
I'm not saying it would be easy, but I'm wondering whether it makes change to move individual USB device drivers to work queues when the long term goal is to use tasklets for URB completion anyway.
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 10 lines · Laurent Pinchart
Quoted 6 lines
Quoted 2 lines
Instead of fixing the issue in the uvcvideo driver, would it then make more sense to fix it in the remaining hcd drivers ?
Unfortunately that's not so easy. It involves some subtle changes related to the way isochronous endpoints are handled. I wouldn't know what to change in any of the HCDs, except the ones that I maintain.
I'm not saying it would be easy, but I'm wondering whether it makes change to move individual USB device drivers to work queues when the long term goal is to use tasklets for URB completion anyway.
I'm not sure that this is a long-term goal for every HCD. For instance, there probably isn't much incentive to convert a driver if its host controllers can only run at low speed or full speed.
Alan Stern
Quoted 18 lines
-----Original Message-----
From: Alan Stern [mailto:[email protected]]
Sent: Wednesday, September 9, 2015 6:30 PM
To: Laurent Pinchart
Cc: Hans de Goede; Kaukab, Yousaf; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1] media: uvcvideo: handle urb completion in a work queueQuoted 7 lines · Laurent Pinchart
Quoted 6 lines
Quoted 2 lines
Instead of fixing the issue in the uvcvideo driver, would it then make more sense to fix it in the remaining hcd drivers ?
Unfortunately that's not so easy. It involves some subtle changes related to the way isochronous endpoints are handled. I wouldn't know what to change in any of the HCDs, except the ones that I maintain.
Quoted 8 lines
Quoted 3 lines
I'm not saying it would be easy, but I'm wondering whether it makes change to move individual USB device drivers to work queues when the long term goal is to use tasklets for URB completion anyway.
I'm not sure that this is a long-term goal for every HCD. For instance, there probably isn't much incentive to convert a driver if its host controllers can only run at low speed or full speed.
I can convert this patch to use tasklets instead and only schedule the tasklet if urb->complete is called in interrupt context. This way, hcd using tasklet or not, uvc driver behavior will be almost same. Only difference is that local interrupts will still be enabled when tasklet scheduled from uvc driver is executing the completion function.
This patch can be dropped once all hcd's start using tasklets for the completion callback (if that ever happens).
BR,
Yousaf
Quoted 22 lines · Hans de Goede
Hi,
Quoted 12 lines · Alan Stern
Quoted 10 lines · Hans de Goede
Hi,
Quoted 6 lines · Mian Yousaf Kaukab
urb completion callback is executed in host controllers interrupt context. To keep preempt disable time short, add urbs to a list on completion and schedule work to process the list.
Moreover, save timestamp and sof number in the urb completion callback to avoid any delays.
Quoted 6 lines
Quoted 3 lines
Erm, I thought that we had already moved to using threaded interrupt handling for the urb completion a while (1-2 years ?) back. Is this then still needed ?
We moved to handling URB completions in a tasklet, not a threaded handler.
Quoted 7 lines
Right.
Quoted 2 lines
(Similar idea, though.) And the change was made in only one or two HCDs, not in all of them.
Ah, I was under the impression this was a core change, not a per hcd change.
In fact, both the core and the HCD needed to be changed. For example, see commits 94dfd7edfd5c (core) and 9118f9eb4f1e (ehci-hcd). (There was more to it than just those two commits, of course.)
In one respect the change still isn't complete: Since the completion callback occurs in a tasklet, we should allow interrupts to remain enabled while the callback runs. But some class drivers still expect interrupts to be disabled at that time, so the core has to disable interrupts before invoking the callback and then re-enable them afterward.
There was a proposal to fix up a number of drivers so that we could leave interrupts enabled the whole time. But I don't think it ever got merged.
Alan Stern