]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ast.c
a0181460feeb00a5f06e1211f70b87d4612f2556
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
56 * This file contains routines to check whether an ast is needed.
58 * ast_check() - check whether ast is needed for interrupt or context
59 * switch. Usually called by clock interrupt handler.
64 #include <platforms.h>
67 #include <kern/counters.h>
68 #include <kern/cpu_number.h>
69 #include <kern/misc_protos.h>
70 #include <kern/queue.h>
71 #include <kern/sched_prim.h>
72 #include <kern/thread.h>
73 #include <kern/processor.h>
75 #include <kern/wait_queue.h>
76 #include <mach/policy.h>
79 #include <ppc/trap.h> // for CHUD AST hook
96 boolean_t preempt_trap
= (reasons
== AST_PREEMPTION
);
97 ast_t
*myast
= ast_pending();
98 thread_t thread
= current_thread();
102 * CHUD hook - all threads including idle processor threads
105 if(*myast
& AST_PPC_CHUD_ALL
) {
106 perfASTHook(0, NULL
, 0, 0);
108 if(*myast
== AST_NONE
) {
109 return; // nothing left to do
113 *myast
&= ~AST_PPC_CHUD_ALL
;
121 * Handle ASTs for all threads
122 * except idle processor threads.
124 if (!(thread
->state
& TH_IDLE
)) {
126 * Check for urgent preemption.
128 if ( (reasons
& AST_URGENT
) &&
129 wait_queue_assert_possible(thread
) ) {
130 if (reasons
& AST_PREEMPT
) {
131 counter(c_ast_taken_block
++);
132 thread_block_reason(THREAD_CONTINUE_NULL
, NULL
,
133 AST_PREEMPT
| AST_URGENT
);
136 reasons
&= ~AST_PREEMPTION
;
140 * The kernel preempt traps
141 * skip all other ASTs.
144 ml_set_interrupts_enabled(enable
);
150 if (reasons
& AST_BSD
) {
151 thread_ast_clear(thread
, AST_BSD
);
159 if (reasons
& AST_APC
)
160 act_execute_returnhandlers();
162 ml_set_interrupts_enabled(FALSE
);
165 * Check for preemption.
167 if (reasons
& AST_PREEMPT
) {
168 processor_t myprocessor
= current_processor();
170 if (csw_needed(thread
, myprocessor
))
171 reasons
= AST_PREEMPT
;
175 if ( (reasons
& AST_PREEMPT
) &&
176 wait_queue_assert_possible(thread
) ) {
177 counter(c_ast_taken_block
++);
178 thread_block_reason((thread_continue_t
)thread_exception_return
, NULL
, AST_PREEMPT
);
183 ml_set_interrupts_enabled(enable
);
187 * Called at splsched.
191 processor_t processor
)
193 register thread_t thread
= processor
->active_thread
;
195 processor
->current_pri
= thread
->sched_pri
;
196 if ( processor
->state
== PROCESSOR_RUNNING
||
197 processor
->state
== PROCESSOR_SHUTDOWN
) {
198 register ast_t preempt
;
201 * Propagate thread ast to processor.
203 ast_propagate(thread
->ast
);
206 * Context switch check.
208 if ((preempt
= csw_check(thread
, processor
)) != AST_NONE
)