]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/mk_sp.c
xnu-1699.22.73.tar.gz
[apple/xnu.git] / osfmk / kern / mk_sp.c
index 9df11b21512b6e8e1eb1a754a297938ec290c36f..d8e86124badd6d1704314414a3cd69ed1961138d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -76,33 +76,40 @@ thread_policy_common(
                        invalid_policy(policy)          )
                return(KERN_INVALID_ARGUMENT);
 
+       if (thread->static_param)
+               return (KERN_SUCCESS);
+
+       if ((policy == POLICY_TIMESHARE)
+               && !SCHED(supports_timeshare_mode)())
+               policy = TH_MODE_FIXED;
+
        s = splsched();
        thread_lock(thread);
 
-       if (    !(thread->sched_mode & TH_MODE_REALTIME)        &&
-                       !(thread->safe_mode & TH_MODE_REALTIME)                 ) {
-               if (!(thread->sched_mode & TH_MODE_FAILSAFE)) {
-                       integer_t       oldmode = (thread->sched_mode & TH_MODE_TIMESHARE);
+       if (    (thread->sched_mode != TH_MODE_REALTIME)        &&
+                       (thread->saved_mode != TH_MODE_REALTIME)                ) {
+               if (!(thread->sched_flags & TH_SFLAG_DEMOTED_MASK)) {
+                       boolean_t       oldmode = thread->sched_mode == TH_MODE_TIMESHARE;
 
                        if (policy == POLICY_TIMESHARE && !oldmode) {
-                               thread->sched_mode |= TH_MODE_TIMESHARE;
+                               thread->sched_mode = TH_MODE_TIMESHARE;
 
-                               if (thread->state & TH_RUN)
-                                       pset_share_incr(thread->processor_set);
+                               if ((thread->state & (TH_RUN|TH_IDLE)) == TH_RUN)
+                                       sched_share_incr();
                        }
                        else
                        if (policy != POLICY_TIMESHARE && oldmode) {
-                               thread->sched_mode &= ~TH_MODE_TIMESHARE;
+                               thread->sched_mode = TH_MODE_FIXED;
 
-                               if (thread->state & TH_RUN)
-                                       pset_share_decr(thread->processor_set);
+                               if ((thread->state & (TH_RUN|TH_IDLE)) == TH_RUN)
+                                       sched_share_decr();
                        }
                }
                else {
                        if (policy == POLICY_TIMESHARE)
-                               thread->safe_mode |= TH_MODE_TIMESHARE;
+                               thread->saved_mode = TH_MODE_TIMESHARE;
                        else
-                               thread->safe_mode &= ~TH_MODE_TIMESHARE;
+                               thread->saved_mode = TH_MODE_FIXED;
                }
 
                if (priority >= thread->max_priority)
@@ -126,6 +133,12 @@ thread_policy_common(
 
                thread->importance = priority - thread->task_priority;
 
+#if CONFIG_EMBEDDED
+               /* No one can have a base priority less than MAXPRI_THROTTLE */
+               if (priority < MAXPRI_THROTTLE) 
+                       priority = MAXPRI_THROTTLE;
+#endif /* CONFIG_EMBEDDED */
+
                set_priority(thread, priority);
        }
 
@@ -156,17 +169,11 @@ thread_set_policy(
        kern_return_t                   result = KERN_SUCCESS;
 
        if (    thread == THREAD_NULL                   ||
-                       pset == PROCESSOR_SET_NULL              )
+                       pset == PROCESSOR_SET_NULL || pset != &pset0)
                return (KERN_INVALID_ARGUMENT);
 
        thread_mtx_lock(thread);
 
-       if (pset != thread->processor_set) {
-               thread_mtx_unlock(thread);
-
-               return (KERN_FAILURE);
-       }
-
        switch (policy) {
 
        case POLICY_RR:
@@ -267,9 +274,9 @@ thread_policy(
        boolean_t                               set_limit)
 {
        kern_return_t                   result = KERN_SUCCESS;
-       processor_set_t                 pset;
-       policy_limit_t                  limit;
-       int                                             limcount;
+       processor_set_t                 pset = &pset0;
+       policy_limit_t                  limit = NULL;
+       int                                             limcount = 0;
        policy_rr_limit_data_t                  rr_limit;
        policy_fifo_limit_data_t                fifo_limit;
        policy_timeshare_limit_data_t   ts_limit;
@@ -279,13 +286,6 @@ thread_policy(
 
        thread_mtx_lock(thread);
 
-       pset = thread->processor_set;
-       if (pset == PROCESSOR_SET_NULL) {
-               thread_mtx_unlock(thread);
-
-               return (KERN_INVALID_ARGUMENT);
-       }
-
        if (    invalid_policy(policy)                                                                                  ||
                        ((POLICY_TIMESHARE | POLICY_RR | POLICY_FIFO) & policy) == 0    ) {
                thread_mtx_unlock(thread);