]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
54 * Author: Avadis Tevanian, Jr.
62 #include <mach/boolean.h>
63 #include <mach/kern_return.h>
64 #include <mach/machine.h>
65 #include <kern/host.h>
66 #include <kern/mach_param.h>
67 #include <kern/sched.h>
69 #include <kern/thread.h>
70 #include <kern/processor.h>
71 #include <machine/machparam.h>
74 * thread_quantum_expire:
76 * Recalculate the quantum and priority for a thread.
80 thread_quantum_expire(
81 timer_call_param_t p0
,
82 timer_call_param_t p1
)
84 register processor_t myprocessor
= p0
;
85 register thread_t thread
= p1
;
92 * Check for fail-safe trip.
94 if (!(thread
->sched_mode
& TH_MODE_TIMESHARE
)) {
95 extern uint64_t max_unsafe_computation
;
96 uint64_t new_computation
;
98 new_computation
= myprocessor
->quantum_end
;
99 new_computation
-= thread
->computation_epoch
;
100 if (new_computation
+ thread
->computation_metered
>
101 max_unsafe_computation
) {
102 extern uint32_t sched_safe_duration
;
104 if (thread
->sched_mode
& TH_MODE_REALTIME
) {
105 thread
->priority
= DEPRESSPRI
;
107 thread
->safe_mode
|= TH_MODE_REALTIME
;
108 thread
->sched_mode
&= ~TH_MODE_REALTIME
;
111 thread
->safe_release
= sched_tick
+ sched_safe_duration
;
112 thread
->sched_mode
|= (TH_MODE_FAILSAFE
|TH_MODE_TIMESHARE
);
113 thread
->sched_mode
&= ~TH_MODE_PREEMPT
;
118 * Recompute scheduled priority if appropriate.
120 if (thread
->sched_stamp
!= sched_tick
)
121 update_priority(thread
);
123 if (thread
->sched_mode
& TH_MODE_TIMESHARE
) {
124 thread_timer_delta(thread
);
125 thread
->sched_usage
+= thread
->sched_delta
;
126 thread
->sched_delta
= 0;
129 * Adjust the scheduled priority if
130 * the thread has not been promoted
131 * and is not depressed.
133 if ( !(thread
->sched_mode
& TH_MODE_PROMOTED
) &&
134 !(thread
->sched_mode
& TH_MODE_ISDEPRESSED
) )
135 compute_my_priority(thread
);
139 * This quantum is up, give this thread another.
141 if (first_quantum(myprocessor
))
142 myprocessor
->slice_quanta
--;
144 thread
->current_quantum
= (thread
->sched_mode
& TH_MODE_REALTIME
)?
145 thread
->realtime
.computation
: std_quantum
;
146 myprocessor
->quantum_end
+= thread
->current_quantum
;
147 timer_call_enter1(&myprocessor
->quantum_timer
,
148 thread
, myprocessor
->quantum_end
);
150 thread_unlock(thread
);
153 * Check for and schedule ast if needed.
155 ast_check(myprocessor
);