xref: /xnu-12377.41.6/osfmk/kern/telemetry.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1 /*
2  * Copyright (c) 2012-2013 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 _KERNEL_TELEMETRY_H_
30 #define _KERNEL_TELEMETRY_H_
31 
32 #include <stdint.h>
33 #include <sys/cdefs.h>
34 #include <mach/mach_types.h>
35 #include <kern/thread.h>
36 
37 __BEGIN_DECLS
38 
39 /*
40  * No longer supported.
41  */
42 #define TELEMETRY_CMD_TIMER_EVENT 1
43 #define TELEMETRY_CMD_VOUCHER_NAME 2
44 #define TELEMETRY_CMD_VOUCHER_STAIN TELEMETRY_CMD_VOUCHER_NAME
45 
46 enum telemetry_pmi {
47 	TELEMETRY_PMI_NONE,
48 	TELEMETRY_PMI_INSTRS,
49 	TELEMETRY_PMI_CYCLES,
50 };
51 #define TELEMETRY_CMD_PMI_SETUP 3
52 
53 #if XNU_KERNEL_PRIVATE
54 
55 /* implemented in OSKextLib.cpp */
56 extern void telemetry_backtrace_add_kexts(
57 	char                 *buf,
58 	size_t                buflen,
59 	uintptr_t            *frames,
60 	uint32_t              framecnt);
61 
62 extern void telemetry_backtrace_to_string(
63 	char                 *buf,
64 	size_t                buflen,
65 	uint32_t              tot,
66 	uintptr_t            *frames);
67 
68 extern void telemetry_init(void);
69 
70 extern void compute_telemetry(void *);
71 
72 extern void telemetry_ast(thread_t thread, uint32_t reasons);
73 
74 extern int telemetry_kernel_gather(user_addr_t user_buffer, uint32_t *user_length);
75 extern int telemetry_gather(user_addr_t buffer, uint32_t *length, bool mark);
76 
77 extern int telemetry_pmi_setup(enum telemetry_pmi pmi_type, uint64_t interval);
78 
79 #if CONFIG_MACF
80 extern int telemetry_macf_mark_curthread(void);
81 #endif
82 
83 extern void bootprofile_wake_from_sleep(void);
84 extern void bootprofile_get(void **buffer, uint32_t *length);
85 extern int bootprofile_gather(user_addr_t buffer, uint32_t *length);
86 
87 #endif /* XNU_KERNEL_PRIVATE */
88 
89 __END_DECLS
90 
91 #endif /* _KERNEL_TELEMETRY_H_ */
92