xref: /xnu-12377.41.6/osfmk/mach/thread_policy.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions  * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions  *
4*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions  *
6*bbb1b6f9SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*bbb1b6f9SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*bbb1b6f9SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*bbb1b6f9SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*bbb1b6f9SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*bbb1b6f9SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*bbb1b6f9SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*bbb1b6f9SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*bbb1b6f9SApple OSS Distributions  *
15*bbb1b6f9SApple OSS Distributions  * Please obtain a copy of the License at
16*bbb1b6f9SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*bbb1b6f9SApple OSS Distributions  *
18*bbb1b6f9SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*bbb1b6f9SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*bbb1b6f9SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*bbb1b6f9SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*bbb1b6f9SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*bbb1b6f9SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*bbb1b6f9SApple OSS Distributions  * limitations under the License.
25*bbb1b6f9SApple OSS Distributions  *
26*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*bbb1b6f9SApple OSS Distributions  */
28*bbb1b6f9SApple OSS Distributions 
29*bbb1b6f9SApple OSS Distributions #ifndef _MACH_THREAD_POLICY_H_
30*bbb1b6f9SApple OSS Distributions #define _MACH_THREAD_POLICY_H_
31*bbb1b6f9SApple OSS Distributions 
32*bbb1b6f9SApple OSS Distributions #include <mach/mach_types.h>
33*bbb1b6f9SApple OSS Distributions 
34*bbb1b6f9SApple OSS Distributions /*
35*bbb1b6f9SApple OSS Distributions  * These are the calls for accessing the policy parameters
36*bbb1b6f9SApple OSS Distributions  * of a particular thread.
37*bbb1b6f9SApple OSS Distributions  *
38*bbb1b6f9SApple OSS Distributions  * The extra 'get_default' parameter to the second call is
39*bbb1b6f9SApple OSS Distributions  * IN/OUT as follows:
40*bbb1b6f9SApple OSS Distributions  * 1) if asserted on the way in it indicates that the default
41*bbb1b6f9SApple OSS Distributions  * values should be returned, not the ones currently set, in
42*bbb1b6f9SApple OSS Distributions  * this case 'get_default' will always be asserted on return;
43*bbb1b6f9SApple OSS Distributions  * 2) if unasserted on the way in, the current settings are
44*bbb1b6f9SApple OSS Distributions  * desired and if still unasserted on return, then the info
45*bbb1b6f9SApple OSS Distributions  * returned reflects the current settings, otherwise if
46*bbb1b6f9SApple OSS Distributions  * 'get_default' returns asserted, it means that there are no
47*bbb1b6f9SApple OSS Distributions  * current settings due to other parameters taking precedence,
48*bbb1b6f9SApple OSS Distributions  * and the default ones are being returned instead.
49*bbb1b6f9SApple OSS Distributions  */
50*bbb1b6f9SApple OSS Distributions 
51*bbb1b6f9SApple OSS Distributions typedef natural_t       thread_policy_flavor_t;
52*bbb1b6f9SApple OSS Distributions typedef integer_t       *thread_policy_t;
53*bbb1b6f9SApple OSS Distributions 
54*bbb1b6f9SApple OSS Distributions /*
55*bbb1b6f9SApple OSS Distributions  *  kern_return_t	thread_policy_set(
56*bbb1b6f9SApple OSS Distributions  *                                       thread_t					thread,
57*bbb1b6f9SApple OSS Distributions  *                                       thread_policy_flavor_t		flavor,
58*bbb1b6f9SApple OSS Distributions  *                                       thread_policy_t				policy_info,
59*bbb1b6f9SApple OSS Distributions  *                                       mach_msg_type_number_t		count);
60*bbb1b6f9SApple OSS Distributions  *
61*bbb1b6f9SApple OSS Distributions  *  kern_return_t	thread_policy_get(
62*bbb1b6f9SApple OSS Distributions  *                                       thread_t					thread,
63*bbb1b6f9SApple OSS Distributions  *                                       thread_policy_flavor_t		flavor,
64*bbb1b6f9SApple OSS Distributions  *                                       thread_policy_t				policy_info,
65*bbb1b6f9SApple OSS Distributions  *                                       mach_msg_type_number_t		*count,
66*bbb1b6f9SApple OSS Distributions  *                                       boolean_t					*get_default);
67*bbb1b6f9SApple OSS Distributions  */
68*bbb1b6f9SApple OSS Distributions 
69*bbb1b6f9SApple OSS Distributions /*
70*bbb1b6f9SApple OSS Distributions  * Defined flavors.
71*bbb1b6f9SApple OSS Distributions  */
72*bbb1b6f9SApple OSS Distributions /*
73*bbb1b6f9SApple OSS Distributions  * THREAD_STANDARD_POLICY:
74*bbb1b6f9SApple OSS Distributions  *
75*bbb1b6f9SApple OSS Distributions  * This is the standard (fair) scheduling mode, assigned to new
76*bbb1b6f9SApple OSS Distributions  * threads.  The thread will be given processor time in a manner
77*bbb1b6f9SApple OSS Distributions  * which apportions approximately equal share to long running
78*bbb1b6f9SApple OSS Distributions  * computations.
79*bbb1b6f9SApple OSS Distributions  *
80*bbb1b6f9SApple OSS Distributions  * Parameters:
81*bbb1b6f9SApple OSS Distributions  *	[none]
82*bbb1b6f9SApple OSS Distributions  */
83*bbb1b6f9SApple OSS Distributions 
84*bbb1b6f9SApple OSS Distributions #define THREAD_STANDARD_POLICY                  1
85*bbb1b6f9SApple OSS Distributions 
86*bbb1b6f9SApple OSS Distributions struct thread_standard_policy {
87*bbb1b6f9SApple OSS Distributions 	natural_t               no_data;
88*bbb1b6f9SApple OSS Distributions };
89*bbb1b6f9SApple OSS Distributions 
90*bbb1b6f9SApple OSS Distributions typedef struct thread_standard_policy   thread_standard_policy_data_t;
91*bbb1b6f9SApple OSS Distributions typedef struct thread_standard_policy   *thread_standard_policy_t;
92*bbb1b6f9SApple OSS Distributions 
93*bbb1b6f9SApple OSS Distributions #define THREAD_STANDARD_POLICY_COUNT    0
94*bbb1b6f9SApple OSS Distributions 
95*bbb1b6f9SApple OSS Distributions /*
96*bbb1b6f9SApple OSS Distributions  * THREAD_EXTENDED_POLICY:
97*bbb1b6f9SApple OSS Distributions  *
98*bbb1b6f9SApple OSS Distributions  * Extended form of THREAD_STANDARD_POLICY, which supplies a
99*bbb1b6f9SApple OSS Distributions  * hint indicating whether this is a long running computation.
100*bbb1b6f9SApple OSS Distributions  *
101*bbb1b6f9SApple OSS Distributions  * Parameters:
102*bbb1b6f9SApple OSS Distributions  *
103*bbb1b6f9SApple OSS Distributions  * timeshare: TRUE (the default) results in identical scheduling
104*bbb1b6f9SApple OSS Distributions  * behavior as THREAD_STANDARD_POLICY.
105*bbb1b6f9SApple OSS Distributions  */
106*bbb1b6f9SApple OSS Distributions 
107*bbb1b6f9SApple OSS Distributions #define THREAD_EXTENDED_POLICY                  1
108*bbb1b6f9SApple OSS Distributions 
109*bbb1b6f9SApple OSS Distributions struct thread_extended_policy {
110*bbb1b6f9SApple OSS Distributions 	boolean_t               timeshare;
111*bbb1b6f9SApple OSS Distributions };
112*bbb1b6f9SApple OSS Distributions 
113*bbb1b6f9SApple OSS Distributions typedef struct thread_extended_policy   thread_extended_policy_data_t;
114*bbb1b6f9SApple OSS Distributions typedef struct thread_extended_policy   *thread_extended_policy_t;
115*bbb1b6f9SApple OSS Distributions 
116*bbb1b6f9SApple OSS Distributions #define THREAD_EXTENDED_POLICY_COUNT    ((mach_msg_type_number_t) \
117*bbb1b6f9SApple OSS Distributions 	(sizeof (thread_extended_policy_data_t) / sizeof (integer_t)))
118*bbb1b6f9SApple OSS Distributions 
119*bbb1b6f9SApple OSS Distributions /*
120*bbb1b6f9SApple OSS Distributions  * THREAD_TIME_CONSTRAINT_POLICY:
121*bbb1b6f9SApple OSS Distributions  *
122*bbb1b6f9SApple OSS Distributions  * This scheduling mode is for threads which have real time
123*bbb1b6f9SApple OSS Distributions  * constraints on their execution.
124*bbb1b6f9SApple OSS Distributions  *
125*bbb1b6f9SApple OSS Distributions  * Parameters:
126*bbb1b6f9SApple OSS Distributions  *
127*bbb1b6f9SApple OSS Distributions  * period: This is the nominal amount of time between separate
128*bbb1b6f9SApple OSS Distributions  * processing arrivals, specified in absolute time units.  A
129*bbb1b6f9SApple OSS Distributions  * value of 0 indicates that there is no inherent periodicity in
130*bbb1b6f9SApple OSS Distributions  * the computation.
131*bbb1b6f9SApple OSS Distributions  *
132*bbb1b6f9SApple OSS Distributions  * computation: This is the nominal amount of computation
133*bbb1b6f9SApple OSS Distributions  * time needed during a separate processing arrival, specified
134*bbb1b6f9SApple OSS Distributions  * in absolute time units.  The thread may be preempted after
135*bbb1b6f9SApple OSS Distributions  * the computation time has elapsed.
136*bbb1b6f9SApple OSS Distributions  * If (computation < constraint/2) it will be forced to
137*bbb1b6f9SApple OSS Distributions  * constraint/2 to avoid unintended preemption and associated
138*bbb1b6f9SApple OSS Distributions  * timer interrupts.
139*bbb1b6f9SApple OSS Distributions  *
140*bbb1b6f9SApple OSS Distributions  * constraint: This is the maximum amount of real time that
141*bbb1b6f9SApple OSS Distributions  * may elapse from the start of a separate processing arrival
142*bbb1b6f9SApple OSS Distributions  * to the end of computation for logically correct functioning,
143*bbb1b6f9SApple OSS Distributions  * specified in absolute time units.  Must be (>= computation).
144*bbb1b6f9SApple OSS Distributions  * Note that latency = (constraint - computation).
145*bbb1b6f9SApple OSS Distributions  *
146*bbb1b6f9SApple OSS Distributions  * preemptible: IGNORED (This indicates that the computation may be
147*bbb1b6f9SApple OSS Distributions  * interrupted, subject to the constraint specified above.)
148*bbb1b6f9SApple OSS Distributions  */
149*bbb1b6f9SApple OSS Distributions 
150*bbb1b6f9SApple OSS Distributions #define THREAD_TIME_CONSTRAINT_POLICY           2
151*bbb1b6f9SApple OSS Distributions 
152*bbb1b6f9SApple OSS Distributions struct thread_time_constraint_policy {
153*bbb1b6f9SApple OSS Distributions 	uint32_t                period;
154*bbb1b6f9SApple OSS Distributions 	uint32_t                computation;
155*bbb1b6f9SApple OSS Distributions 	uint32_t                constraint;
156*bbb1b6f9SApple OSS Distributions 	boolean_t               preemptible;
157*bbb1b6f9SApple OSS Distributions };
158*bbb1b6f9SApple OSS Distributions 
159*bbb1b6f9SApple OSS Distributions typedef struct thread_time_constraint_policy    \
160*bbb1b6f9SApple OSS Distributions         thread_time_constraint_policy_data_t;
161*bbb1b6f9SApple OSS Distributions typedef struct thread_time_constraint_policy    \
162*bbb1b6f9SApple OSS Distributions         *thread_time_constraint_policy_t;
163*bbb1b6f9SApple OSS Distributions 
164*bbb1b6f9SApple OSS Distributions #define THREAD_TIME_CONSTRAINT_POLICY_COUNT     ((mach_msg_type_number_t) \
165*bbb1b6f9SApple OSS Distributions 	(sizeof (thread_time_constraint_policy_data_t) / sizeof (integer_t)))
166*bbb1b6f9SApple OSS Distributions 
167*bbb1b6f9SApple OSS Distributions /*
168*bbb1b6f9SApple OSS Distributions  * THREAD_PRECEDENCE_POLICY:
169*bbb1b6f9SApple OSS Distributions  *
170*bbb1b6f9SApple OSS Distributions  * This may be used to indicate the relative value of the
171*bbb1b6f9SApple OSS Distributions  * computation compared to the other threads in the task.
172*bbb1b6f9SApple OSS Distributions  *
173*bbb1b6f9SApple OSS Distributions  * Parameters:
174*bbb1b6f9SApple OSS Distributions  *
175*bbb1b6f9SApple OSS Distributions  * importance: The importance is specified as a signed value.
176*bbb1b6f9SApple OSS Distributions  */
177*bbb1b6f9SApple OSS Distributions 
178*bbb1b6f9SApple OSS Distributions #define THREAD_PRECEDENCE_POLICY                3
179*bbb1b6f9SApple OSS Distributions 
180*bbb1b6f9SApple OSS Distributions struct thread_precedence_policy {
181*bbb1b6f9SApple OSS Distributions 	integer_t               importance;
182*bbb1b6f9SApple OSS Distributions };
183*bbb1b6f9SApple OSS Distributions 
184*bbb1b6f9SApple OSS Distributions typedef struct thread_precedence_policy         thread_precedence_policy_data_t;
185*bbb1b6f9SApple OSS Distributions typedef struct thread_precedence_policy         *thread_precedence_policy_t;
186*bbb1b6f9SApple OSS Distributions 
187*bbb1b6f9SApple OSS Distributions #define THREAD_PRECEDENCE_POLICY_COUNT  ((mach_msg_type_number_t) \
188*bbb1b6f9SApple OSS Distributions 	(sizeof (thread_precedence_policy_data_t) / sizeof (integer_t)))
189*bbb1b6f9SApple OSS Distributions 
190*bbb1b6f9SApple OSS Distributions /*
191*bbb1b6f9SApple OSS Distributions  * THREAD_AFFINITY_POLICY:
192*bbb1b6f9SApple OSS Distributions  *
193*bbb1b6f9SApple OSS Distributions  * This policy is experimental.
194*bbb1b6f9SApple OSS Distributions  * This may be used to express affinity relationships
195*bbb1b6f9SApple OSS Distributions  * between threads in the task. Threads with the same affinity tag will
196*bbb1b6f9SApple OSS Distributions  * be scheduled to share an L2 cache if possible. That is, affinity tags
197*bbb1b6f9SApple OSS Distributions  * are a hint to the scheduler for thread placement.
198*bbb1b6f9SApple OSS Distributions  *
199*bbb1b6f9SApple OSS Distributions  * The namespace of affinity tags is generally local to one task. However,
200*bbb1b6f9SApple OSS Distributions  * a child task created after the assignment of affinity tags by its parent
201*bbb1b6f9SApple OSS Distributions  * will share that namespace. In particular, a family of forked processes
202*bbb1b6f9SApple OSS Distributions  * may be created with a shared affinity namespace.
203*bbb1b6f9SApple OSS Distributions  *
204*bbb1b6f9SApple OSS Distributions  * Parameters:
205*bbb1b6f9SApple OSS Distributions  * tag: The affinity set identifier.
206*bbb1b6f9SApple OSS Distributions  */
207*bbb1b6f9SApple OSS Distributions 
208*bbb1b6f9SApple OSS Distributions #define THREAD_AFFINITY_POLICY          4
209*bbb1b6f9SApple OSS Distributions 
210*bbb1b6f9SApple OSS Distributions struct thread_affinity_policy {
211*bbb1b6f9SApple OSS Distributions 	integer_t       affinity_tag;
212*bbb1b6f9SApple OSS Distributions };
213*bbb1b6f9SApple OSS Distributions 
214*bbb1b6f9SApple OSS Distributions #define THREAD_AFFINITY_TAG_NULL                0
215*bbb1b6f9SApple OSS Distributions 
216*bbb1b6f9SApple OSS Distributions typedef struct thread_affinity_policy           thread_affinity_policy_data_t;
217*bbb1b6f9SApple OSS Distributions typedef struct thread_affinity_policy           *thread_affinity_policy_t;
218*bbb1b6f9SApple OSS Distributions 
219*bbb1b6f9SApple OSS Distributions #define THREAD_AFFINITY_POLICY_COUNT    ((mach_msg_type_number_t) \
220*bbb1b6f9SApple OSS Distributions 	(sizeof (thread_affinity_policy_data_t) / sizeof (integer_t)))
221*bbb1b6f9SApple OSS Distributions 
222*bbb1b6f9SApple OSS Distributions /*
223*bbb1b6f9SApple OSS Distributions  * THREAD_BACKGROUND_POLICY:
224*bbb1b6f9SApple OSS Distributions  */
225*bbb1b6f9SApple OSS Distributions 
226*bbb1b6f9SApple OSS Distributions #define THREAD_BACKGROUND_POLICY        5
227*bbb1b6f9SApple OSS Distributions 
228*bbb1b6f9SApple OSS Distributions struct thread_background_policy {
229*bbb1b6f9SApple OSS Distributions 	integer_t       priority;
230*bbb1b6f9SApple OSS Distributions };
231*bbb1b6f9SApple OSS Distributions 
232*bbb1b6f9SApple OSS Distributions #define THREAD_BACKGROUND_POLICY_DARWIN_BG 0x1000
233*bbb1b6f9SApple OSS Distributions 
234*bbb1b6f9SApple OSS Distributions typedef struct thread_background_policy         thread_background_policy_data_t;
235*bbb1b6f9SApple OSS Distributions typedef struct thread_background_policy         *thread_background_policy_t;
236*bbb1b6f9SApple OSS Distributions 
237*bbb1b6f9SApple OSS Distributions #define THREAD_BACKGROUND_POLICY_COUNT  ((mach_msg_type_number_t) \
238*bbb1b6f9SApple OSS Distributions 	(sizeof (thread_background_policy_data_t) / sizeof (integer_t)))
239*bbb1b6f9SApple OSS Distributions 
240*bbb1b6f9SApple OSS Distributions 
241*bbb1b6f9SApple OSS Distributions #define THREAD_LATENCY_QOS_POLICY       7
242*bbb1b6f9SApple OSS Distributions typedef integer_t       thread_latency_qos_t;
243*bbb1b6f9SApple OSS Distributions 
244*bbb1b6f9SApple OSS Distributions struct thread_latency_qos_policy {
245*bbb1b6f9SApple OSS Distributions 	thread_latency_qos_t thread_latency_qos_tier;
246*bbb1b6f9SApple OSS Distributions };
247*bbb1b6f9SApple OSS Distributions 
248*bbb1b6f9SApple OSS Distributions typedef struct thread_latency_qos_policy        thread_latency_qos_policy_data_t;
249*bbb1b6f9SApple OSS Distributions typedef struct thread_latency_qos_policy        *thread_latency_qos_policy_t;
250*bbb1b6f9SApple OSS Distributions 
251*bbb1b6f9SApple OSS Distributions #define THREAD_LATENCY_QOS_POLICY_COUNT ((mach_msg_type_number_t)       \
252*bbb1b6f9SApple OSS Distributions 	    (sizeof (thread_latency_qos_policy_data_t) / sizeof (integer_t)))
253*bbb1b6f9SApple OSS Distributions 
254*bbb1b6f9SApple OSS Distributions #define THREAD_THROUGHPUT_QOS_POLICY    8
255*bbb1b6f9SApple OSS Distributions typedef integer_t       thread_throughput_qos_t;
256*bbb1b6f9SApple OSS Distributions 
257*bbb1b6f9SApple OSS Distributions struct thread_throughput_qos_policy {
258*bbb1b6f9SApple OSS Distributions 	thread_throughput_qos_t thread_throughput_qos_tier;
259*bbb1b6f9SApple OSS Distributions };
260*bbb1b6f9SApple OSS Distributions 
261*bbb1b6f9SApple OSS Distributions typedef struct thread_throughput_qos_policy     thread_throughput_qos_policy_data_t;
262*bbb1b6f9SApple OSS Distributions typedef struct thread_throughput_qos_policy     *thread_throughput_qos_policy_t;
263*bbb1b6f9SApple OSS Distributions 
264*bbb1b6f9SApple OSS Distributions #define THREAD_THROUGHPUT_QOS_POLICY_COUNT      ((mach_msg_type_number_t) \
265*bbb1b6f9SApple OSS Distributions 	    (sizeof (thread_throughput_qos_policy_data_t) / sizeof (integer_t)))
266*bbb1b6f9SApple OSS Distributions 
267*bbb1b6f9SApple OSS Distributions #ifdef PRIVATE
268*bbb1b6f9SApple OSS Distributions #include <mach/thread_policy_private.h>
269*bbb1b6f9SApple OSS Distributions #endif
270*bbb1b6f9SApple OSS Distributions 
271*bbb1b6f9SApple OSS Distributions #endif  /* _MACH_THREAD_POLICY_H_ */
272