gpt4 book ai didi

linux-kernel - module_init() 与 core_initcall() 与 early_initcall()

转载 作者:行者123 更新时间:2023-12-03 09:16:21 24 4
gpt4 key购买 nike

在驱动程序中,我经常看到使用这三种类型的 init 函数。

module_init()
core_initcall()
early_initcall()
  • 我应该在什么情况下使用它们?
  • 另外,还有其他的初始化方式吗?
  • 最佳答案

    module_init 用于标记要用作 Linux 设备驱动程序入口点的函数。
    它被称为

  • do_initcalls() 期间(对于内置驱动程序)
  • 在模块插入时(对于 *.ko 模块)

  • 可以有 只有 1 module_init() 每个驱动模块。
    *_initcall()函数通常用于设置函数指针以初始化各种子系统。

    do_initcalls() within Linux kernel source code包含对各种 initcall 列表的调用以及在 Linux 内核启动期间调用它们的相对顺序。
  • early_initcall()
  • core_initcall()
  • postcore_initcall()
  • arch_initcall()
  • subsys_initcall()
  • fs_initcall()
  • device_initcall()
  • late_initcall() 内置模块结束
  • modprobeinsmod*.ko模块。

  • 使用 module_init() 在设备驱动程序中是 equivalent to registering a device_initcall() .

    请记住,在编译期间,在 Linux 内核中链接各种驱动程序目标文件( *.o )的顺序很重要;它决定了它们在运行时被调用的顺序。

    *_initcall functions of the same level
    will be called during boot in the order they are linked.



    例如更改 drivers/scsi/Makefile 中 SCSI 驱动程序的链接顺序将更改检测 SCSI Controller 的顺序,从而更改磁盘的编号。

    关于linux-kernel - module_init() 与 core_initcall() 与 early_initcall(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18605653/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com