]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/monotonic.h
1 #ifndef SYS_MONOTONIC_H
2 #define SYS_MONOTONIC_H
7 #include <sys/ioccom.h>
12 * XXX These declarations are subject to change at any time.
15 #define MT_IOC(x) _IO('m', (x))
17 #define MT_IOC_RESET MT_IOC(0)
19 #define MT_IOC_ADD MT_IOC(1)
21 struct monotonic_config
{
23 uint64_t allowed_ctr_mask
;
27 union monotonic_ctl_add
{
29 struct monotonic_config config
;
38 * - Consider a separate IOC for disable -- to avoid the copyin to determine
39 * which way to set it.
41 #define MT_IOC_ENABLE MT_IOC(2)
43 union monotonic_ctl_enable
{
49 #define MT_IOC_COUNTS MT_IOC(3)
51 union monotonic_ctl_counts
{
61 #define MT_IOC_GET_INFO MT_IOC(4)
63 union monotonic_ctl_info
{
65 unsigned int nmonitors
;
66 unsigned int ncounters
;
70 #if XNU_KERNEL_PRIVATE
72 #include <kern/monotonic.h>
73 #include <machine/monotonic.h>
74 #include <sys/kdebug.h>
75 #include <kern/locks.h>
78 #define COUNTS_INSTRS __counts[MT_CORE_INSTRS]
79 #else /* defined(MT_CORE_INSTRS) */
80 #define COUNTS_INSTRS 0
81 #endif /* !defined(MT_CORE_INSTRS) */
84 * MT_KDBG_TMP* macros are meant for temporary (i.e. not checked-in)
85 * performance investigations.
89 * Record the current CPU counters.
91 * Preemption must be disabled.
93 #define MT_KDBG_TMPCPU_EVT(CODE) \
94 KDBG_EVENTID(DBG_MONOTONIC, DBG_MT_TMPCPU, CODE)
96 #define MT_KDBG_TMPCPU_(CODE, FUNC) \
98 if (kdebug_enable && \
99 kdebug_debugid_enabled(MT_KDBG_TMPCPU_EVT(CODE))) { \
100 uint64_t __counts[MT_CORE_NFIXED]; \
101 mt_fixed_counts(__counts); \
102 KDBG(MT_KDBG_TMPCPU_EVT(CODE) | (FUNC), COUNTS_INSTRS, \
103 __counts[MT_CORE_CYCLES]); \
107 #define MT_KDBG_TMPCPU(CODE) MT_KDBG_TMPCPU_(CODE, DBG_FUNC_NONE)
108 #define MT_KDBG_TMPCPU_START(CODE) MT_KDBG_TMPCPU_(CODE, DBG_FUNC_START)
109 #define MT_KDBG_TMPCPU_END(CODE) MT_KDBG_TMPCPU_(CODE, DBG_FUNC_END)
112 * Record the current thread counters.
114 * Interrupts must be disabled.
116 #define MT_KDBG_TMPTH_EVT(CODE) \
117 KDBG_EVENTID(DBG_MONOTONIC, DBG_MT_TMPTH, CODE)
119 #define MT_KDBG_TMPTH_(CODE, FUNC) \
121 if (kdebug_enable && \
122 kdebug_debugid_enabled(MT_KDBG_TMPTH_EVT(CODE))) { \
123 uint64_t __counts[MT_CORE_NFIXED]; \
124 mt_cur_thread_fixed_counts(__counts); \
125 KDBG(MT_KDBG_TMPTH_EVT(CODE) | (FUNC), COUNTS_INSTRS, \
126 __counts[MT_CORE_CYCLES]); \
130 #define MT_KDBG_TMPTH(CODE) MT_KDBG_TMPTH_(CODE, DBG_FUNC_NONE)
131 #define MT_KDBG_TMPTH_START(CODE) MT_KDBG_TMPTH_(CODE, DBG_FUNC_START)
132 #define MT_KDBG_TMPTH_END(CODE) MT_KDBG_TMPTH_(CODE, DBG_FUNC_END)
135 const char *mtd_name
;
136 int (* const mtd_init
)(struct mt_device
*dev
);
137 int (* const mtd_add
)(struct monotonic_config
*config
, uint32_t *ctr_out
);
138 void (* const mtd_reset
)(void);
139 void (* const mtd_enable
)(bool enable
);
140 int (* const mtd_read
)(uint64_t ctr_mask
, uint64_t *counts_out
);
141 decl_lck_mtx_data(, mtd_lock
);
143 uint8_t mtd_nmonitors
;
144 uint8_t mtd_ncounters
;
147 typedef struct mt_device
*mt_device_t
;
149 extern struct mt_device mt_devices
[];
151 extern lck_grp_t
*mt_lock_grp
;
153 int mt_dev_init(void);
155 #endif /* XNU_KERNEL_PRIVATE */
159 #endif /* !defined(SYS_MONOTONIC_H) */