2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Author: Avadis Tevanian, Jr.
63 * Priority related scheduler bits.
66 #include <mach/boolean.h>
67 #include <mach/kern_return.h>
68 #include <mach/machine.h>
69 #include <kern/host.h>
70 #include <kern/mach_param.h>
71 #include <kern/sched.h>
72 #include <sys/kdebug.h>
74 #include <kern/thread.h>
75 #include <kern/processor.h>
76 #include <kern/ledger.h>
77 #include <machine/machparam.h>
78 #include <kern/machine.h>
80 #ifdef CONFIG_MACH_APPROXIMATE_TIME
81 #include <machine/commpage.h> /* for commpage_update_mach_approximate_time */
85 * thread_quantum_expire:
87 * Recalculate the quantum and priority for a thread.
93 thread_quantum_expire(
94 timer_call_param_t p0
,
95 timer_call_param_t p1
)
97 processor_t processor
= p0
;
102 uint64_t ignore1
, ignore2
;
104 assert(processor
== current_processor());
105 assert(thread
== current_thread());
107 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED
, MACH_SCHED_QUANTUM_EXPIRED
) | DBG_FUNC_START
, 0, 0, 0, 0, 0);
109 SCHED_STATS_QUANTUM_TIMER_EXPIRATION(processor
);
112 * We bill CPU time to both the individual thread and its task.
114 * Because this balance adjustment could potentially attempt to wake this very
115 * thread, we must credit the ledger before taking the thread lock. The ledger
116 * pointers are only manipulated by the thread itself at the ast boundary.
118 ledger_credit(thread
->t_ledger
, task_ledgers
.cpu_time
, thread
->quantum_remaining
);
119 ledger_credit(thread
->t_threadledger
, thread_ledgers
.cpu_time
, thread
->quantum_remaining
);
121 if (thread
->t_bankledger
) {
122 ledger_credit(thread
->t_bankledger
, bank_ledgers
.cpu_time
,
123 (thread
->quantum_remaining
- thread
->t_deduct_bank_ledger_time
));
125 thread
->t_deduct_bank_ledger_time
= 0;
128 ctime
= mach_absolute_time();
130 #ifdef CONFIG_MACH_APPROXIMATE_TIME
131 commpage_update_mach_approximate_time(ctime
);
137 * We've run up until our quantum expiration, and will (potentially)
138 * continue without re-entering the scheduler, so update this now.
140 processor
->last_dispatch
= ctime
;
141 thread
->last_run_time
= ctime
;
144 * Check for fail-safe trip.
146 if ((thread
->sched_mode
== TH_MODE_REALTIME
|| thread
->sched_mode
== TH_MODE_FIXED
) &&
147 !(thread
->sched_flags
& TH_SFLAG_PROMOTED_MASK
) &&
148 !(thread
->options
& TH_OPT_SYSTEM_CRITICAL
)) {
149 uint64_t new_computation
;
151 new_computation
= ctime
- thread
->computation_epoch
;
152 new_computation
+= thread
->computation_metered
;
153 if (new_computation
> max_unsafe_computation
) {
154 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED
, MACH_FAILSAFE
)|DBG_FUNC_NONE
,
155 (uintptr_t)thread
->sched_pri
, (uintptr_t)thread
->sched_mode
, 0, 0, 0);
157 thread
->safe_release
= ctime
+ sched_safe_duration
;
159 sched_thread_mode_demote(thread
, TH_SFLAG_FAILSAFE
);
164 * Recompute scheduled priority if appropriate.
166 if (SCHED(can_update_priority
)(thread
))
167 SCHED(update_priority
)(thread
);
169 SCHED(lightweight_update_priority
)(thread
);
171 if (thread
->sched_mode
!= TH_MODE_REALTIME
)
172 SCHED(quantum_expire
)(thread
);
174 processor
->current_pri
= thread
->sched_pri
;
175 processor
->current_thmode
= thread
->sched_mode
;
177 /* Tell platform layer that we are still running this thread */
178 urgency
= thread_get_urgency(thread
, &ignore1
, &ignore2
);
179 machine_thread_going_on_core(thread
, urgency
, 0);
182 * This quantum is up, give this thread another.
184 processor
->first_timeslice
= FALSE
;
186 thread_quantum_init(thread
);
188 /* Reload precise timing global policy to thread-local policy */
189 thread
->precise_user_kernel_time
= use_precise_user_kernel_time(thread
);
192 * Since non-precise user/kernel time doesn't update the state/thread timer
193 * during privilege transitions, synthesize an event now.
195 if (!thread
->precise_user_kernel_time
) {
196 timer_switch(PROCESSOR_DATA(processor
, current_state
),
198 PROCESSOR_DATA(processor
, current_state
));
199 timer_switch(PROCESSOR_DATA(processor
, thread_timer
),
201 PROCESSOR_DATA(processor
, thread_timer
));
204 processor
->quantum_end
= ctime
+ thread
->quantum_remaining
;
207 * Context switch check.
209 if ((preempt
= csw_check(processor
, AST_QUANTUM
)) != AST_NONE
)
212 thread_unlock(thread
);
214 timer_call_enter1(&processor
->quantum_timer
, thread
,
215 processor
->quantum_end
, TIMER_CALL_SYS_CRITICAL
| TIMER_CALL_LOCAL
);
217 #if defined(CONFIG_SCHED_TIMESHARE_CORE)
218 sched_timeshare_consider_maintenance(ctime
);
219 #endif /* CONFIG_SCHED_TIMESHARE_CORE */
222 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED
, MACH_SCHED_QUANTUM_EXPIRED
) | DBG_FUNC_END
, preempt
, 0, 0, 0, 0);
226 * sched_set_thread_base_priority:
228 * Set the base priority of the thread
229 * and reset its scheduled priority.
231 * This is the only path to change base_pri.
233 * Called with the thread locked.
236 sched_set_thread_base_priority(thread_t thread
, int priority
)
238 int old_priority
= thread
->base_pri
;
239 thread
->base_pri
= priority
;
241 /* A thread is 'throttled' when its base priority is at or below MAXPRI_THROTTLE */
242 if ((priority
> MAXPRI_THROTTLE
) && (old_priority
<= MAXPRI_THROTTLE
)) {
243 sched_set_thread_throttled(thread
, FALSE
);
244 } else if ((priority
<= MAXPRI_THROTTLE
) && (old_priority
> MAXPRI_THROTTLE
)) {
245 sched_set_thread_throttled(thread
, TRUE
);
248 thread_recompute_sched_pri(thread
, FALSE
);
252 * thread_recompute_sched_pri:
254 * Reset the scheduled priority of the thread
255 * according to its base priority if the
256 * thread has not been promoted or depressed.
258 * This is the standard way to push base_pri changes into sched_pri,
259 * or to recalculate the appropriate sched_pri after clearing
260 * a promotion or depression.
262 * Called at splsched with the thread locked.
265 thread_recompute_sched_pri(
267 boolean_t override_depress
)
271 if (thread
->sched_mode
== TH_MODE_TIMESHARE
)
272 priority
= SCHED(compute_timeshare_priority
)(thread
);
274 priority
= thread
->base_pri
;
276 if ((!(thread
->sched_flags
& TH_SFLAG_PROMOTED_MASK
) || (priority
> thread
->sched_pri
)) &&
277 (!(thread
->sched_flags
& TH_SFLAG_DEPRESSED_MASK
) || override_depress
)) {
278 set_sched_pri(thread
, priority
);
283 sched_default_quantum_expire(thread_t thread __unused
)
286 * No special behavior when a timeshare, fixed, or realtime thread
287 * uses up its entire quantum
291 #if defined(CONFIG_SCHED_TIMESHARE_CORE)
294 * lightweight_update_priority:
296 * Update the scheduled priority for
297 * a timesharing thread.
299 * Only for use on the current thread.
301 * Called with the thread locked.
304 lightweight_update_priority(thread_t thread
)
306 assert(thread
->runq
== PROCESSOR_NULL
);
307 assert(thread
== current_thread());
309 if (thread
->sched_mode
== TH_MODE_TIMESHARE
) {
313 thread_timer_delta(thread
, delta
);
316 * Accumulate timesharing usage only
317 * during contention for processor
320 if (thread
->pri_shift
< INT8_MAX
)
321 thread
->sched_usage
+= delta
;
323 thread
->cpu_delta
+= delta
;
325 priority
= sched_compute_timeshare_priority(thread
);
328 * Adjust the scheduled priority like thread_recompute_sched_pri,
329 * except with the benefit of knowing the thread is on this core.
331 if ((!(thread
->sched_flags
& TH_SFLAG_PROMOTED_MASK
) || (priority
> thread
->sched_pri
)) &&
332 (!(thread
->sched_flags
& TH_SFLAG_DEPRESSED_MASK
)) &&
333 priority
!= thread
->sched_pri
) {
335 thread
->sched_pri
= priority
;
337 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED
, MACH_SCHED_CHANGE_PRIORITY
),
338 (uintptr_t)thread_tid(thread
),
341 0, /* eventually, 'reason' */
348 * Define shifts for simulating (5/8) ** n
350 * Shift structures for holding update shifts. Actual computation
351 * is usage = (usage >> shift1) +/- (usage >> abs(shift2)) where the
352 * +/- is determined by the sign of shift 2.
359 #define SCHED_DECAY_TICKS 32
360 static struct shift_data sched_decay_shifts
[SCHED_DECAY_TICKS
] = {
361 {1,1},{1,3},{1,-3},{2,-7},{3,5},{3,-5},{4,-8},{5,7},
362 {5,-7},{6,-10},{7,10},{7,-9},{8,-11},{9,12},{9,-11},{10,-13},
363 {11,14},{11,-13},{12,-15},{13,17},{13,-15},{14,-17},{15,19},{16,18},
364 {16,-19},{17,22},{18,20},{18,-20},{19,26},{20,22},{20,-22},{21,-27}
368 * sched_compute_timeshare_priority:
370 * Calculate the timesharing priority based upon usage and load.
372 extern int sched_pri_decay_band_limit
;
376 sched_compute_timeshare_priority(thread_t thread
)
378 /* start with base priority */
379 int priority
= thread
->base_pri
- (thread
->sched_usage
>> thread
->pri_shift
);
381 if (priority
< MINPRI_USER
)
382 priority
= MINPRI_USER
;
383 else if (priority
> MAXPRI_KERNEL
)
384 priority
= MAXPRI_KERNEL
;
391 * can_update_priority
393 * Make sure we don't do re-dispatches more frequently than a scheduler tick.
395 * Called with the thread locked.
401 if (sched_tick
== thread
->sched_stamp
)
410 * Perform housekeeping operations driven by scheduler tick.
412 * Called with the thread locked.
416 register thread_t thread
)
418 register unsigned ticks
;
419 register uint32_t delta
;
421 ticks
= sched_tick
- thread
->sched_stamp
;
423 thread
->sched_stamp
+= ticks
;
424 if (sched_use_combined_fgbg_decay
)
425 thread
->pri_shift
= sched_combined_fgbg_pri_shift
;
426 else if (thread
->sched_flags
& TH_SFLAG_THROTTLED
)
427 thread
->pri_shift
= sched_background_pri_shift
;
429 thread
->pri_shift
= sched_pri_shift
;
431 /* If requested, accelerate aging of sched_usage */
432 if (sched_decay_usage_age_factor
> 1)
433 ticks
*= sched_decay_usage_age_factor
;
436 * Gather cpu usage data.
438 thread_timer_delta(thread
, delta
);
439 if (ticks
< SCHED_DECAY_TICKS
) {
440 register struct shift_data
*shiftp
;
443 * Accumulate timesharing usage only
444 * during contention for processor
447 if (thread
->pri_shift
< INT8_MAX
)
448 thread
->sched_usage
+= delta
;
450 thread
->cpu_usage
+= delta
+ thread
->cpu_delta
;
451 thread
->cpu_delta
= 0;
453 shiftp
= &sched_decay_shifts
[ticks
];
454 if (shiftp
->shift2
> 0) {
456 (thread
->cpu_usage
>> shiftp
->shift1
) +
457 (thread
->cpu_usage
>> shiftp
->shift2
);
458 thread
->sched_usage
=
459 (thread
->sched_usage
>> shiftp
->shift1
) +
460 (thread
->sched_usage
>> shiftp
->shift2
);
464 (thread
->cpu_usage
>> shiftp
->shift1
) -
465 (thread
->cpu_usage
>> -(shiftp
->shift2
));
466 thread
->sched_usage
=
467 (thread
->sched_usage
>> shiftp
->shift1
) -
468 (thread
->sched_usage
>> -(shiftp
->shift2
));
472 thread
->cpu_usage
= thread
->cpu_delta
= 0;
473 thread
->sched_usage
= 0;
477 * Check for fail-safe release.
479 if ((thread
->sched_flags
& TH_SFLAG_FAILSAFE
) &&
480 mach_absolute_time() >= thread
->safe_release
) {
481 sched_thread_mode_undemote(thread
, TH_SFLAG_FAILSAFE
);
485 * Recompute scheduled priority if appropriate.
487 if (thread
->sched_mode
== TH_MODE_TIMESHARE
) {
488 int priority
= sched_compute_timeshare_priority(thread
);
491 * Adjust the scheduled priority like thread_recompute_sched_pri,
492 * except without setting an AST.
494 if ((!(thread
->sched_flags
& TH_SFLAG_PROMOTED_MASK
) || (priority
> thread
->sched_pri
)) &&
495 (!(thread
->sched_flags
& TH_SFLAG_DEPRESSED_MASK
)) &&
496 priority
!= thread
->sched_pri
) {
498 boolean_t removed
= thread_run_queue_remove(thread
);
500 thread
->sched_pri
= priority
;
502 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED
, MACH_SCHED_CHANGE_PRIORITY
),
503 (uintptr_t)thread_tid(thread
),
506 0, /* eventually, 'reason' */
510 thread_run_queue_reinsert(thread
, SCHED_TAILQ
);
517 #endif /* CONFIG_SCHED_TIMESHARE_CORE */
520 /* sched_mode == TH_MODE_TIMESHARE controls whether a thread has a timeshare count when it has a run count */
522 void sched_share_incr(thread_t thread
) {
523 assert((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
);
524 assert(thread
->sched_mode
== TH_MODE_TIMESHARE
);
525 assert(thread
->SHARE_COUNT
== 0);
526 thread
->SHARE_COUNT
++;
527 (void)hw_atomic_add(&sched_share_count
, 1);
530 void sched_share_decr(thread_t thread
) {
531 assert((thread
->state
& (TH_RUN
|TH_IDLE
)) != TH_RUN
|| thread
->sched_mode
!= TH_MODE_TIMESHARE
);
532 assert(thread
->SHARE_COUNT
== 1);
533 (void)hw_atomic_sub(&sched_share_count
, 1);
534 thread
->SHARE_COUNT
--;
537 /* TH_SFLAG_THROTTLED controls whether a thread has a background count when it has a run count and a share count */
539 void sched_background_incr(thread_t thread
) {
540 assert((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
);
541 assert(thread
->sched_mode
== TH_MODE_TIMESHARE
);
542 assert((thread
->sched_flags
& TH_SFLAG_THROTTLED
) == TH_SFLAG_THROTTLED
);
544 assert(thread
->BG_COUNT
== 0);
546 int val
= hw_atomic_add(&sched_background_count
, 1);
549 /* Always do the background change while holding a share count */
550 assert(thread
->SHARE_COUNT
== 1);
553 void sched_background_decr(thread_t thread
) {
554 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
&& thread
->sched_mode
== TH_MODE_TIMESHARE
)
555 assert((thread
->sched_flags
& TH_SFLAG_THROTTLED
) != TH_SFLAG_THROTTLED
);
556 assert(thread
->BG_COUNT
== 1);
557 int val
= hw_atomic_sub(&sched_background_count
, 1);
560 assert(thread
->BG_COUNT
== 0);
562 /* Always do the background change while holding a share count */
563 assert(thread
->SHARE_COUNT
== 1);
568 assert_thread_sched_count(thread_t thread
) {
569 /* Only 0 or 1 are acceptable values */
570 assert(thread
->BG_COUNT
== 0 || thread
->BG_COUNT
== 1);
571 assert(thread
->SHARE_COUNT
== 0 || thread
->SHARE_COUNT
== 1);
573 /* BG is only allowed when you already have a share count */
574 if (thread
->BG_COUNT
== 1)
575 assert(thread
->SHARE_COUNT
== 1);
576 if (thread
->SHARE_COUNT
== 0)
577 assert(thread
->BG_COUNT
== 0);
579 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) != TH_RUN
||
580 (thread
->sched_mode
!= TH_MODE_TIMESHARE
))
581 assert(thread
->SHARE_COUNT
== 0);
583 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
&&
584 (thread
->sched_mode
== TH_MODE_TIMESHARE
))
585 assert(thread
->SHARE_COUNT
== 1);
587 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) != TH_RUN
||
588 (thread
->sched_mode
!= TH_MODE_TIMESHARE
) ||
589 !(thread
->sched_flags
& TH_SFLAG_THROTTLED
))
590 assert(thread
->BG_COUNT
== 0);
592 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
&&
593 (thread
->sched_mode
== TH_MODE_TIMESHARE
) &&
594 (thread
->sched_flags
& TH_SFLAG_THROTTLED
))
595 assert(thread
->BG_COUNT
== 1);
598 #endif /* MACH_ASSERT */
601 * Set the thread's true scheduling mode
602 * Called with thread mutex and thread locked
603 * The thread has already been removed from the runqueue.
605 * (saved_mode is handled before this point)
608 sched_set_thread_mode(thread_t thread
, sched_mode_t new_mode
)
610 assert_thread_sched_count(thread
);
611 assert(thread
->runq
== PROCESSOR_NULL
);
613 sched_mode_t old_mode
= thread
->sched_mode
;
615 thread
->sched_mode
= new_mode
;
619 case TH_MODE_REALTIME
:
620 if (old_mode
== TH_MODE_TIMESHARE
) {
621 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
) {
622 if (thread
->sched_flags
& TH_SFLAG_THROTTLED
)
623 sched_background_decr(thread
);
625 sched_share_decr(thread
);
630 case TH_MODE_TIMESHARE
:
631 if (old_mode
!= TH_MODE_TIMESHARE
) {
632 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
) {
633 sched_share_incr(thread
);
635 if (thread
->sched_flags
& TH_SFLAG_THROTTLED
)
636 sched_background_incr(thread
);
642 panic("unexpected mode: %d", new_mode
);
646 assert_thread_sched_count(thread
);
650 * Demote the true scheduler mode to timeshare (called with the thread locked)
653 sched_thread_mode_demote(thread_t thread
, uint32_t reason
)
655 assert(reason
& TH_SFLAG_DEMOTED_MASK
);
656 assert((thread
->sched_flags
& reason
) != reason
);
657 assert_thread_sched_count(thread
);
659 if (thread
->policy_reset
)
662 if (thread
->sched_flags
& TH_SFLAG_DEMOTED_MASK
) {
663 /* Another demotion reason is already active */
664 thread
->sched_flags
|= reason
;
668 assert(thread
->saved_mode
== TH_MODE_NONE
);
670 boolean_t removed
= thread_run_queue_remove(thread
);
672 thread
->sched_flags
|= reason
;
674 thread
->saved_mode
= thread
->sched_mode
;
676 sched_set_thread_mode(thread
, TH_MODE_TIMESHARE
);
678 thread_recompute_priority(thread
);
681 thread_run_queue_reinsert(thread
, SCHED_TAILQ
);
683 assert_thread_sched_count(thread
);
687 * Un-demote the true scheduler mode back to the saved mode (called with the thread locked)
690 sched_thread_mode_undemote(thread_t thread
, uint32_t reason
)
692 assert(reason
& TH_SFLAG_DEMOTED_MASK
);
693 assert((thread
->sched_flags
& reason
) == reason
);
694 assert(thread
->saved_mode
!= TH_MODE_NONE
);
695 assert(thread
->sched_mode
== TH_MODE_TIMESHARE
);
696 assert(thread
->policy_reset
== 0);
698 assert_thread_sched_count(thread
);
700 thread
->sched_flags
&= ~reason
;
702 if (thread
->sched_flags
& TH_SFLAG_DEMOTED_MASK
) {
703 /* Another demotion reason is still active */
707 boolean_t removed
= thread_run_queue_remove(thread
);
709 sched_set_thread_mode(thread
, thread
->saved_mode
);
711 thread
->saved_mode
= TH_MODE_NONE
;
713 thread_recompute_priority(thread
);
716 thread_run_queue_reinsert(thread
, SCHED_TAILQ
);
720 * Set the thread to be categorized as 'background'
721 * Called with thread mutex and thread lock held
723 * TODO: Eventually, 'background' should be a true sched_mode.
726 sched_set_thread_throttled(thread_t thread
, boolean_t wants_throttle
)
728 if (thread
->policy_reset
)
731 assert(((thread
->sched_flags
& TH_SFLAG_THROTTLED
) ? TRUE
: FALSE
) != wants_throttle
);
733 assert_thread_sched_count(thread
);
735 if (wants_throttle
) {
736 thread
->sched_flags
|= TH_SFLAG_THROTTLED
;
737 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
&& thread
->sched_mode
== TH_MODE_TIMESHARE
) {
738 sched_background_incr(thread
);
741 thread
->sched_flags
&= ~TH_SFLAG_THROTTLED
;
742 if ((thread
->state
& (TH_RUN
|TH_IDLE
)) == TH_RUN
&& thread
->sched_mode
== TH_MODE_TIMESHARE
) {
743 sched_background_decr(thread
);
747 assert_thread_sched_count(thread
);