Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 223389
b: refs/heads/master
c: 879aa24
h: refs/heads/master
i:
  223387: 5d24fd1
v: v3
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Dec 1, 2010
1 parent 60861c6 commit 96c61f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2877842de8cbf6272b0a851cb12587b7dd8c2afb
refs/heads/master: 879aa24d6394aa04b690a600a41ff500441ad384
31 changes: 28 additions & 3 deletions trunk/drivers/media/video/v4l2-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,38 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (vdev->lock)
mutex_unlock(vdev->lock);
} else if (vdev->fops->ioctl) {
/* TODO: convert all drivers to unlocked_ioctl */
/* This code path is a replacement for the BKL. It is a major
* hack but it will have to do for those drivers that are not
* yet converted to use unlocked_ioctl.
*
* There are two options: if the driver implements struct
* v4l2_device, then the lock defined there is used to
* serialize the ioctls. Otherwise the v4l2 core lock defined
* below is used. This lock is really bad since it serializes
* completely independent devices.
*
* Both variants suffer from the same problem: if the driver
* sleeps, then it blocks all ioctls since the lock is still
* held. This is very common for VIDIOC_DQBUF since that
* normally waits for a frame to arrive. As a result any other
* ioctl calls will proceed very, very slowly since each call
* will have to wait for the VIDIOC_QBUF to finish. Things that
* should take 0.01s may now take 10-20 seconds.
*
* The workaround is to *not* take the lock for VIDIOC_DQBUF.
* This actually works OK for videobuf-based drivers, since
* videobuf will take its own internal lock.
*/
static DEFINE_MUTEX(v4l2_ioctl_mutex);
struct mutex *m = vdev->v4l2_dev ?
&vdev->v4l2_dev->ioctl_lock : &v4l2_ioctl_mutex;

mutex_lock(&v4l2_ioctl_mutex);
if (cmd != VIDIOC_DQBUF && mutex_lock_interruptible(m))
return -ERESTARTSYS;
if (video_is_registered(vdev))
ret = vdev->fops->ioctl(filp, cmd, arg);
mutex_unlock(&v4l2_ioctl_mutex);
if (cmd != VIDIOC_DQBUF)
mutex_unlock(m);
} else
ret = -ENOTTY;

Expand Down
1 change: 1 addition & 0 deletions trunk/drivers/media/video/v4l2-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)

INIT_LIST_HEAD(&v4l2_dev->subdevs);
spin_lock_init(&v4l2_dev->lock);
mutex_init(&v4l2_dev->ioctl_lock);
v4l2_dev->dev = dev;
if (dev == NULL) {
/* If dev == NULL, then name must be filled in by the caller */
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/media/v4l2-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct v4l2_device {
unsigned int notification, void *arg);
/* The control handler. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
/* BKL replacement mutex. Temporary solution only. */
struct mutex ioctl_lock;
};

/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
Expand Down

0 comments on commit 96c61f1

Please sign in to comment.