- thread_machine_set_current(thread);
- thread_lock(thread);
- thread->state &= ~TH_UNINT;
- thread->last_processor = processor;
+ PMAP_ACTIVATE_KERNEL(processor->cpu_id);
+
+ /*
+ * Acquire a stack if none attached. The panic
+ * should never occur since the thread is expected
+ * to have reserved stack.
+ */
+ load_context_kprintf("stack %x, stackptr %x\n",
+ thread->kernel_stack, thread->machine.kstackptr);
+ if (!thread->kernel_stack) {
+ load_context_kprintf("calling stack_alloc_try\n");
+ if (!stack_alloc_try(thread))
+ panic("load_context");
+ }
+
+ /*
+ * The idle processor threads are not counted as
+ * running for load calculations.
+ */
+ if (!(thread->state & TH_IDLE))
+ sched_run_incr();
+
+ processor->active_thread = thread;