#include <kern/machine.h>
#include <kern/processor.h>
#include <kern/sched_prim.h>
-#include <kern/sf.h>
+#include <kern/mk_sp.h>
#include <kern/startup.h>
#include <kern/task.h>
#include <kern/thread.h>
ipc_bootstrap();
vm_mem_init();
ipc_init();
- pager_mux_hash_init();
/*
* As soon as the virtual memory system is up, we record
* Initialize the IPC, task, and thread subsystems.
*/
ledger_init();
- swapper_init();
task_init();
act_init();
thread_init();
- subsystem_init();
/*
* Initialize the Event Trace Analysis Package.
/*
* 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.
+ * threads.
*/
- startup_thread = kernel_thread_with_priority(kernel_task, MAXPRI_KERNBAND,
- start_kernel_threads, FALSE);
-
+ startup_thread = kernel_thread_with_priority(
+ kernel_task, MAXPRI_KERNEL,
+ start_kernel_threads, TRUE, FALSE);
/*
- * 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.
+ * Pretend it is already running.
*
- * We can do all of this without locking, because nothing
+ * We can do this without locking, because nothing
* else is running yet.
*/
startup_thread->state = TH_RUN;
- (void) thread_resume(startup_thread->top_act);
+ hw_atomic_add(&startup_thread->processor_set->run_count, 1);
+
/*
* Start the thread.
*/
* service threads.
*/
for (i = 0; i < NCPUS; i++) {
- if (1 /*machine_slot[i].is_cpu*/) {
- processor_t processor = cpu_to_processor(i);
- thread_t thread;
- spl_t s;
-
- thread = kernel_thread_with_priority(kernel_task,
- MAXPRI_KERNBAND, idle_thread, FALSE);
- s = splsched();
- thread_lock(thread);
- thread_bind_locked(thread, processor);
- processor->idle_thread = thread;
- thread->state |= TH_IDLE;
- thread_go_locked(thread, THREAD_AWAKENED);
- thread_unlock(thread);
- splx(s);
- }
+ processor_t processor = cpu_to_processor(i);
+ thread_t thread;
+ spl_t s;
+
+ thread = kernel_thread_with_priority(
+ kernel_task, MAXPRI_KERNEL,
+ idle_thread, TRUE, FALSE);
+ s = splsched();
+ thread_lock(thread);
+ thread_bind_locked(thread, processor);
+ processor->idle_thread = thread;
+ thread->ref_count++;
+ thread->state |= TH_IDLE;
+ thread_go_locked(thread, THREAD_AWAKENED);
+ thread_unlock(thread);
+ splx(s);
}
/*
- * Initialize the thread callout mechanism.
+ * Initialize the thread reaper mechanism.
*/
- thread_call_initialize();
+ thread_reaper_init();
/*
- * Invoke some black magic.
+ * Initialize the stack swapin mechanism.
*/
-#if __ppc__
- mapping_adjust();
-#endif
+ swapin_init();
/*
- * Invoke the thread reaper mechanism.
+ * Initialize the periodic scheduler mechanism.
*/
- thread_reaper();
+ sched_tick_init();
/*
- * Start the stack swapin thread
+ * Initialize the thread callout mechanism.
*/
- kernel_thread(kernel_task, swapin_thread);
+ thread_call_initialize();
/*
- * Invoke the periodic scheduler mechanism.
+ * Invoke some black magic.
*/
- kernel_thread(kernel_task, sched_tick_thread);
+#if __ppc__
+ mapping_adjust();
+#endif
/*
* Create the clock service.
processor_t myprocessor = current_processor();
thread_t thread;
+ myprocessor->cpu_data = get_cpu_data();
thread = myprocessor->next_thread;
myprocessor->next_thread = THREAD_NULL;
if (thread == THREAD_NULL) {
thread = machine_wake_thread;
machine_wake_thread = THREAD_NULL;
}
+ thread_machine_set_current(thread);
+ if (thread == machine_wake_thread)
+ thread_bind(thread, myprocessor);
+
cpu_launch_first_thread(thread);
/*NOTREACHED*/
panic("slave_main");
ipc_processor_enable(processor);
}
-#if 0
- printf("start_cpu_thread done on cpu %x\n", cpu_number());
-#endif
- /* TODO: Mark this processor ready to dispatch threads */
-
(void) thread_terminate(current_act());
}
thread_t thread)
{
register int mycpu = cpu_number();
+ processor_t processor = cpu_to_processor(mycpu);
- /* initialize preemption disabled */
- cpu_data[mycpu].preemption_level = 1;
+ processor->cpu_data->preemption_level = 0;
cpu_up(mycpu);
start_timer(&kernel_timer[mycpu]);
+ clock_get_uptime(&processor->last_dispatch);
- if (thread == THREAD_NULL) {
- thread = cpu_to_processor(mycpu)->idle_thread;
- if (thread == THREAD_NULL)
- panic("cpu_launch_first_thread");
- }
+ if (thread == THREAD_NULL || thread == processor->idle_thread)
+ panic("cpu_launch_first_thread");
rtclock_reset(); /* start realtime clock ticking */
PMAP_ACTIVATE_KERNEL(mycpu);
thread_machine_set_current(thread);
thread_lock(thread);
thread->state &= ~TH_UNINT;
+ thread->last_processor = processor;
+ processor->current_pri = thread->sched_pri;
+ _mk_sp_thread_begin(thread, processor);
thread_unlock(thread);
timer_switch(&thread->system_timer);