]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/priority.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
57 * Author: Avadis Tevanian, Jr.
65 #include <mach/boolean.h>
66 #include <mach/kern_return.h>
67 #include <mach/machine.h>
68 #include <kern/host.h>
69 #include <kern/mach_param.h>
70 #include <kern/sched.h>
72 #include <kern/thread.h>
73 #include <kern/processor.h>
74 #include <machine/machparam.h>
77 * thread_quantum_expire:
79 * Recalculate the quantum and priority for a thread.
83 thread_quantum_expire(
84 timer_call_param_t p0
,
85 timer_call_param_t p1
)
87 register processor_t myprocessor
= p0
;
88 register thread_t thread
= p1
;
95 * Check for fail-safe trip.
97 if (!(thread
->sched_mode
& TH_MODE_TIMESHARE
)) {
98 extern uint64_t max_unsafe_computation
;
99 uint64_t new_computation
;
101 new_computation
= myprocessor
->quantum_end
;
102 new_computation
-= thread
->computation_epoch
;
103 if (new_computation
+ thread
->computation_metered
>
104 max_unsafe_computation
) {
105 extern uint32_t sched_safe_duration
;
107 if (thread
->sched_mode
& TH_MODE_REALTIME
) {
108 thread
->priority
= DEPRESSPRI
;
110 thread
->safe_mode
|= TH_MODE_REALTIME
;
111 thread
->sched_mode
&= ~TH_MODE_REALTIME
;
114 pset_share_incr(thread
->processor_set
);
116 thread
->safe_release
= sched_tick
+ sched_safe_duration
;
117 thread
->sched_mode
|= (TH_MODE_FAILSAFE
|TH_MODE_TIMESHARE
);
118 thread
->sched_mode
&= ~TH_MODE_PREEMPT
;
123 * Recompute scheduled priority if appropriate.
125 if (thread
->sched_stamp
!= sched_tick
)
126 update_priority(thread
);
128 if (thread
->sched_mode
& TH_MODE_TIMESHARE
) {
129 thread_timer_delta(thread
);
130 thread
->sched_usage
+= thread
->sched_delta
;
131 thread
->sched_delta
= 0;
134 * Adjust the scheduled priority if
135 * the thread has not been promoted
136 * and is not depressed.
138 if ( !(thread
->sched_mode
& TH_MODE_PROMOTED
) &&
139 !(thread
->sched_mode
& TH_MODE_ISDEPRESSED
) )
140 compute_my_priority(thread
);
144 * This quantum is up, give this thread another.
146 if (first_timeslice(myprocessor
))
147 myprocessor
->timeslice
--;
149 thread_quantum_init(thread
);
150 myprocessor
->quantum_end
+= thread
->current_quantum
;
151 timer_call_enter1(&myprocessor
->quantum_timer
,
152 thread
, myprocessor
->quantum_end
);
154 thread_unlock(thread
);
157 * Check for and schedule ast if needed.
159 ast_check(myprocessor
);