xref: /xnu-8792.61.2/osfmk/machine/machine_perfmon.h (revision 42e220869062b56f8d7d0726fd4c88954f87902c)
1 // Copyright (c) 2020 Apple Inc. All rights reserved.
2 //
3 // @APPLE_OSREFERENCE_LICENSE_HEADER_START@
4 //
5 // This file contains Original Code and/or Modifications of Original Code
6 // as defined in and that are subject to the Apple Public Source License
7 // Version 2.0 (the 'License'). You may not use this file except in
8 // compliance with the License. The rights granted to you under the License
9 // may not be used to create, or enable the creation or redistribution of,
10 // unlawful or unlicensed copies of an Apple operating system, or to
11 // circumvent, violate, or enable the circumvention or violation of, any
12 // terms of an Apple operating system software license agreement.
13 //
14 // Please obtain a copy of the License at
15 // http://www.opensource.apple.com/apsl/ and read it before using this file.
16 //
17 // The Original Code and all software distributed under the License are
18 // distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19 // EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
20 // INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
22 // Please see the License for the specific language governing rights and
23 // limitations under the License.
24 //
25 // @APPLE_OSREFERENCE_LICENSE_HEADER_END@
26 
27 #if KERNEL
28 #include <kern/perfmon.h>
29 #endif // KERNEL
30 #include <stddef.h>
31 #include <stdint.h>
32 #include <sys/queue.h>
33 
34 struct perfmon_counter {
35 	uint64_t pc_number;
36 };
37 
38 struct perfmon_config {
39 	struct perfmon_source *pc_source;
40 	struct perfmon_spec pc_spec;
41 	unsigned short pc_attr_ids[PERFMON_SPEC_MAX_ATTR_COUNT];
42 
43 	struct perfmon_counter *pc_counters;
44 	uint64_t pc_counters_used;
45 	uint64_t pc_attrs_used;
46 
47 	bool pc_configured:1;
48 };
49 static_assert(PERFMON_SPEC_MAX_ATTR_COUNT < sizeof(uint64_t) * CHAR_BIT,
50     "attr IDs must fit in 64-bit integer");
51 
52 #if KERNEL
53 /// Fill in an array of register values for all units.
54 void perfmon_machine_sample_regs(enum perfmon_kind kind, uint64_t *regs,
55     size_t regs_len);
56 #endif // KERNEL
57 
58 // Set up the counters as specified by the configuration.
59 int perfmon_machine_configure(enum perfmon_kind kind,
60     const perfmon_config_t config);
61 
62 // Reset the counters to an inactive state.
63 void perfmon_machine_reset(enum perfmon_kind kind);
64