]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b A |
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 | /* | |
54 | * | |
55 | * This file contains routines to check whether an ast is needed. | |
56 | * | |
57 | * ast_check() - check whether ast is needed for interrupt or context | |
58 | * switch. Usually called by clock interrupt handler. | |
59 | * | |
60 | */ | |
61 | ||
62 | #include <cputypes.h> | |
1c79356b | 63 | #include <platforms.h> |
1c79356b A |
64 | |
65 | #include <kern/ast.h> | |
66 | #include <kern/counters.h> | |
67 | #include <kern/cpu_number.h> | |
68 | #include <kern/misc_protos.h> | |
69 | #include <kern/queue.h> | |
1c79356b A |
70 | #include <kern/sched_prim.h> |
71 | #include <kern/thread.h> | |
1c79356b A |
72 | #include <kern/processor.h> |
73 | #include <kern/spl.h> | |
91447636 | 74 | #include <kern/wait_queue.h> |
1c79356b | 75 | #include <mach/policy.h> |
1c79356b | 76 | |
91447636 A |
77 | #ifdef __ppc__ |
78 | #include <ppc/trap.h> // for CHUD AST hook | |
79 | #endif | |
1c79356b A |
80 | |
81 | void | |
82 | ast_init(void) | |
83 | { | |
1c79356b A |
84 | } |
85 | ||
55e303ae A |
86 | /* |
87 | * Called at splsched. | |
88 | */ | |
1c79356b A |
89 | void |
90 | ast_taken( | |
91447636 A |
91 | ast_t reasons, |
92 | boolean_t enable | |
1c79356b A |
93 | ) |
94 | { | |
91447636 A |
95 | boolean_t preempt_trap = (reasons == AST_PREEMPTION); |
96 | ast_t *myast = ast_pending(); | |
97 | thread_t thread = current_thread(); | |
98 | ||
99 | #ifdef __ppc__ | |
100 | /* | |
101 | * CHUD hook - all threads including idle processor threads | |
102 | */ | |
103 | if(perfASTHook) { | |
104 | if(*myast & AST_PPC_CHUD_ALL) { | |
105 | perfASTHook(0, NULL, 0, 0); | |
106 | ||
107 | if(*myast == AST_NONE) { | |
108 | return; // nothing left to do | |
109 | } | |
110 | } | |
111 | } else { | |
112 | *myast &= ~AST_PPC_CHUD_ALL; | |
113 | } | |
114 | #endif | |
1c79356b | 115 | |
91447636 A |
116 | reasons &= *myast; |
117 | *myast &= ~reasons; | |
1c79356b A |
118 | |
119 | /* | |
55e303ae A |
120 | * Handle ASTs for all threads |
121 | * except idle processor threads. | |
1c79356b | 122 | */ |
91447636 | 123 | if (!(thread->state & TH_IDLE)) { |
55e303ae A |
124 | /* |
125 | * Check for urgent preemption. | |
126 | */ | |
127 | if ( (reasons & AST_URGENT) && | |
91447636 | 128 | wait_queue_assert_possible(thread) ) { |
55e303ae A |
129 | if (reasons & AST_PREEMPT) { |
130 | counter(c_ast_taken_block++); | |
91447636 | 131 | thread_block_reason(THREAD_CONTINUE_NULL, NULL, |
55e303ae A |
132 | AST_PREEMPT | AST_URGENT); |
133 | } | |
134 | ||
135 | reasons &= ~AST_PREEMPTION; | |
1c79356b | 136 | } |
0b4e3aa0 | 137 | |
55e303ae A |
138 | /* |
139 | * The kernel preempt traps | |
140 | * skip all other ASTs. | |
141 | */ | |
142 | if (!preempt_trap) { | |
143 | ml_set_interrupts_enabled(enable); | |
0b4e3aa0 | 144 | |
1c79356b | 145 | #ifdef MACH_BSD |
55e303ae A |
146 | /* |
147 | * Handle BSD hook. | |
148 | */ | |
149 | if (reasons & AST_BSD) { | |
91447636 A |
150 | thread_ast_clear(thread, AST_BSD); |
151 | bsd_ast(thread); | |
55e303ae | 152 | } |
1c79356b A |
153 | #endif |
154 | ||
55e303ae A |
155 | /* |
156 | * Thread APC hook. | |
157 | */ | |
158 | if (reasons & AST_APC) | |
159 | act_execute_returnhandlers(); | |
160 | ||
161 | ml_set_interrupts_enabled(FALSE); | |
162 | ||
163 | /* | |
164 | * Check for preemption. | |
165 | */ | |
166 | if (reasons & AST_PREEMPT) { | |
167 | processor_t myprocessor = current_processor(); | |
168 | ||
91447636 | 169 | if (csw_needed(thread, myprocessor)) |
55e303ae A |
170 | reasons = AST_PREEMPT; |
171 | else | |
172 | reasons = AST_NONE; | |
173 | } | |
174 | if ( (reasons & AST_PREEMPT) && | |
91447636 | 175 | wait_queue_assert_possible(thread) ) { |
55e303ae | 176 | counter(c_ast_taken_block++); |
91447636 | 177 | thread_block_reason((thread_continue_t)thread_exception_return, NULL, AST_PREEMPT); |
55e303ae A |
178 | } |
179 | } | |
1c79356b | 180 | } |
0b4e3aa0 | 181 | |
55e303ae | 182 | ml_set_interrupts_enabled(enable); |
1c79356b A |
183 | } |
184 | ||
9bccf70c A |
185 | /* |
186 | * Called at splsched. | |
187 | */ | |
1c79356b | 188 | void |
9bccf70c A |
189 | ast_check( |
190 | processor_t processor) | |
1c79356b | 191 | { |
91447636 | 192 | register thread_t thread = processor->active_thread; |
1c79356b | 193 | |
91447636 A |
194 | processor->current_pri = thread->sched_pri; |
195 | if ( processor->state == PROCESSOR_RUNNING || | |
196 | processor->state == PROCESSOR_SHUTDOWN ) { | |
9bccf70c | 197 | register ast_t preempt; |
1c79356b | 198 | |
1c79356b | 199 | /* |
0b4e3aa0 | 200 | * Propagate thread ast to processor. |
1c79356b | 201 | */ |
91447636 | 202 | ast_propagate(thread->ast); |
1c79356b A |
203 | |
204 | /* | |
205 | * Context switch check. | |
206 | */ | |
91447636 | 207 | if ((preempt = csw_check(thread, processor)) != AST_NONE) |
9bccf70c | 208 | ast_on(preempt); |
1c79356b | 209 | } |
1c79356b | 210 | } |