From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Devin Heitmueller <dheitmueller@kernellabs.com>
Cc: Manu Abraham <abraham.manu@gmail.com>,
Hans Verkuil <hverkuil@xs4all.nl>,
linux-media@vger.kernel.org
Subject: Re: [RFC] Serialization flag example
Date: Fri, 02 Apr 2010 18:15:19 -0300 [thread overview]
Message-ID: <4BB65E67.9050605@redhat.com> (raw)
In-Reply-To: <x2v829197381004021053nf77e2d42q4f1614eced7f999d@mail.gmail.com>
Devin Heitmueller wrote:
> On Fri, Apr 2, 2010 at 1:43 PM, Manu Abraham <abraham.manu@gmail.com> wrote:
>> IMO, A framework shouldn't lock.
Current DVB framework is locked with BKL. I agree that an unconditional
lock like this is very bad. We need to get rid of it as soon as possible.
> Hello Manu,
>
> The argument I am trying to make is that there are numerous cases
> where you should not be able to use both a particular DVB and V4L
> device at the same time. The implementation of such locking should be
> handled by the v4l-dvb core, but the definition of the relationships
> dictating which devices cannot be used in parallel is still the
> responsibility of the driver.
>
> This way, a bridge driver can say "this DVB device cannot be used at
> the same time as this V4L device" but the actual enforcement of the
> locking is done in the core. For cases where the devices can be used
> in parallel, the bridge driver doesn't have to do anything.
Although both are some sort of locks, the BKL replacement lock is
basically a memory barrier to serialize data, avoiding that the driver's
internal structs to be corrupted or to return a wrong value. Only the
driver really knows what should be protected.
In the case of V4L/DVB devices, the struct to be protected is the struct *_dev
(struct core, on cx88, struct em28xx on em28xx, struct saa7134_dev, and so on).
Of course, if everything got serialized by the core, and assuming that the
driver doesn't have IRQ's and/or other threads accessing the same data, the
problem disappears, at the expense of a performance reduction that may or
may not be relevant.
That's said, except for the most simple drivers, like radio ones, there's always
some sort of IRQ and/or threads evolved, touching on struct *_dev.
For example, both cx88 and saa7134 have (depending on the hardware):
- IRQ to announce that a data buffer was filled for video, vbi, alsa;
- IRQ for IR;
- IR polling;
- video audio standard detection thread;
A lock to protect the internal data structs should protect all the above. Even
the most pedantic core-only lock won't solve it.
Yet, a lock, on core, for ioctl/poll/open/close may be part of a protection, if
the same lock is used also to protect the other usages of struct *_dev.
So, I'm OK on having an optional mutex parameter to be passed to V4L core, to provide
the BKL removal.
In the case of a V4L x DVB type of lock, this is not to protect some memory, but,
instead, to limit the usage of a hardware that is not capable of simultaneously
provide V4L and DVB streams. This is a common case on almost all devices, but, as
Hermann pointed, there are a few devices that are capable of doing both analog
and digital streams at the same time, but saa7134 driver currently doesn't support.
Some drivers, like cx88 has a sort of lock meant to protect such things. It is
implemented on res_get/res_check/res_locked/res_free. Currently, the lock is only
protecting simultaneous usage of the analog part of the driver. It works by not
allowing to start two simultaneous video streams of the same memory access type,
for example, while allowing multiple device opens, for example to call V4L controls,
while another application is streaming. It also allows having a mmapped or overlay
stream and a separate read() stream (used on applications like xawtv and xdtv to
record a video on PCI devices that has enough bandwidth to provide two simultaneous
streams).
Maybe this kind of lock can be abstracted, and we can add a class of resource protectors
inside the core, for the drivers to use it when needed.
--
Cheers,
Mauro
next prev parent reply other threads:[~2010-04-02 21:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-01 17:37 [RFC] Serialization flag example Hans Verkuil
2010-04-01 18:24 ` Mauro Carvalho Chehab
2010-04-01 20:57 ` Hans Verkuil
2010-04-01 21:32 ` Mauro Carvalho Chehab
2010-04-02 8:57 ` Hans Verkuil
2010-04-02 16:06 ` Mauro Carvalho Chehab
2010-04-03 0:30 ` Andy Walls
2010-04-02 17:43 ` Manu Abraham
2010-04-02 17:53 ` Devin Heitmueller
2010-04-02 18:24 ` Manu Abraham
2010-04-02 18:34 ` Devin Heitmueller
2010-04-02 21:15 ` Mauro Carvalho Chehab [this message]
2010-04-03 0:47 ` Andy Walls
-- strict thread matches above, loose matches on Subject: below --
2010-04-03 11:55 Aw: " hermann-pitton
2010-04-04 3:14 ` David Ellingsworth
2010-04-05 22:46 ` Laurent Pinchart
2010-04-05 22:58 ` Hans Verkuil
2010-04-06 6:30 ` Hans Verkuil
2010-04-06 12:59 ` Mauro Carvalho Chehab
2010-04-06 13:54 ` Hans Verkuil
2010-04-06 14:42 ` Mauro Carvalho Chehab
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=4BB65E67.9050605@redhat.com \
--to=mchehab@redhat.com \
--cc=abraham.manu@gmail.com \
--cc=dheitmueller@kernellabs.com \
--cc=hverkuil@xs4all.nl \
--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