/* * swapin_thread: [exported] * * This procedure executes as a kernel thread. Threads that need to * be swapped in are swapped in by this thread. */ void __attribute__((noreturn)) swapin_thread_continue(void) { for (;;) { thread_t thread; spl_t s; s = splsched(); swapper_lock(); while ((thread = (thread_t) dequeue_head(&swapin_queue)) != THREAD_NULL) { kern_return_t kr; swapper_unlock(); (void) splx(s); kr = thread_doswapin(thread); /* may block */ s = splsched(); swapper_lock(); if (kr != KERN_SUCCESS) { enqueue_head(&swapin_queue, (queue_entry_t) thread); break; } } assert_wait((event_t) &swapin_queue, FALSE); swapper_unlock(); (void) splx(s); counter(c_swapin_thread_block++); thread_block(swapin_thread_continue); } }
/* * Now running in a thread. Create the rest of the kernel threads * and the bootstrap task. */ void start_kernel_threads() { register int i; /* * Create the idle threads and the other * service threads. */ for (i = 0; i < NCPUS; i++) { if (machine_slot[i].is_cpu) { thread_t th; (void) thread_create(kernel_task, &th); thread_bind(th, cpu_to_processor(i)); thread_start(th, idle_thread); thread_doswapin(th); (void) thread_resume(th); } } (void) kernel_thread(kernel_task, reaper_thread, (char *) 0); (void) kernel_thread(kernel_task, swapin_thread, (char *) 0); (void) kernel_thread(kernel_task, sched_thread, (char *) 0); #if NCPUS > 1 /* * Create the shutdown thread. */ (void) kernel_thread(kernel_task, action_thread, (char *) 0); /* * Allow other CPUs to run. */ start_other_cpus(); #endif NCPUS > 1 /* * Create the device service. */ device_service_create(); /* * Initialize NORMA ipc system. */ #if NORMA_IPC norma_ipc_init(); #endif NORMA_IPC /* * Initialize NORMA vm system. */ #if NORMA_VM norma_vm_init(); #endif NORMA_VM /* * Start the user bootstrap. */ bootstrap_create(); #if XPR_DEBUG xprinit(); /* XXX */ #endif XPR_DEBUG /* * Become the pageout daemon. */ (void) spl0(); vm_pageout(); /*NOTREACHED*/ }
/* * Running in virtual memory, on the interrupt stack. * Does not return. Dispatches initial thread. * * Assumes that master_cpu is set. */ void setup_main() { thread_t startup_thread; panic_init(); printf_init(); sched_init(); vm_mem_bootstrap(); ipc_bootstrap(); vm_mem_init(); ipc_init(); /* * As soon as the virtual memory system is up, we record * that this CPU is using the kernel pmap. */ PMAP_ACTIVATE_KERNEL(master_cpu); init_timers(); init_timeout(); #if XPR_DEBUG xprbootstrap(); #endif XPR_DEBUG timestamp_init(); mapable_time_init(); machine_init(); machine_info.max_cpus = NCPUS; machine_info.memory_size = phys_last_addr - phys_first_addr; /* XXX mem_size */ machine_info.avail_cpus = 0; machine_info.major_version = KERNEL_MAJOR_VERSION; machine_info.minor_version = KERNEL_MINOR_VERSION; /* * Initialize the IPC, task, and thread subsystems. */ task_init(); thread_init(); swapper_init(); #if MACH_HOST pset_sys_init(); #endif MACH_HOST /* * Kick off the time-out driven routines by calling * them the first time. */ recompute_priorities(); compute_mach_factor(); /* * Create a kernel thread to start the other kernel * threads. Thread_resume (from kernel_thread) calls * thread_setrun, which may look at current thread; * we must avoid this, since there is no current thread. */ /* * Create the thread, and point it at the routine. */ (void) thread_create(kernel_task, &startup_thread); thread_start(startup_thread, start_kernel_threads); /* * Give it a kernel stack. */ thread_doswapin(startup_thread); /* * Pretend it is already running, and resume it. * Since it looks as if it is running, thread_resume * will not try to put it on the run queues. * * We can do all of this without locking, because nothing * else is running yet. */ startup_thread->state |= TH_RUN; (void) thread_resume(startup_thread); /* * Start the thread. */ cpu_launch_first_thread(startup_thread); /*NOTREACHED*/ }
/* * Now running in a thread. Create the rest of the kernel threads * and the bootstrap task. */ void start_kernel_threads() { register int i; /* * Create the idle threads and the other * service threads. */ for (i = 0; i < NCPUS; i++) { if (machine_slot[i].is_cpu) { thread_t th; (void) thread_create(kernel_task, &th); thread_bind(th, cpu_to_processor(i)); thread_start(th, idle_thread); thread_doswapin(th); (void) thread_resume(th); } } (void) kernel_thread(kernel_task, reaper_thread, (char *) 0); (void) kernel_thread(kernel_task, swapin_thread, (char *) 0); (void) kernel_thread(kernel_task, sched_thread, (char *) 0); #if NCPUS > 1 /* * Create the shutdown thread. */ (void) kernel_thread(kernel_task, action_thread, (char *) 0); /* * Allow other CPUs to run. */ start_other_cpus(); #endif /* NCPUS > 1 */ /* * Create the device service. */ device_service_create(); /* * Initialize kernel task's creation time. * When we created the kernel task in task_init, the mapped * time was not yet available. Now, last thing before starting * the user bootstrap, record the current time as the kernel * task's creation time. */ record_time_stamp (&kernel_task->creation_time); /* * Start the user bootstrap. */ bootstrap_create(); #if XPR_DEBUG xprinit(); /* XXX */ #endif /* XPR_DEBUG */ /* * Become the pageout daemon. */ (void) spl0(); vm_pageout(); /*NOTREACHED*/ }