1 /* 2 * Copyright (c) 2000-2021 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 29 #ifndef _SYS_RESOURCE_PRIVATE_H_ 30 #define _SYS_RESOURCE_PRIVATE_H_ 31 32 #include <os/base.h> 33 #include <stdint.h> 34 #include <sys/cdefs.h> 35 36 /* 37 * The kind of counters to copy into the destination buffer with 38 * `thread_selfcounts`. 39 */ 40 __enum_decl(thread_selfcounts_kind_t, uint32_t, { 41 /* 42 * Get the current thread's cycles and instructions -- may return ENOTSUP 43 * on certain hardware. 44 */ 45 THSC_CPI = 1, 46 /* 47 * Same as `THSC_CPI`, except fills in an array indexed by CPU perf-level, 48 * with `sysctl hw.nperflevels` entries. 49 */ 50 THSC_CPI_PER_PERF_LEVEL = 2, 51 /* 52 * Get the current thread's cycles, instructions, user time and system time. 53 * Instructions and cycles may be left 0 on certain hardware. System time 54 * may be accounted for by user time and left 0 on certain hardware. 55 */ 56 THSC_TIME_CPI = 3, 57 /* 58 * Same as `THSC_TIME_CPI`, except fills in an array indexed by CPU 59 * perf-level, with `sysctl hw.nperflevels` entries. 60 */ 61 THSC_TIME_CPI_PER_PERF_LEVEL = 4, 62 /* 63 * Get the current thread's cycles, instructions, times, and energy usage. 64 */ 65 THSC_TIME_ENERGY_CPI = 5, 66 /* 67 * Same as `THSC_TIME_ENERGY_CPI`, except fills in an array indexd by CPU 68 * perf-level, with `sysctl hw.nperflevels` entries. 69 */ 70 THSC_TIME_ENERGY_CPI_PER_PERF_LEVEL = 6, 71 }); 72 73 /* 74 * The data structure expected by `THSC_CPI*`. 75 */ 76 struct thsc_cpi { 77 uint64_t tcpi_instructions; 78 uint64_t tcpi_cycles; 79 }; 80 81 /* 82 * The data structure expected by `THSC_TIME_CPI*`. 83 */ 84 struct thsc_time_cpi { 85 uint64_t ttci_instructions; 86 uint64_t ttci_cycles; 87 uint64_t ttci_user_time_mach; 88 uint64_t ttci_system_time_mach; 89 }; 90 91 /* 92 * The data structure expected by `THSC_TIME_ENERGY_CPI*`. 93 */ 94 struct thsc_time_energy_cpi { 95 uint64_t ttec_instructions; 96 uint64_t ttec_cycles; 97 uint64_t ttec_user_time_mach; 98 uint64_t ttec_system_time_mach; 99 uint64_t ttec_energy_nj; 100 }; 101 102 #ifndef KERNEL 103 104 #include <stddef.h> 105 #include <Availability.h> 106 #include <AvailabilityInternalPrivate.h> 107 108 __BEGIN_DECLS 109 110 /* 111 * Get the current thread's counters according to a `kind` and store them into 112 * `dst`. 113 */ 114 __SPI_AVAILABLE(macos(12.4), ios(15.4), watchos(8.5), tvos(15.4)) 115 int thread_selfcounts(thread_selfcounts_kind_t kind, void *dst, size_t size); 116 117 __END_DECLS 118 119 #endif /* !defined(KERNEL) */ 120 121 /* Additional private parameters to getpriority()/setpriority() */ 122 123 #define PRIO_DARWIN_GPU 5 /* Second argument is a PID */ 124 125 __enum_decl(darwin_gpu_role_t, uint8_t, { 126 /* GPU Role unmanaged, default value at task start */ 127 PRIO_DARWIN_GPU_UNKNOWN = 0x0, 128 /* existing allow state for compatibility */ 129 PRIO_DARWIN_GPU_ALLOW = 0x1, 130 /* GPU access is denied by Runningboard */ 131 PRIO_DARWIN_GPU_DENY = 0x2, 132 /* Allowed to use GPU at Background priority, not visible to user, prioritizes running most-efficiently */ 133 PRIO_DARWIN_GPU_BACKGROUND = 0x3, 134 /* GPU used for non-visible-UI long-running progress-bar workloads, balances between sustainable thermals and perf */ 135 PRIO_DARWIN_GPU_UTILITY = 0x4, 136 /* Renders visible UI, known to be a non-focal app */ 137 PRIO_DARWIN_GPU_UI_NON_FOCAL = 0x5, 138 /* Renders visible UI, unknown focality */ 139 PRIO_DARWIN_GPU_UI = 0x6, 140 /* Renders visible UI, is part of a focal app */ 141 PRIO_DARWIN_GPU_UI_FOCAL = 0x7, 142 }); 143 144 #define PRIO_DARWIN_ROLE 6 /* Second argument is a PID */ 145 146 #define PRIO_DARWIN_ROLE_DEFAULT 0x0 /* Reset to default state */ 147 #define PRIO_DARWIN_ROLE_UI_FOCAL 0x1 /* On screen, focal UI */ 148 #define PRIO_DARWIN_ROLE_UI 0x2 /* On screen UI, focal unknown */ 149 #define PRIO_DARWIN_ROLE_NON_UI 0x3 /* Off screen, non-focal UI */ 150 #define PRIO_DARWIN_ROLE_UI_NON_FOCAL 0x4 /* On screen, non-focal UI */ 151 #define PRIO_DARWIN_ROLE_TAL_LAUNCH 0x5 /* Throttled-launch (for OS X TAL resume) */ 152 #define PRIO_DARWIN_ROLE_DARWIN_BG 0x6 /* Throttled for running in the background */ 153 #define PRIO_DARWIN_ROLE_USER_INIT 0x7 /* Off-screen doing user-initiated work */ 154 155 #define PRIO_DARWIN_GAME_MODE 7 /* Second argument is a PID */ 156 #define PRIO_DARWIN_CARPLAY_MODE 8 /* Second argument is a PID */ 157 #define PRIO_DARWIN_RUNAWAY_MITIGATION 9 /* Second argument is a PID */ 158 159 #define PRIO_DARWIN_GAME_MODE_OFF 0x0 160 #define PRIO_DARWIN_GAME_MODE_ON 0x1 161 162 #define PRIO_DARWIN_CARPLAY_MODE_OFF 0x0 163 #define PRIO_DARWIN_CARPLAY_MODE_ON 0x1 164 165 #define PRIO_DARWIN_RUNAWAY_MITIGATION_OFF 0x0 166 #define PRIO_DARWIN_RUNAWAY_MITIGATION_ON 0x1 167 168 /* 169 * Flags for I/O monitor control. 170 */ 171 #define IOMON_ENABLE 0x01 172 #define IOMON_DISABLE 0x02 173 174 /* Private I/O type */ 175 #define IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY 1 176 #define IOPOL_TYPE_VFS_ALTLINK 11 177 #define IOPOL_TYPE_VFS_NOCACHE_WRITE_FS_BLKSIZE 12 178 #define IOPOL_TYPE_VFS_SUPPORT_LONG_PATHS 13 179 180 #define IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT 0 181 #define IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE 1 182 183 #define IOPOL_VFS_ALTLINK_DISABLED 0 184 #define IOPOL_VFS_ALTLINK_ENABLED 1 185 186 #define IOPOL_VFS_SUPPORT_LONG_PATHS_DEFAULT 0 187 #define IOPOL_VFS_SUPPORT_LONG_PATHS_ON 1 188 189 /* 190 * Structures for use in communicating via iopolicysys() between Libc and the 191 * kernel. Not to be used by user programs directly. 192 */ 193 194 /* 195 * the command to iopolicysys() 196 */ 197 #define IOPOL_CMD_GET 0x00000001 /* Get I/O policy */ 198 #define IOPOL_CMD_SET 0x00000002 /* Set I/O policy */ 199 200 /* 201 * Second parameter to iopolicysys() 202 */ 203 struct _iopol_param_t { 204 int iop_scope; /* current process or a thread */ 205 int iop_iotype; 206 int iop_policy; 207 }; 208 209 #endif /* !defined(_SYS_RESOURCE_PRIVATE_H_) */ 210