xref: /xnu-8020.140.41/bsd/sys/resource_private.h (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
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 	THSC_CPI = 0x01,
42 });
43 
44 /*
45  * The data structure expected by `thread_selfcounts(THSC_CPI, ...)`.
46  */
47 struct thsc_cpi {
48 	uint64_t tcpi_instructions;
49 	uint64_t tcpi_cycles;
50 };
51 
52 #ifndef KERNEL
53 
54 #include <stddef.h>
55 #include <AvailabilityInternalPrivate.h>
56 
57 __BEGIN_DECLS
58 
59 /*
60  * Get the current thread's counters according to a `kind` and store them into
61  * `dst`.
62  */
63     __SPI_AVAILABLE(macos(12.4), ios(15.4), watchos(8.5), tvos(15.4))
64 int thread_selfcounts(thread_selfcounts_kind_t kind, void *dst, size_t size);
65 
66 /*
67  * Get the current thread's cycles and instructions.  May return ENOTSUP on
68  * certain hardware.
69  */
70 #define thread_selfcounts_cpi(DST) thread_selfcounts(THSC_CPI, (DST), sizeof(struct thsc_cpi))
71 
72 __END_DECLS
73 
74 #endif /* !defined(KERNEL) */
75 
76 #endif  /* !defined(_SYS_RESOURCE_PRIVATE_H_) */
77