]> git.saurik.com Git - apple/xnu.git/blame_incremental - osfmk/kern/ast.c
xnu-792.6.22.tar.gz
[apple/xnu.git] / osfmk / kern / ast.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
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>
63#include <platforms.h>
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>
70#include <kern/sched_prim.h>
71#include <kern/thread.h>
72#include <kern/processor.h>
73#include <kern/spl.h>
74#include <kern/wait_queue.h>
75#include <mach/policy.h>
76
77#ifdef __ppc__
78#include <ppc/trap.h> // for CHUD AST hook
79#endif
80
81void
82ast_init(void)
83{
84}
85
86/*
87 * Called at splsched.
88 */
89void
90ast_taken(
91 ast_t reasons,
92 boolean_t enable
93)
94{
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
115
116 reasons &= *myast;
117 *myast &= ~reasons;
118
119 /*
120 * Handle ASTs for all threads
121 * except idle processor threads.
122 */
123 if (!(thread->state & TH_IDLE)) {
124 /*
125 * Check for urgent preemption.
126 */
127 if ( (reasons & AST_URGENT) &&
128 wait_queue_assert_possible(thread) ) {
129 if (reasons & AST_PREEMPT) {
130 counter(c_ast_taken_block++);
131 thread_block_reason(THREAD_CONTINUE_NULL, NULL,
132 AST_PREEMPT | AST_URGENT);
133 }
134
135 reasons &= ~AST_PREEMPTION;
136 }
137
138 /*
139 * The kernel preempt traps
140 * skip all other ASTs.
141 */
142 if (!preempt_trap) {
143 ml_set_interrupts_enabled(enable);
144
145#ifdef MACH_BSD
146 /*
147 * Handle BSD hook.
148 */
149 if (reasons & AST_BSD) {
150 thread_ast_clear(thread, AST_BSD);
151 bsd_ast(thread);
152 }
153#endif
154
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
169 if (csw_needed(thread, myprocessor))
170 reasons = AST_PREEMPT;
171 else
172 reasons = AST_NONE;
173 }
174 if ( (reasons & AST_PREEMPT) &&
175 wait_queue_assert_possible(thread) ) {
176 counter(c_ast_taken_block++);
177 thread_block_reason((thread_continue_t)thread_exception_return, NULL, AST_PREEMPT);
178 }
179 }
180 }
181
182 ml_set_interrupts_enabled(enable);
183}
184
185/*
186 * Called at splsched.
187 */
188void
189ast_check(
190 processor_t processor)
191{
192 register thread_t thread = processor->active_thread;
193
194 processor->current_pri = thread->sched_pri;
195 if ( processor->state == PROCESSOR_RUNNING ||
196 processor->state == PROCESSOR_SHUTDOWN ) {
197 register ast_t preempt;
198
199 /*
200 * Propagate thread ast to processor.
201 */
202 ast_propagate(thread->ast);
203
204 /*
205 * Context switch check.
206 */
207 if ((preempt = csw_check(thread, processor)) != AST_NONE)
208 ast_on(preempt);
209 }
210}