xref: /xnu-8020.101.4/bsd/sys/perfmon_private.h (revision e7776783b89a353188416a9a346c6cdb4928faad)
1*e7776783SApple OSS Distributions // Copyright (c) 2020 Apple Inc. All rights reserved.
2*e7776783SApple OSS Distributions //
3*e7776783SApple OSS Distributions // @APPLE_OSREFERENCE_LICENSE_HEADER_START@
4*e7776783SApple OSS Distributions //
5*e7776783SApple OSS Distributions // This file contains Original Code and/or Modifications of Original Code
6*e7776783SApple OSS Distributions // as defined in and that are subject to the Apple Public Source License
7*e7776783SApple OSS Distributions // Version 2.0 (the 'License'). You may not use this file except in
8*e7776783SApple OSS Distributions // compliance with the License. The rights granted to you under the License
9*e7776783SApple OSS Distributions // may not be used to create, or enable the creation or redistribution of,
10*e7776783SApple OSS Distributions // unlawful or unlicensed copies of an Apple operating system, or to
11*e7776783SApple OSS Distributions // circumvent, violate, or enable the circumvention or violation of, any
12*e7776783SApple OSS Distributions // terms of an Apple operating system software license agreement.
13*e7776783SApple OSS Distributions //
14*e7776783SApple OSS Distributions // Please obtain a copy of the License at
15*e7776783SApple OSS Distributions // http://www.opensource.apple.com/apsl/ and read it before using this file.
16*e7776783SApple OSS Distributions //
17*e7776783SApple OSS Distributions // The Original Code and all software distributed under the License are
18*e7776783SApple OSS Distributions // distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19*e7776783SApple OSS Distributions // EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
20*e7776783SApple OSS Distributions // INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
21*e7776783SApple OSS Distributions // FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
22*e7776783SApple OSS Distributions // Please see the License for the specific language governing rights and
23*e7776783SApple OSS Distributions // limitations under the License.
24*e7776783SApple OSS Distributions //
25*e7776783SApple OSS Distributions // @APPLE_OSREFERENCE_LICENSE_HEADER_END@
26*e7776783SApple OSS Distributions 
27*e7776783SApple OSS Distributions #ifndef BSD_PERFMON_PRIVATE_H
28*e7776783SApple OSS Distributions #define BSD_PERFMON_PRIVATE_H
29*e7776783SApple OSS Distributions 
30*e7776783SApple OSS Distributions #if KERNEL
31*e7776783SApple OSS Distributions #include <machine/limits.h>
32*e7776783SApple OSS Distributions #else // KERNEL
33*e7776783SApple OSS Distributions #include <limits.h>
34*e7776783SApple OSS Distributions #endif // !KERNEL
35*e7776783SApple OSS Distributions #include <stdint.h>
36*e7776783SApple OSS Distributions #include <stdbool.h>
37*e7776783SApple OSS Distributions #include <sys/cdefs.h>
38*e7776783SApple OSS Distributions 
39*e7776783SApple OSS Distributions __BEGIN_DECLS
40*e7776783SApple OSS Distributions 
41*e7776783SApple OSS Distributions struct perfmon_layout {
42*e7776783SApple OSS Distributions 	unsigned short pl_counter_count;
43*e7776783SApple OSS Distributions 	unsigned short pl_fixed_offset;
44*e7776783SApple OSS Distributions 	unsigned short pl_fixed_count;
45*e7776783SApple OSS Distributions 	unsigned short pl_unit_count;
46*e7776783SApple OSS Distributions 	unsigned short pl_reg_count;
47*e7776783SApple OSS Distributions 	unsigned short pl_attr_count;
48*e7776783SApple OSS Distributions };
49*e7776783SApple OSS Distributions 
50*e7776783SApple OSS Distributions typedef char perfmon_name_t[16];
51*e7776783SApple OSS Distributions 
52*e7776783SApple OSS Distributions struct perfmon_event {
53*e7776783SApple OSS Distributions 	char pe_name[32];
54*e7776783SApple OSS Distributions 	uint64_t pe_number;
55*e7776783SApple OSS Distributions 	unsigned short pe_counter;
56*e7776783SApple OSS Distributions };
57*e7776783SApple OSS Distributions 
58*e7776783SApple OSS Distributions struct perfmon_attr {
59*e7776783SApple OSS Distributions 	perfmon_name_t pa_name;
60*e7776783SApple OSS Distributions 	uint64_t pa_value;
61*e7776783SApple OSS Distributions };
62*e7776783SApple OSS Distributions 
63*e7776783SApple OSS Distributions struct perfmon_spec {
64*e7776783SApple OSS Distributions 	struct perfmon_event *ps_events;
65*e7776783SApple OSS Distributions 	struct perfmon_attr *ps_attrs;
66*e7776783SApple OSS Distributions 	unsigned short ps_event_count;
67*e7776783SApple OSS Distributions 	unsigned short ps_attr_count;
68*e7776783SApple OSS Distributions };
69*e7776783SApple OSS Distributions 
70*e7776783SApple OSS Distributions #if !MACH_KERNEL_PRIVATE
71*e7776783SApple OSS Distributions 
72*e7776783SApple OSS Distributions #include <sys/ioccom.h>
73*e7776783SApple OSS Distributions 
74*e7776783SApple OSS Distributions // A perfmon file is initially mutable, where events can be added and
75*e7776783SApple OSS Distributions // attributes set.  The fine-grained nature of this API gives clients insight
76*e7776783SApple OSS Distributions // into which specific configuration was erroneous and the associated overheads
77*e7776783SApple OSS Distributions // are taken only when the system is configured, at process startup.
78*e7776783SApple OSS Distributions enum perfmon_ioctl {
79*e7776783SApple OSS Distributions 	// PMU metadata, always allowed.
80*e7776783SApple OSS Distributions 
81*e7776783SApple OSS Distributions 	// Immutable information about the PMU.
82*e7776783SApple OSS Distributions 	PERFMON_CTL_GET_LAYOUT = _IOR('P', 0, struct perfmon_layout),
83*e7776783SApple OSS Distributions 	PERFMON_CTL_LIST_ATTRS = _IO('P', 1),
84*e7776783SApple OSS Distributions 	PERFMON_CTL_LIST_REGS = _IO('P', 2),
85*e7776783SApple OSS Distributions 
86*e7776783SApple OSS Distributions 	// Get diagnostic information by sampling the hardware registers.
87*e7776783SApple OSS Distributions 	PERFMON_CTL_SAMPLE_REGS = _IO('P', 3),
88*e7776783SApple OSS Distributions 
89*e7776783SApple OSS Distributions 	// Set up a configuration, only allowed when open for writing and before
90*e7776783SApple OSS Distributions 	// configure.
91*e7776783SApple OSS Distributions 
92*e7776783SApple OSS Distributions 	// Add an event to the configuration.
93*e7776783SApple OSS Distributions 	PERFMON_CTL_ADD_EVENT = _IOWR('P', 5, struct perfmon_event),
94*e7776783SApple OSS Distributions 	// Apply attributes to a given event, or globally.
95*e7776783SApple OSS Distributions 	PERFMON_CTL_SET_ATTR = _IOW('P', 6, struct perfmon_attr),
96*e7776783SApple OSS Distributions 
97*e7776783SApple OSS Distributions 	// Control the state of the PMU, only allowed when open for writing.
98*e7776783SApple OSS Distributions 
99*e7776783SApple OSS Distributions 	// Configure the monitor, no more settings can be adjusted after this is
100*e7776783SApple OSS Distributions 	// called, one time only.
101*e7776783SApple OSS Distributions 	PERFMON_CTL_CONFIGURE = _IO('P', 7),
102*e7776783SApple OSS Distributions 	// Start counting, only allowed after configuration and counting stopped.
103*e7776783SApple OSS Distributions 	PERFMON_CTL_START = _IO('P', 8),
104*e7776783SApple OSS Distributions 	// Stop counting, only allowed with counting started.
105*e7776783SApple OSS Distributions 	PERFMON_CTL_STOP = _IO('P', 9),
106*e7776783SApple OSS Distributions 
107*e7776783SApple OSS Distributions 	// Query the confguration, only allowed when open for writing.
108*e7776783SApple OSS Distributions 	PERFMON_CTL_SPECIFY = _IOWR('P', 10, struct perfmon_spec),
109*e7776783SApple OSS Distributions };
110*e7776783SApple OSS Distributions 
111*e7776783SApple OSS Distributions #if XNU_KERNEL_PRIVATE
112*e7776783SApple OSS Distributions 
113*e7776783SApple OSS Distributions // Called from the pseudo-device initializer in config/MASTER.
114*e7776783SApple OSS Distributions int perfmon_dev_init(void);
115*e7776783SApple OSS Distributions 
116*e7776783SApple OSS Distributions #endif // XNU_KERNEL_PRIVATE
117*e7776783SApple OSS Distributions 
118*e7776783SApple OSS Distributions #endif // !MACH_KERNEL_PRIVATE
119*e7776783SApple OSS Distributions 
120*e7776783SApple OSS Distributions __END_DECLS
121*e7776783SApple OSS Distributions 
122*e7776783SApple OSS Distributions #endif // !defined(BSD_PERFMON_PRIVATE_H)
123