]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ast.h
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 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.
57 * kern/ast.h: Definitions for Asynchronous System Traps.
64 #include <platforms.h>
66 #include <kern/assert.h>
67 #include <kern/cpu_number.h>
68 #include <kern/macro_help.h>
69 #include <kern/lock.h>
71 #include <machine/ast.h>
74 * A processor takes an AST when it is about to return from an
75 * interrupt context, and calls ast_taken.
77 * Machine-dependent code is responsible for maintaining
78 * a set of reasons for an AST, and passing this set to ast_taken.
80 typedef uint32_t ast_t
;
85 #define AST_BLOCK 0x01
86 #define AST_QUANTUM 0x02
87 #define AST_HANDOFF 0x04
88 #define AST_YIELD 0x08
89 #define AST_URGENT 0x10
90 #define AST_APC 0x20 /* migration APC hook */
92 * JMM - This is here temporarily. AST_BSD is used to simulate a
93 * general purpose mechanism for setting asynchronous procedure calls
99 #define AST_ALL (~AST_NONE)
101 #define AST_SCHEDULING (AST_PREEMPT | AST_YIELD | AST_HANDOFF)
102 #define AST_PREEMPT (AST_BLOCK | AST_QUANTUM | AST_URGENT)
104 extern volatile ast_t need_ast
[NCPUS
];
108 * machine/ast.h is responsible for defining aston and astoff.
110 #else /* MACHINE_AST */
113 #define astoff(mycpu)
115 #endif /* MACHINE_AST */
117 /* Initialize module */
118 extern void ast_init(void);
121 extern void ast_taken(
125 /* Check for pending ASTs */
126 extern void ast_check(
127 processor_t processor
);
130 * Per-thread ASTs are reset at context-switch time.
132 #ifndef MACHINE_AST_PER_THREAD
133 #define MACHINE_AST_PER_THREAD 0
136 #define AST_PER_THREAD (AST_APC | AST_BSD | MACHINE_AST_PER_THREAD)
138 * ast_needed(), ast_on(), ast_off(), ast_context(), and ast_propagate()
141 #define ast_needed(mycpu) (need_ast[mycpu] != AST_NONE)
143 #define ast_on_fast(reasons) \
145 int mycpu = cpu_number(); \
146 if ((need_ast[mycpu] |= (reasons)) != AST_NONE) \
150 #define ast_off_fast(reasons) \
152 int mycpu = cpu_number(); \
153 if ((need_ast[mycpu] &= ~(reasons)) == AST_NONE) \
157 #define ast_propagate(reasons) ast_on(reasons)
159 #define ast_context(act, mycpu) \
161 assert((mycpu) == cpu_number()); \
162 if ((need_ast[mycpu] = \
163 ((need_ast[mycpu] &~ AST_PER_THREAD) | (act)->ast)) != AST_NONE) \
169 #define ast_on(reason) ast_on_fast(reason)
170 #define ast_off(reason) ast_off_fast(reason)
172 #define thread_ast_set(act, reason) \
173 (hw_atomic_or(&(act)->ast, (reason)))
174 #define thread_ast_clear(act, reason) \
175 (hw_atomic_and(&(act)->ast, ~(reason)))
176 #define thread_ast_clear_all(act) \
177 (hw_atomic_and(&(act)->ast, AST_NONE))
180 * NOTE: if thread is the current thread, thread_ast_set() should
181 * be followed by ast_propagate().
184 #ifdef MACH_KERNEL_PRIVATE
186 #define ast_urgency() (need_ast[cpu_number()] & AST_URGENT)
188 #endif /* MACH_KERNEL_PRIVATE */
190 #endif /* _KERN_AST_H_ */