]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/ast.h
xnu-3248.50.21.tar.gz
[apple/xnu.git] / osfmk / kern / ast.h
CommitLineData
1c79356b 1/*
39236c6e 2 * Copyright (c) 2000-2012 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31/*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56/*
57 */
58
59/*
60 * kern/ast.h: Definitions for Asynchronous System Traps.
61 */
62
63#ifndef _KERN_AST_H_
64#define _KERN_AST_H_
65
1c79356b
A
66
67#include <kern/assert.h>
1c79356b 68#include <kern/macro_help.h>
1c79356b 69#include <kern/spl.h>
1c79356b
A
70
71/*
9bccf70c
A
72 * A processor takes an AST when it is about to return from an
73 * interrupt context, and calls ast_taken.
74 *
75 * Machine-dependent code is responsible for maintaining
76 * a set of reasons for an AST, and passing this set to ast_taken.
1c79356b 77 */
9bccf70c 78typedef uint32_t ast_t;
1c79356b 79
fe8ab488
A
80/*
81 * When returning from interrupt/trap context to kernel mode,
82 * the pending ASTs are masked with AST_URGENT to determine if
83 * ast_taken(AST_PREEMPTION) should be called, for instance to
84 * effect preemption of a kernel thread by a realtime thread.
85 * This is also done when re-enabling preemption or re-enabling
86 * interrupts, since an AST may have been set while preemption
87 * was disabled, and it should take effect as soon as possible.
88 *
89 * When returning from interrupt/trap/syscall context to user
90 * mode, any and all ASTs that are pending should be handled.
91 *
92 * If a thread context switches, only ASTs not in AST_PER_THREAD
93 * remain active. The per-thread ASTs are stored in the thread_t
94 * and re-enabled when the thread context switches back.
95 *
96 * Typically the preemption ASTs are set as a result of threads
97 * becoming runnable, threads changing priority, or quantum
98 * expiration. If a thread becomes runnable and is chosen
99 * to run on another processor, cause_ast_check() may be called
100 * to IPI that processor and request csw_check() be run there.
101 */
102
1c79356b
A
103/*
104 * Bits for reasons
105 */
55e303ae
A
106#define AST_PREEMPT 0x01
107#define AST_QUANTUM 0x02
108#define AST_URGENT 0x04
109#define AST_HANDOFF 0x08
110#define AST_YIELD 0x10
0b4e3aa0 111#define AST_APC 0x20 /* migration APC hook */
316670eb 112#define AST_LEDGER 0x40
55e303ae 113#define AST_BSD 0x80
316670eb
A
114#define AST_KPERF 0x100 /* kernel profiling */
115#define AST_MACF 0x200 /* MACF user ret pending */
39236c6e
A
116#define AST_CHUD 0x400
117#define AST_CHUD_URGENT 0x800
118#define AST_GUARD 0x1000
fe8ab488
A
119#define AST_TELEMETRY_USER 0x2000 /* telemetry sample requested on interrupt from userspace */
120#define AST_TELEMETRY_KERNEL 0x4000 /* telemetry sample requested on interrupt from kernel */
121#define AST_TELEMETRY_WINDOWED 0x8000 /* telemetry sample meant for the window buffer */
fe8ab488 122#define AST_SFI 0x10000 /* Evaluate if SFI wait is needed before return to userspace */
1c79356b 123
0b4e3aa0 124#define AST_NONE 0x00
55e303ae 125#define AST_ALL (~AST_NONE)
1c79356b 126
55e303ae
A
127#define AST_SCHEDULING (AST_PREEMPTION | AST_YIELD | AST_HANDOFF)
128#define AST_PREEMPTION (AST_PREEMPT | AST_QUANTUM | AST_URGENT)
1c79356b 129
39236c6e 130#define AST_CHUD_ALL (AST_CHUD_URGENT|AST_CHUD)
fe8ab488 131#define AST_TELEMETRY_ALL (AST_TELEMETRY_USER | AST_TELEMETRY_KERNEL | AST_TELEMETRY_WINDOWED)
39236c6e 132
3e170ce0
A
133/* Per-thread ASTs follow the thread at context-switch time. */
134#define AST_PER_THREAD (AST_APC | AST_BSD | AST_MACF | AST_LEDGER | AST_GUARD | AST_TELEMETRY_USER | AST_TELEMETRY_KERNEL | AST_TELEMETRY_WINDOWED)
1c79356b
A
135
136/* Initialize module */
0b4e3aa0 137extern void ast_init(void);
1c79356b
A
138
139/* Handle ASTs */
0b4e3aa0
A
140extern void ast_taken(
141 ast_t mask,
142 boolean_t enable);
1c79356b
A
143
144/* Check for pending ASTs */
3e170ce0 145extern void ast_check(processor_t processor);
1c79356b 146
91447636 147/* Pending ast mask for the current processor */
3e170ce0 148extern ast_t *ast_pending(void);
91447636 149
3e170ce0
A
150/* Set AST flags on current processor */
151extern void ast_on(ast_t reasons);
1c79356b 152
3e170ce0
A
153/* Clear AST flags on current processor */
154extern void ast_off(ast_t reasons);
1c79356b 155
3e170ce0
A
156/* Re-set current processor's per-thread AST flags to those set on thread */
157extern void ast_context(thread_t thread);
158
159#define ast_propagate(reasons) ast_on(reasons)
1c79356b 160
91447636 161/*
3e170ce0
A
162 * Set an AST on a thread with thread_ast_set.
163 *
164 * You can then propagate it to the current processor with ast_propagate(),
165 * or tell another processor to act on it with cause_ast_check().
166 *
167 * See act_set_ast() for an example.
91447636 168 */
3e170ce0
A
169#define thread_ast_set(act, reason) (hw_atomic_or_noret(&(act)->ast, (reason)))
170#define thread_ast_clear(act, reason) (hw_atomic_and_noret(&(act)->ast, ~(reason)))
1c79356b 171
91447636
A
172#ifdef MACH_BSD
173
91447636
A
174extern void act_set_astbsd(thread_t);
175extern void bsd_ast(thread_t);
176
177#endif /* MACH_BSD */
1c79356b 178
1c79356b 179#endif /* _KERN_AST_H_ */