X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/0b4e3aa066abc0728aacb4bbeb86f53f9737156e..91447636331957f3d9b5ca5b508f07c526b0074d:/osfmk/kern/thread_policy.c diff --git a/osfmk/kern/thread_policy.c b/osfmk/kern/thread_policy.c index e9eacf91b..c9e75fc1e 100644 --- a/osfmk/kern/thread_policy.c +++ b/osfmk/kern/thread_policy.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -19,15 +19,12 @@ * * @APPLE_LICENSE_HEADER_END@ */ -/* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. - * - * HISTORY - * - * 15 October 2000 (debo) - * Created. - */ +#include +#include + +#include +#include #include static void @@ -36,27 +33,24 @@ thread_recompute_priority( kern_return_t thread_policy_set( - thread_act_t act, + thread_t thread, thread_policy_flavor_t flavor, thread_policy_t policy_info, mach_msg_type_number_t count) { kern_return_t result = KERN_SUCCESS; - thread_t thread; spl_t s; - if (act == THR_ACT_NULL) + if (thread == THREAD_NULL) return (KERN_INVALID_ARGUMENT); - thread = act_lock_thread(act); - if (!act->active) { - act_unlock_thread(act); + thread_mtx_lock(thread); + if (!thread->active) { + thread_mtx_unlock(thread); return (KERN_TERMINATED); } - assert(thread != THREAD_NULL); - switch (flavor) { case THREAD_EXTENDED_POLICY: @@ -74,13 +68,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 +113,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 +129,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); } @@ -167,7 +178,7 @@ thread_policy_set( break; } - act_unlock_thread(act); + thread_mtx_unlock(thread); return (result); } @@ -179,7 +190,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; @@ -198,15 +209,7 @@ thread_recompute_priority( priority = MINPRI; } - if (thread->depress_priority >= 0) - thread->depress_priority = priority; - else { - thread->priority = priority; - compute_priority(thread, TRUE); - - if (thread == current_thread()) - ast_on(AST_BLOCK); - } + set_priority(thread, priority); } void @@ -231,30 +234,51 @@ thread_task_priority( splx(s); } +void +thread_policy_reset( + thread_t thread) +{ + if (!(thread->sched_mode & TH_MODE_FAILSAFE)) { + thread->sched_mode &= ~TH_MODE_REALTIME; + + if (!(thread->sched_mode & TH_MODE_TIMESHARE)) { + thread->sched_mode |= TH_MODE_TIMESHARE; + + if (thread->state & TH_RUN) + pset_share_incr(thread->processor_set); + } + } + else { + thread->safe_mode = 0; + thread->sched_mode &= ~TH_MODE_FAILSAFE; + } + + thread->importance = 0; + + thread_recompute_priority(thread); +} + kern_return_t thread_policy_get( - thread_act_t act, + thread_t thread, thread_policy_flavor_t flavor, thread_policy_t policy_info, mach_msg_type_number_t *count, boolean_t *get_default) { kern_return_t result = KERN_SUCCESS; - thread_t thread; spl_t s; - if (act == THR_ACT_NULL) + if (thread == THREAD_NULL) return (KERN_INVALID_ARGUMENT); - thread = act_lock_thread(act); - if (!act->active) { - act_unlock_thread(act); + thread_mtx_lock(thread); + if (!thread->active) { + thread_mtx_unlock(thread); return (KERN_TERMINATED); } - assert(thread != THREAD_NULL); - switch (flavor) { case THREAD_EXTENDED_POLICY: @@ -359,7 +383,7 @@ thread_policy_get( break; } - act_unlock_thread(act); + thread_mtx_unlock(thread); return (result); }