]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/machine.c
xnu-3248.30.4.tar.gz
[apple/xnu.git] / osfmk / kern / machine.c
index 1e7d3e96fc78da756365faa92de93e59878a7bb0..dfe33564daf69530a432c5eaed8bbb2a31ff7678 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -79,7 +79,6 @@
 #include <kern/cpu_data.h>
 #include <kern/ipc_host.h>
 #include <kern/host.h>
 #include <kern/cpu_data.h>
 #include <kern/ipc_host.h>
 #include <kern/host.h>
-#include <kern/lock.h>
 #include <kern/machine.h>
 #include <kern/misc_protos.h>
 #include <kern/processor.h>
 #include <kern/machine.h>
 #include <kern/misc_protos.h>
 #include <kern/processor.h>
 #include <kern/task.h>
 #include <kern/thread.h>
 
 #include <kern/task.h>
 #include <kern/thread.h>
 
+#include <machine/commpage.h>
+
 #if HIBERNATION
 #include <IOKit/IOHibernatePrivate.h>
 #endif
 #include <IOKit/IOPlatformExpert.h>
 
 #if HIBERNATION
 #include <IOKit/IOHibernatePrivate.h>
 #endif
 #include <IOKit/IOPlatformExpert.h>
 
+#if CONFIG_DTRACE
+extern void (*dtrace_cpu_state_changed_hook)(int, boolean_t);
+#endif
+
 /*
  *     Exported variables:
  */
 /*
  *     Exported variables:
  */
@@ -120,14 +125,21 @@ processor_up(
        init_ast_check(processor);
        pset = processor->processor_set;
        pset_lock(pset);
        init_ast_check(processor);
        pset = processor->processor_set;
        pset_lock(pset);
-       pset->processor_count++;
-       enqueue_head(&pset->active_queue, (queue_entry_t)processor);
+       ++pset->online_processor_count;
+       enqueue_tail(&pset->active_queue, (queue_entry_t)processor);
        processor->state = PROCESSOR_RUNNING;
        (void)hw_atomic_add(&processor_avail_count, 1);
        processor->state = PROCESSOR_RUNNING;
        (void)hw_atomic_add(&processor_avail_count, 1);
+       commpage_update_active_cpus();
        pset_unlock(pset);
        ml_cpu_up();
        splx(s);
        pset_unlock(pset);
        ml_cpu_up();
        splx(s);
+
+#if CONFIG_DTRACE
+       if (dtrace_cpu_state_changed_hook)
+               (*dtrace_cpu_state_changed_hook)(processor->cpu_id, TRUE);
+#endif
 }
 }
+#include <atm/atm_internal.h>
 
 kern_return_t
 host_reboot(
 
 kern_return_t
 host_reboot(
@@ -139,10 +151,12 @@ host_reboot(
 
        assert(host_priv == &realhost);
 
 
        assert(host_priv == &realhost);
 
+#if DEVELOPMENT || DEBUG
        if (options & HOST_REBOOT_DEBUGGER) {
                Debugger("Debugger");
                return (KERN_SUCCESS);
        }
        if (options & HOST_REBOOT_DEBUGGER) {
                Debugger("Debugger");
                return (KERN_SUCCESS);
        }
+#endif
 
     if (options & HOST_REBOOT_UPSDELAY) {
         // UPS power cutoff path
 
     if (options & HOST_REBOOT_UPSDELAY) {
         // UPS power cutoff path
@@ -198,7 +212,9 @@ processor_shutdown(
         */
        while (processor->state == PROCESSOR_DISPATCHING) {
                pset_unlock(pset);
         */
        while (processor->state == PROCESSOR_DISPATCHING) {
                pset_unlock(pset);
+               splx(s);
                delay(1);
                delay(1);
+               s = splsched();
                pset_lock(pset);
        }
 
                pset_lock(pset);
        }
 
@@ -212,15 +228,11 @@ processor_shutdown(
                return (KERN_SUCCESS);
        }
 
                return (KERN_SUCCESS);
        }
 
-       if (processor->state == PROCESSOR_IDLE) {
-               remqueue(&pset->idle_queue, (queue_entry_t)processor);
-               pset->idle_count--;
-       }
+       if (processor->state == PROCESSOR_IDLE)
+               remqueue((queue_entry_t)processor);
        else
        if (processor->state == PROCESSOR_RUNNING)
        else
        if (processor->state == PROCESSOR_RUNNING)
-               remqueue(&pset->active_queue, (queue_entry_t)processor);
-       else
-               panic("processor_shutdown");
+               remqueue((queue_entry_t)processor);
 
        processor->state = PROCESSOR_SHUTDOWN;
 
 
        processor->state = PROCESSOR_SHUTDOWN;
 
@@ -229,13 +241,13 @@ processor_shutdown(
        processor_doshutdown(processor);
        splx(s);
 
        processor_doshutdown(processor);
        splx(s);
 
-       cpu_exit_wait(PROCESSOR_DATA(processor, slot_num));
+       cpu_exit_wait(processor->cpu_id);
 
        return (KERN_SUCCESS);
 }
 
 /*
 
        return (KERN_SUCCESS);
 }
 
 /*
- * Called at splsched.
+ * Called with interrupts disabled.
  */
 void
 processor_doshutdown(
  */
 void
 processor_doshutdown(
@@ -243,6 +255,7 @@ processor_doshutdown(
 {
        thread_t                        old_thread, self = current_thread();
        processor_t                     prev;
 {
        thread_t                        old_thread, self = current_thread();
        processor_t                     prev;
+       processor_set_t                 pset;
 
        /*
         *      Get onto the processor to shutdown
 
        /*
         *      Get onto the processor to shutdown
@@ -250,18 +263,31 @@ processor_doshutdown(
        prev = thread_bind(processor);
        thread_block(THREAD_CONTINUE_NULL);
 
        prev = thread_bind(processor);
        thread_block(THREAD_CONTINUE_NULL);
 
-#if HIBERNATION
-       if (processor_avail_count < 2)
-               hibernate_vm_lock();
+       assert(processor->state == PROCESSOR_SHUTDOWN);
+
+#if CONFIG_DTRACE
+       if (dtrace_cpu_state_changed_hook)
+               (*dtrace_cpu_state_changed_hook)(processor->cpu_id, FALSE);
 #endif
 
 #endif
 
-       assert(processor->state == PROCESSOR_SHUTDOWN);
+       ml_cpu_down();
 
 #if HIBERNATION
 
 #if HIBERNATION
-       if (processor_avail_count < 2)
+       if (processor_avail_count < 2) {
+               hibernate_vm_lock();
                hibernate_vm_unlock();
                hibernate_vm_unlock();
+       }
 #endif
 
 #endif
 
+       pset = processor->processor_set;
+       pset_lock(pset);
+       processor->state = PROCESSOR_OFF_LINE;
+       --pset->online_processor_count;
+       (void)hw_atomic_sub(&processor_avail_count, 1);
+       commpage_update_active_cpus();
+       SCHED(processor_queue_shutdown)(processor);
+       /* pset lock dropped */
+
        /*
         *      Continue processor shutdown in shutdown context.
         */
        /*
         *      Continue processor shutdown in shutdown context.
         */
@@ -269,28 +295,10 @@ processor_doshutdown(
        old_thread = machine_processor_shutdown(self, processor_offline, processor);
 
        thread_dispatch(old_thread, self);
        old_thread = machine_processor_shutdown(self, processor_offline, processor);
 
        thread_dispatch(old_thread, self);
-
-       /*
-        * If we just shutdown another processor, move any
-        * threads and timer call outs to the current processor.
-        */
-       if (processor != current_processor()) {
-               processor_set_t         pset = processor->processor_set;
-
-               pset_lock(pset);
-
-               if (processor->state == PROCESSOR_OFF_LINE || processor->state == PROCESSOR_SHUTDOWN) {
-                       timer_call_shutdown(processor);
-                       processor_queue_shutdown(processor);
-                       return;
-               }
-
-               pset_unlock(pset);
-       }
 }
 
 /*
 }
 
 /*
- *     Complete the shutdown and place the processor offline.
+ *Complete the shutdown and place the processor offline.
  *
  *     Called at splsched in the shutdown context.
  */
  *
  *     Called at splsched in the shutdown context.
  */
@@ -299,11 +307,11 @@ processor_offline(
        processor_t                     processor)
 {
        thread_t                        new_thread, old_thread = processor->active_thread;
        processor_t                     processor)
 {
        thread_t                        new_thread, old_thread = processor->active_thread;
-       processor_set_t         pset;
 
        new_thread = processor->idle_thread;
        processor->active_thread = new_thread;
        processor->current_pri = IDLEPRI;
 
        new_thread = processor->idle_thread;
        processor->active_thread = new_thread;
        processor->current_pri = IDLEPRI;
+       processor->current_thmode = TH_MODE_NONE;
        processor->deadline = UINT64_MAX;
        new_thread->last_processor = processor;
 
        processor->deadline = UINT64_MAX;
        new_thread->last_processor = processor;
 
@@ -314,17 +322,7 @@ processor_offline(
 
        thread_dispatch(old_thread, new_thread);
 
 
        thread_dispatch(old_thread, new_thread);
 
-       PMAP_DEACTIVATE_KERNEL(PROCESSOR_DATA(processor, slot_num));
-
-       pset = processor->processor_set;
-       pset_lock(pset);
-       pset->processor_count--;
-       processor->state = PROCESSOR_OFF_LINE;
-       if (processor == pset->low_hint)
-               pset->low_hint = PROCESSOR_NULL;
-       (void)hw_atomic_sub(&processor_avail_count, 1);
-       pset_unlock(pset);
-       ml_cpu_down();
+       PMAP_DEACTIVATE_KERNEL(processor->cpu_id);
 
        cpu_sleep();
        panic("zombie processor");
 
        cpu_sleep();
        panic("zombie processor");