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_H_
30 #define _MACH_TASK_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 task.
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 
51 typedef natural_t       task_policy_flavor_t;
52 typedef integer_t       *task_policy_t;
53 
54 /*
55  *  kern_return_t	task_policy_set(
56  *                                       task_t					task,
57  *                                       task_policy_flavor_t	flavor,
58  *                                       task_policy_t			policy_info,
59  *                                       mach_msg_type_number_t	count);
60  *
61  *  kern_return_t	task_policy_get(
62  *                                       task_t					task,
63  *                                       task_policy_flavor_t	flavor,
64  *                                       task_policy_t			policy_info,
65  *                                       mach_msg_type_number_t	*count,
66  *                                       boolean_t				*get_default);
67  */
68 
69 /*
70  * Defined flavors.
71  */
72 /*
73  * TASK_CATEGORY_POLICY:
74  *
75  * This provides information to the kernel about the role
76  * of the task in the system.
77  *
78  * Parameters:
79  *
80  * role: Enumerated as follows:
81  *
82  * TASK_UNSPECIFIED is the default, since the role is not
83  * inherited from the parent.
84  *
85  * TASK_FOREGROUND_APPLICATION should be assigned when the
86  * task is a normal UI application in the foreground from
87  * the HI point of view.
88  * **N.B. There may be more than one of these at a given time.
89  *
90  * TASK_BACKGROUND_APPLICATION should be assigned when the
91  * task is a normal UI application in the background from
92  * the HI point of view.
93  *
94  * TASK_CONTROL_APPLICATION should be assigned to the unique
95  * UI application which implements the pop-up application dialog.
96  * There can only be one task at a time with this designation,
97  * which is assigned FCFS.
98  *
99  * TASK_GRAPHICS_SERVER should be assigned to the graphics
100  * management (window) server.  There can only be one task at
101  * a time with this designation, which is assigned FCFS.
102  */
103 
104 #define TASK_CATEGORY_POLICY            1
105 
106 #define TASK_SUPPRESSION_POLICY         3
107 #define TASK_POLICY_STATE               4
108 #define TASK_BASE_QOS_POLICY            8
109 #define TASK_OVERRIDE_QOS_POLICY        9
110 #define TASK_BASE_LATENCY_QOS_POLICY    10
111 #define TASK_BASE_THROUGHPUT_QOS_POLICY 11
112 
113 
114 enum task_role {
115 	TASK_RENICED                    = -1,
116 	TASK_UNSPECIFIED                = 0,
117 	TASK_FOREGROUND_APPLICATION     = 1,
118 	TASK_BACKGROUND_APPLICATION     = 2,
119 	TASK_CONTROL_APPLICATION        = 3,
120 	TASK_GRAPHICS_SERVER            = 4,
121 	TASK_THROTTLE_APPLICATION       = 5,
122 	TASK_NONUI_APPLICATION          = 6,
123 	TASK_DEFAULT_APPLICATION        = 7,
124 	TASK_DARWINBG_APPLICATION       = 8,
125 };
126 
127 typedef integer_t       task_role_t;
128 
129 struct task_category_policy {
130 	task_role_t             role;
131 };
132 
133 typedef struct task_category_policy             task_category_policy_data_t;
134 typedef struct task_category_policy             *task_category_policy_t;
135 
136 #define TASK_CATEGORY_POLICY_COUNT      ((mach_msg_type_number_t) \
137 	(sizeof (task_category_policy_data_t) / sizeof (integer_t)))
138 
139 
140 enum task_latency_qos {
141 	LATENCY_QOS_TIER_UNSPECIFIED = 0x0,
142 	LATENCY_QOS_TIER_0 = ((0xFF << 16) | 1),
143 	LATENCY_QOS_TIER_1 = ((0xFF << 16) | 2),
144 	LATENCY_QOS_TIER_2 = ((0xFF << 16) | 3),
145 	LATENCY_QOS_TIER_3 = ((0xFF << 16) | 4),
146 	LATENCY_QOS_TIER_4 = ((0xFF << 16) | 5),
147 	LATENCY_QOS_TIER_5 = ((0xFF << 16) | 6)
148 };
149 typedef integer_t       task_latency_qos_t;
150 enum task_throughput_qos {
151 	THROUGHPUT_QOS_TIER_UNSPECIFIED = 0x0,
152 	THROUGHPUT_QOS_TIER_0 = ((0xFE << 16) | 1),
153 	THROUGHPUT_QOS_TIER_1 = ((0xFE << 16) | 2),
154 	THROUGHPUT_QOS_TIER_2 = ((0xFE << 16) | 3),
155 	THROUGHPUT_QOS_TIER_3 = ((0xFE << 16) | 4),
156 	THROUGHPUT_QOS_TIER_4 = ((0xFE << 16) | 5),
157 	THROUGHPUT_QOS_TIER_5 = ((0xFE << 16) | 6),
158 };
159 
160 #define LATENCY_QOS_LAUNCH_DEFAULT_TIER LATENCY_QOS_TIER_3
161 #define THROUGHPUT_QOS_LAUNCH_DEFAULT_TIER THROUGHPUT_QOS_TIER_3
162 
163 typedef integer_t       task_throughput_qos_t;
164 
165 struct task_qos_policy {
166 	task_latency_qos_t task_latency_qos_tier;
167 	task_throughput_qos_t task_throughput_qos_tier;
168 };
169 
170 typedef struct task_qos_policy *task_qos_policy_t;
171 #define TASK_QOS_POLICY_COUNT   ((mach_msg_type_number_t) \
172 	(sizeof (struct task_qos_policy) / sizeof (integer_t)))
173 
174 /* These should be removed - they belong in proc_info.h */
175 #define PROC_FLAG_DARWINBG           0x8000    /* process in darwin background */
176 #define PROC_FLAG_EXT_DARWINBG           0x10000   /* process in darwin background - external enforcement */
177 #define PROC_FLAG_IOS_APPLEDAEMON    0x20000   /* process is apple ios daemon */
178 #define PROC_FLAG_IOS_IMPPROMOTION   0x80000   /* process is apple ios daemon */
179 #define PROC_FLAG_ADAPTIVE           0x100000  /* Process is adaptive */
180 #define PROC_FLAG_ADAPTIVE_IMPORTANT 0x200000  /* Process is adaptive, and is currently important */
181 #define PROC_FLAG_IMPORTANCE_DONOR   0x400000  /* Process is marked as an importance donor */
182 #define PROC_FLAG_SUPPRESSED         0x800000  /* Process is suppressed */
183 #define PROC_FLAG_APPLICATION        0x1000000 /* Process is an application */
184 #define PROC_FLAG_IOS_APPLICATION PROC_FLAG_APPLICATION /* Process is an application */
185 
186 
187 
188 
189 #endif  /* _MACH_TASK_POLICY_H_ */