diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2010-11-26 04:47:28 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-12-01 17:10:19 -0500 |
commit | 879aa24d6394aa04b690a600a41ff500441ad384 (patch) | |
tree | 024886e8a84ab3f7e88c1e2c5aeceae28cc344bb /drivers/media/video | |
parent | 2877842de8cbf6272b0a851cb12587b7dd8c2afb (diff) |
[media] V4L: improve the BKL replacement heuristic
The BKL replacement mutex had some serious performance side-effects on
V4L drivers. It is replaced by a better heuristic that works around the
worst of the side-effects.
Read the v4l2-dev.c comments for the whole sorry story. This is a
temporary measure only until we can convert all v4l drivers to use
unlocked_ioctl.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r-- | drivers/media/video/v4l2-dev.c | 31 | ||||
-rw-r--r-- | drivers/media/video/v4l2-device.c | 1 |
2 files changed, 29 insertions, 3 deletions
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index bfd392e2436d..6b64fd607b20 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c | |||
@@ -245,13 +245,38 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
245 | if (vdev->lock) | 245 | if (vdev->lock) |
246 | mutex_unlock(vdev->lock); | 246 | mutex_unlock(vdev->lock); |
247 | } else if (vdev->fops->ioctl) { | 247 | } else if (vdev->fops->ioctl) { |
248 | /* TODO: convert all drivers to unlocked_ioctl */ | 248 | /* This code path is a replacement for the BKL. It is a major |
249 | * hack but it will have to do for those drivers that are not | ||
250 | * yet converted to use unlocked_ioctl. | ||
251 | * | ||
252 | * There are two options: if the driver implements struct | ||
253 | * v4l2_device, then the lock defined there is used to | ||
254 | * serialize the ioctls. Otherwise the v4l2 core lock defined | ||
255 | * below is used. This lock is really bad since it serializes | ||
256 | * completely independent devices. | ||
257 | * | ||
258 | * Both variants suffer from the same problem: if the driver | ||
259 | * sleeps, then it blocks all ioctls since the lock is still | ||
260 | * held. This is very common for VIDIOC_DQBUF since that | ||
261 | * normally waits for a frame to arrive. As a result any other | ||
262 | * ioctl calls will proceed very, very slowly since each call | ||
263 | * will have to wait for the VIDIOC_QBUF to finish. Things that | ||
264 | * should take 0.01s may now take 10-20 seconds. | ||
265 | * | ||
266 | * The workaround is to *not* take the lock for VIDIOC_DQBUF. | ||
267 | * This actually works OK for videobuf-based drivers, since | ||
268 | * videobuf will take its own internal lock. | ||
269 | */ | ||
249 | static DEFINE_MUTEX(v4l2_ioctl_mutex); | 270 | static DEFINE_MUTEX(v4l2_ioctl_mutex); |
271 | struct mutex *m = vdev->v4l2_dev ? | ||
272 | &vdev->v4l2_dev->ioctl_lock : &v4l2_ioctl_mutex; | ||
250 | 273 | ||
251 | mutex_lock(&v4l2_ioctl_mutex); | 274 | if (cmd != VIDIOC_DQBUF && mutex_lock_interruptible(m)) |
275 | return -ERESTARTSYS; | ||
252 | if (video_is_registered(vdev)) | 276 | if (video_is_registered(vdev)) |
253 | ret = vdev->fops->ioctl(filp, cmd, arg); | 277 | ret = vdev->fops->ioctl(filp, cmd, arg); |
254 | mutex_unlock(&v4l2_ioctl_mutex); | 278 | if (cmd != VIDIOC_DQBUF) |
279 | mutex_unlock(m); | ||
255 | } else | 280 | } else |
256 | ret = -ENOTTY; | 281 | ret = -ENOTTY; |
257 | 282 | ||
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c index 0b08f96b74a5..7fe6f92af480 100644 --- a/drivers/media/video/v4l2-device.c +++ b/drivers/media/video/v4l2-device.c | |||
@@ -35,6 +35,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) | |||
35 | 35 | ||
36 | INIT_LIST_HEAD(&v4l2_dev->subdevs); | 36 | INIT_LIST_HEAD(&v4l2_dev->subdevs); |
37 | spin_lock_init(&v4l2_dev->lock); | 37 | spin_lock_init(&v4l2_dev->lock); |
38 | mutex_init(&v4l2_dev->ioctl_lock); | ||
38 | v4l2_dev->dev = dev; | 39 | v4l2_dev->dev = dev; |
39 | if (dev == NULL) { | 40 | if (dev == NULL) { |
40 | /* If dev == NULL, then name must be filled in by the caller */ | 41 | /* If dev == NULL, then name must be filled in by the caller */ |