]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 A |
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. | |
1c79356b | 11 | * |
e5568f75 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
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. | |
35 | * | |
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. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | /* | |
53 | * File: clock_prim.c | |
54 | * Author: Avadis Tevanian, Jr. | |
55 | * Date: 1986 | |
56 | * | |
57 | * Clock primitives. | |
58 | */ | |
59 | ||
60 | #include <cpus.h> | |
61 | ||
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> | |
68 | #include <kern/spl.h> | |
69 | #include <kern/thread.h> | |
70 | #include <kern/processor.h> | |
71 | #include <machine/machparam.h> | |
1c79356b A |
72 | |
73 | /* | |
0b4e3aa0 | 74 | * thread_quantum_expire: |
1c79356b A |
75 | * |
76 | * Recalculate the quantum and priority for a thread. | |
1c79356b A |
77 | */ |
78 | ||
79 | void | |
0b4e3aa0 A |
80 | thread_quantum_expire( |
81 | timer_call_param_t p0, | |
82 | timer_call_param_t p1) | |
1c79356b | 83 | { |
0b4e3aa0 A |
84 | register processor_t myprocessor = p0; |
85 | register thread_t thread = p1; | |
1c79356b A |
86 | spl_t s; |
87 | ||
0b4e3aa0 A |
88 | s = splsched(); |
89 | thread_lock(thread); | |
1c79356b A |
90 | |
91 | /* | |
9bccf70c | 92 | * Check for fail-safe trip. |
1c79356b | 93 | */ |
0b4e3aa0 A |
94 | if (!(thread->sched_mode & TH_MODE_TIMESHARE)) { |
95 | extern uint64_t max_unsafe_computation; | |
96 | uint64_t new_computation; | |
97 | ||
98 | new_computation = myprocessor->quantum_end; | |
99 | new_computation -= thread->computation_epoch; | |
9bccf70c | 100 | if (new_computation + thread->computation_metered > |
0b4e3aa0 A |
101 | max_unsafe_computation) { |
102 | extern uint32_t sched_safe_duration; | |
103 | ||
104 | if (thread->sched_mode & TH_MODE_REALTIME) { | |
9bccf70c | 105 | thread->priority = DEPRESSPRI; |
0b4e3aa0 A |
106 | |
107 | thread->safe_mode |= TH_MODE_REALTIME; | |
108 | thread->sched_mode &= ~TH_MODE_REALTIME; | |
109 | } | |
1c79356b | 110 | |
55e303ae A |
111 | pset_share_incr(thread->processor_set); |
112 | ||
0b4e3aa0 A |
113 | thread->safe_release = sched_tick + sched_safe_duration; |
114 | thread->sched_mode |= (TH_MODE_FAILSAFE|TH_MODE_TIMESHARE); | |
9bccf70c | 115 | thread->sched_mode &= ~TH_MODE_PREEMPT; |
0b4e3aa0 A |
116 | } |
117 | } | |
1c79356b A |
118 | |
119 | /* | |
9bccf70c | 120 | * Recompute scheduled priority if appropriate. |
1c79356b | 121 | */ |
0b4e3aa0 A |
122 | if (thread->sched_stamp != sched_tick) |
123 | update_priority(thread); | |
124 | else | |
9bccf70c | 125 | if (thread->sched_mode & TH_MODE_TIMESHARE) { |
0b4e3aa0 A |
126 | thread_timer_delta(thread); |
127 | thread->sched_usage += thread->sched_delta; | |
128 | thread->sched_delta = 0; | |
9bccf70c A |
129 | |
130 | /* | |
131 | * Adjust the scheduled priority if | |
132 | * the thread has not been promoted | |
133 | * and is not depressed. | |
134 | */ | |
135 | if ( !(thread->sched_mode & TH_MODE_PROMOTED) && | |
136 | !(thread->sched_mode & TH_MODE_ISDEPRESSED) ) | |
137 | compute_my_priority(thread); | |
0b4e3aa0 | 138 | } |
1c79356b | 139 | |
0b4e3aa0 A |
140 | /* |
141 | * This quantum is up, give this thread another. | |
142 | */ | |
55e303ae A |
143 | if (first_timeslice(myprocessor)) |
144 | myprocessor->timeslice--; | |
1c79356b | 145 | |
55e303ae | 146 | thread_quantum_init(thread); |
0b4e3aa0 A |
147 | myprocessor->quantum_end += thread->current_quantum; |
148 | timer_call_enter1(&myprocessor->quantum_timer, | |
149 | thread, myprocessor->quantum_end); | |
1c79356b | 150 | |
0b4e3aa0 | 151 | thread_unlock(thread); |
1c79356b | 152 | |
0b4e3aa0 A |
153 | /* |
154 | * Check for and schedule ast if needed. | |
155 | */ | |
9bccf70c A |
156 | ast_check(myprocessor); |
157 | ||
158 | splx(s); | |
1c79356b | 159 | } |