X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=init%2Fmain.c;h=4c194c47395f9b7c06fc4dd713d920eadcd2f757;hb=c7ac0a6982b4512b54614ebfdd6a1805b5e9b273;hp=6416eab8d19b0296423fd906f5edc8793010e721;hpb=c7089c9ff74690b4a1387b120eb5710f3510249f;p=linux-2.6.git diff --git a/init/main.c b/init/main.c index 6416eab8d..4c194c473 100644 --- a/init/main.c +++ b/init/main.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -40,53 +41,39 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include - -#include -#ifdef CONFIG_CKRM_CPU_SCHEDULE -int __init init_ckrm_sched_res(void); -#else -#define init_ckrm_sched_res() ((void)0) -#endif -//#include - -/* - * This is one of the first .c files built. Error out early - * if we have compiler trouble.. - */ -#if __GNUC__ == 2 && __GNUC_MINOR__ == 96 -#ifdef CONFIG_FRAME_POINTER -#error This compiler cannot compile correctly with frame pointers enabled -#endif -#endif +#include +#include #ifdef CONFIG_X86_LOCAL_APIC #include #endif /* - * Versions of gcc older than that listed below may actually compile - * and link okay, but the end product can have subtle run time bugs. - * To avoid associated bogus bug reports, we flatly refuse to compile - * with a gcc that is known to be too old from the very beginning. + * This is one of the first .c files built. Error out early if we have compiler + * trouble. + * + * Versions of gcc older than that listed below may actually compile and link + * okay, but the end product can have subtle run time bugs. To avoid associated + * bogus bug reports, we flatly refuse to compile with a gcc that is known to be + * too old from the very beginning. */ -#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 95) +#if (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 2) #error Sorry, your GCC is too old. It builds incorrect kernels. #endif -extern char *linux_banner; - static int init(void *); extern void init_IRQ(void); -extern void sock_init(void); extern void fork_init(unsigned long); extern void mca_init(void); extern void sbus_init(void); @@ -101,6 +88,14 @@ extern void free_initmem(void); extern void populate_rootfs(void); extern void driver_init(void); extern void prepare_namespace(void); +#ifdef CONFIG_ACPI +extern void acpi_early_init(void); +#else +static inline void acpi_early_init(void) { } +#endif +#ifndef CONFIG_DEBUG_RODATA +static inline void mark_rodata_ro(void) { } +#endif #ifdef CONFIG_TC extern void tc_init(void); @@ -109,21 +104,11 @@ extern void tc_init(void); enum system_states system_state; EXPORT_SYMBOL(system_state); -/* - * The kernel_magic value represents the address of _end, which allows - * namelist tools to "match" each other respectively. That way a tool - * that looks at /dev/mem can verify that it is using the right System.map - * file -- if kernel_magic doesn't equal the namelist value of _end, - * something's wrong. - */ -extern unsigned long _end; -unsigned long *kernel_magic = &_end; - /* * Boot command-line arguments */ -#define MAX_INIT_ARGS 8 -#define MAX_INIT_ENVS 8 +#define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT +#define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT extern void time_init(void); /* Default late time init is NULL. archs can override this later. */ @@ -134,6 +119,7 @@ extern void softirq_init(void); char saved_command_line[COMMAND_LINE_SIZE]; static char *execute_command; +static char *ramdisk_execute_command; /* Setup configured maximum number of CPUs to activate */ static unsigned int max_cpus = NR_CPUS; @@ -168,14 +154,13 @@ static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; static const char *panic_later, *panic_param; -__setup("profile=", profile_setup); +extern struct obs_kernel_param __setup_start[], __setup_end[]; static int __init obsolete_checksetup(char *line) { struct obs_kernel_param *p; - extern struct obs_kernel_param __setup_start, __setup_end; - p = &__setup_start; + p = __setup_start; do { int n = strlen(p->str); if (!strncmp(line, p->str, n)) { @@ -192,62 +177,18 @@ static int __init obsolete_checksetup(char *line) return 1; } p++; - } while (p < &__setup_end); + } while (p < __setup_end); return 0; } -/* this should be approx 2 Bo*oMips to start (note initial shift), and will - still work even if initially too large, it will just take slightly longer */ +/* + * This should be approx 2 Bo*oMips to start (note initial shift), and will + * still work even if initially too large, it will just take slightly longer + */ unsigned long loops_per_jiffy = (1<<12); EXPORT_SYMBOL(loops_per_jiffy); -/* This is the number of bits of precision for the loops_per_jiffy. Each - bit takes on average 1.5/HZ seconds. This (like the original) is a little - better than 1% */ -#define LPS_PREC 8 - -void __devinit calibrate_delay(void) -{ - unsigned long ticks, loopbit; - int lps_precision = LPS_PREC; - - loops_per_jiffy = (1<<12); - - printk("Calibrating delay loop... "); - while ((loops_per_jiffy <<= 1) != 0) { - /* wait for "start of" clock tick */ - ticks = jiffies; - while (ticks == jiffies) - /* nothing */; - /* Go .. */ - ticks = jiffies; - __delay(loops_per_jiffy); - ticks = jiffies - ticks; - if (ticks) - break; - } - -/* Do a binary approximation to get loops_per_jiffy set to equal one clock - (up to lps_precision bits) */ - loops_per_jiffy >>= 1; - loopbit = loops_per_jiffy; - while ( lps_precision-- && (loopbit >>= 1) ) { - loops_per_jiffy |= loopbit; - ticks = jiffies; - while (ticks == jiffies); - ticks = jiffies; - __delay(loops_per_jiffy); - if (jiffies != ticks) /* longer than 1 tick */ - loops_per_jiffy &= ~loopbit; - } - -/* Round the value and print it */ - printk("%lu.%02lu BogoMIPS\n", - loops_per_jiffy/(500000/HZ), - (loops_per_jiffy/(5000/HZ)) % 100); -} - static int __init debug_kernel(char *str) { if (*str) @@ -267,20 +208,41 @@ static int __init quiet_kernel(char *str) __setup("debug", debug_kernel); __setup("quiet", quiet_kernel); -/* Unknown boot options get handed to init, unless they look like - failed parameters */ +static int __init loglevel(char *str) +{ + get_option(&str, &console_loglevel); + return 1; +} + +__setup("loglevel=", loglevel); + +/* + * Unknown boot options get handed to init, unless they look like + * failed parameters + */ static int __init unknown_bootoption(char *param, char *val) { /* Change NUL term back to "=", to make "param" the whole string. */ - if (val) - val[-1] = '='; + if (val) { + /* param=val or param="val"? */ + if (val == param+strlen(param)+1) + val[-1] = '='; + else if (val == param+strlen(param)+2) { + val[-2] = '='; + memmove(val-1, val, strlen(val)+1); + val--; + } else + BUG(); + } /* Handle obsolete-style parameters */ if (obsolete_checksetup(param)) return 0; - /* Preemptive maintenance for "why didn't my mispelled command - line work?" */ + /* + * Preemptive maintenance for "why didn't my mispelled command + * line work?" + */ if (strchr(param, '.') && (!val || strchr(param, '.') < val)) { printk(KERN_ERR "Unknown boot option `%s': ignoring\n", param); return 0; @@ -320,7 +282,8 @@ static int __init init_setup(char *str) unsigned int i; execute_command = str; - /* In case LILO is going to boot us with default command line, + /* + * In case LILO is going to boot us with default command line, * it prepends "auto" before the whole cmdline which makes * the shell think it should execute a script with such name. * So we ignore all arguments entered _before_ init=... [MJ] @@ -331,8 +294,19 @@ static int __init init_setup(char *str) } __setup("init=", init_setup); +static int __init rdinit_setup(char *str) +{ + unsigned int i; + + ramdisk_execute_command = str; + /* See "auto" comment in init_setup */ + for (i = 1; i < MAX_INIT_ARGS; i++) + argv_init[i] = NULL; + return 1; +} +__setup("rdinit=", rdinit_setup); + extern void setup_arch(char **); -extern void cpu_idle(void); #ifndef CONFIG_SMP @@ -359,8 +333,6 @@ static void __init setup_per_cpu_areas(void) { unsigned long size, i; char *ptr; - /* Created by linker magic */ - extern char __per_cpu_start[], __per_cpu_end[]; /* Copy section for each CPU (we discard the original) */ size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES); @@ -392,12 +364,11 @@ static void __init smp_init(void) } /* Any cleanup work */ - printk("Brought up %ld CPUs\n", (long)num_online_cpus()); + printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus()); smp_cpus_done(max_cpus); #if 0 /* Get other processors into their bootup holding patterns. */ - smp_threads_ready=1; smp_commence(); #endif } @@ -414,21 +385,30 @@ static void __init smp_init(void) */ static void noinline rest_init(void) + __releases(kernel_lock) { kernel_thread(init, NULL, CLONE_FS | CLONE_SIGHAND); numa_default_policy(); - system_state = SYSTEM_BOOTING_SCHEDULER_OK; unlock_kernel(); - cpu_idle(); + + /* + * The boot idle thread must execute schedule() + * at least one to get things moving: + */ + preempt_enable_no_resched(); + schedule(); + preempt_disable(); + + /* Call into cpu_idle with preempt disabled */ + cpu_idle(); } /* Check for early params. */ static int __init do_early_param(char *param, char *val) { struct obs_kernel_param *p; - extern struct obs_kernel_param __setup_start, __setup_end; - for (p = &__setup_start; p < &__setup_end; p++) { + for (p = __setup_start; p < __setup_end; p++) { if (p->early && strcmp(param, p->str) == 0) { if (p->setup_func(val) != 0) printk(KERN_WARNING @@ -468,6 +448,7 @@ asmlinkage void __init start_kernel(void) */ lock_kernel(); page_address_init(); + printk(KERN_NOTICE); printk(linux_banner); setup_arch(&command_line); setup_per_cpu_areas(); @@ -484,10 +465,14 @@ asmlinkage void __init start_kernel(void) * time - but meanwhile we still have a functioning scheduler. */ sched_init(); - + /* + * Disable preemption - early bootup scheduling is extremely + * fragile until we cpu_idle() for the first time. + */ + preempt_disable(); build_all_zonelists(); page_alloc_init(); - printk("Kernel command line: %s\n", saved_command_line); + printk(KERN_NOTICE "Kernel command line: %s\n", saved_command_line); parse_early_param(); parse_args("Booting kernel", command_line, __start___param, __stop___param - __start___param, @@ -497,12 +482,8 @@ asmlinkage void __init start_kernel(void) rcu_init(); init_IRQ(); pidhash_init(); - /* MEF: In 2.6.5. ckrm_init was right after pidhash_init() but - before sched_init(). Will leave it after pidhash_init() - and cross finger. - */ - ckrm_init(); init_timers(); + hrtimers_init(); softirq_init(); time_init(); @@ -525,8 +506,10 @@ asmlinkage void __init start_kernel(void) } #endif vfs_caches_init_early(); + cpuset_init_early(); mem_init(); kmem_cache_init(); + setup_per_cpu_pageset(); numa_policy_init(); if (late_time_init) late_time_init(); @@ -543,7 +526,8 @@ asmlinkage void __init start_kernel(void) proc_caches_init(); buffer_init(); unnamed_dev_init(); - security_scaffolding_startup(); + key_init(); + security_init(); vfs_caches_init(num_physpages); radix_tree_init(); signals_init(); @@ -552,15 +536,11 @@ asmlinkage void __init start_kernel(void) #ifdef CONFIG_PROC_FS proc_root_init(); #endif + cpuset_init(); check_bugs(); - /* - * We count on the initial thread going ok - * Like idlers init is an unlocked kernel thread, which will - * make syscalls (and thus be locked). - */ - init_idle(current, smp_processor_id()); + acpi_early_init(); /* before LAPIC and SMP init */ /* Do the rest non-__init'ed, we're now alive */ rest_init(); @@ -577,19 +557,19 @@ __setup("initcall_debug", initcall_debug_setup); struct task_struct *child_reaper = &init_task; -extern initcall_t __initcall_start, __initcall_end; +extern initcall_t __initcall_start[], __initcall_end[]; static void __init do_initcalls(void) { initcall_t *call; int count = preempt_count(); - for (call = &__initcall_start; call < &__initcall_end; call++) { + for (call = __initcall_start; call < __initcall_end; call++) { char *msg; if (initcall_debug) { printk(KERN_DEBUG "Calling initcall 0x%p", *call); - print_symbol(": %s()", (unsigned long) *call); + print_fn_descriptor_symbol(": %s()", (unsigned long) *call); printk("\n"); } @@ -605,7 +585,7 @@ static void __init do_initcalls(void) local_irq_enable(); } if (msg) { - printk("error in initcall at 0x%p: " + printk(KERN_WARNING "error in initcall at 0x%p: " "returned with %s\n", *call, msg); } } @@ -623,16 +603,15 @@ static void __init do_initcalls(void) */ static void __init do_basic_setup(void) { + /* drivers will send hotplug events */ + init_workqueues(); + usermodehelper_init(); driver_init(); #ifdef CONFIG_SYSCTL sysctl_init(); #endif - /* Networking initialization needs a process context */ - sock_init(); - - init_workqueues(); do_initcalls(); } @@ -645,6 +624,7 @@ static void do_pre_smp_initcalls(void) migration_init(); #endif spawn_ksoftirqd(); + spawn_softlockup_task(); } static void run_init_process(char *init_filename) @@ -674,6 +654,10 @@ static inline void fixup_cpu_present_map(void) static int init(void * unused) { lock_kernel(); + /* + * init can run on any cpu. + */ + set_cpus_allowed(current, CPU_MASK_ALL); /* * Tell the world that we're going to be the grim * reaper of innocent orphaned children. @@ -684,13 +668,15 @@ static int init(void * unused) */ child_reaper = current; - /* Sets up cpus_possible() */ smp_prepare_cpus(max_cpus); do_pre_smp_initcalls(); fixup_cpu_present_map(); smp_init(); + sched_init_smp(); + + cpuset_init_smp(); /* * Do this before initcalls, because some drivers want to access @@ -700,18 +686,18 @@ static int init(void * unused) do_basic_setup(); - init_ckrm_sched_res(); - - sched_init_smp(); - /* * check if there is an early userspace init. If yes, let it do all * the work */ - if (sys_access((const char __user *) "/init", 0) == 0) - execute_command = "/init"; - else + + if (!ramdisk_execute_command) + ramdisk_execute_command = "/init"; + + if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) { + ramdisk_execute_command = NULL; prepare_namespace(); + } /* * Ok, we have completed the initial bootup, and @@ -720,25 +706,33 @@ static int init(void * unused) */ free_initmem(); unlock_kernel(); + mark_rodata_ro(); system_state = SYSTEM_RUNNING; numa_default_policy(); if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) - printk("Warning: unable to open an initial console.\n"); + printk(KERN_WARNING "Warning: unable to open an initial console.\n"); (void) sys_dup(0); (void) sys_dup(0); - + + if (ramdisk_execute_command) { + run_init_process(ramdisk_execute_command); + printk(KERN_WARNING "Failed to execute %s\n", + ramdisk_execute_command); + } + /* * We try each of these until one succeeds. * * The Bourne shell can be used instead of init if we are * trying to recover a really broken machine. */ - - if (execute_command) + if (execute_command) { run_init_process(execute_command); - + printk(KERN_WARNING "Failed to execute %s. Attempting " + "defaults...\n", execute_command); + } run_init_process("/sbin/init"); run_init_process("/etc/init"); run_init_process("/bin/init"); @@ -746,16 +740,3 @@ static int init(void * unused) panic("No init found. Try passing init= option to kernel."); } - -static int early_param_test(char *rest) -{ - printk("early_parm_test: %s\n", rest ?: "(null)"); - return rest ? 0 : -EINVAL; -} -early_param("testsetup", early_param_test); -static int early_setup_test(char *rest) -{ - printk("early_setup_test: %s\n", rest ?: "(null)"); - return 0; -} -__setup("testsetup_long", early_setup_test);