31caeb97a7881302498266457ec8731b105562e1
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
;
86 register processor_set_t pset
;
89 pset
= myprocessor
->processor_set
;
92 * Update set_quanta for timesharing.
94 pset
->set_quanta
= pset
->machine_quanta
[
95 (pset
->runq
.count
> pset
->processor_count
) ?
96 pset
->processor_count
: pset
->runq
.count
];
102 * Check for failsafe trip.
104 if (!(thread
->sched_mode
& TH_MODE_TIMESHARE
)) {
105 extern uint64_t max_unsafe_computation
;
106 uint64_t new_computation
;
108 new_computation
= myprocessor
->quantum_end
;
109 new_computation
-= thread
->computation_epoch
;
110 if (new_computation
+ thread
->metered_computation
>
111 max_unsafe_computation
) {
112 extern uint32_t sched_safe_duration
;
114 if (thread
->sched_mode
& TH_MODE_REALTIME
) {
115 if (thread
->depress_priority
< 0)
116 thread
->priority
= MINPRI
;
118 thread
->depress_priority
= MINPRI
;
120 thread
->safe_mode
|= TH_MODE_REALTIME
;
121 thread
->sched_mode
&= ~TH_MODE_REALTIME
;
124 thread
->safe_release
= sched_tick
+ sched_safe_duration
;
125 thread
->sched_mode
|= (TH_MODE_FAILSAFE
|TH_MODE_TIMESHARE
);
130 * Now recompute the priority of the thread if appropriate.
132 if (thread
->sched_stamp
!= sched_tick
)
133 update_priority(thread
);
135 if ( (thread
->sched_mode
& TH_MODE_TIMESHARE
) &&
136 thread
->depress_priority
< 0 ) {
137 thread_timer_delta(thread
);
138 thread
->sched_usage
+= thread
->sched_delta
;
139 thread
->sched_delta
= 0;
140 compute_my_priority(thread
);
144 * This quantum is up, give this thread another.
146 if (first_quantum(myprocessor
))
147 myprocessor
->slice_quanta
--;
149 thread
->current_quantum
= (thread
->sched_mode
& TH_MODE_REALTIME
)?
150 thread
->realtime
.computation
: std_quantum
;
151 myprocessor
->quantum_end
+= thread
->current_quantum
;
152 timer_call_enter1(&myprocessor
->quantum_timer
,
153 thread
, myprocessor
->quantum_end
);
155 thread_unlock(thread
);
159 * Check for and schedule ast if needed.