]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/exc_resource.h
2 * Copyright (c) 2011-2012 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1989 Carnegie-Mellon University
31 * Copyright (c) 1988 Carnegie-Mellon University
32 * Copyright (c) 1987 Carnegie-Mellon University
33 * All rights reserved. The CMU software License Agreement specifies
34 * the terms and conditions for use and redistribution.
38 * EXC_RESOURCE related macros, namespace etc.
41 #ifndef _EXC_RESOURCE_H_
42 #define _EXC_RESOURCE_H_
45 * Generic exception code format:
48 * +----------------------------------------------------------+
49 * |[63:61] type | [60:58] flavor | [57:0] type-specific data |
50 * +----------------------------------------------------------+
54 /* EXC_RESOURCE type and flavor decoding routines */
55 #define EXC_RESOURCE_DECODE_RESOURCE_TYPE(code) \
56 (((code) >> 61) & 0x7ULL)
57 #define EXC_RESOURCE_DECODE_FLAVOR(code) \
58 (((code) >> 58) & 0x7ULL)
60 /* EXC_RESOURCE Types */
61 #define RESOURCE_TYPE_CPU 1
62 #define RESOURCE_TYPE_WAKEUPS 2
63 #define RESOURCE_TYPE_MEMORY 3
64 #define RESOURCE_TYPE_IO 4
65 #define RESOURCE_TYPE_THREADS 5
67 /* RESOURCE_TYPE_CPU flavors */
68 #define FLAVOR_CPU_MONITOR 1
69 #define FLAVOR_CPU_MONITOR_FATAL 2
72 * RESOURCE_TYPE_CPU exception code & subcode.
74 * This is sent by the kernel when the CPU usage monitor
75 * is tripped. [See proc_set_cpumon_params()]
78 * +-----------------------------------------------+
79 * |[63:61] RESOURCE |[60:58] FLAVOR_CPU_ |[57:32] |
80 * |_TYPE_CPU |MONITOR[_FATAL] |Unused |
81 * +-----------------------------------------------+
82 * |[31:7] Interval (sec) | [6:0] CPU limit (%)|
83 * +-----------------------------------------------+
86 * +-----------------------------------------------+
87 * | | [6:0] % of CPU |
88 * | | actually consumed |
89 * +-----------------------------------------------+
93 /* RESOURCE_TYPE_CPU decoding macros */
94 #define EXC_RESOURCE_CPUMONITOR_DECODE_INTERVAL(code) \
95 (((code) >> 7) & 0x1FFFFFFULL)
96 #define EXC_RESOURCE_CPUMONITOR_DECODE_PERCENTAGE(code) \
98 #define EXC_RESOURCE_CPUMONITOR_DECODE_PERCENTAGE_OBSERVED(subcode) \
102 /* RESOURCE_TYPE_WAKEUPS flavors */
103 #define FLAVOR_WAKEUPS_MONITOR 1
106 * RESOURCE_TYPE_WAKEUPS exception code & subcode.
108 * This is sent by the kernel when the platform idle
109 * wakeups monitor is tripped.
110 * [See proc_set_wakeupsmon_params()]
113 * +-----------------------------------------------+
114 * |[63:61] RESOURCE |[60:58] FLAVOR_ |[57:32] |
115 * |_TYPE_WAKEUPS |WAKEUPS_MONITOR |Unused |
116 * +-----------------------------------------------+
117 * | [31:20] Observation | [19:0] # of wakeups |
118 * | interval (sec) | permitted (per sec) |
119 * +-----------------------------------------------+
122 * +-----------------------------------------------+
123 * | | [19:0] # of wakeups |
124 * | | observed (per sec) |
125 * +-----------------------------------------------+
129 #define EXC_RESOURCE_CPUMONITOR_DECODE_WAKEUPS_PERMITTED(code) \
131 #define EXC_RESOURCE_CPUMONITOR_DECODE_OBSERVATION_INTERVAL(code) \
132 (((code) >> 20) & 0xFFFFFULL)
133 #define EXC_RESOURCE_CPUMONITOR_DECODE_WAKEUPS_OBSERVED(subcode) \
134 ((subcode) & 0xFFFFFULL)
136 /* RESOURCE_TYPE_MEMORY flavors */
137 #define FLAVOR_HIGH_WATERMARK 1
140 * RESOURCE_TYPE_MEMORY / FLAVOR_HIGH_WATERMARK
141 * exception code & subcode.
143 * This is sent by the kernel when a task crosses its high
144 * watermark memory limit.
147 * +------------------------------------------------+
148 * |[63:61] RESOURCE |[60:58] FLAVOR_HIGH_ |[57:32] |
149 * |_TYPE_MEMORY |WATERMARK |Unused |
150 * +------------------------------------------------+
151 * | | [12:0] HWM limit (MB)|
152 * +------------------------------------------------+
155 * +------------------------------------------------+
157 * +------------------------------------------------+
161 #define EXC_RESOURCE_HWM_DECODE_LIMIT(code) \
164 /* RESOURCE_TYPE_IO flavors */
165 #define FLAVOR_IO_PHYSICAL_WRITES 1
166 #define FLAVOR_IO_LOGICAL_WRITES 2
169 * RESOURCE_TYPE_IO exception code & subcode.
171 * This is sent by the kernel when a task crosses its
175 * +-----------------------------------------------+
176 * |[63:61] RESOURCE |[60:58] FLAVOR_IO_ |[57:32] |
177 * |_TYPE_IO |PHYSICAL/LOGICAL |Unused |
178 * +-----------------------------------------------+
179 * |[31:15] Interval (sec) | [14:0] Limit (MB) |
180 * +-----------------------------------------------+
183 * +-----------------------------------------------+
184 * | | [14:0] I/O Count |
186 * +-----------------------------------------------+
190 /* RESOURCE_TYPE_IO decoding macros */
191 #define EXC_RESOURCE_IO_DECODE_INTERVAL(code) \
192 (((code) >> 15) & 0x1FFFFULL)
193 #define EXC_RESOURCE_IO_DECODE_LIMIT(code) \
195 #define EXC_RESOURCE_IO_OBSERVED(subcode) \
196 ((subcode) & 0x7FFFULL)
200 * RESOURCE_TYPE_THREADS exception code & subcode
202 * This is sent by the kernel when a task crosses its
206 #define EXC_RESOURCE_THREADS_DECODE_THREADS(code) \
209 /* RESOURCE_TYPE_THREADS flavors */
210 #define FLAVOR_THREADS_HIGH_WATERMARK 1
214 /* EXC_RESOURCE type and flavor encoding macros */
215 #define EXC_RESOURCE_ENCODE_TYPE(code, type) \
216 ((code) |= (((uint64_t)(type) & 0x7ULL) << 61))
217 #define EXC_RESOURCE_ENCODE_FLAVOR(code, flavor) \
218 ((code) |= (((uint64_t)(flavor) & 0x7ULL) << 58))
220 /* RESOURCE_TYPE_CPU::FLAVOR_CPU_MONITOR specific encoding macros */
221 #define EXC_RESOURCE_CPUMONITOR_ENCODE_INTERVAL(code, interval) \
222 ((code) |= (((uint64_t)(interval) & 0x1FFFFFFULL) << 7))
223 #define EXC_RESOURCE_CPUMONITOR_ENCODE_PERCENTAGE(code, percentage) \
224 ((code) |= (((uint64_t)(percentage) & 0x7FULL)))
226 /* RESOURCE_TYPE_WAKEUPS::FLAVOR_WAKEUPS_MONITOR specific encoding macros */
227 #define EXC_RESOURCE_CPUMONITOR_ENCODE_WAKEUPS_PERMITTED(code, num) \
228 ((code) |= ((uint64_t)(num) & 0xFFFFFULL))
229 #define EXC_RESOURCE_CPUMONITOR_ENCODE_OBSERVATION_INTERVAL(code, num) \
230 ((code) |= (((uint64_t)(num) & 0xFFFULL) << 20))
231 #define EXC_RESOURCE_CPUMONITOR_ENCODE_WAKEUPS_OBSERVED(subcode, num) \
232 ((subcode) |= ((uint64_t)(num) & 0xFFFFFULL))
234 /* RESOURCE_TYPE_MEMORY::FLAVOR_HIGH_WATERMARK specific encoding macros */
235 #define EXC_RESOURCE_HWM_ENCODE_LIMIT(code, num) \
236 ((code) |= ((uint64_t)(num) & 0x1FFFULL))
238 /* RESOURCE_TYPE_IO::FLAVOR_IO_PHYSICAL_WRITES/FLAVOR_IO_LOGICAL_WRITES specific encoding macros */
239 #define EXC_RESOURCE_IO_ENCODE_INTERVAL(code, interval) \
240 ((code) |= (((uint64_t)(interval) & 0x1FFFFULL) << 15))
241 #define EXC_RESOURCE_IO_ENCODE_LIMIT(code, limit) \
242 ((code) |= (((uint64_t)(limit) & 0x7FFFULL)))
243 #define EXC_RESOURCE_IO_ENCODE_OBSERVED(subcode, num) \
244 ((subcode) |= (((uint64_t)(num) & 0x7FFFULL)))
246 /* RESOURCE_TYPE_THREADS specific encoding macros */
247 #define EXC_RESOURCE_THREADS_ENCODE_THREADS(code, threads) \
248 ((code) |= (((uint64_t)(threads) & 0x7FFFULL)))
253 #endif /* _EXC_RESOURCE_H_ */