]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ast.c
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
55 * This file contains routines to check whether an ast is needed.
57 * ast_check() - check whether ast is needed for interrupt or context
58 * switch. Usually called by clock interrupt handler.
63 #include <platforms.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>
74 #include <kern/wait_queue.h>
75 #include <mach/policy.h>
78 #include <ppc/trap.h> // for CHUD AST hook
95 boolean_t preempt_trap
= (reasons
== AST_PREEMPTION
);
96 ast_t
*myast
= ast_pending();
97 thread_t thread
= current_thread();
101 * CHUD hook - all threads including idle processor threads
104 if(*myast
& AST_PPC_CHUD_ALL
) {
105 perfASTHook(0, NULL
, 0, 0);
107 if(*myast
== AST_NONE
) {
108 return; // nothing left to do
112 *myast
&= ~AST_PPC_CHUD_ALL
;
120 * Handle ASTs for all threads
121 * except idle processor threads.
123 if (!(thread
->state
& TH_IDLE
)) {
125 * Check for urgent preemption.
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
);
135 reasons
&= ~AST_PREEMPTION
;
139 * The kernel preempt traps
140 * skip all other ASTs.
143 ml_set_interrupts_enabled(enable
);
149 if (reasons
& AST_BSD
) {
150 thread_ast_clear(thread
, AST_BSD
);
158 if (reasons
& AST_APC
)
159 act_execute_returnhandlers();
161 ml_set_interrupts_enabled(FALSE
);
164 * Check for preemption.
166 if (reasons
& AST_PREEMPT
) {
167 processor_t myprocessor
= current_processor();
169 if (csw_needed(thread
, myprocessor
))
170 reasons
= AST_PREEMPT
;
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
);
182 ml_set_interrupts_enabled(enable
);
186 * Called at splsched.
190 processor_t processor
)
192 register thread_t thread
= processor
->active_thread
;
194 processor
->current_pri
= thread
->sched_pri
;
195 if ( processor
->state
== PROCESSOR_RUNNING
||
196 processor
->state
== PROCESSOR_SHUTDOWN
) {
197 register ast_t preempt
;
200 * Propagate thread ast to processor.
202 ast_propagate(thread
->ast
);
205 * Context switch check.
207 if ((preempt
= csw_check(thread
, processor
)) != AST_NONE
)