]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/thread_policy.c
xnu-517.9.4.tar.gz
[apple/xnu.git] / osfmk / kern / thread_policy.c
index d7e2c311ac28316e389583200ca9d4425a8846c7..2d7e2765c572cc2fdbf0dcda82d7e38f53077247 100644 (file)
@@ -28,6 +28,7 @@
  *  Created.
  */
 
+#include <kern/processor.h>
 #include <kern/thread.h>
 
 static void
@@ -74,13 +75,24 @@ thread_policy_set(
                thread_lock(thread);
 
                if (!(thread->sched_mode & TH_MODE_FAILSAFE)) {
+                       integer_t       oldmode = (thread->sched_mode & TH_MODE_TIMESHARE);
+
                        thread->sched_mode &= ~TH_MODE_REALTIME;
 
-                       if (timeshare)
+                       if (timeshare && !oldmode) {
                                thread->sched_mode |= TH_MODE_TIMESHARE;
+
+                               if (thread->state & TH_RUN)
+                                       pset_share_incr(thread->processor_set);
+                       }
                        else
+                       if (!timeshare && oldmode) {
                                thread->sched_mode &= ~TH_MODE_TIMESHARE;
 
+                               if (thread->state & TH_RUN)
+                                       pset_share_decr(thread->processor_set);
+                       }
+
                        thread_recompute_priority(thread);
                }
                else {
@@ -108,7 +120,8 @@ thread_policy_set(
                }
 
                info = (thread_time_constraint_policy_t)policy_info;
-               if (    info->computation > max_rt_quantum      ||
+               if (    info->constraint < info->computation    ||
+                               info->computation > max_rt_quantum              ||
                                info->computation < min_rt_quantum              ) {
                        result = KERN_INVALID_ARGUMENT;
                        break;
@@ -123,7 +136,12 @@ thread_policy_set(
                thread->realtime.preemptible = info->preemptible;
 
                if (!(thread->sched_mode & TH_MODE_FAILSAFE)) {
-                       thread->sched_mode &= ~TH_MODE_TIMESHARE;
+                       if (thread->sched_mode & TH_MODE_TIMESHARE) {
+                               thread->sched_mode &= ~TH_MODE_TIMESHARE;
+
+                               if (thread->state & TH_RUN)
+                                       pset_share_decr(thread->processor_set);
+                       }
                        thread->sched_mode |= TH_MODE_REALTIME;
                        thread_recompute_priority(thread);
                }
@@ -179,7 +197,7 @@ thread_recompute_priority(
        integer_t               priority;
 
        if (thread->sched_mode & TH_MODE_REALTIME)
-               priority = BASEPRI_REALTIME;
+               priority = BASEPRI_RTQUEUES;
        else {
                if (thread->importance > MAXPRI)
                        priority = MAXPRI;