]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
b0d623f7 | 2 | * Copyright (c) 2000-2009 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
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. | |
41 | * | |
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. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | ||
59 | /* | |
60 | * | |
61 | * This file contains routines to check whether an ast is needed. | |
62 | * | |
63 | * ast_check() - check whether ast is needed for interrupt or context | |
64 | * switch. Usually called by clock interrupt handler. | |
65 | * | |
66 | */ | |
67 | ||
68 | #include <cputypes.h> | |
1c79356b | 69 | #include <platforms.h> |
1c79356b A |
70 | |
71 | #include <kern/ast.h> | |
72 | #include <kern/counters.h> | |
73 | #include <kern/cpu_number.h> | |
74 | #include <kern/misc_protos.h> | |
75 | #include <kern/queue.h> | |
1c79356b A |
76 | #include <kern/sched_prim.h> |
77 | #include <kern/thread.h> | |
1c79356b A |
78 | #include <kern/processor.h> |
79 | #include <kern/spl.h> | |
91447636 | 80 | #include <kern/wait_queue.h> |
1c79356b | 81 | #include <mach/policy.h> |
0c530ab8 | 82 | #include <machine/trap.h> // for CHUD AST hook |
6d2010ae A |
83 | #include <machine/pal_routines.h> |
84 | ||
85 | ||
86 | volatile perfASTCallback perfASTHook; | |
1c79356b | 87 | |
b0d623f7 | 88 | |
1c79356b A |
89 | void |
90 | ast_init(void) | |
91 | { | |
1c79356b A |
92 | } |
93 | ||
55e303ae A |
94 | /* |
95 | * Called at splsched. | |
96 | */ | |
1c79356b A |
97 | void |
98 | ast_taken( | |
91447636 A |
99 | ast_t reasons, |
100 | boolean_t enable | |
1c79356b A |
101 | ) |
102 | { | |
91447636 A |
103 | boolean_t preempt_trap = (reasons == AST_PREEMPTION); |
104 | ast_t *myast = ast_pending(); | |
105 | thread_t thread = current_thread(); | |
6d2010ae | 106 | perfASTCallback perf_hook = perfASTHook; |
91447636 | 107 | |
91447636 A |
108 | /* |
109 | * CHUD hook - all threads including idle processor threads | |
110 | */ | |
b0d623f7 A |
111 | if (perf_hook) { |
112 | if (*myast & AST_CHUD_ALL) { | |
6d2010ae | 113 | (*perf_hook)(reasons, myast); |
91447636 | 114 | |
b0d623f7 A |
115 | if (*myast == AST_NONE) |
116 | return; | |
91447636 | 117 | } |
91447636 | 118 | } |
b0d623f7 A |
119 | else |
120 | *myast &= ~AST_CHUD_ALL; | |
1c79356b | 121 | |
91447636 A |
122 | reasons &= *myast; |
123 | *myast &= ~reasons; | |
1c79356b A |
124 | |
125 | /* | |
55e303ae A |
126 | * Handle ASTs for all threads |
127 | * except idle processor threads. | |
1c79356b | 128 | */ |
91447636 | 129 | if (!(thread->state & TH_IDLE)) { |
55e303ae A |
130 | /* |
131 | * Check for urgent preemption. | |
132 | */ | |
133 | if ( (reasons & AST_URGENT) && | |
91447636 | 134 | wait_queue_assert_possible(thread) ) { |
55e303ae A |
135 | if (reasons & AST_PREEMPT) { |
136 | counter(c_ast_taken_block++); | |
91447636 | 137 | thread_block_reason(THREAD_CONTINUE_NULL, NULL, |
55e303ae A |
138 | AST_PREEMPT | AST_URGENT); |
139 | } | |
140 | ||
141 | reasons &= ~AST_PREEMPTION; | |
1c79356b | 142 | } |
0b4e3aa0 | 143 | |
55e303ae A |
144 | /* |
145 | * The kernel preempt traps | |
146 | * skip all other ASTs. | |
147 | */ | |
148 | if (!preempt_trap) { | |
149 | ml_set_interrupts_enabled(enable); | |
0b4e3aa0 | 150 | |
1c79356b | 151 | #ifdef MACH_BSD |
55e303ae A |
152 | /* |
153 | * Handle BSD hook. | |
154 | */ | |
155 | if (reasons & AST_BSD) { | |
91447636 A |
156 | thread_ast_clear(thread, AST_BSD); |
157 | bsd_ast(thread); | |
55e303ae | 158 | } |
1c79356b A |
159 | #endif |
160 | ||
55e303ae A |
161 | /* |
162 | * Thread APC hook. | |
163 | */ | |
164 | if (reasons & AST_APC) | |
165 | act_execute_returnhandlers(); | |
166 | ||
167 | ml_set_interrupts_enabled(FALSE); | |
168 | ||
169 | /* | |
170 | * Check for preemption. | |
171 | */ | |
c910b4d9 A |
172 | if (reasons & AST_PREEMPT) |
173 | reasons = csw_check(current_processor()); | |
55e303ae | 174 | |
55e303ae | 175 | if ( (reasons & AST_PREEMPT) && |
91447636 | 176 | wait_queue_assert_possible(thread) ) { |
55e303ae | 177 | counter(c_ast_taken_block++); |
91447636 | 178 | thread_block_reason((thread_continue_t)thread_exception_return, NULL, AST_PREEMPT); |
55e303ae A |
179 | } |
180 | } | |
1c79356b | 181 | } |
0b4e3aa0 | 182 | |
55e303ae | 183 | ml_set_interrupts_enabled(enable); |
1c79356b A |
184 | } |
185 | ||
9bccf70c A |
186 | /* |
187 | * Called at splsched. | |
188 | */ | |
1c79356b | 189 | void |
9bccf70c A |
190 | ast_check( |
191 | processor_t processor) | |
1c79356b | 192 | { |
cf7d32b8 A |
193 | thread_t thread = processor->active_thread; |
194 | ||
195 | processor->current_pri = thread->sched_pri; | |
6d2010ae | 196 | processor->current_thmode = thread->sched_mode; |
91447636 A |
197 | if ( processor->state == PROCESSOR_RUNNING || |
198 | processor->state == PROCESSOR_SHUTDOWN ) { | |
cf7d32b8 | 199 | ast_t preempt; |
1c79356b | 200 | |
1c79356b | 201 | /* |
0b4e3aa0 | 202 | * Propagate thread ast to processor. |
1c79356b | 203 | */ |
6d2010ae A |
204 | pal_ast_check(thread); |
205 | ||
91447636 | 206 | ast_propagate(thread->ast); |
1c79356b A |
207 | |
208 | /* | |
209 | * Context switch check. | |
210 | */ | |
c910b4d9 | 211 | if ((preempt = csw_check(processor)) != AST_NONE) |
9bccf70c | 212 | ast_on(preempt); |
1c79356b | 213 | } |
1c79356b | 214 | } |