Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: uvc: decrease the interrupt load to a quarter

With usb3 we handle many more requests. Decrease the interrupt load by
only enabling the interrupt every quarter of the allocated requests.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

--
v1 -> v2: - edited patch description
- removed extra parantheses
- added a comment for the logic
- using unsigned int instead of int
- reinitializing req_int_count in uvcg_video_enable
v2 -> v3: -
Link: https://lore.kernel.org/r/20210628155311.16762-6-m.grzeschik@pengutronix.de

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Michael Grzeschik and committed by
Greg Kroah-Hartman
fc78941d e81e7f9a

+18
+2
drivers/usb/gadget/function/uvc.h
··· 101 101 struct list_head req_free; 102 102 spinlock_t req_lock; 103 103 104 + unsigned int req_int_count; 105 + 104 106 void (*encode) (struct usb_request *req, struct uvc_video *video, 105 107 struct uvc_buffer *buf); 106 108
+16
drivers/usb/gadget/function/uvc_video.c
··· 360 360 361 361 video->encode(req, video, buf); 362 362 363 + /* With usb3 we have more requests. This will decrease the 364 + * interrupt load to a quarter but also catches the corner 365 + * cases, which needs to be handled */ 366 + if (list_empty(&video->req_free) || 367 + buf->state == UVC_BUF_STATE_DONE || 368 + !(video->req_int_count % 369 + DIV_ROUND_UP(video->uvc_num_requests, 4))) { 370 + video->req_int_count = 0; 371 + req->no_interrupt = 0; 372 + } else { 373 + req->no_interrupt = 1; 374 + } 375 + 363 376 /* Queue the USB request */ 364 377 ret = uvcg_video_ep_queue(video, req); 365 378 spin_unlock_irqrestore(&queue->irqlock, flags); ··· 381 368 uvcg_queue_cancel(queue, 0); 382 369 break; 383 370 } 371 + video->req_int_count++; 384 372 } 385 373 386 374 spin_lock_irqsave(&video->req_lock, flags); ··· 429 415 } else 430 416 video->encode = video->queue.use_sg ? 431 417 uvc_video_encode_isoc_sg : uvc_video_encode_isoc; 418 + 419 + video->req_int_count = 0; 432 420 433 421 schedule_work(&video->pump); 434 422