]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/process_policy.h
3e389da3d3fdaea0988808868b58fa92e963bd86
[apple/xnu.git] / bsd / sys / process_policy.h
1 /*
2 * Copyright (c) 2010 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 _SYS_PROCESS_POLICY_H
30 #define _SYS_PROCESS_POLICY_H
31
32 #include <sys/cdefs.h>
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <stdint.h>
36
37 #if defined(XNU_KERNEL_PRIVATE)
38
39 #if defined(XNU_TARGET_OS_OSX)
40 #define PROCESS_POLICY_OSX 1
41 #else /* defined(XNU_TARGET_OS_OSX) */
42 #define PROCESS_POLICY_OSX 0
43 #endif /* defined(XNU_TARGET_OS_OSX) */
44
45 #else /* defined(XNU_KERNEL_PRIVATE) */
46
47 #include <TargetConditionals.h>
48
49 #define PROCESS_POLICY_OSX !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
50 #endif /* defined(XNU_KERNEL_PRIVATE) */
51
52 __BEGIN_DECLS
53
54 /* defns of scope */
55 #define PROC_POLICY_SCOPE_PROCESS 1 /* the policy setting is for process wide effect */
56 #define PROC_POLICY_SCOPE_THREAD 2 /* the policy setting is for thread inside a proc */
57
58 /* defns of actions with no attributes */
59 #define PROC_POLICY_ACTION_APPLY 1 /* enforce the set policy */
60 #define PROC_POLICY_ACTION_RESTORE 2 /* revert the applied action back */
61 #define PROC_POLICY_ACTION_DENYINHERIT 3 /* set for no inheritence of the specified policy */
62 #define PROC_POLICY_ACTION_DENYSELFSET 4 /* set for the process to set its own policy */
63 #define PROC_POLICY_ACTION_ENABLE 5 /* enable policy and its actions */
64 #define PROC_POLICY_ACTION_DISABLE 6 /* disable policy and its actions, also clears any actions that have already happened */
65 /* defns of actions with attributes */
66 #define PROC_POLICY_ACTION_SET 10 /* set the policy attributes */
67 #define PROC_POLICY_ACTION_GET 11 /* get the policy attributes */
68 #define PROC_POLICY_ACTION_ADD 12 /* add a policy attribute */
69 #define PROC_POLICY_ACTION_REMOVE 13 /* remove a policy attribute */
70 #define PROC_POLICY_ACTION_HOLD 14 /* hold an importance boost assertion */
71 #define PROC_POLICY_ACTION_DROP 15 /* drop an importance boost assertion */
72
73 /* policies */
74 #define PROC_POLICY NONE 0
75 #define PROC_POLICY_BACKGROUND 1 /* darwin background policy */
76 #define PROC_POLICY_HARDWARE_ACCESS 2 /* access to various hardware */
77 #define PROC_POLICY_RESOURCE_STARVATION 3 /* behavior on resource starvation */
78 #define PROC_POLICY_RESOURCE_USAGE 4 /* behavior on resource consumption */
79 #if !PROCESS_POLICY_OSX
80 #define PROC_POLICY_APP_LIFECYCLE 5 /* app life cycle management */
81 #else /* !PROCESS_POLICY_OSX */
82 #define PROC_POLICY_RESERVED 5 /* behavior on resource consumption */
83 #endif /* !PROCESS_POLICY_OSX */
84 #define PROC_POLICY_APPTYPE 6 /* behavior on resource consumption */
85 #define PROC_POLICY_BOOST 7 /* importance boost/drop */
86 #define PROC_POLICY_NO_SMT 8 /* Disallow Simultaneous Multi-Threading */
87 #define PROC_POLICY_TECS 9 /* Enable CPU security for threads */
88
89 /* sub policies for background policy */
90 #define PROC_POLICY_BG_NONE 0 /* none */
91 #define PROC_POLICY_BG_LOWCPUPRI 1 /* Low cpu priority */
92 #define PROC_POLICY_BG_DISKTHROTTLE 2 /* disk accesses throttled */
93 #define PROC_POLICY_BG_NETTHROTTLE 4 /* network accesses throttled */
94 #define PROC_POLICY_BG_GPUDENY 8 /* no access to GPU */
95 #if !PROCESS_POLICY_OSX
96 #define PROC_POLICY_BG_ALL 0x0F
97 #else /* !PROCESS_POLICY_OSX */
98 #define PROC_POLICY_BG_ALL 0x07
99 #endif /* !PROCESS_POLICY_OSX */
100 #define PROC_POLICY_BG_DEFAULT PROC_POLICY_BG_ALL
101
102 /* sub policies for hardware */
103 #define PROC_POLICY_HWACCESS_NONE 0
104 #define PROC_POLICY_HWACCESS_DISK 1 /* disk access */
105 #define PROC_POLICY_HWACCESS_GPU 2 /* GPU access */
106 #define PROC_POLICY_HWACCESS_NETWORK 3 /* network access */
107 #define PROC_POLICY_HWACCESS_CPU 4 /* cpu access */
108
109 /* attribute values for disk hardware access, bit different as it should reflect IOPOL_XXX */
110 #define PROC_POLICY_DISKACC_NONE 0
111 #define PROC_POLICY_DISKACC_NORMAL 1 /* normal access to the disk */
112 #define PROC_POLICY_DISKACC_FULLACCESS 1 /* normal access to the disk */
113 #define PROC_POLICY_DISKACC_PASSIVE 2 /* treat the I/Os as passive */
114 #define PROC_POLICY_DISKACC_THROTTLE 3 /* throttle the disk IOs */
115 #define PROC_POLICY_DISKACC_DEFAULT PROC_POLICY_DISKACC_FULLACCESS
116
117 /* attribute values for GPU hardware access */
118 #define PROC_POLICY_GPUACC_NONE 0
119 #define PROC_POLICY_GPUACC_FULLACCESS 0 /* complete access to the GPU */
120 #define PROC_POLICY_GPUACC_DENYACCESS 1 /* deny any access to the GPU */
121 #define PROC_POLICY_GPUACC_DEFAULT PROC_POLICY_GPUACC_FULLACCESS /* default is complete access */
122
123 /* atrribute values for network hardware access */
124 #define PROC_POLICY_NETACC_NONE 0
125 #define PROC_POLICY_NETACC_FULLACCESS 0 /* complete access to the network */
126 #define PROC_POLICY_NETACC_THROTTLE 1 /* throttle access to network */
127 #define PROC_POLICY_NETACC_DEFAULT PROC_POLICY_NETACC_FULLACCESS /* default is complete access */
128
129 /* atrribute values for network hardware access */
130 #define PROC_POLICY_CPUACC_NONE 0
131 #define PROC_POLICY_CPUACC_FULLACCESS 0 /* access to all avialable cpus */
132 #define PROC_POLICY_CPUACC_ONE 1 /* access to only one available cpu */
133 #define PROC_POLICY_CPUACC_LLCACHE 2 /* access to only one last level cache */
134 #define PROC_POLICY_CPUACC_DEFAULT PROC_POLICY_CPUACC_FULLACCESS /* default is access to all cpus */
135
136
137 /* System Resource management (ie usage and starvation related) definitions */
138
139 /* sub policies for resource starvation */
140 #define PROC_POLICY_RS_NONE 0
141 #define PROC_POLICY_RS_VIRTUALMEM 1 /* virtual memory starvation */
142
143 /* sub policies for resource usage */
144 #define PROC_POLICY_RUSAGE_NONE 0
145 #define PROC_POLICY_RUSAGE_WIREDMEM 1 /* wired memory usages */
146 #define PROC_POLICY_RUSAGE_VIRTMEM 2 /* virtual memory usage */
147 #define PROC_POLICY_RUSAGE_CPU 3 /* amount of cpu usage */
148 #define PROC_POLICY_RUSAGE_DISK 4 /* amount of disk usage */
149 #define PROC_POLICY_RUSAGE_NETWORK 5 /* amount of network usage */
150 #define PROC_POLICY_RUSAGE_POWER 6 /* amount of power/battery consumption */
151
152 /* attribute values for the resource usage and low resource - MUST match corresponding task definitions */
153 #define PROC_POLICY_RSRCACT_NONE 0
154 #define PROC_POLICY_RSRCACT_THROTTLE 1 /* throttle on resource condition */
155 #define PROC_POLICY_RSRCACT_SUSPEND 2 /* suspend on resource condition */
156 #define PROC_POLICY_RSRCACT_TERMINATE 3 /* kill on resource condition */
157 #define PROC_POLICY_RSRCACT_NOTIFY_KQ 4 /* send kqueue notification */
158 #define PROC_POLICY_RSRCACT_NOTIFY_EXC 5 /* send exception */
159
160 #define PROC_POLICY_CPUMON_DISABLE 0xFF /* Disable CPU usage monitor */
161 #define PROC_POLICY_CPUMON_DEFAULTS 0xFE /* Set default CPU usage monitor params */
162
163 /* sub policies for importance boost/drop */
164 #define PROC_POLICY_IMP_IMPORTANT 1 /* Important-level boost */
165 #define PROC_POLICY_IMP_STANDARD 2 /* Standard-level boost */
166 #define PROC_POLICY_IMP_DONATION 3 /* Mark a task as an importance source */
167
168 typedef struct proc_policy_attribute {
169 uint32_t ppattr_attribute; /* the policy attribute to be modified or returned */
170 uint32_t ppattr_resv; /* pad field */
171 uint64_t ppattr_value1; /* 64bit policy specific attribute */
172 uint64_t ppattr_value2; /* 64bit policy specific attribute */
173 uint64_t ppattr_value3; /* 64bit policy specific attribute */
174 uint64_t ppattr_resv1[4]; /* reserved for future use */
175 } proc_policy_attribute_t;
176
177
178 typedef struct proc_policy_cpuusage_attr {
179 uint32_t ppattr_cpu_attr; /* specified action as in PROC_POLICY_RSRCACT_xx */
180 uint32_t ppattr_cpu_percentage; /* percentage of interval */
181 uint64_t ppattr_cpu_attr_interval; /* 64bit interval in nsecs */
182 uint64_t ppattr_cpu_attr_deadline; /* 64bit deadline in nsecs */
183 } proc_policy_cpuusage_attr_t;
184
185 #if !PROCESS_POLICY_OSX
186 /* sub policies for app lifecycle management */
187 #define PROC_POLICY_APPLIFE_NONE 0 /* does nothing.. */
188 #define PROC_POLICY_APPLIFE_STATE 1 /* sets the app to various lifecycle states */
189 #define PROC_POLICY_APPLIFE_DEVSTATUS 2 /* notes the device in inactive or short/long term */
190 #define PROC_POLICY_APPLIFE_PIDBIND 3 /* a thread is to be bound to another processes app state */
191 #endif /* !PROCESS_POLICY_OSX */
192
193 /* sub policies for PROC_POLICY_APPTYPE */
194 #define PROC_POLICY_APPTYPE_NONE 0 /* does nothing.. */
195 #define PROC_POLICY_APPTYPE_MODIFY 1 /* sets the app to various lifecycle states */
196 #if !PROCESS_POLICY_OSX
197 #define PROC_POLICY_APPTYPE_THREADTHR 2 /* notes the device in inactive or short/long term */
198 #endif /* !PROCESS_POLICY_OSX */
199
200 /* exported apptypes for PROC_POLICY_APPTYPE */
201 #define PROC_POLICY_OSX_APPTYPE_TAL 1 /* TAL-launched app */
202
203 #define PROC_POLICY_OSX_APPTYPE_DASHCLIENT 2 /* Dashboard client (deprecated) */
204 #define PROC_POLICY_IOS_DONATEIMP 6 /* donates priority imp (deprecated) */
205 #define PROC_POLICY_IOS_HOLDIMP 7 /* hold importance assertion (deprecated) */
206 #define PROC_POLICY_IOS_DROPIMP 8 /* drop importance assertion (deprecated) */
207
208 #ifndef KERNEL
209 int process_policy(int scope, int action, int policy, int policy_subtype, proc_policy_attribute_t * attrp, pid_t target_pid, uint64_t target_threadid);
210 #endif /* KERNEL */
211
212
213 __END_DECLS
214
215 #endif /*_SYS_PROCESS_POLICY_H */