+ if (SCHED(can_update_priority)(thread))
+ SCHED(update_priority)(thread);
+ else
+ SCHED(lightweight_update_priority)(thread);
+
+ if (thread->sched_mode != TH_MODE_REALTIME)
+ SCHED(quantum_expire)(thread);
+
+ processor->current_pri = thread->sched_pri;
+ processor->current_thmode = thread->sched_mode;
+
+ /* Tell platform layer that we are still running this thread */
+ urgency = thread_get_urgency(thread, &ignore1, &ignore2);
+ machine_thread_going_on_core(thread, urgency, 0);
+
+ /*
+ * This quantum is up, give this thread another.
+ */
+ processor->first_timeslice = FALSE;
+
+ thread_quantum_init(thread);
+
+ /* Reload precise timing global policy to thread-local policy */
+ thread->precise_user_kernel_time = use_precise_user_kernel_time(thread);
+
+ /*
+ * Since non-precise user/kernel time doesn't update the state/thread timer
+ * during privilege transitions, synthesize an event now.
+ */
+ if (!thread->precise_user_kernel_time) {
+ timer_switch(PROCESSOR_DATA(processor, current_state),
+ ctime,
+ PROCESSOR_DATA(processor, current_state));
+ timer_switch(PROCESSOR_DATA(processor, thread_timer),
+ ctime,
+ PROCESSOR_DATA(processor, thread_timer));
+ }
+
+ processor->quantum_end = ctime + thread->quantum_remaining;
+
+ /*
+ * Context switch check.
+ */
+ if ((preempt = csw_check(processor, AST_QUANTUM)) != AST_NONE)
+ ast_on(preempt);
+
+ thread_unlock(thread);
+
+ timer_call_enter1(&processor->quantum_timer, thread,
+ processor->quantum_end, TIMER_CALL_SYS_CRITICAL | TIMER_CALL_LOCAL);
+
+#if defined(CONFIG_SCHED_TIMESHARE_CORE)
+ sched_timeshare_consider_maintenance(ctime);
+#endif /* CONFIG_SCHED_TIMESHARE_CORE */
+
+
+ KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED, MACH_SCHED_QUANTUM_EXPIRED) | DBG_FUNC_END, preempt, 0, 0, 0, 0);
+}
+
+/*
+ * sched_set_thread_base_priority:
+ *
+ * Set the base priority of the thread
+ * and reset its scheduled priority.
+ *
+ * This is the only path to change base_pri.
+ *
+ * Called with the thread locked.
+ */
+void
+sched_set_thread_base_priority(thread_t thread, int priority)
+{
+ assert(priority >= MINPRI);
+
+ if (thread->sched_mode == TH_MODE_REALTIME)
+ assert(priority <= BASEPRI_RTQUEUES);
+ else
+ assert(priority < BASEPRI_RTQUEUES);
+
+ thread->base_pri = priority;
+
+ sched_update_thread_bucket(thread);
+
+ thread_recompute_sched_pri(thread, FALSE);
+}
+
+/*
+ * thread_recompute_sched_pri:
+ *
+ * Reset the scheduled priority of the thread
+ * according to its base priority if the
+ * thread has not been promoted or depressed.
+ *
+ * This is the standard way to push base_pri changes into sched_pri,
+ * or to recalculate the appropriate sched_pri after clearing
+ * a promotion or depression.
+ *
+ * Called at splsched with the thread locked.
+ */
+void
+thread_recompute_sched_pri(
+ thread_t thread,
+ boolean_t override_depress)
+{
+ int priority;
+
+ if (thread->sched_mode == TH_MODE_TIMESHARE)
+ priority = SCHED(compute_timeshare_priority)(thread);