Re: [PATCH] video4linux: Push down the BKL

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mauro Carvalho Chehab
Date: Monday, May 26, 2008 - 2:10 pm

On Mon, 26 May 2008 16:23:17 -0400
Alan Cox <alan@redhat.com> wrote:


True. I'm thinking on locking the data that is being GET/SET by VIDIOC_foo ioctls.

I can see a few strategies for removing KBL.

The hardest and optimal scenario is to look inside all drivers, fix the locks
(and pray for a further patch to not break them). I'm afraid that this is a long
term strategy.

There are also other strategies that will also produce non-optimal results, but
may avoid the usage of BKL.

For example, a very simple scenario would simply replace BKL by one mutex.
This way, just one ioctl could be handled at the same time. This is something
dumb, but will free the machine to do other tasks while an ioctl is being
executed. I bet this would work with all (or almost all) drivers. I don't see
any big drawback of this scenario, from the userspace POV.

Smarter scenarios can be designed if you use different mutexes for different
groups of data, at video_ioctl2 level.

Of course, at video_ioctl2 level, you don't see the real data. However, you'll
see data blocks. For example, if you're calling a VIDIOC_S_CROP, you're
certainly changing whatever data structures you have that changes crop window.
A concurrent call to VIDIOC_G_CROP needs to be blocked, otherwise the get will
return a data that is being changing. IMO, such trivial dependencies can be
safely handled at vidioc_ioctl2.

We may try to group VIDIOC functions into some mutexes to avoid bad usages. For
example, one mutex for ioctl's that touches on video buffers. This will lock on
calls for iocls like VIDIOC_DBUF, VIDIOC_REQBUF, etc.

We take some care with ioctls that would affect all groups of data,
like VIDIOC_S_STD. This ioctl will likely change several data structures that
affects other get operations, like changing resolution. It may also need to
stop and/or return -EBUSY, if video buffers are mmapped.

Such scenarios wouldn't avoid the need of implementing a few locks at the
drivers, but will make driver's live simpler.
 

Seems fine to me ;)

Cheers,
Mauro
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] video4linux: Push down the BKL, Alan Cox, (Thu May 22, 2:37 pm)
Re: [PATCH] video4linux: Push down the BKL, Andy Walls, (Thu May 22, 7:08 pm)
Re: [PATCH] video4linux: Push down the BKL, Hans Verkuil, (Thu May 22, 11:16 pm)
Re: [PATCH] video4linux: Push down the BKL, Hans Verkuil, (Thu May 22, 11:28 pm)
Re: [PATCH] video4linux: Push down the BKL, Alan Cox, (Fri May 23, 2:09 am)
Re: [PATCH] video4linux: Push down the BKL , Jonathan Corbet, (Fri May 23, 6:56 am)
Re: [PATCH] video4linux: Push down the BKL, Alan Cox, (Fri May 23, 8:39 am)
Re: [PATCH] video4linux: Push down the BKL , Jonathan Corbet, (Fri May 23, 9:09 am)
Re: [PATCH] video4linux: Push down the BKL, Alan Cox, (Fri May 23, 11:58 am)
Re: [PATCH] video4linux: Push down the BKL, Hans Verkuil, (Fri May 23, 12:05 pm)
Re: [PATCH] video4linux: Push down the BKL, Mike Isely, (Sun May 25, 4:46 pm)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Mon May 26, 9:34 am)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Mon May 26, 9:39 am)
Re: [PATCH] video4linux: Push down the BKL, Hans Verkuil, (Mon May 26, 9:46 am)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Mon May 26, 9:59 am)
Re: [PATCH] video4linux: Push down the BKL, Alan Cox, (Mon May 26, 1:23 pm)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Mon May 26, 2:10 pm)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Mon May 26, 2:14 pm)
Re: [PATCH] video4linux: Push down the BKL, Alan Cox, (Mon May 26, 3:01 pm)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Tue May 27, 6:10 am)
Re: [PATCH] video4linux: Push down the BKL, Jonathan Corbet, (Tue May 27, 8:41 am)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Tue May 27, 9:31 am)
Re: [PATCH] video4linux: Push down the BKL, Jonathan Corbet, (Tue May 27, 9:37 am)
Re: [PATCH] video4linux: Push down the BKL, Alan Cox, (Tue May 27, 11:14 am)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Tue May 27, 11:59 am)
Re: [PATCH] video4linux: Push down the BKL, Devin Heitmueller, (Tue May 27, 12:26 pm)
Re: [PATCH] video4linux: Push down the BKL, Arjan van de Ven, (Tue May 27, 12:50 pm)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Tue May 27, 1:24 pm)
Re: [PATCH] video4linux: Push down the BKL, Mauro Carvalho Chehab, (Tue May 27, 2:00 pm)
Re: [PATCH] video4linux: Push down the BKL, Devin Heitmueller, (Tue May 27, 2:22 pm)
Re: [PATCH] video4linux: Push down the BKL, Andy Walls, (Tue May 27, 4:48 pm)
Re: [PATCH] video4linux: Push down the BKL, Devin Heitmueller, (Tue May 27, 5:46 pm)
Re: [PATCH] video4linux: Push down the BKL, Andy Walls, (Tue May 27, 7:37 pm)
Re: [PATCH] video4linux: Push down the BKL, Devin Heitmueller, (Tue May 27, 7:47 pm)
Re: [PATCH] video4linux: Push down the BKL, Hans Verkuil, (Tue May 27, 11:13 pm)
Re: [PATCH] video4linux: Push down the BKL, Alan Cox, (Wed May 28, 1:34 am)