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_GAME_MODE 7 /* Second argument is a PID */ 124 125 #define PRIO_DARWIN_GAME_MODE_OFF 0x0 126 #define PRIO_DARWIN_GAME_MODE_ON 0x1 127 128 #endif /* !defined(_SYS_RESOURCE_PRIVATE_H_) */ 129