0

This is a function in Linux kernel, (it's called inside start_kernel())

void __init parse_early_param(void)
{
    static int done __initdata;
    static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;

    if (done)
        return;

    /* All fall through to do_early_param. */
    strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
    parse_early_options(tmp_cmdline);
    done = 1;
}

As we know static variable done is stored in the data segment so if the function finishes, the data is still there. In the above function, the variable data is static and if it's nonzero, the function returns immediately. but if not, it performs the parsing of command line and sets done to 1. Does this mean that this parse_early_param() is processed by multiple core? I don't think so because at this stage, only the first core is running. As I understand, other cores are woken up very late in the start_kernel() (see for_each_possible_cpu macro in vmalloc_init() function, does the code run in only one cpu? or in every cpu?). So what is the logic in this function?

0andriy
  • 4,183
  • 1
  • 24
  • 37
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • There are two stages of parameters. One is during very early stages and another is after we have decompressed kernel relocated to new addresses and MMU is set and so on. `done` is responsible for that (There is no `data` variable in the function). – 0andriy Dec 02 '20 at 19:20
  • @0andriy yes, that's correct. I checked and saw parse_early_param is first called inside start_kernel once through setup_arch function and then directly. thanks! (if you make a short answer, I'll choose it). – Chan Kim Dec 03 '20 at 05:46

0 Answers0