linux kernel driver_init()

linux kernel driver_init()

Linux version 3.4.39

/* init/main.c */
asmlinkage void __init start_kernel(void)
    |
    ...
    /* Do the rest non-__init'ed, we're now alive */
	rest_init();
        |
        ...
        kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
        ...
        pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
        ...
        /* Call into cpu_idle with preempt disabled */
	    cpu_idle(); /* idle process, pid:0 */

static int __init kernel_init(void * unused)
    |
    ...
    /*
    * Ok, the machine is now initialized. None of the devices
    * have been touched yet, but the CPU subsystem is up and
    * running, and memory and process management works.
    *
    * Now we can finally start doing some real work..
    */
    static void __init do_basic_setup(void)
    {
	    cpuset_init_smp();
	    usermodehelper_init();
	    shmem_init();
	    driver_init();
	    init_irq_proc();
	    do_ctors();
	    usermodehelper_enable();
	    do_initcalls();
    }
    ...
    init_post()
        |
        run_init_process(); /* init prcess, pid:1 */
    ...

int kthreadd(void *unused) {
    /* kthreadd process, pid:2 */
}

/* drivers/base/init.c */
#include <linux/memory.h>

#include "base.h"

/**
 * driver_init - initialize driver model.
 *
 * Call the driver model init functions to initialize their
 * subsystems. Called early from init/main.c.
 */
void __init driver_init(void)
{
	/* These are the core pieces */
	devtmpfs_init();
	devices_init();
	buses_init();
	classes_init();
	firmware_init();
	hypervisor_init();

	/* These are also core pieces, but must come after the
	 * core core pieces.
	 */
	platform_bus_init();
	cpu_dev_init();
	memory_dev_init();
}

static void __init do_initcalls(void)
{
	int level;

    for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
	    do_initcall_level(level);
}

Author: Yangkai Wang
wang_yangkai@163.com
Coding in 2021/05/06

posted @   王阳开  阅读(2891)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示