]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ast.c
1f7d743f19f7e951afcac1585bdc89518f815e75
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
63 * This file contains routines to check whether an ast is needed.
65 * ast_check() - check whether ast is needed for interrupt or context
66 * switch. Usually called by clock interrupt handler.
71 #include <platforms.h>
74 #include <kern/counters.h>
75 #include <kern/cpu_number.h>
76 #include <kern/misc_protos.h>
77 #include <kern/queue.h>
78 #include <kern/sched_prim.h>
79 #include <kern/thread.h>
80 #include <kern/processor.h>
82 #include <kern/wait_queue.h>
83 #include <mach/policy.h>
86 #include <ppc/trap.h> // for CHUD AST hook
103 boolean_t preempt_trap
= (reasons
== AST_PREEMPTION
);
104 ast_t
*myast
= ast_pending();
105 thread_t thread
= current_thread();
109 * CHUD hook - all threads including idle processor threads
112 if(*myast
& AST_PPC_CHUD_ALL
) {
113 perfASTHook(0, NULL
, 0, 0);
115 if(*myast
== AST_NONE
) {
116 return; // nothing left to do
120 *myast
&= ~AST_PPC_CHUD_ALL
;
128 * Handle ASTs for all threads
129 * except idle processor threads.
131 if (!(thread
->state
& TH_IDLE
)) {
133 * Check for urgent preemption.
135 if ( (reasons
& AST_URGENT
) &&
136 wait_queue_assert_possible(thread
) ) {
137 if (reasons
& AST_PREEMPT
) {
138 counter(c_ast_taken_block
++);
139 thread_block_reason(THREAD_CONTINUE_NULL
, NULL
,
140 AST_PREEMPT
| AST_URGENT
);
143 reasons
&= ~AST_PREEMPTION
;
147 * The kernel preempt traps
148 * skip all other ASTs.
151 ml_set_interrupts_enabled(enable
);
157 if (reasons
& AST_BSD
) {
158 thread_ast_clear(thread
, AST_BSD
);
166 if (reasons
& AST_APC
)
167 act_execute_returnhandlers();
169 ml_set_interrupts_enabled(FALSE
);
172 * Check for preemption.
174 if (reasons
& AST_PREEMPT
) {
175 processor_t myprocessor
= current_processor();
177 if (csw_needed(thread
, myprocessor
))
178 reasons
= AST_PREEMPT
;
182 if ( (reasons
& AST_PREEMPT
) &&
183 wait_queue_assert_possible(thread
) ) {
184 counter(c_ast_taken_block
++);
185 thread_block_reason((thread_continue_t
)thread_exception_return
, NULL
, AST_PREEMPT
);
190 ml_set_interrupts_enabled(enable
);
194 * Called at splsched.
198 processor_t processor
)
200 register thread_t thread
= processor
->active_thread
;
202 processor
->current_pri
= thread
->sched_pri
;
203 if ( processor
->state
== PROCESSOR_RUNNING
||
204 processor
->state
== PROCESSOR_SHUTDOWN
) {
205 register ast_t preempt
;
208 * Propagate thread ast to processor.
210 ast_propagate(thread
->ast
);
213 * Context switch check.
215 if ((preempt
= csw_check(thread
, processor
)) != AST_NONE
)