]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/monotonic.h
2 * Copyright (c) 2017-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef SYS_MONOTONIC_H
30 #define SYS_MONOTONIC_H
34 #include <sys/cdefs.h>
38 struct mt_cpu_inscyc
{
39 uint64_t mtci_instructions
;
45 #if !MACH_KERNEL_PRIVATE
47 #include <sys/ioccom.h>
52 * XXX These declarations are subject to change at any time.
55 #define MT_IOC(x) _IO('m', (x))
56 #define MT_IOC_RESET MT_IOC(0)
57 #define MT_IOC_ADD MT_IOC(1)
58 #define MT_IOC_ENABLE MT_IOC(2)
59 #define MT_IOC_COUNTS MT_IOC(3)
60 #define MT_IOC_GET_INFO MT_IOC(4)
64 #endif /* !MACH_KERNEL_PRIVATE */
68 struct monotonic_config
{
70 uint64_t allowed_ctr_mask
;
74 union monotonic_ctl_add
{
76 struct monotonic_config config
;
84 union monotonic_ctl_enable
{
91 union monotonic_ctl_counts
{
102 union monotonic_ctl_info
{
104 unsigned int nmonitors
;
105 unsigned int ncounters
;
111 #if XNU_KERNEL_PRIVATE
115 #include <kern/monotonic.h>
116 #include <machine/monotonic.h>
117 #include <sys/kdebug.h>
118 #include <kern/locks.h>
122 #ifdef MT_CORE_INSTRS
123 #define COUNTS_INSTRS __counts[MT_CORE_INSTRS]
124 #else /* defined(MT_CORE_INSTRS) */
125 #define COUNTS_INSTRS 0
126 #endif /* !defined(MT_CORE_INSTRS) */
129 * MT_KDBG_TMP* macros are meant for temporary (i.e. not checked-in)
130 * performance investigations.
134 * Record the current CPU counters.
136 * Preemption must be disabled.
138 #define MT_KDBG_TMPCPU_EVT(CODE) \
139 KDBG_EVENTID(DBG_MONOTONIC, DBG_MT_TMPCPU, CODE)
141 #define MT_KDBG_TMPCPU_(CODE, FUNC) \
143 if (kdebug_enable && \
144 kdebug_debugid_enabled(MT_KDBG_TMPCPU_EVT(CODE))) { \
145 uint64_t __counts[MT_CORE_NFIXED]; \
146 mt_fixed_counts(__counts); \
147 KDBG(MT_KDBG_TMPCPU_EVT(CODE) | (FUNC), COUNTS_INSTRS, \
148 __counts[MT_CORE_CYCLES]); \
152 #define MT_KDBG_TMPCPU(CODE) MT_KDBG_TMPCPU_(CODE, DBG_FUNC_NONE)
153 #define MT_KDBG_TMPCPU_START(CODE) MT_KDBG_TMPCPU_(CODE, DBG_FUNC_START)
154 #define MT_KDBG_TMPCPU_END(CODE) MT_KDBG_TMPCPU_(CODE, DBG_FUNC_END)
157 * Record the current thread counters.
159 * Interrupts must be disabled.
161 #define MT_KDBG_TMPTH_EVT(CODE) \
162 KDBG_EVENTID(DBG_MONOTONIC, DBG_MT_TMPTH, CODE)
164 #define MT_KDBG_TMPTH_(CODE, FUNC) \
166 if (kdebug_enable && \
167 kdebug_debugid_enabled(MT_KDBG_TMPTH_EVT(CODE))) { \
168 uint64_t __counts[MT_CORE_NFIXED]; \
169 mt_cur_thread_fixed_counts(__counts); \
170 KDBG(MT_KDBG_TMPTH_EVT(CODE) | (FUNC), COUNTS_INSTRS, \
171 __counts[MT_CORE_CYCLES]); \
175 #define MT_KDBG_TMPTH(CODE) MT_KDBG_TMPTH_(CODE, DBG_FUNC_NONE)
176 #define MT_KDBG_TMPTH_START(CODE) MT_KDBG_TMPTH_(CODE, DBG_FUNC_START)
177 #define MT_KDBG_TMPTH_END(CODE) MT_KDBG_TMPTH_(CODE, DBG_FUNC_END)
179 extern lck_grp_t
* mt_lock_grp
;
181 int mt_dev_init(void);
184 const char *mtd_name
;
185 int(*const mtd_init
)(struct mt_device
*dev
);
186 int(*const mtd_add
)(struct monotonic_config
*config
, uint32_t *ctr_out
);
187 void(*const mtd_reset
)(void);
188 void(*const mtd_enable
)(bool enable
);
189 int(*const mtd_read
)(uint64_t ctr_mask
, uint64_t *counts_out
);
190 decl_lck_mtx_data(, mtd_lock
);
192 uint8_t mtd_nmonitors
;
193 uint8_t mtd_ncounters
;
196 typedef struct mt_device
*mt_device_t
;
198 extern struct mt_device mt_devices
[];
202 #endif /* MONOTONIC */
204 #endif /* XNU_KERNEL_PRIVATE */
206 #endif /* !defined(SYS_MONOTONIC_H) */