]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - init/main.c
perf: Move perf_event_init() into main.c
[linux-2.6.git] / init / main.c
index 7917695bf71eeec3ba1fba336fd7631d8c02a233..559e862865008a95bf114363f891954e62f5ce3b 100644 (file)
 #include <linux/string.h>
 #include <linux/ctype.h>
 #include <linux/delay.h>
-#include <linux/utsname.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
-#include <linux/smp_lock.h>
 #include <linux/initrd.h>
 #include <linux/bootmem.h>
+#include <linux/acpi.h>
 #include <linux/tty.h>
-#include <linux/gfp.h>
 #include <linux/percpu.h>
 #include <linux/kmod.h>
 #include <linux/vmalloc.h>
@@ -33,7 +31,6 @@
 #include <linux/start_kernel.h>
 #include <linux/security.h>
 #include <linux/smp.h>
-#include <linux/workqueue.h>
 #include <linux/profile.h>
 #include <linux/rcupdate.h>
 #include <linux/moduleparam.h>
 #include <linux/debug_locks.h>
 #include <linux/debugobjects.h>
 #include <linux/lockdep.h>
+#include <linux/kmemleak.h>
 #include <linux/pid_namespace.h>
 #include <linux/device.h>
 #include <linux/kthread.h>
 #include <linux/sched.h>
 #include <linux/signal.h>
 #include <linux/idr.h>
+#include <linux/kgdb.h>
 #include <linux/ftrace.h>
 #include <linux/async.h>
-#include <linux/kmemtrace.h>
-#include <trace/boot.h>
+#include <linux/kmemcheck.h>
+#include <linux/sfi.h>
+#include <linux/shmem_fs.h>
+#include <linux/slab.h>
+#include <linux/perf_event.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -86,11 +88,6 @@ extern void sbus_init(void);
 extern void prio_tree_init(void);
 extern void radix_tree_init(void);
 extern void free_initmem(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
@@ -125,7 +122,9 @@ static char *ramdisk_execute_command;
 
 #ifdef CONFIG_SMP
 /* Setup configured maximum number of CPUs to activate */
-unsigned int __initdata setup_max_cpus = NR_CPUS;
+unsigned int setup_max_cpus = NR_CPUS;
+EXPORT_SYMBOL(setup_max_cpus);
+
 
 /*
  * Setup routine for controlling SMP activation
@@ -150,6 +149,20 @@ static int __init nosmp(char *str)
 
 early_param("nosmp", nosmp);
 
+/* this is hard limit */
+static int __init nrcpus(char *str)
+{
+       int nr_cpus;
+
+       get_option(&str, &nr_cpus);
+       if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
+               nr_cpu_ids = nr_cpus;
+
+       return 0;
+}
+
+early_param("nr_cpus", nrcpus);
+
 static int __init maxcpus(char *str)
 {
        get_option(&str, &setup_max_cpus);
@@ -161,7 +174,7 @@ static int __init maxcpus(char *str)
 
 early_param("maxcpus", maxcpus);
 #else
-const unsigned int setup_max_cpus = NR_CPUS;
+static const unsigned int setup_max_cpus = NR_CPUS;
 #endif
 
 /*
@@ -184,15 +197,15 @@ static int __init set_reset_devices(char *str)
 
 __setup("reset_devices", set_reset_devices);
 
-static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
-char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
+static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
+const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
 static const char *panic_later, *panic_param;
 
-extern struct obs_kernel_param __setup_start[], __setup_end[];
+extern const struct obs_kernel_param __setup_start[], __setup_end[];
 
 static int __init obsolete_checksetup(char *line)
 {
-       struct obs_kernel_param *p;
+       const struct obs_kernel_param *p;
        int had_early_param = 0;
 
        p = __setup_start;
@@ -252,7 +265,7 @@ early_param("loglevel", loglevel);
 
 /*
  * Unknown boot options get handed to init, unless they look like
- * failed parameters
+ * unused parameters (modprobe will find them in /proc/cmdline).
  */
 static int __init unknown_bootoption(char *param, char *val)
 {
@@ -273,14 +286,9 @@ static int __init unknown_bootoption(char *param, char *val)
        if (obsolete_checksetup(param))
                return 0;
 
-       /*
-        * Preemptive maintenance for "why didn't my misspelled command
-        * line work?"
-        */
-       if (strchr(param, '.') && (!val || strchr(param, '.') < val)) {
-               printk(KERN_ERR "Unknown boot option `%s': ignoring\n", param);
+       /* Unused module parameter. */
+       if (strchr(param, '.') && (!val || strchr(param, '.') < val))
                return 0;
-       }
 
        if (panic_later)
                return 0;
@@ -355,17 +363,11 @@ static void __init smp_init(void)
 #define smp_init()     do { } while (0)
 #endif
 
-static inline void setup_per_cpu_areas(void) { }
 static inline void setup_nr_cpu_ids(void) { }
 static inline void smp_prepare_cpus(unsigned int maxcpus) { }
 
 #else
 
-#if NR_CPUS > BITS_PER_LONG
-cpumask_t cpu_mask_all __read_mostly = CPU_MASK_ALL;
-EXPORT_SYMBOL(cpu_mask_all);
-#endif
-
 /* Setup number of possible processor ids */
 int nr_cpu_ids __read_mostly = NR_CPUS;
 EXPORT_SYMBOL(nr_cpu_ids);
@@ -376,40 +378,11 @@ static void __init setup_nr_cpu_ids(void)
        nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
 }
 
-#ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
-
-EXPORT_SYMBOL(__per_cpu_offset);
-
-static void __init setup_per_cpu_areas(void)
-{
-       unsigned long size, i;
-       char *ptr;
-       unsigned long nr_possible_cpus = num_possible_cpus();
-
-       /* Copy section for each CPU (we discard the original) */
-       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
-       ptr = alloc_bootmem_pages(size * nr_possible_cpus);
-
-       for_each_possible_cpu(i) {
-               __per_cpu_offset[i] = ptr - __per_cpu_start;
-               memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
-               ptr += size;
-       }
-}
-#endif /* CONFIG_HAVE_SETUP_PER_CPU_AREA */
-
 /* Called by boot processor to activate the rest. */
 static void __init smp_init(void)
 {
        unsigned int cpu;
 
-       /*
-        * Set up the current CPU as possible to migrate to.
-        * The other ones will be done by cpu_up/cpu_down()
-        */
-       set_cpu_active(smp_processor_id(), true);
-
        /* FIXME: This should be done in userspace --RR */
        for_each_present_cpu(cpu) {
                if (num_online_cpus() >= setup_max_cpus)
@@ -448,23 +421,31 @@ static void __init setup_command_line(char *command_line)
  * gcc-3.4 accidentally inlines this function, so use noinline.
  */
 
+static __initdata DECLARE_COMPLETION(kthreadd_done);
+
 static noinline void __init_refok rest_init(void)
-       __releases(kernel_lock)
 {
        int pid;
 
+       rcu_scheduler_starting();
+       /*
+        * We need to spawn init first so that it obtains pid 1, however
+        * the init task will end up wanting to create kthreads, which, if
+        * we schedule it before we create kthreadd, will OOPS.
+        */
        kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
        numa_default_policy();
        pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
+       rcu_read_lock();
        kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
-       unlock_kernel();
+       rcu_read_unlock();
+       complete(&kthreadd_done);
 
        /*
         * The boot idle thread must execute schedule()
         * at least once to get things moving:
         */
        init_idle_bootup_task(current);
-       rcu_scheduler_starting();
        preempt_enable_no_resched();
        schedule();
        preempt_disable();
@@ -476,7 +457,7 @@ static noinline void __init_refok rest_init(void)
 /* Check for early params. */
 static int __init do_early_param(char *param, char *val)
 {
-       struct obs_kernel_param *p;
+       const struct obs_kernel_param *p;
 
        for (p = __setup_start; p < __setup_end; p++) {
                if ((p->early && strcmp(param, p->str) == 0) ||
@@ -521,6 +502,7 @@ static void __init boot_cpu_init(void)
        int cpu = smp_processor_id();
        /* Mark the boot cpu "present", "online" etc for SMP and UP case */
        set_cpu_online(cpu, true);
+       set_cpu_active(cpu, true);
        set_cpu_present(cpu, true);
        set_cpu_possible(cpu, true);
 }
@@ -538,15 +520,22 @@ void __init __weak thread_info_cache_init(void)
  */
 static void __init mm_init(void)
 {
+       /*
+        * page_cgroup requires countinous pages as memmap
+        * and it's bigger than MAX_ORDER unless SPARSEMEM.
+        */
+       page_cgroup_init_flatmem();
        mem_init();
        kmem_cache_init();
+       percpu_init_late();
+       pgtable_cache_init();
        vmalloc_init();
 }
 
 asmlinkage void __init start_kernel(void)
 {
        char * command_line;
-       extern struct kernel_param __start___param[], __stop___param[];
+       extern const struct kernel_param __start___param[], __stop___param[];
 
        smp_setup_processor_id();
 
@@ -566,13 +555,11 @@ asmlinkage void __init start_kernel(void)
 
        local_irq_disable();
        early_boot_irqs_off();
-       early_init_irq_lock_class();
 
 /*
  * Interrupts are still disabled. Do necessary setups, then
  * enable them
  */
-       lock_kernel();
        tick_init();
        boot_cpu_init();
        page_address_init();
@@ -580,11 +567,11 @@ asmlinkage void __init start_kernel(void)
        setup_arch(&command_line);
        mm_init_owner(&init_mm, &init_task);
        setup_command_line(command_line);
-       setup_per_cpu_areas();
        setup_nr_cpu_ids();
+       setup_per_cpu_areas();
        smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
 
-       build_all_zonelists();
+       build_all_zonelists(NULL);
        page_alloc_init();
 
        printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
@@ -617,16 +604,18 @@ asmlinkage void __init start_kernel(void)
                                "enabled *very* early, fixing it\n");
                local_irq_disable();
        }
+       perf_event_init();
        rcu_init();
+       radix_tree_init();
        /* init some links before init_ISA_irqs() */
        early_irq_init();
        init_IRQ();
+       prio_tree_init();
        init_timers();
        hrtimers_init();
        softirq_init();
        timekeeping_init();
        time_init();
-       sched_clock_init();
        profile_init();
        if (!irqs_disabled())
                printk(KERN_CRIT "start_kernel(): bug: interrupts were "
@@ -634,6 +623,11 @@ asmlinkage void __init start_kernel(void)
        early_boot_irqs_on();
        local_irq_enable();
 
+       /* Interrupts are enabled now so all GFP allocations are safe. */
+       gfp_allowed_mask = __GFP_BITS_MASK;
+
+       kmem_cache_init_late();
+
        /*
         * HACK ALERT! This is early. We're enabling the console before
         * we've done PCI setups etc, and console_init() must be aware of
@@ -662,21 +656,18 @@ asmlinkage void __init start_kernel(void)
                initrd_start = 0;
        }
 #endif
-       cpuset_init_early();
        page_cgroup_init();
        enable_debug_pagealloc();
-       cpu_hotplug_init();
-       kmemtrace_init();
+       kmemleak_init();
        debug_objects_mem_init();
        idr_init_cache();
        setup_per_cpu_pageset();
        numa_policy_init();
        if (late_time_init)
                late_time_init();
+       sched_clock_init();
        calibrate_delay();
        pidmap_init();
-       pgtable_cache_init();
-       prio_tree_init();
        anon_vma_init();
 #ifdef CONFIG_X86
        if (efi_enabled)
@@ -684,13 +675,13 @@ asmlinkage void __init start_kernel(void)
 #endif
        thread_info_cache_init();
        cred_init();
-       fork_init(num_physpages);
+       fork_init(totalram_pages);
        proc_caches_init();
        buffer_init();
        key_init();
        security_init();
-       vfs_caches_init(num_physpages);
-       radix_tree_init();
+       dbg_late_init();
+       vfs_caches_init(totalram_pages);
        signals_init();
        /* rootfs populating might need page-writeback */
        page_writeback_init();
@@ -705,6 +696,7 @@ asmlinkage void __init start_kernel(void)
        check_bugs();
 
        acpi_early_init(); /* before LAPIC and SMP init */
+       sfi_init_late();
 
        ftrace_init();
 
@@ -712,41 +704,54 @@ asmlinkage void __init start_kernel(void)
        rest_init();
 }
 
+/* Call all constructor functions linked into the kernel. */
+static void __init do_ctors(void)
+{
+#ifdef CONFIG_CONSTRUCTORS
+       ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
+
+       for (; fn < (ctor_fn_t *) __ctors_end; fn++)
+               (*fn)();
+#endif
+}
+
 int initcall_debug;
 core_param(initcall_debug, initcall_debug, bool, 0644);
 
-int do_one_initcall(initcall_t fn)
+static char msgbuf[64];
+
+static int __init_or_module do_one_initcall_debug(initcall_t fn)
 {
-       int count = preempt_count();
        ktime_t calltime, delta, rettime;
-       char msgbuf[64];
-       struct boot_trace_call call;
-       struct boot_trace_ret ret;
-
-       if (initcall_debug) {
-               call.caller = task_pid_nr(current);
-               printk("calling  %pF @ %i\n", fn, call.caller);
-               calltime = ktime_get();
-               trace_boot_call(&call, fn);
-               enable_boot_trace();
-       }
+       unsigned long long duration;
+       int ret;
+
+       printk(KERN_DEBUG "calling  %pF @ %i\n", fn, task_pid_nr(current));
+       calltime = ktime_get();
+       ret = fn();
+       rettime = ktime_get();
+       delta = ktime_sub(rettime, calltime);
+       duration = (unsigned long long) ktime_to_ns(delta) >> 10;
+       printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n", fn,
+               ret, duration);
+
+       return ret;
+}
 
-       ret.result = fn();
+int __init_or_module do_one_initcall(initcall_t fn)
+{
+       int count = preempt_count();
+       int ret;
 
-       if (initcall_debug) {
-               disable_boot_trace();
-               rettime = ktime_get();
-               delta = ktime_sub(rettime, calltime);
-               ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
-               trace_boot_ret(&ret, fn);
-               printk("initcall %pF returned %d after %Ld usecs\n", fn,
-                       ret.result, ret.duration);
-       }
+       if (initcall_debug)
+               ret = do_one_initcall_debug(fn);
+       else
+               ret = fn();
 
        msgbuf[0] = 0;
 
-       if (ret.result && ret.result != -ENODEV && initcall_debug)
-               sprintf(msgbuf, "error code %d ", ret.result);
+       if (ret && ret != -ENODEV && initcall_debug)
+               sprintf(msgbuf, "error code %d ", ret);
 
        if (preempt_count() != count) {
                strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
@@ -760,7 +765,7 @@ int do_one_initcall(initcall_t fn)
                printk("initcall %pF returned with %s\n", fn, msgbuf);
        }
 
-       return ret.result;
+       return ret;
 }
 
 
@@ -768,10 +773,10 @@ extern initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[];
 
 static void __init do_initcalls(void)
 {
-       initcall_t *call;
+       initcall_t *fn;
 
-       for (call = __early_initcall_end; call < __initcall_end; call++)
-               do_one_initcall(*call);
+       for (fn = __early_initcall_end; fn < __initcall_end; fn++)
+               do_one_initcall(*fn);
 
        /* Make sure there is no pending stuff from the initcall sequence */
        flush_scheduled_work();
@@ -786,24 +791,24 @@ static void __init do_initcalls(void)
  */
 static void __init do_basic_setup(void)
 {
-       rcu_init_sched(); /* needed by module_init stage. */
-       init_workqueues();
        cpuset_init_smp();
        usermodehelper_init();
+       init_tmpfs();
        driver_init();
        init_irq_proc();
+       do_ctors();
        do_initcalls();
 }
 
 static void __init do_pre_smp_initcalls(void)
 {
-       initcall_t *call;
+       initcall_t *fn;
 
-       for (call = __initcall_start; call < __early_initcall_end; call++)
-               do_one_initcall(*call);
+       for (fn = __initcall_start; fn < __early_initcall_end; fn++)
+               do_one_initcall(*fn);
 }
 
-static void run_init_process(char *init_filename)
+static void run_init_process(const char *init_filename)
 {
        argv_init[0] = init_filename;
        kernel_execve(init_filename, argv_init, envp_init);
@@ -813,21 +818,14 @@ static void run_init_process(char *init_filename)
  * makes it inline to init() and it becomes part of init.text section
  */
 static noinline int init_post(void)
-       __releases(kernel_lock)
 {
        /* need to finish all async __init code before freeing the memory */
        async_synchronize_full();
        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(KERN_WARNING "Warning: unable to open an initial console.\n");
-
-       (void) sys_dup(0);
-       (void) sys_dup(0);
 
        current->signal->flags |= SIGNAL_UNKILLABLE;
 
@@ -853,12 +851,20 @@ static noinline int init_post(void)
        run_init_process("/bin/init");
        run_init_process("/bin/sh");
 
-       panic("No init found.  Try passing init= option to kernel.");
+       panic("No init found.  Try passing init= option to kernel. "
+             "See Linux Documentation/init.txt for guidance.");
 }
 
 static int __init kernel_init(void * unused)
 {
-       lock_kernel();
+       /*
+        * Wait until kthreadd is all set-up.
+        */
+       wait_for_completion(&kthreadd_done);
+       /*
+        * init can allocate pages on any node
+        */
+       set_mems_allowed(node_states[N_HIGH_MEMORY]);
        /*
         * init can run on any cpu.
         */
@@ -878,13 +884,19 @@ static int __init kernel_init(void * unused)
        smp_prepare_cpus(setup_max_cpus);
 
        do_pre_smp_initcalls();
-       start_boot_trace();
+       lockup_detector_init();
 
        smp_init();
        sched_init_smp();
 
        do_basic_setup();
 
+       /* Open the /dev/console on the rootfs, this should never fail */
+       if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
+               printk(KERN_WARNING "Warning: unable to open an initial console.\n");
+
+       (void) sys_dup(0);
+       (void) sys_dup(0);
        /*
         * check if there is an early userspace init.  If yes, let it do all
         * the work