xref: /xnu-11417.140.69/bsd/sys/resource_private.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions  * Copyright (c) 2000-2021 Apple Inc. All rights reserved.
3*43a90889SApple OSS Distributions  *
4*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*43a90889SApple OSS Distributions  *
6*43a90889SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*43a90889SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*43a90889SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*43a90889SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*43a90889SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*43a90889SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*43a90889SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*43a90889SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*43a90889SApple OSS Distributions  *
15*43a90889SApple OSS Distributions  * Please obtain a copy of the License at
16*43a90889SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*43a90889SApple OSS Distributions  *
18*43a90889SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*43a90889SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*43a90889SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*43a90889SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*43a90889SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*43a90889SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*43a90889SApple OSS Distributions  * limitations under the License.
25*43a90889SApple OSS Distributions  *
26*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*43a90889SApple OSS Distributions  */
28*43a90889SApple OSS Distributions 
29*43a90889SApple OSS Distributions #ifndef _SYS_RESOURCE_PRIVATE_H_
30*43a90889SApple OSS Distributions #define _SYS_RESOURCE_PRIVATE_H_
31*43a90889SApple OSS Distributions 
32*43a90889SApple OSS Distributions #include <os/base.h>
33*43a90889SApple OSS Distributions #include <stdint.h>
34*43a90889SApple OSS Distributions #include <sys/cdefs.h>
35*43a90889SApple OSS Distributions 
36*43a90889SApple OSS Distributions /*
37*43a90889SApple OSS Distributions  * The kind of counters to copy into the destination buffer with
38*43a90889SApple OSS Distributions  * `thread_selfcounts`.
39*43a90889SApple OSS Distributions  */
40*43a90889SApple OSS Distributions __enum_decl(thread_selfcounts_kind_t, uint32_t, {
41*43a90889SApple OSS Distributions 	/*
42*43a90889SApple OSS Distributions 	 * Get the current thread's cycles and instructions -- may return ENOTSUP
43*43a90889SApple OSS Distributions 	 * on certain hardware.
44*43a90889SApple OSS Distributions 	 */
45*43a90889SApple OSS Distributions 	THSC_CPI = 1,
46*43a90889SApple OSS Distributions 	/*
47*43a90889SApple OSS Distributions 	 * Same as `THSC_CPI`, except fills in an array indexed by CPU perf-level,
48*43a90889SApple OSS Distributions 	 * with `sysctl hw.nperflevels` entries.
49*43a90889SApple OSS Distributions 	 */
50*43a90889SApple OSS Distributions 	THSC_CPI_PER_PERF_LEVEL = 2,
51*43a90889SApple OSS Distributions 	/*
52*43a90889SApple OSS Distributions 	 * Get the current thread's cycles, instructions, user time and system time.
53*43a90889SApple OSS Distributions 	 * Instructions and cycles may be left 0 on certain hardware.  System time
54*43a90889SApple OSS Distributions 	 * may be accounted for by user time and left 0 on certain hardware.
55*43a90889SApple OSS Distributions 	 */
56*43a90889SApple OSS Distributions 	THSC_TIME_CPI = 3,
57*43a90889SApple OSS Distributions 	/*
58*43a90889SApple OSS Distributions 	 * Same as `THSC_TIME_CPI`, except fills in an array indexed by CPU
59*43a90889SApple OSS Distributions 	 * perf-level, with `sysctl hw.nperflevels` entries.
60*43a90889SApple OSS Distributions 	 */
61*43a90889SApple OSS Distributions 	THSC_TIME_CPI_PER_PERF_LEVEL = 4,
62*43a90889SApple OSS Distributions 	/*
63*43a90889SApple OSS Distributions 	 * Get the current thread's cycles, instructions, times, and energy usage.
64*43a90889SApple OSS Distributions 	 */
65*43a90889SApple OSS Distributions 	THSC_TIME_ENERGY_CPI = 5,
66*43a90889SApple OSS Distributions 	/*
67*43a90889SApple OSS Distributions 	 * Same as `THSC_TIME_ENERGY_CPI`, except fills in an array indexd by CPU
68*43a90889SApple OSS Distributions 	 * perf-level, with `sysctl hw.nperflevels` entries.
69*43a90889SApple OSS Distributions 	 */
70*43a90889SApple OSS Distributions 	THSC_TIME_ENERGY_CPI_PER_PERF_LEVEL = 6,
71*43a90889SApple OSS Distributions });
72*43a90889SApple OSS Distributions 
73*43a90889SApple OSS Distributions /*
74*43a90889SApple OSS Distributions  * The data structure expected by `THSC_CPI*`.
75*43a90889SApple OSS Distributions  */
76*43a90889SApple OSS Distributions struct thsc_cpi {
77*43a90889SApple OSS Distributions 	uint64_t tcpi_instructions;
78*43a90889SApple OSS Distributions 	uint64_t tcpi_cycles;
79*43a90889SApple OSS Distributions };
80*43a90889SApple OSS Distributions 
81*43a90889SApple OSS Distributions /*
82*43a90889SApple OSS Distributions  * The data structure expected by `THSC_TIME_CPI*`.
83*43a90889SApple OSS Distributions  */
84*43a90889SApple OSS Distributions struct thsc_time_cpi {
85*43a90889SApple OSS Distributions 	uint64_t ttci_instructions;
86*43a90889SApple OSS Distributions 	uint64_t ttci_cycles;
87*43a90889SApple OSS Distributions 	uint64_t ttci_user_time_mach;
88*43a90889SApple OSS Distributions 	uint64_t ttci_system_time_mach;
89*43a90889SApple OSS Distributions };
90*43a90889SApple OSS Distributions 
91*43a90889SApple OSS Distributions /*
92*43a90889SApple OSS Distributions  * The data structure expected by `THSC_TIME_ENERGY_CPI*`.
93*43a90889SApple OSS Distributions  */
94*43a90889SApple OSS Distributions struct thsc_time_energy_cpi {
95*43a90889SApple OSS Distributions 	uint64_t ttec_instructions;
96*43a90889SApple OSS Distributions 	uint64_t ttec_cycles;
97*43a90889SApple OSS Distributions 	uint64_t ttec_user_time_mach;
98*43a90889SApple OSS Distributions 	uint64_t ttec_system_time_mach;
99*43a90889SApple OSS Distributions 	uint64_t ttec_energy_nj;
100*43a90889SApple OSS Distributions };
101*43a90889SApple OSS Distributions 
102*43a90889SApple OSS Distributions #ifndef KERNEL
103*43a90889SApple OSS Distributions 
104*43a90889SApple OSS Distributions #include <stddef.h>
105*43a90889SApple OSS Distributions #include <Availability.h>
106*43a90889SApple OSS Distributions #include <AvailabilityInternalPrivate.h>
107*43a90889SApple OSS Distributions 
108*43a90889SApple OSS Distributions __BEGIN_DECLS
109*43a90889SApple OSS Distributions 
110*43a90889SApple OSS Distributions /*
111*43a90889SApple OSS Distributions  * Get the current thread's counters according to a `kind` and store them into
112*43a90889SApple OSS Distributions  * `dst`.
113*43a90889SApple OSS Distributions  */
114*43a90889SApple OSS Distributions __SPI_AVAILABLE(macos(12.4), ios(15.4), watchos(8.5), tvos(15.4))
115*43a90889SApple OSS Distributions int thread_selfcounts(thread_selfcounts_kind_t kind, void *dst, size_t size);
116*43a90889SApple OSS Distributions 
117*43a90889SApple OSS Distributions __END_DECLS
118*43a90889SApple OSS Distributions 
119*43a90889SApple OSS Distributions #endif /* !defined(KERNEL) */
120*43a90889SApple OSS Distributions 
121*43a90889SApple OSS Distributions /* Additional private parameters to getpriority()/setpriority( */
122*43a90889SApple OSS Distributions 
123*43a90889SApple OSS Distributions #define PRIO_DARWIN_GPU         5               /* Second argument is a PID */
124*43a90889SApple OSS Distributions 
125*43a90889SApple OSS Distributions #define PRIO_DARWIN_GPU_ALLOW   0x1
126*43a90889SApple OSS Distributions #define PRIO_DARWIN_GPU_DENY    0x2
127*43a90889SApple OSS Distributions 
128*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE        6               /* Second argument is a PID */
129*43a90889SApple OSS Distributions 
130*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE_DEFAULT        0x0     /* Reset to default state */
131*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE_UI_FOCAL       0x1     /* On  screen,     focal UI */
132*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE_UI             0x2     /* On  screen UI,  focal unknown */
133*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE_NON_UI         0x3     /* Off screen, non-focal UI */
134*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE_UI_NON_FOCAL   0x4     /* On  screen, non-focal UI */
135*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE_TAL_LAUNCH     0x5     /* Throttled-launch (for OS X TAL resume) */
136*43a90889SApple OSS Distributions #define PRIO_DARWIN_ROLE_DARWIN_BG      0x6     /* Throttled for running in the background */
137*43a90889SApple OSS Distributions 
138*43a90889SApple OSS Distributions #define PRIO_DARWIN_GAME_MODE   7               /* Second argument is a PID */
139*43a90889SApple OSS Distributions #define PRIO_DARWIN_CARPLAY_MODE   8            /* Second argument is a PID */
140*43a90889SApple OSS Distributions 
141*43a90889SApple OSS Distributions #define PRIO_DARWIN_GAME_MODE_OFF   0x0
142*43a90889SApple OSS Distributions #define PRIO_DARWIN_GAME_MODE_ON    0x1
143*43a90889SApple OSS Distributions 
144*43a90889SApple OSS Distributions #define PRIO_DARWIN_CARPLAY_MODE_OFF   0x0
145*43a90889SApple OSS Distributions #define PRIO_DARWIN_CARPLAY_MODE_ON    0x1
146*43a90889SApple OSS Distributions 
147*43a90889SApple OSS Distributions /*
148*43a90889SApple OSS Distributions  * Flags for I/O monitor control.
149*43a90889SApple OSS Distributions  */
150*43a90889SApple OSS Distributions #define IOMON_ENABLE                    0x01
151*43a90889SApple OSS Distributions #define IOMON_DISABLE                   0x02
152*43a90889SApple OSS Distributions 
153*43a90889SApple OSS Distributions /* Private I/O type */
154*43a90889SApple OSS Distributions #define IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY 1
155*43a90889SApple OSS Distributions #define IOPOL_TYPE_VFS_ALTLINK 11
156*43a90889SApple OSS Distributions #define IOPOL_TYPE_VFS_NOCACHE_WRITE_FS_BLKSIZE  12
157*43a90889SApple OSS Distributions #define IOPOL_TYPE_VFS_SUPPORT_LONG_PATHS 13
158*43a90889SApple OSS Distributions 
159*43a90889SApple OSS Distributions #define IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT  0
160*43a90889SApple OSS Distributions #define IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE     1
161*43a90889SApple OSS Distributions 
162*43a90889SApple OSS Distributions #define IOPOL_VFS_ALTLINK_DISABLED 0
163*43a90889SApple OSS Distributions #define IOPOL_VFS_ALTLINK_ENABLED  1
164*43a90889SApple OSS Distributions 
165*43a90889SApple OSS Distributions #define IOPOL_VFS_SUPPORT_LONG_PATHS_DEFAULT 0
166*43a90889SApple OSS Distributions #define IOPOL_VFS_SUPPORT_LONG_PATHS_ON 1
167*43a90889SApple OSS Distributions 
168*43a90889SApple OSS Distributions /*
169*43a90889SApple OSS Distributions  * Structures for use in communicating via iopolicysys() between Libc and the
170*43a90889SApple OSS Distributions  * kernel.  Not to be used by user programs directly.
171*43a90889SApple OSS Distributions  */
172*43a90889SApple OSS Distributions 
173*43a90889SApple OSS Distributions /*
174*43a90889SApple OSS Distributions  * the command to iopolicysys()
175*43a90889SApple OSS Distributions  */
176*43a90889SApple OSS Distributions #define IOPOL_CMD_GET           0x00000001      /* Get I/O policy */
177*43a90889SApple OSS Distributions #define IOPOL_CMD_SET           0x00000002      /* Set I/O policy */
178*43a90889SApple OSS Distributions 
179*43a90889SApple OSS Distributions /*
180*43a90889SApple OSS Distributions  * Second parameter to iopolicysys()
181*43a90889SApple OSS Distributions  */
182*43a90889SApple OSS Distributions struct _iopol_param_t {
183*43a90889SApple OSS Distributions 	int iop_scope;  /* current process or a thread */
184*43a90889SApple OSS Distributions 	int iop_iotype;
185*43a90889SApple OSS Distributions 	int iop_policy;
186*43a90889SApple OSS Distributions };
187*43a90889SApple OSS Distributions 
188*43a90889SApple OSS Distributions #endif  /* !defined(_SYS_RESOURCE_PRIVATE_H_) */
189