]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ast.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
58 * This file contains routines to check whether an ast is needed.
60 * ast_check() - check whether ast is needed for interrupt or context
61 * switch. Usually called by clock interrupt handler.
67 #include <platforms.h>
70 #include <kern/counters.h>
71 #include <kern/cpu_number.h>
72 #include <kern/misc_protos.h>
73 #include <kern/queue.h>
74 #include <kern/sched_prim.h>
75 #include <kern/thread.h>
76 #include <kern/thread_act.h>
77 #include <kern/thread_swap.h>
78 #include <kern/processor.h>
80 #include <mach/policy.h>
82 volatile ast_t need_ast
[NCPUS
];
90 for (i
=0; i
<NCPUS
; i
++) {
91 need_ast
[i
] = AST_NONE
;
93 #endif /* MACHINE_AST */
103 register processor_t myprocessor
;
104 register thread_t self
= current_thread();
105 boolean_t preempt_trap
= (reasons
== AST_PREEMPT
);
107 disable_preemption();
108 mycpu
= cpu_number();
109 reasons
&= need_ast
[mycpu
];
110 need_ast
[mycpu
] &= ~reasons
;
114 * No ast for an idle thread
116 if (self
->state
& TH_IDLE
)
117 goto enable_and_return
;
120 * Check for urgent preemption
122 if ((reasons
& AST_URGENT
) && wait_queue_assert_possible(self
)) {
123 if (reasons
& AST_BLOCK
) {
124 counter(c_ast_taken_block
++);
125 thread_block_reason((void (*)(void))0, AST_BLOCK
);
128 reasons
&= ~AST_PREEMPT
;
130 goto enable_and_return
;
134 goto enable_and_return
;
136 ml_set_interrupts_enabled(enable
);
142 if (reasons
& AST_BSD
) {
143 extern void bsd_ast(thread_act_t act
);
144 thread_act_t act
= self
->top_act
;
146 thread_ast_clear(act
, AST_BSD
);
154 if (reasons
& AST_APC
) {
155 act_execute_returnhandlers();
159 * Check for normal preemption
161 reasons
&= AST_BLOCK
;
163 disable_preemption();
164 myprocessor
= current_processor();
165 if (csw_needed(self
, myprocessor
))
169 if ( (reasons
& AST_BLOCK
) &&
170 wait_queue_assert_possible(self
) ) {
171 counter(c_ast_taken_block
++);
172 thread_block_reason(thread_exception_return
, AST_BLOCK
);
178 ml_set_interrupts_enabled(enable
);
185 * Called at splsched.
189 processor_t processor
)
191 register thread_t self
= processor
->cpu_data
->active_thread
;
193 processor
->current_pri
= self
->sched_pri
;
194 if (processor
->state
== PROCESSOR_RUNNING
) {
195 register ast_t preempt
;
199 * Propagate thread ast to processor.
201 ast_propagate(self
->top_act
->ast
);
204 * Context switch check.
206 if ((preempt
= csw_check(self
, processor
)) != AST_NONE
)
210 if ( processor
->state
== PROCESSOR_DISPATCHING
||
211 processor
->state
== PROCESSOR_IDLE
) {
215 if (processor
->state
== PROCESSOR_SHUTDOWN
)
216 goto processor_running
;
218 if (processor
->state
== PROCESSOR_ASSIGN
)