TheLoneJoker
TheLoneJoker

Reputation: 1629

Measure time taken for linux kernel from bootup to userpace

Is there a Kernel instrumentation based way to measure the time at which the Kernel transfers over to the Userspace during boot-up ? I could use printk's with timing information, but I just wasn't sure, where exactly to place this printk, in order to observe when the Kernel transfers over to the Userspace.

Upvotes: 3

Views: 1729

Answers (2)

Create your own init that logs to /dev/kmsg immediately

A simpler alternative to hacking the kernel code with a printk is to use the following init:

#include <stdio.h>
#include <unistd.h>

int main(void) {
    FILE *fp;
    fp = fopen("/dev/kmsg", "w");
    fputs("hello init\n", fp);
    fclose(fp);
    while (1)
        sleep(0xFFFFFFFF);
}

and use the kernel command line parameters:

init=/path/to/myinit printk.devkmsg=on printk.time=y

Now just after the boot ends and init starts we see a message:

[<timestamp>] hello init

This is not 100% precise as you will lose some CPU cycles for the fopen, but I don't think it will matter much.

Minimal reproducible setup to test it out:

Upvotes: 0

itisravi
itisravi

Reputation: 3561

The start_kernel() is called by architecture specific code (arch/architecture_type). After the kernel loads, it calls the first user-space process,i.e. /sbin/init (or systemd on a more recent distribution) from init_post() Both these functions are defined in init/main.c.

You might want to read this blog for a detailed description of the boot process.

Upvotes: 5

Related Questions