mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
To: Kieran Bingham <kbingham@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	laurent.pinchart@ideasonboard.com,
	Olivier BRAUN <olivier.braun@stereolabs.com>,
	kieran.bingham@ideasonboard.com,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Baoyou Xie <baoyou.xie@linaro.org>,
	Jaejoong Kim <climbbb.kim@gmail.com>,
	Kate Stewart <kstewart@linuxfoundation.org>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Daniel Patrick Johnson <teknotus@teknot.us>,
	Jim Lin <jilin@nvidia.com>
Subject: Re: [RFC/RFT PATCH 6/6] uvcvideo: Move decode processing to process context
Date: Thu, 4 Jan 2018 19:54:28 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1801041941320.13441@axis700.grange> (raw)
In-Reply-To: <48e2716d3902214a89aa30f3d1672512f8ea8773.1515010476.git-series.kieran.bingham@ideasonboard.com>

On Wed, 3 Jan 2018, Kieran Bingham wrote:

> From: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> Newer high definition cameras, and cameras with multiple lenses such as
> the range of stereovision cameras now available have ever increasing
> data rates.
> 
> The inclusion of a variable length packet header in URB packets mean
> that we must memcpy the frame data out to our destination 'manually'.
> This can result in data rates of up to 2 gigabits per second being
> processed.
> 
> To improve efficiency, and maximise throughput, handle the URB decode
> processing through a work queue to move it from interrupt context, and
> allow multiple processors to work on URBs in parallel.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  drivers/media/usb/uvc/uvc_queue.c |  12 +++-
>  drivers/media/usb/uvc/uvc_video.c | 114 ++++++++++++++++++++++++++-----
>  drivers/media/usb/uvc/uvcvideo.h  |  24 +++++++-
>  3 files changed, 132 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
> index 204dd91a8526..07fcbfc132c9 100644
> --- a/drivers/media/usb/uvc/uvc_queue.c
> +++ b/drivers/media/usb/uvc/uvc_queue.c
> @@ -179,10 +179,22 @@ static void uvc_stop_streaming(struct vb2_queue *vq)
>  	struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
>  	struct uvc_streaming *stream = uvc_queue_to_stream(queue);
>  
> +	/* Prevent new buffers coming in. */
> +	spin_lock_irq(&queue->irqlock);
> +	queue->flags |= UVC_QUEUE_STOPPING;
> +	spin_unlock_irq(&queue->irqlock);
> +
> +	/*
> +	 * All pending work should be completed before disabling the stream, as
> +	 * all URBs will be free'd during uvc_video_enable(s, 0).
> +	 */
> +	flush_workqueue(stream->async_wq);
> +
>  	uvc_video_enable(stream, 0);
>  
>  	spin_lock_irq(&queue->irqlock);
>  	uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);
> +	queue->flags &= ~UVC_QUEUE_STOPPING;
>  	spin_unlock_irq(&queue->irqlock);
>  }
>  
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 045ac655313c..b7b32a6bc2dc 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1058,21 +1058,70 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
>  	return data[0];
>  }
>  
> -static void uvc_video_decode_data(struct uvc_streaming *stream,
> -		struct uvc_buffer *buf, const __u8 *data, int len)
> +/*
> + * uvc_video_decode_data_work: Asynchronous memcpy processing
> + *
> + * Perform memcpy tasks in process context, with completion handlers
> + * to return the URB, and buffer handles.
> + *
> + * The work submitter must pre-determine that the work is safe
> + */
> +static void uvc_video_decode_data_work(struct work_struct *work)
>  {
> -	unsigned int maxlen, nbytes;
> -	void *mem;
> +	struct uvc_urb *uvc_urb = container_of(work, struct uvc_urb, work);
> +	struct uvc_streaming *stream = uvc_urb->stream;
> +	struct uvc_video_queue *queue = &stream->queue;
> +	unsigned int i;
> +	bool stopping;
> +	int ret;
> +
> +	for (i = 0; i < uvc_urb->packets; i++) {
> +		struct uvc_decode_op *op = &uvc_urb->decodes[i];
> +
> +		memcpy(op->dst, op->src, op->len);
> +
> +		/* Release reference taken on this buffer */
> +		uvc_queue_buffer_release(op->buf);
> +	}
> +
> +	/*
> +	 * Prevent resubmitting URBs when shutting down to ensure that no new
> +	 * work item will be scheduled after uvc_stop_streaming() flushes the
> +	 * work queue.
> +	 */
> +	spin_lock_irq(&queue->irqlock);
> +	stopping = queue->flags & UVC_QUEUE_STOPPING;
> +	spin_unlock_irq(&queue->irqlock);

Are you sure this locking really helps? What if uvc_stop_streaming() runs 
here?

Thanks
Guennadi

> +
> +	if (stopping)
> +		return;
> +
> +	ret = usb_submit_urb(uvc_urb->urb, GFP_ATOMIC);
> +	if (ret < 0)
> +		uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n",
> +			   ret);
> +}

  reply	other threads:[~2018-01-04 18:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 20:32 [RFC/RFT PATCH 0/6] Asynchronous UVC Kieran Bingham
2018-01-03 20:32 ` [RFC/RFT PATCH 1/6] uvcvideo: Refactor URB descriptors Kieran Bingham
2018-01-04 18:24   ` Guennadi Liakhovetski
2018-01-06 18:30     ` Kieran Bingham
2018-01-03 20:32 ` [RFC/RFT PATCH 2/6] uvcvideo: Convert decode functions to use new context structure Kieran Bingham
2018-01-03 20:32 ` [RFC/RFT PATCH 3/6] uvcvideo: Protect queue internals with helper Kieran Bingham
2018-01-04 18:25   ` Guennadi Liakhovetski
2018-01-06 18:37     ` Kieran Bingham
2018-01-03 20:32 ` [RFC/RFT PATCH 4/6] uvcvideo: queue: Simplify spin-lock usage Kieran Bingham
2018-01-03 20:32 ` [RFC/RFT PATCH 5/6] uvcvideo: queue: Support asynchronous buffer handling Kieran Bingham
2018-01-03 20:32 ` [RFC/RFT PATCH 6/6] uvcvideo: Move decode processing to process context Kieran Bingham
2018-01-04 18:54   ` Guennadi Liakhovetski [this message]
2018-01-06 18:29     ` Kieran Bingham
2018-01-03 21:13 ` [RFC/RFT PATCH 0/6] Asynchronous UVC Troy Kisky
2018-01-04 10:25   ` Kieran Bingham
2018-06-05  9:01   ` Kieran Bingham
2018-06-05 19:18     ` Troy Kisky

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=alpine.DEB.2.20.1801041941320.13441@axis700.grange \
    --to=g.liakhovetski@gmx.de \
    --cc=baoyou.xie@linaro.org \
    --cc=climbbb.kim@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hans.verkuil@cisco.com \
    --cc=jilin@nvidia.com \
    --cc=kbingham@kernel.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=olivier.braun@stereolabs.com \
    --cc=teknotus@teknot.us \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®