Re: [PATCH] video4linux: Push down the BKL

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Devin Heitmueller <devin.heitmueller@...>
Cc: Jonathan Corbet <corbet@...>, Alan Cox <alan@...>, <video4linux-list@...>, <linux-kernel@...>, Alan Cox <alan@...>
Date: Tuesday, May 27, 2008 - 5:00 pm

Hi Devin,

On Tue, 27 May 2008 15:26:27 -0400
"Devin Heitmueller" <devin.heitmueller@gmail.com> wrote:


Arjan pointed some good reasons about why we shouldn't use r/w semaphores. So,
it seems better to keep using mutexes.



The hybrid device mode lock is somewhat complex. The simplest solution would be
to block an open() call, if the device is already used by a different mode.

This will minimize things like firmware reload, on xc3028 devices, where you
have different firmwares for analog and digital modes.

Also, some USB devices (like HVR-900/HVR-950) switches off analog audio and tv
demod chips when in digital mode (the reverse is also true - e.g. digital demod
is switched off at analog mode).

So, if you are in digital mode, on HVR-900, and changes to analog, you'll need
to re-initialize tvp5150/msp3400. The current code for those devices handles
this at open(). If we let this to happen later, we'll need to re-send the video
and audio parameters to all I2C connected devices, when switching mode.

On the other hand, some userspace apps, like mythtv, opens both analog and
digital API's. I'm not sure if it does this at the same time, but, if so, a
lock at open() will cause a regression there (someone told me that this is the
case - I didn't test it here yet).

One possible solution of providing a proper code to change mode, and not
blocking open() would be to write something like this:

static int check_and_switch_mode(void *priv, int digital)
{
	struct dev_foo *dev = priv;

	mutex_lock(dev->lock);

	if (digital)
		return change_to_digital(dev);
	else
		return change_to_analog(dev);

	mutex_unlock(dev->lock);
}

Since this should be called for every valid V4L2 and DVB ioctl, the better
place for it would be to add this as a new function callback, at video_ioctl2.
Something like [1]:

--- a/linux/drivers/media/video/videodev.c	Tue May 27 16:02:56 2008 -0300
+++ b/linux/drivers/media/video/videodev.c	Tue May 27 17:34:04 2008 -0300
@@ -821,6 +821,10 @@
 		v4l_print_ioctl(vfd->name, cmd);
 		printk("\n");
 	}
+
+	if (_IOC_TYPE(cmd)=='v') || _IOC_TYPE(cmd)=='V') &&
+		vfd->vidioc_switch_mode)
+		ret=vfd->vidioc_switch_mode(fh, 0);
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
 	/***********************************************************



And something like this, at dvb core [2]:

diff -r b94d587ee596 linux/drivers/media/dvb/dvb-core/dvb_frontend.c
--- a/linux/drivers/media/dvb/dvb-core/dvb_frontend.c	Tue May 27 16:02:56 2008 -0300
+++ b/linux/drivers/media/dvb/dvb-core/dvb_frontend.c	Tue May 27 17:35:57 2008 -0300
@@ -784,6 +784,9 @@
 	     cmd == FE_DISEQC_RECV_SLAVE_REPLY))
 		return -EPERM;
 
+	if (fe->ops.switch_mode)
+		err = fe->ops.switch_mode(fe, 1);
+
 	if (down_interruptible (&fepriv->sem))
 		return -ERESTARTSYS;

[1] The code can be more conservative, changing mode only if S_STD or a video
stream ioctl is called.

[2] We need to think more about the proper places for the DVB changing mode. I
suspect that we'll need to add the mode change callback there and/or at other
different places.

PS.: I suspect that the real code will be much more complex than the above skeletons.

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