xnu-4570.41.2.tar.gz
[apple/xnu.git] / osfmk / kern / exc_resource.h
CommitLineData
39236c6e
A
1/*
2 * Copyright (c) 2011-2012 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
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.
35 */
36
37/*
38 * EXC_RESOURCE related macros, namespace etc.
39 */
40
41#ifndef _EXC_RESOURCE_H_
42#define _EXC_RESOURCE_H_
43
44/*
45 * Generic exception code format:
46 *
47 * code:
48 * +----------------------------------------------------------+
49 * |[63:61] type | [60:58] flavor | [57:0] type-specific data |
50 * +----------------------------------------------------------+
51 */
52
53
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)
59
60/* EXC_RESOURCE Types */
61#define RESOURCE_TYPE_CPU 1
62#define RESOURCE_TYPE_WAKEUPS 2
63#define RESOURCE_TYPE_MEMORY 3
39037602 64#define RESOURCE_TYPE_IO 4
39236c6e
A
65
66/* RESOURCE_TYPE_CPU flavors */
fe8ab488
A
67#define FLAVOR_CPU_MONITOR 1
68#define FLAVOR_CPU_MONITOR_FATAL 2
39236c6e
A
69
70/*
71 * RESOURCE_TYPE_CPU exception code & subcode.
72 *
73 * This is sent by the kernel when the CPU usage monitor
74 * is tripped. [See proc_set_cpumon_params()]
75 *
76 * code:
77 * +-----------------------------------------------+
78 * |[63:61] RESOURCE |[60:58] FLAVOR_CPU_ |[57:32] |
fe8ab488 79 * |_TYPE_CPU |MONITOR[_FATAL] |Unused |
39236c6e
A
80 * +-----------------------------------------------+
81 * |[31:7] Interval (sec) | [6:0] CPU limit (%)|
82 * +-----------------------------------------------+
83 *
84 * subcode:
85 * +-----------------------------------------------+
86 * | | [6:0] % of CPU |
87 * | | actually consumed |
88 * +-----------------------------------------------+
89 *
90 */
91
92/* RESOURCE_TYPE_CPU decoding macros */
93#define EXC_RESOURCE_CPUMONITOR_DECODE_INTERVAL(code) \
94 (((code) >> 7) & 0x1FFFFFFULL)
95#define EXC_RESOURCE_CPUMONITOR_DECODE_PERCENTAGE(code) \
96 ((code) & 0x7FULL)
97#define EXC_RESOURCE_CPUMONITOR_DECODE_PERCENTAGE_OBSERVED(subcode) \
98 ((subcode) & 0x7FULL)
99
100
101/* RESOURCE_TYPE_WAKEUPS flavors */
102#define FLAVOR_WAKEUPS_MONITOR 1
103
104/*
105 * RESOURCE_TYPE_WAKEUPS exception code & subcode.
106 *
107 * This is sent by the kernel when the platform idle
108 * wakeups monitor is tripped.
109 * [See proc_set_wakeupsmon_params()]
110 *
111 * code:
112 * +-----------------------------------------------+
113 * |[63:61] RESOURCE |[60:58] FLAVOR_ |[57:32] |
114 * |_TYPE_WAKEUPS |WAKEUPS_MONITOR |Unused |
115 * +-----------------------------------------------+
116 * | [31:20] Observation | [19:0] # of wakeups |
117 * | interval (sec) | permitted (per sec) |
118 * +-----------------------------------------------+
119 *
120 * subcode:
121 * +-----------------------------------------------+
122 * | | [19:0] # of wakeups |
123 * | | observed (per sec) |
124 * +-----------------------------------------------+
125 *
126 */
127
128#define EXC_RESOURCE_CPUMONITOR_DECODE_WAKEUPS_PERMITTED(code) \
129 ((code) & 0xFFFULL)
130#define EXC_RESOURCE_CPUMONITOR_DECODE_OBSERVATION_INTERVAL(code) \
131 (((code) >> 20) & 0xFFFFFULL)
132#define EXC_RESOURCE_CPUMONITOR_DECODE_WAKEUPS_OBSERVED(subcode) \
133 ((subcode) & 0xFFFFFULL)
134
135/* RESOURCE_TYPE_MEMORY flavors */
136#define FLAVOR_HIGH_WATERMARK 1
137
138/*
139 * RESOURCE_TYPE_MEMORY / FLAVOR_HIGH_WATERMARK
140 * exception code & subcode.
141 *
142 * This is sent by the kernel when a task crosses its high
143 * watermark memory limit.
144 *
145 * code:
146 * +------------------------------------------------+
147 * |[63:61] RESOURCE |[60:58] FLAVOR_HIGH_ |[57:32] |
148 * |_TYPE_MEMORY |WATERMARK |Unused |
149 * +------------------------------------------------+
150 * | | [12:0] HWM limit (MB)|
151 * +------------------------------------------------+
152 *
153 * subcode:
154 * +------------------------------------------------+
155 * | unused |
156 * +------------------------------------------------+
157 *
158 */
159
160#define EXC_RESOURCE_HWM_DECODE_LIMIT(code) \
161 ((code) & 0x1FFFULL)
162
39037602
A
163/* RESOURCE_TYPE_IO flavors */
164#define FLAVOR_IO_PHYSICAL_WRITES 1
165#define FLAVOR_IO_LOGICAL_WRITES 2
166
167/*
168 * RESOURCE_TYPE_IO exception code & subcode.
169 *
170 * This is sent by the kernel when a task crosses its
171 * I/O limits.
172 *
173 * code:
174 * +-----------------------------------------------+
175 * |[63:61] RESOURCE |[60:58] FLAVOR_IO_ |[57:32] |
176 * |_TYPE_IO |PHYSICAL/LOGICAL |Unused |
177 * +-----------------------------------------------+
178 * |[31:15] Interval (sec) | [14:0] Limit (MB) |
179 * +-----------------------------------------------+
180 *
181 * subcode:
182 * +-----------------------------------------------+
183 * | | [14:0] I/O Count |
184 * | | (in MB) |
185 * +-----------------------------------------------+
186 *
187 */
188
189/* RESOURCE_TYPE_IO decoding macros */
190#define EXC_RESOURCE_IO_DECODE_INTERVAL(code) \
191 (((code) >> 15) & 0x1FFFFULL)
192#define EXC_RESOURCE_IO_DECODE_LIMIT(code) \
193 ((code) & 0x7FFFULL)
194#define EXC_RESOURCE_IO_OBSERVED(subcode) \
195 ((subcode) & 0x7FFFULL)
196
39236c6e
A
197
198#ifdef KERNEL
199
200/* EXC_RESOURCE type and flavor encoding macros */
201#define EXC_RESOURCE_ENCODE_TYPE(code, type) \
202 ((code) |= (((uint64_t)(type) & 0x7ULL) << 61))
203#define EXC_RESOURCE_ENCODE_FLAVOR(code, flavor) \
204 ((code) |= (((uint64_t)(flavor) & 0x7ULL) << 58))
205
206/* RESOURCE_TYPE_CPU::FLAVOR_CPU_MONITOR specific encoding macros */
207#define EXC_RESOURCE_CPUMONITOR_ENCODE_INTERVAL(code, interval) \
208 ((code) |= (((uint64_t)(interval) & 0x1FFFFFFULL) << 7))
209#define EXC_RESOURCE_CPUMONITOR_ENCODE_PERCENTAGE(code, percentage) \
210 ((code) |= (((uint64_t)(percentage) & 0x7FULL)))
211
212/* RESOURCE_TYPE_WAKEUPS::FLAVOR_WAKEUPS_MONITOR specific encoding macros */
213#define EXC_RESOURCE_CPUMONITOR_ENCODE_WAKEUPS_PERMITTED(code, num) \
214 ((code) |= ((uint64_t)(num) & 0xFFFFFULL))
215#define EXC_RESOURCE_CPUMONITOR_ENCODE_OBSERVATION_INTERVAL(code, num) \
216 ((code) |= (((uint64_t)(num) & 0xFFFULL) << 20))
217#define EXC_RESOURCE_CPUMONITOR_ENCODE_WAKEUPS_OBSERVED(subcode, num) \
218 ((subcode) |= ((uint64_t)(num) & 0xFFFFFULL))
219
220/* RESOURCE_TYPE_MEMORY::FLAVOR_HIGH_WATERMARK specific encoding macros */
221#define EXC_RESOURCE_HWM_ENCODE_LIMIT(code, num) \
222 ((code) |= ((uint64_t)(num) & 0x1FFFULL))
223
39037602
A
224/* RESOURCE_TYPE_IO::FLAVOR_IO_PHYSICAL_WRITES/FLAVOR_IO_LOGICAL_WRITES specific encoding macros */
225#define EXC_RESOURCE_IO_ENCODE_INTERVAL(code, interval) \
226 ((code) |= (((uint64_t)(interval) & 0x1FFFFULL) << 15))
227#define EXC_RESOURCE_IO_ENCODE_LIMIT(code, limit) \
228 ((code) |= (((uint64_t)(limit) & 0x7FFFULL)))
229#define EXC_RESOURCE_IO_ENCODE_OBSERVED(subcode, num) \
230 ((subcode) |= (((uint64_t)(num) & 0x7FFFULL)))
231
39236c6e
A
232#endif /* KERNEL */
233
234
235#endif /* _EXC_RESOURCE_H_ */