public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean-Francois Moine <moinejf@free.fr>
To: James Blanford <jhblanford@gmail.com>
Cc: linux-media@vger.kernel.org
Subject: Re: Race in gspca main or missing lock in stv06xx subdriver?
Date: Tue, 15 Sep 2009 12:41:06 +0200	[thread overview]
Message-ID: <20090915124106.35ad1382@tele> (raw)
In-Reply-To: <20090914111757.543c7e77@blackbart.localnet.prv>

On Mon, 14 Sep 2009 11:17:57 -0400
James Blanford <jhblanford@gmail.com> wrote:

> Howdy folks,
> 
> I have my old quickcam express webcam working, with HDCS1000
> sensor, 046d:840. It's clearly throwing away every other frame.  What
> seems to be happening is, while the last packet of the previous frame
> is being analyzed by the subdriver, the first packet of the next frame
> is assigned to the current frame buffer.  By the time that packet is
> analysed and sent back to the main driver, it's frame buffer has been
> completely filled and marked as "DONE."  The entire frame is then
> marked for "DISCARD."  This does _not_ happen with all cams using this
> subdriver.
> 
> Here's a little patch, supplied only to help illustrate the problem,
> that allows for the full, expected frame rate of the webcam.  What it
> does is wait until the very last moment to assign a frame buffer to
> any packet, but the last.  I also threw in a few printks so I can see
> where failure takes place without wading through a swamp of debug
> output.
	[snip]
> It works, at least until there is any disruption to the stream, such
> as an exposure change, and then something gets out of sync and it
> starts throwing out every other frame again.  It shows that the driver
> framework and USB bus is capable of handling the full frame rate.
> 
> I'll keep looking for an actual solution, but there is a lot I don't
> understand.  Any suggestions or ideas would be appreciated.  Several
> questions come to mind.  Why bother assigning a frame buffer with
> get_i_frame, before it's needed?  What purpose has frame_wait, when
> it's not called until the frame is completed and the buffer is marked
> as "DONE."  Why are there five, fr_i fr_q fr_o fr_queue index , buffer
> indexing counters?  I'm sure I don't understand all the different
> tasks this driver has to handle and all the different hardware it has
> to deal with.  But I would be surprised if my cam is the only one
> this is happening with.

Hi James,

I think you may have found a big problem, and this one should exist in
all drivers!

As I understood, you say that the URB completion routine (isoc_irq) may
be run many times at the same time.

With gspca, the problem is critical: the frame queue is managed without
any lock thanks to a circular buffer list (the pointers fr_i, fr_q and
fr_o). This mechanism works well when there are only one producer
(interrupt) and one consumer (application) (and to answer the question,
get_i_frame can be called anywere in the interrupt function because the
application is not running). Then, if there may be many producers...

For other drivers, the problem remains: the image fragments could be
received out of order.

How is this possible? Looking at some kernel documents, I found that
the URB completion routine is called from the bottom-half entity (thus,
not under hardware interrupt). A bottom-half may be a tasklet or a soft
irq. There may be only one active tasklet at a time, while there may be
many softirqs running (on the interrupt CPU). It seems that we are in
the last case, and I could not find any mean to change that.

Then, to fix this problem, I see only one solution: have a private
tasklet to do the video streaming, as this is done for some bulk
transfer...

Cheers.

-- 
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/

  reply	other threads:[~2009-09-15 10:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-14 15:17 Race in gspca main or missing lock in stv06xx subdriver? James Blanford
2009-09-15 10:41 ` Jean-Francois Moine [this message]
2009-10-01 13:23   ` Erik Andrén
2009-10-03  7:28     ` Jean-Francois Moine
2009-10-04 10:45       ` Erik Andrén
2009-10-04 15:36   ` Hans de Goede
2009-10-04 16:41     ` Jean-Francois Moine

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=20090915124106.35ad1382@tele \
    --to=moinejf@free.fr \
    --cc=jhblanford@gmail.com \
    --cc=linux-media@vger.kernel.org \
    /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