本文介绍了初始化驱动程序时,module_init 和 subsys_initcall 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

初始化驱动程序时module_initsubsys_initcall有什么区别?

What is the difference between module_init and subsys_initcall while initializing the driver?

推荐答案

差异与时间有关,或者更准确地说,与执行顺序有关.也就是说,声明为subsys_initcall 的过程保证在声明为module_init 的过程之前执行.此顺序可确保子系统和平台驱动程序在设备驱动程序尝试利用前者的功能之前初始化(例如,设备驱动程序注册为子系统设备).

The difference relates to timing, or more precisely, order of execution. That is, the procedure declared as subsys_initcall is guaranteed to be executed before the procedure declared as module_init. This ordering ensures that subsystem and platform drivers are initialized before device drivers try to utilize the former's functionality (e.g. a device driver registers as a subsystem device).

每个宏的实际定义取决于内核是否为(可加载的)模块配置.这些宏(和其他初始化宏)的定义可以在 include/linux/init.h

The actual macro definition for each depends on if the kernel is configured for (loadable) modules or not. The definition for these macros (and other init macros) can be found in include/linux/init.h

请注意,subsys_initcall() 只能由内置(静态链接)模块使用.
module_init 可以被内置或可加载模块使用.

Note that subsys_initcall() can only be used by a built-in (statically linked) module.
module_init can be used by either built-in or loadable modules.

这篇关于初始化驱动程序时,module_init 和 subsys_initcall 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 21:26