linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Andy Walls <awalls@md.metrocast.net>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	linux-media@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: Re: RFC: BKL, locking and ioctls
Date: Sun, 19 Sep 2010 16:26:00 -0300	[thread overview]
Message-ID: <4C9663C8.2060808@redhat.com> (raw)
In-Reply-To: <1284923146.2079.83.camel@morgan.silverblock.net>

Em 19-09-2010 16:05, Andy Walls escreveu:
> On Sun, 2010-09-19 at 08:43 -0300, Mauro Carvalho Chehab wrote: 
>> Hi Hans,
>>
> 
>> A per-dev lock may not be good on devices where you have lots of interfaces, and that allows
>> more than one stream per interface.
>>
>> So, I did a different implementation, implementing the mutex pointer per file handler.
>> On devices that a simple lock is possible, all you need to do is to use the same locking
>> for all file handles, but if drivers want a finer control, they can use a per-file handler
>> lock.
>>
>> I'm adding the patches I did at media-tree.git. I've created a separate branch there (devel/bkl):
>> 	http://git.linuxtv.org/media_tree.git?a=shortlog;h=refs/heads/devel/bkl
>>
>> I've already applied there the other BKL-lock removal patches I've sent before, plus one new
>> one, fixing a lock unbalance at bttv poll function (changeset 32d1c90c85).
>>
>> The v4l2 core patches are at:
>>
>> http://git.linuxtv.org/media_tree.git?a=commit;h=285267378581fbf852f24f3f99d2e937cd200fd5
>> http://git.linuxtv.org/media_tree.git?a=commit;h=5f7b2159c87b08d4f0961c233a2d1d1b87c8b38d
>>
>> The approach I took serializes open, close, ioctl, mmap, read and poll, e. g. all file operations
>> done by the V4L devices.
> 
> Hi Mauro,
> 
> I took a look at your changes in the first link.  The approach seems
> like it serializes too much for one fd, and not enough for multiple fd's
> opened on the same device node.

Had you look at em28xx and vivi implementation? On both cases, we're using a per-device locking.
That's completely valid. For vivi, a per-fh would also work fine, but it won't make any difference,
as the support for multiple streams for vivi got removed. In the care of em28xx, a per-device-node
lock wouldn't work, since the data that needs to be protected is global for the entire device.

A real per-fd implementation will likely need an additional lock on the driver level, for some
ioctls. The core shouldn't prevent it.

> for a single fd, ioctl() probably doesn't need to be serialized against
> read() and poll() at all - at least for drivers that only provide the
> read I/O method.
> 
> read() and poll() on the same device node in most cases can access to
> shared data structure in kernel using test_bit() and atomic_read().
> poll() usually just needs to check if a count is  > 0 in some incoming
> buffer count or incoming byte count somewhere, right?

There are very few drivers that only implements read() method - I think only cx18 and ivtv.
In the mmap() case, you still need to protect read() x mmap(), read() x open(), and other
possible race issues. Some of them will even happen on single fd cases, especially if you
have multiple threads accessing the same fd. Of course, the mutex is more important on multiple-fd
cases, like the em28xx example.

> Multiple opens of the device node (e.g one fd for streaming, one fd for
> control) is what MythTV does, so the locking on a per fd basis doesn't
> work there.

Cheers,
Mauro

  reply	other threads:[~2010-09-19 19:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-19 10:29 RFC: BKL, locking and ioctls Hans Verkuil
2010-09-19 11:43 ` Mauro Carvalho Chehab
2010-09-19 14:58   ` Hans Verkuil
2010-09-19 18:29     ` Mauro Carvalho Chehab
2010-09-19 19:06       ` Hans Verkuil
2010-09-19 20:20         ` Mauro Carvalho Chehab
2010-09-19 21:02           ` Andy Walls
2010-09-19 21:17             ` Hans Verkuil
2010-09-20  0:19               ` Devin Heitmueller
2010-09-19 21:10           ` Hans Verkuil
2010-09-20  2:47             ` Mauro Carvalho Chehab
2010-09-19 19:05   ` Andy Walls
2010-09-19 19:26     ` Mauro Carvalho Chehab [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-09-19 15:38 Andy Walls
2010-09-19 16:10 ` Hans Verkuil
2010-09-19 18:08   ` Mauro Carvalho Chehab
2010-09-19 18:38   ` Andy Walls
2010-09-19 19:10     ` Mauro Carvalho Chehab
2010-09-19 19:38       ` Hans Verkuil
2010-09-19 19:45         ` Hans Verkuil
2010-09-19 19:57         ` Andy Walls
2010-09-19 20:51           ` Mauro Carvalho Chehab
2010-09-20  1:52         ` Mauro Carvalho Chehab
2010-09-20  6:33           ` Hans Verkuil

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=4C9663C8.2060808@redhat.com \
    --to=mchehab@redhat.com \
    --cc=arnd@arndb.de \
    --cc=awalls@md.metrocast.net \
    --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;
as well as URLs for NNTP newsgroup(s).