1 | /* |
2 | * Copyright (c) 2000-2005 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 | #ifndef _MACH_TASK_POLICY_PRIVATE_H_ |
30 | #define _MACH_TASK_POLICY_PRIVATE_H_ |
31 | |
32 | #include <mach/mach_types.h> |
33 | #include <mach/task_policy.h> |
34 | |
35 | /* |
36 | * Internal bitfields are privately exported for *revlocked* |
37 | * tools like msa to decode tracepoints and taskinfo to dump state |
38 | * |
39 | * These struct definitions *will* change in the future. |
40 | * When they do, we will update TASK_POLICY_INTERNAL_STRUCT_VERSION. |
41 | */ |
42 | |
43 | #define TASK_POLICY_INTERNAL_STRUCT_VERSION 4 |
44 | |
45 | #define trp_tal_enabled trp_reserved /* trp_tal_enabled is unused, reuse its slot to grow trp_role */ |
46 | |
47 | struct task_requested_policy { |
48 | uint64_t trp_int_darwinbg :1, /* marked as darwinbg via setpriority */ |
49 | trp_ext_darwinbg :1, |
50 | trp_int_iotier :2, /* IO throttle tier */ |
51 | trp_ext_iotier :2, |
52 | trp_int_iopassive :1, /* should IOs cause lower tiers to be throttled */ |
53 | trp_ext_iopassive :1, |
54 | trp_bg_iotier :2, /* what IO throttle tier should apply to me when I'm darwinbg? (pushed to threads) */ |
55 | trp_terminated :1, /* all throttles should be removed for quick exit or SIGTERM handling */ |
56 | trp_base_latency_qos :3, /* Timer latency QoS */ |
57 | trp_base_through_qos :3, /* Computation throughput QoS */ |
58 | |
59 | trp_apptype :3, /* What apptype did launchd tell us this was (inherited) */ |
60 | trp_boosted :1, /* Has a non-zero importance assertion count */ |
61 | trp_role :5, /* task's system role */ |
62 | trp_over_latency_qos :3, /* Timer latency QoS override */ |
63 | trp_over_through_qos :3, /* Computation throughput QoS override */ |
64 | trp_sfi_managed :1, /* SFI Managed task */ |
65 | trp_qos_clamp :3, /* task qos clamp */ |
66 | |
67 | /* suppression policies (non-embedded only) */ |
68 | trp_sup_active :1, /* Suppression is on */ |
69 | trp_sup_lowpri_cpu :1, /* Wants low priority CPU (MAXPRI_THROTTLE) */ |
70 | trp_sup_timer :3, /* Wanted timer throttling QoS tier */ |
71 | trp_sup_disk :1, /* Wants disk throttling */ |
72 | trp_sup_throughput :3, /* Wants throughput QoS tier */ |
73 | trp_sup_cpu :1, /* Wants suppressed CPU priority (MAXPRI_SUPPRESSED) */ |
74 | trp_sup_bg_sockets :1, /* Wants background sockets */ |
75 | |
76 | trp_reserved :17; |
77 | }; |
78 | |
79 | struct task_effective_policy { |
80 | uint64_t tep_darwinbg :1, /* marked as 'background', and sockets are marked bg when created */ |
81 | tep_lowpri_cpu :1, /* cpu priority == MAXPRI_THROTTLE */ |
82 | tep_io_tier :2, /* effective throttle tier */ |
83 | tep_io_passive :1, /* should IOs cause lower tiers to be throttled */ |
84 | tep_all_sockets_bg :1, /* All existing sockets in process are marked as bg (thread: all created by thread) */ |
85 | tep_new_sockets_bg :1, /* Newly created sockets should be marked as bg */ |
86 | tep_bg_iotier :2, /* What throttle tier should I be in when darwinbg is set? */ |
87 | tep_terminated :1, /* all throttles have been removed for quick exit or SIGTERM handling */ |
88 | tep_qos_ui_is_urgent :1, /* bump UI-Interactive QoS up to the urgent preemption band */ |
89 | tep_latency_qos :3, /* Timer latency QoS level */ |
90 | tep_through_qos :3, /* Computation throughput QoS level */ |
91 | |
92 | tep_tal_engaged :1, /* TAL mode is in effect */ |
93 | tep_watchers_bg :1, /* watchers are BG-ed */ |
94 | tep_sup_active :1, /* suppression behaviors are in effect */ |
95 | tep_role :4, /* task's system role */ |
96 | tep_suppressed_cpu :1, /* cpu priority == MAXPRI_SUPPRESSED (trumped by lowpri_cpu) */ |
97 | tep_sfi_managed :1, /* SFI Managed task */ |
98 | tep_live_donor :1, /* task is a live importance boost donor */ |
99 | tep_qos_clamp :3, /* task qos clamp (applies to qos-disabled threads too) */ |
100 | tep_qos_ceiling :3, /* task qos ceiling (applies to only qos-participating threads) */ |
101 | tep_adaptive_bg :1, /* task is bg solely due to the adaptive daemon clamp */ |
102 | |
103 | tep_reserved :30; |
104 | }; |
105 | |
106 | /* |
107 | * Control structure for applying suppression behaviors to tasks |
108 | */ |
109 | struct task_suppression_policy { |
110 | integer_t active; |
111 | integer_t lowpri_cpu; /* priority MAXPRI_THROTTLE cpu */ |
112 | integer_t timer_throttle; |
113 | integer_t disk_throttle; |
114 | integer_t cpu_limit; |
115 | integer_t suspend; |
116 | integer_t throughput_qos; |
117 | integer_t suppressed_cpu; /* priority MAXPRI_SUPPRESSED cpu */ |
118 | integer_t background_sockets; |
119 | integer_t reserved[7]; |
120 | }; |
121 | |
122 | typedef struct task_suppression_policy *task_suppression_policy_t; |
123 | |
124 | #define TASK_SUPPRESSION_POLICY_COUNT ((mach_msg_type_number_t) \ |
125 | (sizeof (struct task_suppression_policy) / sizeof (integer_t))) |
126 | |
127 | struct task_policy_state { |
128 | uint64_t requested; |
129 | uint64_t effective; |
130 | uint64_t pending; |
131 | uint32_t imp_assertcnt; |
132 | uint32_t imp_externcnt; |
133 | uint64_t flags; |
134 | uint64_t imp_transitions; |
135 | uint64_t tps_requested_policy; |
136 | uint64_t tps_effective_policy; |
137 | }; |
138 | |
139 | typedef struct task_policy_state *task_policy_state_t; |
140 | |
141 | #define TASK_POLICY_STATE_COUNT ((mach_msg_type_number_t) \ |
142 | (sizeof (struct task_policy_state) / sizeof (integer_t))) |
143 | |
144 | |
145 | /* |
146 | * Definitions for munging and unmunging a policy struct |
147 | * Used in task_policy_state and in tracepoints |
148 | * |
149 | * Note: this is tightly bound to the implementation of task policy |
150 | * and the values exported through this API may change or change meaning at any time |
151 | * |
152 | * Do not rely on these values, especially apptype, to decide behaviors at runtime. |
153 | * |
154 | * All per-thread state must be in the first 32 bits of the bitfield. |
155 | */ |
156 | |
157 | #define TASK_APPTYPE_NONE 0 |
158 | #define TASK_APPTYPE_DAEMON_INTERACTIVE 1 |
159 | #define TASK_APPTYPE_DAEMON_STANDARD 2 |
160 | #define TASK_APPTYPE_DAEMON_ADAPTIVE 3 |
161 | #define TASK_APPTYPE_DAEMON_BACKGROUND 4 |
162 | #define TASK_APPTYPE_APP_DEFAULT 5 |
163 | #define TASK_APPTYPE_APP_TAL 6 /* unused */ |
164 | #define TASK_APPTYPE_DRIVER 7 |
165 | |
166 | /* task policy state flags */ |
167 | #define TASK_IMP_RECEIVER 0x00000001 |
168 | #define TASK_IMP_DONOR 0x00000002 |
169 | #define TASK_IMP_LIVE_DONOR 0x00000004 |
170 | #define TASK_DENAP_RECEIVER 0x00000008 |
171 | #define TASK_IS_PIDSUSPENDED 0x00000010 |
172 | |
173 | /* requested_policy */ |
174 | #define POLICY_REQ_INT_DARWIN_BG 0x00000001 |
175 | #define POLICY_REQ_EXT_DARWIN_BG 0x00000002 |
176 | #define POLICY_REQ_INT_IO_TIER_MASK 0x0000000c /* 2 bits */ |
177 | #define POLICY_REQ_INT_IO_TIER_SHIFT 2 |
178 | #define POLICY_REQ_EXT_IO_TIER_MASK 0x00000030 /* 2 bits */ |
179 | #define POLICY_REQ_EXT_IO_TIER_SHIFT 4 |
180 | #define POLICY_REQ_INT_PASSIVE_IO 0x00000040 |
181 | #define POLICY_REQ_EXT_PASSIVE_IO 0x00000080 |
182 | #define POLICY_REQ_BG_IOTIER_MASK 0x00000300 /* 2 bits */ |
183 | #define POLICY_REQ_BG_IOTIER_SHIFT 8 |
184 | |
185 | /* thread requested policy */ |
186 | #define POLICY_REQ_PIDBIND_BG 0x00000400 |
187 | #define POLICY_REQ_WORKQ_BG 0x00000800 /* deprecated */ |
188 | #define POLICY_REQ_TH_QOS_MASK 0x07000000 /* 3 bits (overlaps with ROLE) */ |
189 | #define POLICY_REQ_TH_QOS_SHIFT 24 |
190 | #define POLICY_REQ_TH_QOS_OVER_MASK 0x70000000 /* 3 bits (overlaps with TAL and SFI) */ |
191 | #define POLICY_REQ_TH_QOS_OVER_SHIFT 28 |
192 | |
193 | /* task_requested_policy */ |
194 | #define POLICY_REQ_TERMINATED 0x00001000 |
195 | #define POLICY_REQ_BOOSTED 0x00002000 |
196 | #define POLICY_REQ_INT_GPU_DENY 0x00004000 |
197 | #define POLICY_REQ_EXT_GPU_DENY 0x00008000 |
198 | #define POLICY_REQ_APPTYPE_MASK 0x00070000 /* 3 bits */ |
199 | #define POLICY_REQ_APPTYPE_SHIFT 16 |
200 | #define POLICY_REQ_BASE_LATENCY_QOS_MASK 0x00700000 /* 3 bits */ |
201 | #define POLICY_REQ_BASE_LATENCY_QOS_SHIFT 20 |
202 | #define POLICY_REQ_ROLE_MASK 0x07000000 /* 3 bits */ |
203 | #define POLICY_REQ_ROLE_SHIFT 24 |
204 | #define POLICY_REQ_TAL_ENABLED 0x40000000 |
205 | #define POLICY_REQ_SFI_MANAGED 0x80000000 |
206 | |
207 | /* requested suppression behaviors (note: clipped off in 32-bit tracepoints) */ |
208 | #define POLICY_REQ_SUP_ACTIVE 0x0000000100000000 |
209 | #define POLICY_REQ_SUP_LOWPRI_CPU 0x0000000200000000 |
210 | #define POLICY_REQ_SUP_CPU 0x0000000400000000 |
211 | #define POLICY_REQ_SUP_DISK_THROTTLE 0x0000003000000000 /* 2 bits */ |
212 | #define POLICY_REQ_SUP_CPU_LIMIT 0x0000004000000000 |
213 | #define POLICY_REQ_SUP_SUSPEND 0x0000008000000000 |
214 | #define POLICY_REQ_OVER_LATENCY_QOS_MASK 0x0000070000000000 /* 3 bits */ |
215 | #define POLICY_REQ_OVER_LATENCY_QOS_SHIFT 40 |
216 | #define POLICY_REQ_BASE_THROUGH_QOS_MASK 0x0000700000000000 /* 3 bits */ |
217 | #define POLICY_REQ_BASE_THROUGH_QOS_SHIFT 44 |
218 | #define POLICY_REQ_OVER_THROUGH_QOS_MASK 0x0007000000000000 /* 3 bits */ |
219 | #define POLICY_REQ_OVER_THROUGH_QOS_SHIFT 48 |
220 | #define POLICY_REQ_SUP_TIMER_THROTTLE_MASK 0x0070000000000000 /* 3 bits */ |
221 | #define POLICY_REQ_SUP_TIMER_THROTTLE_SHIFT 52 |
222 | #define POLICY_REQ_SUP_THROUGHPUT_MASK 0x0700000000000000 /* 3 bits */ |
223 | #define POLICY_REQ_SUP_THROUGHPUT_SHIFT 56 |
224 | #define POLICY_REQ_SUP_BG_SOCKETS 0x0800008000000000 |
225 | #define POLICY_REQ_QOS_CLAMP_MASK 0x7000000000000000 /* 3 bits */ |
226 | #define POLICY_REQ_QOS_CLAMP_SHIFT 60 |
227 | |
228 | /* effective policy */ |
229 | #define POLICY_EFF_IO_TIER_MASK 0x00000003 /* 2 bits */ |
230 | #define POLICY_EFF_IO_TIER_SHIFT 0 |
231 | #define POLICY_EFF_IO_PASSIVE 0x00000008 |
232 | #define POLICY_EFF_DARWIN_BG 0x00000010 |
233 | #define POLICY_EFF_LOWPRI_CPU 0x00000020 |
234 | #define POLICY_EFF_ALL_SOCKETS_BG 0x00000040 |
235 | #define POLICY_EFF_NEW_SOCKETS_BG 0x00000080 |
236 | #define POLICY_EFF_BG_IOTIER_MASK 0x00000300 /* 2 bits */ |
237 | #define POLICY_EFF_BG_IOTIER_SHIFT 8 |
238 | #define POLICY_EFF_TERMINATED 0x00000400 |
239 | #define POLICY_EFF_QOS_UI_IS_URGENT 0x80000000 |
240 | |
241 | /* thread effective policy */ |
242 | #define POLICY_EFF_TH_QOS_MASK 0x00700000 /* 3 bits (overlaps with ROLE) */ |
243 | #define POLICY_EFF_TH_QOS_SHIFT 20 |
244 | #define POLICY_EFF_LATENCY_QOS_MASK 0x00070000 /* 3 bits */ |
245 | #define POLICY_EFF_LATENCY_QOS_SHIFT 16 |
246 | #define POLICY_EFF_THROUGH_QOS_MASK 0x07000000 /* 3 bits */ |
247 | #define POLICY_EFF_THROUGH_QOS_SHIFT 24 |
248 | |
249 | /* task effective policy */ |
250 | #define POLICY_EFF_GPU_DENY 0x00001000 |
251 | #define POLICY_EFF_TAL_ENGAGED 0x00002000 |
252 | #define POLICY_EFF_SUSPENDED 0x00004000 |
253 | #define POLICY_EFF_WATCHERS_BG 0x00008000 |
254 | #define POLICY_EFF_SUP_ACTIVE 0x00080000 |
255 | #define POLICY_EFF_ROLE_MASK 0x00700000 /* 3 bits */ |
256 | #define POLICY_EFF_ROLE_SHIFT 20 |
257 | #define POLICY_EFF_SUP_CPU 0x00800000 |
258 | #define POLICY_EFF_SFI_MANAGED 0x08000000 |
259 | #define POLICY_EFF_QOS_CEILING_MASK 0x70000000 |
260 | #define POLICY_EFF_QOS_CEILING_SHIFT 28 |
261 | |
262 | /* pending policy */ |
263 | #define POLICY_PEND_UPDATING 0x00000001 |
264 | #define POLICY_PEND_SOCKETS 0x00000002 |
265 | #define POLICY_PEND_TIMERS 0x00000004 |
266 | #define POLICY_PEND_WATCHERS 0x00000008 |
267 | |
268 | #ifdef MACH_KERNEL_PRIVATE |
269 | |
270 | extern const struct task_requested_policy default_task_requested_policy; |
271 | extern const struct task_effective_policy default_task_effective_policy; |
272 | |
273 | extern kern_return_t |
274 | qos_latency_policy_validate(task_latency_qos_t); |
275 | |
276 | extern kern_return_t |
277 | qos_throughput_policy_validate(task_throughput_qos_t); |
278 | |
279 | extern uint32_t |
280 | qos_extract(uint32_t); |
281 | |
282 | extern uint32_t |
283 | qos_latency_policy_package(uint32_t); |
284 | extern uint32_t |
285 | qos_throughput_policy_package(uint32_t); |
286 | |
287 | #endif /* MACH_KERNEL_PRIVATE */ |
288 | |
289 | #endif /* _MACH_TASK_POLICY_PRIVATE_H_ */ |
290 | |