User: Password:
Subscribe / Log in / New account

Locking & the videobuf2 API

Locking & the videobuf2 API

Posted Jun 16, 2011 6:52 UTC (Thu) by hverkuil (subscriber, #41056)
Parent article: The videobuf2 API

Well, locking is explained in Documentation/video4linux/v4l2-framework, section "v4l2_file_operations and locking". But it doesn't mention videobuf2 (must be fixed) and should probably be expanded/improved a bit.

But in a nutshell: you either set the 'lock' field in struct video_device to a mutex and then the framework will take care of serialization of file operations (mostly ioctls) for you, or you leave it at NULL and you have to do your own locking.

I tend to advocate using the framework serialization rather than doing it yourself since the chances of actually getting the locking right in a complex driver if you do it yourself are pretty close to zero, especially after the driver has undergone a few years of maintenance.

(Log in to post comments)

Locking & the videobuf2 API

Posted Jun 16, 2011 16:03 UTC (Thu) by corbet (editor, #1) [Link]

As you know, some of us are not entirely in agreement there. I don't think you can do a complex driver without being aware of locking; trying to hide it looks to me like an attempt to return to the good old days of uniprocessor systems. I don't know of any other kernel subsystem which tries to hide locking in the midlayers in this way - though there almost certainly is one somewhere.

Locking & the videobuf2 API

Posted Jun 16, 2011 16:28 UTC (Thu) by hverkuil (subscriber, #41056) [Link]

I know. We don't hide it, BTW, you have to explicitly set it up. The simple fact is that the vast majority of V4L2 drivers need to serialize ioctl calls anyway. This is usually implemented pretty badly.

Another reason for doing this was the BKL removal were we needed something reasonably simple to convert old (usually unmaintained) drivers without having to do extensive code reviews.

Locking & the videobuf2 API

Posted Jun 16, 2011 16:34 UTC (Thu) by corbet (editor, #1) [Link]

Understood, that all makes sense, sorry if I sounded critical. You've put in a lot of work and, as a result, V4L2 has gotten a lot better in the time I've been paying attention to it.

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds