]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ast.c
0772a907103c2d138d4e2c446e3989c0109ce493
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>
84 #include <machine/trap.h> // for CHUD AST hook
100 boolean_t preempt_trap
= (reasons
== AST_PREEMPTION
);
101 ast_t
*myast
= ast_pending();
102 thread_t thread
= current_thread();
105 * CHUD hook - all threads including idle processor threads
108 if(*myast
& AST_CHUD_ALL
) {
109 perfASTHook(0, NULL
, 0, 0);
111 if(*myast
== AST_NONE
) {
112 return; // nothing left to do
116 *myast
&= ~AST_CHUD_ALL
;
123 * Handle ASTs for all threads
124 * except idle processor threads.
126 if (!(thread
->state
& TH_IDLE
)) {
128 * Check for urgent preemption.
130 if ( (reasons
& AST_URGENT
) &&
131 wait_queue_assert_possible(thread
) ) {
132 if (reasons
& AST_PREEMPT
) {
133 counter(c_ast_taken_block
++);
134 thread_block_reason(THREAD_CONTINUE_NULL
, NULL
,
135 AST_PREEMPT
| AST_URGENT
);
138 reasons
&= ~AST_PREEMPTION
;
142 * The kernel preempt traps
143 * skip all other ASTs.
146 ml_set_interrupts_enabled(enable
);
152 if (reasons
& AST_BSD
) {
153 thread_ast_clear(thread
, AST_BSD
);
161 if (reasons
& AST_APC
)
162 act_execute_returnhandlers();
164 ml_set_interrupts_enabled(FALSE
);
167 * Check for preemption.
169 if (reasons
& AST_PREEMPT
) {
170 processor_t myprocessor
= current_processor();
172 if (csw_needed(thread
, myprocessor
))
173 reasons
= AST_PREEMPT
;
177 if ( (reasons
& AST_PREEMPT
) &&
178 wait_queue_assert_possible(thread
) ) {
179 counter(c_ast_taken_block
++);
180 thread_block_reason((thread_continue_t
)thread_exception_return
, NULL
, AST_PREEMPT
);
185 ml_set_interrupts_enabled(enable
);
189 * Called at splsched.
193 processor_t processor
)
195 register thread_t thread
= processor
->active_thread
;
197 processor
->current_pri
= thread
->sched_pri
;
198 if ( processor
->state
== PROCESSOR_RUNNING
||
199 processor
->state
== PROCESSOR_SHUTDOWN
) {
200 register ast_t preempt
;
203 * Propagate thread ast to processor.
205 ast_propagate(thread
->ast
);
208 * Context switch check.
210 if ((preempt
= csw_check(thread
, processor
)) != AST_NONE
)