From: Mauro Carvalho Chehab <mchehab@infradead.org>
To: Jonathan Corbet <corbet@lwn.net>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
linux-media@vger.kernel.org,
Florian Tobias Schandinat <FlorianSchandinat@gmx.de>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Daniel Drake <dsd@laptop.org>
Subject: Re: ext_lock (was viafb camera controller driver)
Date: Thu, 21 Oct 2010 00:57:30 -0200 [thread overview]
Message-ID: <4CBFAC1A.90306@infradead.org> (raw)
In-Reply-To: <20101020132342.35a2c401@bike.lwn.net>
Em 20-10-2010 17:23, Jonathan Corbet escreveu:
> On Tue, 19 Oct 2010 08:54:40 +0200
> Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
>> We are working on removing the BKL. As part of that effort it is now possible
>> for drivers to pass a serialization mutex to the v4l core (a mutex pointer was
>> added to struct video_device). If the core sees that mutex then the core will
>> serialize all open/ioctl/read/write/etc. file ops. So all file ops will in that
>> case be called with that mutex held. Which is fine, but if the driver has to do
>> a blocking wait, then you need to unlock the mutex first and lock it again
>> afterwards. And since videobuf does a blocking wait it needs to know about that
>> mutex.
>
> So videobuf is expecting that you're passing this special device mutex
> in particular? In that case, why not just use it directly? Having a
> separate pointer to (what looks like) a distinct lock seems like a way
> to cause fatal confusion. Given the tightness of the rules here (you
> *must* know that this "ext_lock" has been grabbed by the v4l core in the
> current call chain or you cannot possibly unlock it safely), I don't
> get why you wouldn't use the lock directly.
>
> I would be inclined to go even further and emit a warning if the mutex
> is *not* locked. It seems that the rules would require it, no? If
> mutex debugging is turned on, you could even check if the current task
> is the locker, would would be even better.
Yeah, a definitive solution would be to directly use the lock at videobuf. However,
people are re-writing videobuf (the new version is called videobuf2), in order
to fix some know issues on it.
Probably, it is better to wait for the new vb2, test it, and better integrate
its locking schema.
> In general, put me in the "leery of central locking" camp. If you
> don't understand locking, you're going to mess things up somewhere
> along the way. And, as soon as you get into hardware with interrupts,
> it seems like you have to deal with your own locking for access to the
> hardware regardless...
Yeah, if developers don't understand lock, a mess will happen, but this
doesn't matter if the developer is using a central or a driver-priv lock.
With a core-assisted lock, driver code is cleaner, and, hopefully, will be
easier to analyze the lock "exceptions", as the common case (hardware access
via file operations) will already be covered.
Cheers,
Mauro.
next prev parent reply other threads:[~2010-10-21 2:57 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-10 22:23 [PATCH] viafb camera controller driver Jonathan Corbet
2010-10-11 12:09 ` Mauro Carvalho Chehab
2010-10-11 12:18 ` Laurent Pinchart
2010-10-11 15:30 ` Jonathan Corbet
2010-10-11 23:20 ` Laurent Pinchart
2010-10-16 13:44 ` Mauro Carvalho Chehab
2010-10-18 13:25 ` Jonathan Corbet
2010-10-19 3:20 ` Jonathan Corbet
2010-10-19 6:54 ` Hans Verkuil
2010-10-19 7:52 ` Laurent Pinchart
2010-10-19 10:46 ` Mauro Carvalho Chehab
2010-10-19 13:05 ` Laurent Pinchart
2010-10-19 14:04 ` Hans Verkuil
2010-10-19 14:21 ` Hans Verkuil
2010-10-19 14:49 ` Mauro Carvalho Chehab
2010-10-19 14:52 ` Laurent Pinchart
2010-10-19 15:42 ` Mauro Carvalho Chehab
2010-10-20 19:23 ` ext_lock (was viafb camera controller driver) Jonathan Corbet
2010-10-21 2:57 ` Mauro Carvalho Chehab [this message]
2010-10-21 6:51 ` 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=4CBFAC1A.90306@infradead.org \
--to=mchehab@infradead.org \
--cc=FlorianSchandinat@gmx.de \
--cc=corbet@lwn.net \
--cc=dsd@laptop.org \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.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