X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8f6c56a50524aa785f7e596d52dddfb331e18961..6d2010ae8f7a6078e10b361c6962983bab233e0f:/osfmk/kern/mk_sp.c?ds=sidebyside diff --git a/osfmk/kern/mk_sp.c b/osfmk/kern/mk_sp.c index 9df11b215..d8e86124b 100644 --- a/osfmk/kern/mk_sp.c +++ b/osfmk/kern/mk_sp.c @@ -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);