]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/syscall_subr.c
xnu-517.12.7.tar.gz
[apple/xnu.git] / osfmk / kern / syscall_subr.c
index caca3545acee49a33952f66733fd10c2bc973492..26fc9b21401aa79e3ad839f9169910e177bd1df8 100644 (file)
@@ -50,8 +50,6 @@
 /*
  */
 
-#include <cpus.h>
-
 #include <mach/boolean.h>
 #include <mach/thread_switch.h>
 #include <ipc/ipc_port.h>
@@ -72,7 +70,7 @@
 #include <mach/mach_host_server.h>
 #include <mach/mach_syscalls.h>
 
-#include <kern/sf.h>
+#include <kern/mk_sp.h>
 
 /*
  *     swtch and swtch_pri both attempt to context switch (logic in
  *     lock and then be a good citizen and really suspend.
  */
 
-#if            0
-
-/* broken..do not enable */
-
-swtch_continue()
+void
+swtch_continue(void)
 {
-    boolean_t retval;
-       register processor_t myprocessor;
+       register processor_t    myprocessor;
+    boolean_t                          result;
 
     mp_disable_preemption();
        myprocessor = current_processor();
-       retval = (
-#if    NCPUS > 1
-              myprocessor->runq.count > 0 ||
-#endif /*NCPUS > 1*/
-              myprocessor->processor_set->runq.count > 0);
+       result =                myprocessor->runq.count > 0                                     ||
+                               myprocessor->processor_set->runq.count > 0;
        mp_enable_preemption();
-       return retval;
-}
 
-#endif
+       thread_syscall_return(result);
+       /*NOTREACHED*/
+}
 
 boolean_t
 swtch(void)
@@ -118,10 +110,7 @@ swtch(void)
 
        mp_disable_preemption();
        myprocessor = current_processor();
-       if (
-#if    NCPUS > 1
-                       myprocessor->runq.count == 0                                    &&
-#endif /* NCPUS > 1 */
+       if (            myprocessor->runq.count == 0                            &&
                        myprocessor->processor_set->runq.count == 0                     ) {
                mp_enable_preemption();
 
@@ -131,57 +120,64 @@ swtch(void)
 
        counter(c_swtch_block++);
 
-       thread_block((void (*)(void)) 0);
+       thread_block_reason(swtch_continue, AST_YIELD);
 
        mp_disable_preemption();
        myprocessor = current_processor();
-       result = 
-#if    NCPUS > 1
-               myprocessor->runq.count > 0                                                     ||
-#endif /*NCPUS > 1*/
-               myprocessor->processor_set->runq.count > 0;
+       result =                myprocessor->runq.count > 0                                     ||
+                               myprocessor->processor_set->runq.count > 0;
        mp_enable_preemption();
 
        return (result);
 }
 
+void
+swtch_pri_continue(void)
+{
+       register processor_t    myprocessor;
+    boolean_t                          result;
+
+       _mk_sp_thread_depress_abort(current_thread(), FALSE);
+
+    mp_disable_preemption();
+       myprocessor = current_processor();
+       result =                myprocessor->runq.count > 0                                     ||
+                               myprocessor->processor_set->runq.count > 0;
+       mp_enable_preemption();
+
+       thread_syscall_return(result);
+       /*NOTREACHED*/
+}
+
 boolean_t
 swtch_pri(
        int                             pri)
 {
-       thread_t                                self = current_thread();
        register processor_t    myprocessor;
        boolean_t                               result;
-       sched_policy_t                  *policy;
-       spl_t                                   s;
 
-       s = splsched();
-       thread_lock(self);
+       mp_disable_preemption();
        myprocessor = current_processor();
-       if (
-#if    NCPUS > 1
-                       myprocessor->runq.count == 0                                    &&
-#endif /* NCPUS > 1 */
+       if (    myprocessor->runq.count == 0                                    &&
                        myprocessor->processor_set->runq.count == 0                     ) {
-               thread_unlock(self);
-               splx(s);
+               mp_enable_preemption();
 
                return (FALSE);
        }
+       mp_enable_preemption();
+
+       counter(c_swtch_pri_block++);
+
+       _mk_sp_thread_depress_abstime(std_quantum);
 
-       policy = &sched_policy[self->policy];
-       thread_unlock(self);
-       splx(s);
+       thread_block_reason(swtch_pri_continue, AST_YIELD);
 
-       policy->sp_ops.sp_swtch_pri(policy, pri);
+       _mk_sp_thread_depress_abort(current_thread(), FALSE);
 
        mp_disable_preemption();
        myprocessor = current_processor();
-       result = 
-#if    NCPUS > 1
-               myprocessor->runq.count > 0                                                     ||
-#endif /*NCPUS > 1*/
-               myprocessor->processor_set->runq.count > 0;
+       result =        myprocessor->runq.count > 0                                             ||
+                               myprocessor->processor_set->runq.count > 0;
        mp_enable_preemption();
 
        return (result);
@@ -198,10 +194,7 @@ thread_switch(
        int                                             option,
        mach_msg_timeout_t              option_time)
 {
-    register thread_t          self = current_thread();
     register thread_act_t      hint_act = THR_ACT_NULL;
-       sched_policy_t                  *policy;
-       spl_t                                   s;
 
     /*
      * Process option.
@@ -220,7 +213,7 @@ thread_switch(
     if (thread_name != MACH_PORT_NULL) {
                ipc_port_t                      port;
 
-               if (ipc_port_translate_send(self->top_act->task->itk_space,
+               if (ipc_port_translate_send(current_task()->itk_space,
                                                                        thread_name, &port) == KERN_SUCCESS) {
                        ip_reference(port);
                        ip_unlock(port);
@@ -230,17 +223,5 @@ thread_switch(
                }
        }
 
-       s = splsched();
-       thread_lock(self);
-       policy = &sched_policy[self->policy];
-       thread_unlock(self);
-       splx(s);
-
-    /*
-     * This is a scheduling policy-dependent operation.
-     * Call the routine associated with the thread's
-     * scheduling policy.
-     */
-    return (policy->sp_ops.
-                               sp_thread_switch(policy, hint_act, option, option_time));
+    return _mk_sp_thread_switch(hint_act, option, option_time);
 }