ILD

ioctl() vs unlocked_ioctl() vs compat_ioctl()
作者:Yuan Jianpeng 邮箱:yuanjp@hust.edu.cn
发布时间:2018-6-11 站点:Inside Linux Development

ioctl()被大内核锁锁住,在多核系统上,性能较低。unlcoked_ioctl()让每个驱动自己上锁。compat_ioctl() 让64位内核支持32位用户态程序,ioctl的最后一个参数,依赖于驱动自己解释,所以没有通用的方法做这个转化,因此需要compat_ioctl().


参考:

https://unix.stackexchange.com/questions/4711/what-is-the-difference-between-ioctl-unlocked-ioctl-and-compat-ioctl


Meta-answer: All the raw stuff happening to the Linux kernel goes through lkml (the Linux kernel mailing list). For explicative summaries, read or search lwn (Linux weekly news).

Answer: From The new way of ioctl() by Jonathan Corbet:

ioctl() is one of the remaining parts of the kernel which runs under the Big Kernel Lock (BKL). In the past, the usage of the BKL has made it possible for long-running ioctl() methods to create long latencies for unrelated processes.

Follows an explanation of the patch that introduced unlocked_ioctl and compat_ioctl into 2.6.11. The removal of the ioctl field happened a lot later, in 2.6.36.

Explanation: When ioctl was executed, it took the Big Kernel Lock (BKL), so nothing else could execute at the same time. This is very bad on a multiprocessor machine, so there was a big effort to get rid of the BKL. First, unlocked_ioctl was introduced. It lets each driver writer choose what lock to use instead. This can be difficult, so there was a period of transition during which old drivers still worked (using ioctl) but new drivers could use the improved interface (unlocked_ioctl). Eventually all drivers were converted and ioctl could be removed.

compat_ioctl is actually unrelated, even though it was added at the same time. Its purpose is to allow 32-bit userland programs to make ioctl calls on a 64-bit kernel. The meaning of the last argument to ioctl depends on the driver, so there is no way to do a driver-independent conversion.

Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.