1 /* 2 * Copyright (c) 2000-2008 Apple 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 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ 29 /* 30 * Copyright (c) 1982, 1986, 1993 31 * The Regents of the University of California. All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 3. All advertising materials mentioning features or use of this software 42 * must display the following acknowledgement: 43 * This product includes software developed by the University of 44 * California, Berkeley and its contributors. 45 * 4. Neither the name of the University nor the names of its contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * @(#)resource.h 8.2 (Berkeley) 1/4/94 62 */ 63 64 #ifndef _SYS_RESOURCE_H_ 65 #define _SYS_RESOURCE_H_ 66 #include <Availability.h> 67 68 69 #include <sys/appleapiopts.h> 70 #include <sys/cdefs.h> 71 #include <sys/_types.h> 72 73 #undef _SYS_RESOURCE_H_ 74 #include_next <sys/resource.h> 75 76 #if 0 77 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 78 #include <stdint.h> 79 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 80 81 #ifndef KERNEL 82 #include <Availability.h> 83 #endif 84 85 /* [XSI] The timeval structure shall be defined as described in 86 * <sys/time.h> 87 */ 88 #include <sys/_types/_timeval.h> 89 #ifdef KERNEL 90 #include <sys/_types/_user32_timeval.h> 91 #include <sys/_types/_user64_timeval.h> 92 #endif 93 94 /* The id_t type shall be defined as described in <sys/types.h> */ 95 #include <sys/_types/_id_t.h> 96 97 98 /* 99 * Resource limit type (low 63 bits, excluding the sign bit) 100 */ 101 typedef __uint64_t rlim_t; 102 103 104 /***** 105 * PRIORITY 106 */ 107 108 /* 109 * Possible values of the first parameter to getpriority()/setpriority(), 110 * used to indicate the type of the second parameter. 111 */ 112 #define PRIO_PROCESS 0 /* Second argument is a PID */ 113 #define PRIO_PGRP 1 /* Second argument is a GID */ 114 #define PRIO_USER 2 /* Second argument is a UID */ 115 116 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 117 #define PRIO_DARWIN_THREAD 3 /* Second argument is always 0 (current thread) */ 118 #define PRIO_DARWIN_PROCESS 4 /* Second argument is a PID */ 119 120 #ifdef PRIVATE 121 122 #define PRIO_DARWIN_GPU 5 /* Second argument is a PID */ 123 124 #define PRIO_DARWIN_GPU_ALLOW 0x1 125 #define PRIO_DARWIN_GPU_DENY 0x2 126 127 #define PRIO_DARWIN_ROLE 6 /* Second argument is a PID */ 128 129 #define PRIO_DARWIN_ROLE_DEFAULT 0x0 /* Default state */ 130 #define PRIO_DARWIN_ROLE_UI_FOCAL 0x1 /* On screen, focal UI */ 131 #define PRIO_DARWIN_ROLE_UI 0x2 /* On screen, non-focal UI */ 132 #define PRIO_DARWIN_ROLE_NON_UI 0x3 /* Off screen, non-focal UI */ 133 134 #endif /* PRIVATE */ 135 136 /* 137 * Range limitations for the value of the third parameter to setpriority(). 138 */ 139 #define PRIO_MIN -20 140 #define PRIO_MAX 20 141 142 /* 143 * use PRIO_DARWIN_BG to set the current thread into "background" state 144 * which lowers CPU, disk IO, and networking priorites until thread terminates 145 * or "background" state is revoked 146 */ 147 #define PRIO_DARWIN_BG 0x1000 148 149 /* 150 * use PRIO_DARWIN_NONUI to restrict a process's ability to make calls to 151 * the GPU. (deprecated) 152 */ 153 #define PRIO_DARWIN_NONUI 0x1001 154 155 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 156 157 158 159 /***** 160 * RESOURCE USAGE 161 */ 162 163 /* 164 * Possible values of the first parameter to getrusage(), used to indicate 165 * the scope of the information to be returned. 166 */ 167 #define RUSAGE_SELF 0 /* Current process information */ 168 #define RUSAGE_CHILDREN -1 /* Current process' children */ 169 170 /* 171 * A structure representing an accounting of resource utilization. The 172 * address of an instance of this structure is the second parameter to 173 * getrusage(). 174 * 175 * Note: All values other than ru_utime and ru_stime are implementaiton 176 * defined and subject to change in a future release. Their use 177 * is discouraged for standards compliant programs. 178 */ 179 struct rusage { 180 struct timeval ru_utime; /* user time used (PL) */ 181 struct timeval ru_stime; /* system time used (PL) */ 182 #if __DARWIN_C_LEVEL < __DARWIN_C_FULL 183 long ru_opaque[14]; /* implementation defined */ 184 #else 185 /* 186 * Informational aliases for source compatibility with programs 187 * that need more information than that provided by standards, 188 * and which do not mind being OS-dependent. 189 */ 190 long ru_maxrss; /* max resident set size (PL) */ 191 #define ru_first ru_ixrss /* internal: ruadd() range start */ 192 long ru_ixrss; /* integral shared memory size (NU) */ 193 long ru_idrss; /* integral unshared data (NU) */ 194 long ru_isrss; /* integral unshared stack (NU) */ 195 long ru_minflt; /* page reclaims (NU) */ 196 long ru_majflt; /* page faults (NU) */ 197 long ru_nswap; /* swaps (NU) */ 198 long ru_inblock; /* block input operations (atomic) */ 199 long ru_oublock; /* block output operations (atomic) */ 200 long ru_msgsnd; /* messages sent (atomic) */ 201 long ru_msgrcv; /* messages received (atomic) */ 202 long ru_nsignals; /* signals received (atomic) */ 203 long ru_nvcsw; /* voluntary context switches (atomic) */ 204 long ru_nivcsw; /* involuntary " */ 205 #define ru_last ru_nivcsw /* internal: ruadd() range end */ 206 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 207 }; 208 #endif 209 210 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 211 /* 212 * Flavors for proc_pid_rusage(). 213 */ 214 #define RUSAGE_INFO_V0 0 215 #define RUSAGE_INFO_V1 1 216 #define RUSAGE_INFO_V2 2 217 #define RUSAGE_INFO_V3 3 218 #define RUSAGE_INFO_CURRENT RUSAGE_INFO_V3 219 220 221 typedef void *rusage_info_t; 222 223 struct rusage_info_v0 { 224 uint8_t ri_uuid[16]; 225 uint64_t ri_user_time; 226 uint64_t ri_system_time; 227 uint64_t ri_pkg_idle_wkups; 228 uint64_t ri_interrupt_wkups; 229 uint64_t ri_pageins; 230 uint64_t ri_wired_size; 231 uint64_t ri_resident_size; 232 uint64_t ri_phys_footprint; 233 uint64_t ri_proc_start_abstime; 234 uint64_t ri_proc_exit_abstime; 235 }; 236 237 struct rusage_info_v1 { 238 uint8_t ri_uuid[16]; 239 uint64_t ri_user_time; 240 uint64_t ri_system_time; 241 uint64_t ri_pkg_idle_wkups; 242 uint64_t ri_interrupt_wkups; 243 uint64_t ri_pageins; 244 uint64_t ri_wired_size; 245 uint64_t ri_resident_size; 246 uint64_t ri_phys_footprint; 247 uint64_t ri_proc_start_abstime; 248 uint64_t ri_proc_exit_abstime; 249 uint64_t ri_child_user_time; 250 uint64_t ri_child_system_time; 251 uint64_t ri_child_pkg_idle_wkups; 252 uint64_t ri_child_interrupt_wkups; 253 uint64_t ri_child_pageins; 254 uint64_t ri_child_elapsed_abstime; 255 }; 256 257 struct rusage_info_v2 { 258 uint8_t ri_uuid[16]; 259 uint64_t ri_user_time; 260 uint64_t ri_system_time; 261 uint64_t ri_pkg_idle_wkups; 262 uint64_t ri_interrupt_wkups; 263 uint64_t ri_pageins; 264 uint64_t ri_wired_size; 265 uint64_t ri_resident_size; 266 uint64_t ri_phys_footprint; 267 uint64_t ri_proc_start_abstime; 268 uint64_t ri_proc_exit_abstime; 269 uint64_t ri_child_user_time; 270 uint64_t ri_child_system_time; 271 uint64_t ri_child_pkg_idle_wkups; 272 uint64_t ri_child_interrupt_wkups; 273 uint64_t ri_child_pageins; 274 uint64_t ri_child_elapsed_abstime; 275 uint64_t ri_diskio_bytesread; 276 uint64_t ri_diskio_byteswritten; 277 }; 278 279 struct rusage_info_v3 { 280 uint8_t ri_uuid[16]; 281 uint64_t ri_user_time; 282 uint64_t ri_system_time; 283 uint64_t ri_pkg_idle_wkups; 284 uint64_t ri_interrupt_wkups; 285 uint64_t ri_pageins; 286 uint64_t ri_wired_size; 287 uint64_t ri_resident_size; 288 uint64_t ri_phys_footprint; 289 uint64_t ri_proc_start_abstime; 290 uint64_t ri_proc_exit_abstime; 291 uint64_t ri_child_user_time; 292 uint64_t ri_child_system_time; 293 uint64_t ri_child_pkg_idle_wkups; 294 uint64_t ri_child_interrupt_wkups; 295 uint64_t ri_child_pageins; 296 uint64_t ri_child_elapsed_abstime; 297 uint64_t ri_diskio_bytesread; 298 uint64_t ri_diskio_byteswritten; 299 uint64_t ri_cpu_time_qos_default; 300 uint64_t ri_cpu_time_qos_maintenance; 301 uint64_t ri_cpu_time_qos_background; 302 uint64_t ri_cpu_time_qos_utility; 303 uint64_t ri_cpu_time_qos_legacy; 304 uint64_t ri_cpu_time_qos_user_initiated; 305 uint64_t ri_cpu_time_qos_user_interactive; 306 uint64_t ri_billed_system_time; 307 uint64_t ri_serviced_system_time; 308 }; 309 310 typedef struct rusage_info_v3 rusage_info_current; 311 312 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 313 314 #ifdef KERNEL 315 316 struct rusage_superset { 317 struct rusage ru; 318 rusage_info_current ri; 319 }; 320 321 struct rusage_info_child { 322 uint64_t ri_child_user_time; 323 uint64_t ri_child_system_time; 324 uint64_t ri_child_pkg_idle_wkups; 325 uint64_t ri_child_interrupt_wkups; 326 uint64_t ri_child_pageins; 327 uint64_t ri_child_elapsed_abstime; 328 }; 329 330 struct user64_rusage { 331 struct user64_timeval ru_utime; /* user time used */ 332 struct user64_timeval ru_stime; /* system time used */ 333 user64_long_t ru_maxrss; /* max resident set size */ 334 user64_long_t ru_ixrss; /* integral shared memory size */ 335 user64_long_t ru_idrss; /* integral unshared data " */ 336 user64_long_t ru_isrss; /* integral unshared stack " */ 337 user64_long_t ru_minflt; /* page reclaims */ 338 user64_long_t ru_majflt; /* page faults */ 339 user64_long_t ru_nswap; /* swaps */ 340 user64_long_t ru_inblock; /* block input operations */ 341 user64_long_t ru_oublock; /* block output operations */ 342 user64_long_t ru_msgsnd; /* messages sent */ 343 user64_long_t ru_msgrcv; /* messages received */ 344 user64_long_t ru_nsignals; /* signals received */ 345 user64_long_t ru_nvcsw; /* voluntary context switches */ 346 user64_long_t ru_nivcsw; /* involuntary " */ 347 }; 348 349 struct user32_rusage { 350 struct user32_timeval ru_utime; /* user time used */ 351 struct user32_timeval ru_stime; /* system time used */ 352 user32_long_t ru_maxrss; /* max resident set size */ 353 user32_long_t ru_ixrss; /* integral shared memory size */ 354 user32_long_t ru_idrss; /* integral unshared data " */ 355 user32_long_t ru_isrss; /* integral unshared stack " */ 356 user32_long_t ru_minflt; /* page reclaims */ 357 user32_long_t ru_majflt; /* page faults */ 358 user32_long_t ru_nswap; /* swaps */ 359 user32_long_t ru_inblock; /* block input operations */ 360 user32_long_t ru_oublock; /* block output operations */ 361 user32_long_t ru_msgsnd; /* messages sent */ 362 user32_long_t ru_msgrcv; /* messages received */ 363 user32_long_t ru_nsignals; /* signals received */ 364 user32_long_t ru_nvcsw; /* voluntary context switches */ 365 user32_long_t ru_nivcsw; /* involuntary " */ 366 }; 367 368 #endif /* KERNEL */ 369 370 371 /***** 372 * RESOURCE LIMITS 373 */ 374 375 /* 376 * Symbolic constants for resource limits; since all limits are representable 377 * as a type rlim_t, we are permitted to define RLIM_SAVED_* in terms of 378 * RLIM_INFINITY. 379 */ 380 #if 0 381 #define RLIM_INFINITY (((__uint64_t)1 << 63) - 1) /* no limit */ 382 #endif 383 #define RLIM_SAVED_MAX RLIM_INFINITY /* Unrepresentable hard limit */ 384 #define RLIM_SAVED_CUR RLIM_INFINITY /* Unrepresentable soft limit */ 385 386 /* 387 * Possible values of the first parameter to getrlimit()/setrlimit(), to 388 * indicate for which resource the operation is being performed. 389 */ 390 #define RLIMIT_CPU 0 /* cpu time per process */ 391 #define RLIMIT_FSIZE 1 /* file size */ 392 #define RLIMIT_DATA 2 /* data segment size */ 393 #define RLIMIT_STACK 3 /* stack size */ 394 #define RLIMIT_CORE 4 /* core file size */ 395 #if 0 396 #define RLIMIT_AS 5 /* address space (resident set size) */ 397 #endif 398 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 399 #if 0 400 #define RLIMIT_RSS RLIMIT_AS /* source compatibility alias */ 401 #endif 402 #define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */ 403 #define RLIMIT_NPROC 7 /* number of processes */ 404 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 405 #define RLIMIT_NOFILE 8 /* number of open files */ 406 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 407 #if 0 408 #define RLIM_NLIMITS 9 /* total number of resource limits */ 409 #endif 410 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 411 #define _RLIMIT_POSIX_FLAG 0x1000 /* Set bit for strict POSIX */ 412 413 /* 414 * A structure representing a resource limit. The address of an instance 415 * of this structure is the second parameter to getrlimit()/setrlimit(). 416 */ 417 #if 0 418 struct rlimit { 419 rlim_t rlim_cur; /* current (soft) limit */ 420 rlim_t rlim_max; /* maximum value for rlim_cur */ 421 }; 422 #endif 423 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 424 /* 425 * proc_rlimit_control() 426 * 427 * Resource limit flavors 428 */ 429 #define RLIMIT_WAKEUPS_MONITOR 0x1 /* Configure the wakeups monitor. */ 430 #define RLIMIT_CPU_USAGE_MONITOR 0x2 /* Configure the CPU usage monitor. */ 431 #define RLIMIT_THREAD_CPULIMITS 0x3 /* Configure a blocking, per-thread, CPU limits. */ 432 433 /* 434 * Flags for wakeups monitor control. 435 */ 436 #define WAKEMON_ENABLE 0x01 437 #define WAKEMON_DISABLE 0x02 438 #define WAKEMON_GET_PARAMS 0x04 439 #define WAKEMON_SET_DEFAULTS 0x08 440 #define WAKEMON_MAKE_FATAL 0x10 /* Configure the task so that violations are fatal. */ 441 /* 442 * Flags for CPU usage monitor control. 443 */ 444 #define CPUMON_MAKE_FATAL 0x1000 445 446 struct proc_rlimit_control_wakeupmon { 447 uint32_t wm_flags; 448 int32_t wm_rate; 449 }; 450 451 /* I/O type */ 452 #define IOPOL_TYPE_DISK 0 453 #if PRIVATE 454 #define IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY 1 455 #endif 456 457 /* scope */ 458 #define IOPOL_SCOPE_PROCESS 0 459 #define IOPOL_SCOPE_THREAD 1 460 #define IOPOL_SCOPE_DARWIN_BG 2 461 462 /* I/O Priority */ 463 #define IOPOL_DEFAULT 0 464 #define IOPOL_IMPORTANT 1 465 #define IOPOL_PASSIVE 2 466 #define IOPOL_THROTTLE 3 467 #define IOPOL_UTILITY 4 468 #define IOPOL_STANDARD 5 469 470 /* compatibility with older names */ 471 #define IOPOL_APPLICATION IOPOL_STANDARD 472 #define IOPOL_NORMAL IOPOL_IMPORTANT 473 474 #if PRIVATE 475 #define IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT 0 476 #define IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE 1 477 #endif 478 479 #ifdef PRIVATE 480 /* 481 * Structures for use in communicating via iopolicysys() between Libc and the 482 * kernel. Not to be used by user programs directly. 483 */ 484 485 /* 486 * the command to iopolicysys() 487 */ 488 #define IOPOL_CMD_GET 0x00000001 /* Get I/O policy */ 489 #define IOPOL_CMD_SET 0x00000002 /* Set I/O policy */ 490 491 /* 492 * Second parameter to iopolicysys() 493 */ 494 struct _iopol_param_t { 495 int iop_scope; /* current process or a thread */ 496 int iop_iotype; 497 int iop_policy; 498 }; 499 500 #endif /* PRIVATE */ 501 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 502 503 #ifndef KERNEL 504 505 __BEGIN_DECLS 506 #if 0 507 int getpriority(int, id_t); 508 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 509 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 510 int getrlimit(int, struct rlimit *) __DARWIN_ALIAS(getrlimit); 511 int getrusage(int, struct rusage *); 512 int setpriority(int, id_t, int); 513 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 514 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 515 int setrlimit(int, const struct rlimit *) __DARWIN_ALIAS(setrlimit); 516 #endif 517 518 int getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 519 int setiopolicy_np(int, int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 520 __END_DECLS 521 522 #endif /* !KERNEL */ 523 #endif /* !_SYS_RESOURCE_H_ */ 524