All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Grzeschik <m.grzeschik@pengutronix.de>
To: linux-usb@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com,
	caleb.connolly@ideasonboard.com, paul.elder@ideasonboard.com,
	balbi@kernel.org, kernel@pengutronix.de
Subject: [PATCH v3 5/5] usb: gadget: uvc: decrease the interrupt load to a quarter
Date: Mon, 28 Jun 2021 17:53:11 +0200	[thread overview]
Message-ID: <20210628155311.16762-6-m.grzeschik@pengutronix.de> (raw)
In-Reply-To: <20210628155311.16762-1-m.grzeschik@pengutronix.de>

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: -
---
 drivers/usb/gadget/function/uvc.h       |  2 ++
 drivers/usb/gadget/function/uvc_video.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/function/uvc.h
index 36b78f8b3cd4c..255a61bd6a6a8 100644
--- a/drivers/usb/gadget/function/uvc.h
+++ b/drivers/usb/gadget/function/uvc.h
@@ -101,6 +101,8 @@ struct uvc_video {
 	struct list_head req_free;
 	spinlock_t req_lock;
 
+	unsigned int req_int_count;
+
 	void (*encode) (struct usb_request *req, struct uvc_video *video,
 			struct uvc_buffer *buf);
 
diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
index 2cefb8bd4f15b..b4a763e5f70e1 100644
--- a/drivers/usb/gadget/function/uvc_video.c
+++ b/drivers/usb/gadget/function/uvc_video.c
@@ -360,6 +360,19 @@ static void uvcg_video_pump(struct work_struct *work)
 
 		video->encode(req, video, buf);
 
+		/* With usb3 we have more requests. This will decrease the
+		 * interrupt load to a quarter but also catches the corner
+		 * cases, which needs to be handled */
+		if (list_empty(&video->req_free) ||
+		    buf->state == UVC_BUF_STATE_DONE ||
+		    !(video->req_int_count %
+		       DIV_ROUND_UP(video->uvc_num_requests, 4))) {
+			video->req_int_count = 0;
+			req->no_interrupt = 0;
+		} else {
+			req->no_interrupt = 1;
+		}
+
 		/* Queue the USB request */
 		ret = uvcg_video_ep_queue(video, req);
 		spin_unlock_irqrestore(&queue->irqlock, flags);
@@ -368,6 +381,7 @@ static void uvcg_video_pump(struct work_struct *work)
 			uvcg_queue_cancel(queue, 0);
 			break;
 		}
+		video->req_int_count++;
 	}
 
 	spin_lock_irqsave(&video->req_lock, flags);
@@ -416,6 +430,8 @@ int uvcg_video_enable(struct uvc_video *video, int enable)
 		video->encode = video->queue.use_sg ?
 			uvc_video_encode_isoc_sg : uvc_video_encode_isoc;
 
+	video->req_int_count = 0;
+
 	schedule_work(&video->pump);
 
 	return ret;
-- 
2.30.2


  parent reply	other threads:[~2021-06-28 15:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 15:53 [PATCH v3 0/5] usb: gadget: uvc: improve uvc gadget performance Michael Grzeschik
2021-06-28 15:53 ` [PATCH v3 1/5] usb: dwc3: gadget: set gadgets parent to the right controller Michael Grzeschik
2021-07-21  8:01   ` Greg KH
2021-07-21  8:11     ` Felipe Balbi
2021-06-28 15:53 ` [PATCH v3 2/5] usb: gadget: uvc: make uvc_num_requests depend on gadget speed Michael Grzeschik
2021-06-28 15:53 ` [PATCH v3 3/5] usb: gadget: uvc: set v4l2_dev->dev in f_uvc Michael Grzeschik
2021-06-28 15:53 ` [PATCH v3 4/5] usb: gadget: uvc: add scatter gather support Michael Grzeschik
2021-06-28 15:53 ` Michael Grzeschik [this message]
2021-06-28 16:47 ` [PATCH v3 0/5] usb: gadget: uvc: improve uvc gadget performance Michael Grzeschik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210628155311.16762-6-m.grzeschik@pengutronix.de \
    --to=m.grzeschik@pengutronix.de \
    --cc=balbi@kernel.org \
    --cc=caleb.connolly@ideasonboard.com \
    --cc=kernel@pengutronix.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=paul.elder@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.