]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 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. | |
0a7de745 | 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. | |
0a7de745 | 17 | * |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 27 | */ |
1c79356b A |
28 | |
29 | #ifndef _MACH_THREAD_POLICY_H_ | |
30 | #define _MACH_THREAD_POLICY_H_ | |
31 | ||
32 | #include <mach/mach_types.h> | |
33 | ||
34 | /* | |
35 | * These are the calls for accessing the policy parameters | |
36 | * of a particular thread. | |
37 | * | |
38 | * The extra 'get_default' parameter to the second call is | |
39 | * IN/OUT as follows: | |
40 | * 1) if asserted on the way in it indicates that the default | |
41 | * values should be returned, not the ones currently set, in | |
42 | * this case 'get_default' will always be asserted on return; | |
43 | * 2) if unasserted on the way in, the current settings are | |
44 | * desired and if still unasserted on return, then the info | |
45 | * returned reflects the current settings, otherwise if | |
46 | * 'get_default' returns asserted, it means that there are no | |
47 | * current settings due to other parameters taking precedence, | |
48 | * and the default ones are being returned instead. | |
49 | */ | |
50 | ||
0a7de745 A |
51 | typedef natural_t thread_policy_flavor_t; |
52 | typedef integer_t *thread_policy_t; | |
1c79356b A |
53 | |
54 | /* | |
0a7de745 A |
55 | * kern_return_t thread_policy_set( |
56 | * thread_t thread, | |
57 | * thread_policy_flavor_t flavor, | |
58 | * thread_policy_t policy_info, | |
59 | * mach_msg_type_number_t count); | |
60 | * | |
61 | * kern_return_t thread_policy_get( | |
62 | * thread_t thread, | |
63 | * thread_policy_flavor_t flavor, | |
64 | * thread_policy_t policy_info, | |
65 | * mach_msg_type_number_t *count, | |
66 | * boolean_t *get_default); | |
67 | */ | |
1c79356b A |
68 | |
69 | /* | |
70 | * Defined flavors. | |
71 | */ | |
72 | /* | |
73 | * THREAD_STANDARD_POLICY: | |
74 | * | |
0b4e3aa0 A |
75 | * This is the standard (fair) scheduling mode, assigned to new |
76 | * threads. The thread will be given processor time in a manner | |
77 | * which apportions approximately equal share to long running | |
78 | * computations. | |
1c79356b A |
79 | * |
80 | * Parameters: | |
81 | * [none] | |
82 | */ | |
83 | ||
0a7de745 | 84 | #define THREAD_STANDARD_POLICY 1 |
1c79356b A |
85 | |
86 | struct thread_standard_policy { | |
0a7de745 | 87 | natural_t no_data; |
1c79356b A |
88 | }; |
89 | ||
0a7de745 A |
90 | typedef struct thread_standard_policy thread_standard_policy_data_t; |
91 | typedef struct thread_standard_policy *thread_standard_policy_t; | |
1c79356b | 92 | |
0a7de745 | 93 | #define THREAD_STANDARD_POLICY_COUNT 0 |
0b4e3aa0 A |
94 | |
95 | /* | |
96 | * THREAD_EXTENDED_POLICY: | |
97 | * | |
98 | * Extended form of THREAD_STANDARD_POLICY, which supplies a | |
99 | * hint indicating whether this is a long running computation. | |
100 | * | |
101 | * Parameters: | |
102 | * | |
103 | * timeshare: TRUE (the default) results in identical scheduling | |
104 | * behavior as THREAD_STANDARD_POLICY. | |
105 | */ | |
106 | ||
0a7de745 | 107 | #define THREAD_EXTENDED_POLICY 1 |
0b4e3aa0 A |
108 | |
109 | struct thread_extended_policy { | |
0a7de745 | 110 | boolean_t timeshare; |
0b4e3aa0 A |
111 | }; |
112 | ||
0a7de745 A |
113 | typedef struct thread_extended_policy thread_extended_policy_data_t; |
114 | typedef struct thread_extended_policy *thread_extended_policy_t; | |
0b4e3aa0 | 115 | |
0a7de745 | 116 | #define THREAD_EXTENDED_POLICY_COUNT ((mach_msg_type_number_t) \ |
91447636 | 117 | (sizeof (thread_extended_policy_data_t) / sizeof (integer_t))) |
1c79356b A |
118 | |
119 | /* | |
120 | * THREAD_TIME_CONSTRAINT_POLICY: | |
121 | * | |
122 | * This scheduling mode is for threads which have real time | |
123 | * constraints on their execution. | |
124 | * | |
125 | * Parameters: | |
126 | * | |
127 | * period: This is the nominal amount of time between separate | |
128 | * processing arrivals, specified in absolute time units. A | |
129 | * value of 0 indicates that there is no inherent periodicity in | |
130 | * the computation. | |
131 | * | |
132 | * computation: This is the nominal amount of computation | |
133 | * time needed during a separate processing arrival, specified | |
134 | * in absolute time units. | |
135 | * | |
136 | * constraint: This is the maximum amount of real time that | |
137 | * may elapse from the start of a separate processing arrival | |
138 | * to the end of computation for logically correct functioning, | |
139 | * specified in absolute time units. Must be (>= computation). | |
140 | * Note that latency = (constraint - computation). | |
141 | * | |
142 | * preemptible: This indicates that the computation may be | |
143 | * interrupted, subject to the constraint specified above. | |
144 | */ | |
145 | ||
0a7de745 | 146 | #define THREAD_TIME_CONSTRAINT_POLICY 2 |
1c79356b A |
147 | |
148 | struct thread_time_constraint_policy { | |
0a7de745 A |
149 | uint32_t period; |
150 | uint32_t computation; | |
151 | uint32_t constraint; | |
152 | boolean_t preemptible; | |
1c79356b A |
153 | }; |
154 | ||
0a7de745 A |
155 | typedef struct thread_time_constraint_policy \ |
156 | thread_time_constraint_policy_data_t; | |
157 | typedef struct thread_time_constraint_policy \ | |
158 | *thread_time_constraint_policy_t; | |
1c79356b | 159 | |
0a7de745 | 160 | #define THREAD_TIME_CONSTRAINT_POLICY_COUNT ((mach_msg_type_number_t) \ |
91447636 | 161 | (sizeof (thread_time_constraint_policy_data_t) / sizeof (integer_t))) |
1c79356b A |
162 | |
163 | /* | |
164 | * THREAD_PRECEDENCE_POLICY: | |
165 | * | |
166 | * This may be used to indicate the relative value of the | |
167 | * computation compared to the other threads in the task. | |
168 | * | |
169 | * Parameters: | |
170 | * | |
171 | * importance: The importance is specified as a signed value. | |
172 | */ | |
173 | ||
0a7de745 | 174 | #define THREAD_PRECEDENCE_POLICY 3 |
1c79356b A |
175 | |
176 | struct thread_precedence_policy { | |
0a7de745 | 177 | integer_t importance; |
1c79356b A |
178 | }; |
179 | ||
0a7de745 A |
180 | typedef struct thread_precedence_policy thread_precedence_policy_data_t; |
181 | typedef struct thread_precedence_policy *thread_precedence_policy_t; | |
1c79356b | 182 | |
0a7de745 | 183 | #define THREAD_PRECEDENCE_POLICY_COUNT ((mach_msg_type_number_t) \ |
91447636 | 184 | (sizeof (thread_precedence_policy_data_t) / sizeof (integer_t))) |
1c79356b | 185 | |
2d21ac55 A |
186 | /* |
187 | * THREAD_AFFINITY_POLICY: | |
188 | * | |
189 | * This policy is experimental. | |
0a7de745 | 190 | * This may be used to express affinity relationships |
2d21ac55 A |
191 | * between threads in the task. Threads with the same affinity tag will |
192 | * be scheduled to share an L2 cache if possible. That is, affinity tags | |
0a7de745 | 193 | * are a hint to the scheduler for thread placement. |
2d21ac55 A |
194 | * |
195 | * The namespace of affinity tags is generally local to one task. However, | |
196 | * a child task created after the assignment of affinity tags by its parent | |
197 | * will share that namespace. In particular, a family of forked processes | |
198 | * may be created with a shared affinity namespace. | |
199 | * | |
200 | * Parameters: | |
201 | * tag: The affinity set identifier. | |
202 | */ | |
203 | ||
0a7de745 | 204 | #define THREAD_AFFINITY_POLICY 4 |
2d21ac55 A |
205 | |
206 | struct thread_affinity_policy { | |
0a7de745 | 207 | integer_t affinity_tag; |
2d21ac55 A |
208 | }; |
209 | ||
0a7de745 | 210 | #define THREAD_AFFINITY_TAG_NULL 0 |
2d21ac55 | 211 | |
0a7de745 A |
212 | typedef struct thread_affinity_policy thread_affinity_policy_data_t; |
213 | typedef struct thread_affinity_policy *thread_affinity_policy_t; | |
2d21ac55 | 214 | |
0a7de745 | 215 | #define THREAD_AFFINITY_POLICY_COUNT ((mach_msg_type_number_t) \ |
2d21ac55 A |
216 | (sizeof (thread_affinity_policy_data_t) / sizeof (integer_t))) |
217 | ||
6d2010ae A |
218 | /* |
219 | * THREAD_BACKGROUND_POLICY: | |
220 | */ | |
221 | ||
0a7de745 | 222 | #define THREAD_BACKGROUND_POLICY 5 |
6d2010ae A |
223 | |
224 | struct thread_background_policy { | |
0a7de745 | 225 | integer_t priority; |
6d2010ae A |
226 | }; |
227 | ||
39037602 A |
228 | #define THREAD_BACKGROUND_POLICY_DARWIN_BG 0x1000 |
229 | ||
0a7de745 A |
230 | typedef struct thread_background_policy thread_background_policy_data_t; |
231 | typedef struct thread_background_policy *thread_background_policy_t; | |
6d2010ae | 232 | |
0a7de745 | 233 | #define THREAD_BACKGROUND_POLICY_COUNT ((mach_msg_type_number_t) \ |
6d2010ae A |
234 | (sizeof (thread_background_policy_data_t) / sizeof (integer_t))) |
235 | ||
39236c6e | 236 | |
0a7de745 A |
237 | #define THREAD_LATENCY_QOS_POLICY 7 |
238 | typedef integer_t thread_latency_qos_t; | |
fe8ab488 A |
239 | |
240 | struct thread_latency_qos_policy { | |
241 | thread_latency_qos_t thread_latency_qos_tier; | |
242 | }; | |
243 | ||
0a7de745 A |
244 | typedef struct thread_latency_qos_policy thread_latency_qos_policy_data_t; |
245 | typedef struct thread_latency_qos_policy *thread_latency_qos_policy_t; | |
fe8ab488 | 246 | |
0a7de745 | 247 | #define THREAD_LATENCY_QOS_POLICY_COUNT ((mach_msg_type_number_t) \ |
fe8ab488 A |
248 | (sizeof (thread_latency_qos_policy_data_t) / sizeof (integer_t))) |
249 | ||
0a7de745 A |
250 | #define THREAD_THROUGHPUT_QOS_POLICY 8 |
251 | typedef integer_t thread_throughput_qos_t; | |
fe8ab488 A |
252 | |
253 | struct thread_throughput_qos_policy { | |
254 | thread_throughput_qos_t thread_throughput_qos_tier; | |
255 | }; | |
256 | ||
0a7de745 A |
257 | typedef struct thread_throughput_qos_policy thread_throughput_qos_policy_data_t; |
258 | typedef struct thread_throughput_qos_policy *thread_throughput_qos_policy_t; | |
fe8ab488 | 259 | |
0a7de745 | 260 | #define THREAD_THROUGHPUT_QOS_POLICY_COUNT ((mach_msg_type_number_t) \ |
fe8ab488 | 261 | (sizeof (thread_throughput_qos_policy_data_t) / sizeof (integer_t))) |
39236c6e A |
262 | |
263 | #ifdef PRIVATE | |
264 | ||
265 | /* | |
266 | * THREAD_POLICY_STATE: | |
267 | */ | |
0a7de745 | 268 | #define THREAD_POLICY_STATE 6 |
39236c6e | 269 | |
fe8ab488 A |
270 | #define THREAD_POLICY_STATE_FLAG_STATIC_PARAM 0x1 |
271 | ||
39236c6e A |
272 | struct thread_policy_state { |
273 | integer_t requested; | |
274 | integer_t effective; | |
275 | integer_t pending; | |
fe8ab488 | 276 | integer_t flags; |
39037602 A |
277 | uint64_t thps_requested_policy; |
278 | uint64_t thps_effective_policy; | |
279 | uint32_t thps_user_promotions; | |
280 | uint32_t thps_user_promotion_basepri; | |
281 | uint32_t thps_ipc_overrides; | |
282 | uint32_t reserved32; | |
283 | uint64_t reserved[2]; | |
39236c6e A |
284 | }; |
285 | ||
0a7de745 A |
286 | typedef struct thread_policy_state thread_policy_state_data_t; |
287 | typedef struct thread_policy_state *thread_policy_state_t; | |
39236c6e | 288 | |
0a7de745 | 289 | #define THREAD_POLICY_STATE_COUNT ((mach_msg_type_number_t) \ |
39236c6e A |
290 | (sizeof (thread_policy_state_data_t) / sizeof (integer_t))) |
291 | ||
fe8ab488 A |
292 | /* |
293 | * THREAD_QOS_POLICY: | |
294 | */ | |
295 | #define THREAD_QOS_POLICY 9 | |
296 | #define THREAD_QOS_POLICY_OVERRIDE 10 | |
297 | ||
d9a64523 | 298 | typedef uint8_t thread_qos_t; |
fe8ab488 A |
299 | #define THREAD_QOS_UNSPECIFIED 0 |
300 | #define THREAD_QOS_DEFAULT THREAD_QOS_UNSPECIFIED /* Temporary rename */ | |
301 | #define THREAD_QOS_MAINTENANCE 1 | |
302 | #define THREAD_QOS_BACKGROUND 2 | |
303 | #define THREAD_QOS_UTILITY 3 | |
304 | #define THREAD_QOS_LEGACY 4 /* i.e. default workq threads */ | |
305 | #define THREAD_QOS_USER_INITIATED 5 | |
306 | #define THREAD_QOS_USER_INTERACTIVE 6 | |
307 | ||
308 | #define THREAD_QOS_LAST 7 | |
309 | ||
0a7de745 | 310 | #define THREAD_QOS_MIN_TIER_IMPORTANCE (-15) |
fe8ab488 | 311 | |
a1c7dba1 A |
312 | /* |
313 | * Overrides are inputs to the task/thread policy engine that | |
314 | * temporarily elevate the effective QoS of a thread without changing | |
315 | * its steady-state (and round-trip-able) requested QoS. The | |
316 | * interfaces into the kernel allow the caller to associate a resource | |
317 | * and type that describe the reason/lifecycle of the override. For | |
318 | * instance, a contended pthread_mutex_t held by a UTILITY thread | |
319 | * might get an override to USER_INTERACTIVE, with the resource | |
320 | * being the userspace address of the pthread_mutex_t. When the | |
321 | * owning thread releases that resource, it can call into the | |
322 | * task policy subsystem to drop the override because of that resource, | |
323 | * although if more contended locks are held by the thread, the | |
324 | * effective QoS may remain overridden for longer. | |
325 | * | |
326 | * THREAD_QOS_OVERRIDE_TYPE_PTHREAD_MUTEX is used for contended | |
327 | * pthread_mutex_t's via the pthread kext. The holder gets an override | |
328 | * with resource=&mutex and a count of 1 by the initial contender. | |
329 | * Subsequent contenders raise the QoS value, until the holder | |
330 | * decrements the count to 0 and the override is released. | |
331 | * | |
332 | * THREAD_QOS_OVERRIDE_TYPE_PTHREAD_RWLOCK is unimplemented and has no | |
333 | * specified semantics. | |
334 | * | |
335 | * THREAD_QOS_OVERRIDE_TYPE_PTHREAD_EXPLICIT_OVERRIDE are explicitly | |
336 | * paired start/end overrides on a target thread. The resource can | |
337 | * either be a memory allocation in userspace, or the pthread_t of the | |
338 | * overrider if no allocation was used. | |
339 | * | |
39037602 A |
340 | * THREAD_QOS_OVERRIDE_TYPE_WILDCARD is a catch-all which will reset every |
341 | * resource matching the resource value. Passing | |
342 | * THREAD_QOS_OVERRIDE_RESOURCE_WILDCARD as well will reset everything. | |
a1c7dba1 A |
343 | */ |
344 | ||
39037602 A |
345 | #define THREAD_QOS_OVERRIDE_TYPE_UNKNOWN (0) |
346 | #define THREAD_QOS_OVERRIDE_TYPE_PTHREAD_MUTEX (1) | |
347 | #define THREAD_QOS_OVERRIDE_TYPE_PTHREAD_RWLOCK (2) | |
348 | #define THREAD_QOS_OVERRIDE_TYPE_PTHREAD_EXPLICIT_OVERRIDE (3) | |
39037602 | 349 | #define THREAD_QOS_OVERRIDE_TYPE_WILDCARD (5) |
a1c7dba1 A |
350 | |
351 | /* A special resource value to indicate a resource wildcard */ | |
352 | #define THREAD_QOS_OVERRIDE_RESOURCE_WILDCARD (~((user_addr_t)0)) | |
353 | ||
fe8ab488 A |
354 | struct thread_qos_policy { |
355 | integer_t qos_tier; | |
356 | integer_t tier_importance; | |
357 | }; | |
358 | ||
359 | typedef struct thread_qos_policy thread_qos_policy_data_t; | |
360 | typedef struct thread_qos_policy *thread_qos_policy_t; | |
361 | ||
362 | #define THREAD_QOS_POLICY_COUNT ((mach_msg_type_number_t) \ | |
0a7de745 | 363 | (sizeof (thread_qos_policy_data_t) / sizeof (integer_t))) |
fe8ab488 | 364 | |
39236c6e A |
365 | #endif /* PRIVATE */ |
366 | ||
39037602 A |
367 | #ifdef PRIVATE |
368 | ||
369 | /* | |
370 | * Internal bitfields are privately exported for revlocked tracing tools like msa to decode tracepoints. | |
371 | * | |
372 | * These struct definitions *will* change in the future. | |
373 | * When they do, we will update THREAD_POLICY_INTERNAL_STRUCT_VERSION. | |
374 | */ | |
375 | ||
f427ee49 | 376 | #define THREAD_POLICY_INTERNAL_STRUCT_VERSION 6 |
cb323159 | 377 | |
39037602 A |
378 | struct thread_requested_policy { |
379 | uint64_t thrp_int_darwinbg :1, /* marked as darwinbg via setpriority */ | |
0a7de745 A |
380 | thrp_ext_darwinbg :1, |
381 | thrp_int_iotier :2, /* IO throttle tier */ | |
382 | thrp_ext_iotier :2, | |
383 | thrp_int_iopassive :1, /* should IOs cause lower tiers to be throttled */ | |
384 | thrp_ext_iopassive :1, | |
385 | thrp_latency_qos :3, /* Timer latency QoS */ | |
386 | thrp_through_qos :3, /* Computation throughput QoS */ | |
387 | ||
388 | thrp_pidbind_bg :1, /* task i'm bound to is marked 'watchbg' */ | |
389 | thrp_qos :3, /* thread qos class */ | |
390 | thrp_qos_relprio :4, /* thread qos relative priority (store as inverse, -10 -> 0xA) */ | |
391 | thrp_qos_override :3, /* thread qos class override */ | |
392 | thrp_qos_promote :3, /* thread qos class from promotion */ | |
cb323159 | 393 | thrp_qos_kevent_override:3, /* thread qos class from kevent override */ |
0a7de745 | 394 | thrp_terminated :1, /* heading for termination */ |
0a7de745 | 395 | thrp_qos_workq_override :3, /* thread qos class override (workq) */ |
cb323159 | 396 | thrp_qos_wlsvc_override :3, /* workloop servicer qos class override */ |
0a7de745 | 397 | |
f427ee49 | 398 | thrp_reserved :26; |
39037602 A |
399 | }; |
400 | ||
401 | struct thread_effective_policy { | |
402 | uint64_t thep_darwinbg :1, /* marked as 'background', and sockets are marked bg when created */ | |
0a7de745 A |
403 | thep_io_tier :2, /* effective throttle tier */ |
404 | thep_io_passive :1, /* should IOs cause lower tiers to be throttled */ | |
405 | thep_all_sockets_bg :1, /* All existing sockets in process are marked as bg (thread: all created by thread) */ | |
406 | thep_new_sockets_bg :1, /* Newly created sockets should be marked as bg */ | |
407 | thep_terminated :1, /* all throttles have been removed for quick exit or SIGTERM handling */ | |
408 | thep_qos_ui_is_urgent :1, /* bump UI-Interactive QoS up to the urgent preemption band */ | |
409 | thep_latency_qos :3, /* Timer latency QoS level */ | |
410 | thep_through_qos :3, /* Computation throughput QoS level */ | |
411 | ||
412 | thep_qos :3, /* thread qos class */ | |
413 | thep_qos_relprio :4, /* thread qos relative priority (store as inverse, -10 -> 0xA) */ | |
414 | thep_qos_promote :3, /* thread qos class used for promotion */ | |
f427ee49 | 415 | thep_promote_above_task :1, /* thread is promoted above task-level clamp */ |
0a7de745 | 416 | |
f427ee49 | 417 | thep_reserved :39; |
39037602 A |
418 | }; |
419 | ||
420 | #endif /* PRIVATE */ | |
421 | ||
422 | ||
0a7de745 | 423 | #endif /* _MACH_THREAD_POLICY_H_ */ |