内核的选项解析完之后便进入各个子系统初始化函数调用阶段。kernel_init通过do_basic_setup调用do_initcalls函数完成。下面我们先来看do_initcalls的代码:
static void __init do_initcalls(void){
initcall_t *call;
int count = preempt_count();
for (call = __initcall_start; call < __initcall_end; call++) {
ktime_t t0, t1, delta;
char *msg = NULL;
char msgbuf[40];
int result;
if (initcall_debug) {
printk("Calling initcall 0x%p", *call);
print_fn_descriptor_symbol(": %s()",(unsigned long) *call);
printk("\n");
t0 = ktime_get();
}
result = (*call)();
if (initcall_debug) {
t1 = ktime_get();
delta = ktime_sub(t1, t0);
printk("initcall 0x%p", *call);
print_fn_descriptor_symbol(": %s()",(unsigned long) *call);
printk(" returned %d.\n", result);
printk("initcall 0x%p ran for %Ld msecs: ", *call, (unsigned long long)delta.tv64 >> 20);
print_fn_descriptor_symbol("%s()\n",(unsigned long) *call);
}
if (result && result != -ENODEV && initcall_debug) {
sprintf(msgbuf, "error code %d", result);
msg = msgbuf;
}
if (preempt_count() != count) {
msg = "preemption imbalance";
preempt_count() = count;
}
if (irqs_disabled()) {
msg = "disabled interrupts";
local_irq_enable();
}
if (msg) {
printk(KERN_WARNING "initcall at 0x%p", *call);
print_fn_descriptor_symbol(": %s()",(unsigned long) *call);
printk(": returned with %s\n", msg);
}
}
flush_scheduled_work();
}
其中通过result = (*call)();来调用call中保存的初始化函数,而被调用的函数可以异步地完成一些任务