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 #ifndef BSD_PERFMON_PRIVATE_H 28 #define BSD_PERFMON_PRIVATE_H 29 30 #if KERNEL 31 #include <machine/limits.h> 32 #else // KERNEL 33 #include <limits.h> 34 #endif // !KERNEL 35 #include <stdint.h> 36 #include <stdbool.h> 37 #include <sys/cdefs.h> 38 39 __BEGIN_DECLS 40 41 struct perfmon_layout { 42 unsigned short pl_counter_count; 43 unsigned short pl_fixed_offset; 44 unsigned short pl_fixed_count; 45 unsigned short pl_unit_count; 46 unsigned short pl_reg_count; 47 unsigned short pl_attr_count; 48 }; 49 50 typedef char perfmon_name_t[16]; 51 52 struct perfmon_event { 53 char pe_name[32]; 54 uint64_t pe_number; 55 unsigned short pe_counter; 56 }; 57 58 struct perfmon_attr { 59 perfmon_name_t pa_name; 60 uint64_t pa_value; 61 }; 62 63 struct perfmon_spec { 64 struct perfmon_event *ps_events; 65 struct perfmon_attr *ps_attrs; 66 unsigned short ps_event_count; 67 unsigned short ps_attr_count; 68 }; 69 70 #if !MACH_KERNEL_PRIVATE 71 72 #include <sys/ioccom.h> 73 74 // A perfmon file is initially mutable, where events can be added and 75 // attributes set. The fine-grained nature of this API gives clients insight 76 // into which specific configuration was erroneous and the associated overheads 77 // are taken only when the system is configured, at process startup. 78 enum perfmon_ioctl { 79 // PMU metadata, always allowed. 80 81 // Immutable information about the PMU. 82 PERFMON_CTL_GET_LAYOUT = _IOR('P', 0, struct perfmon_layout), 83 PERFMON_CTL_LIST_ATTRS = _IO('P', 1), 84 PERFMON_CTL_LIST_REGS = _IO('P', 2), 85 86 // Get diagnostic information by sampling the hardware registers. 87 PERFMON_CTL_SAMPLE_REGS = _IO('P', 3), 88 89 // Set up a configuration, only allowed when open for writing and before 90 // configure. 91 92 // Add an event to the configuration. 93 PERFMON_CTL_ADD_EVENT = _IOWR('P', 5, struct perfmon_event), 94 // Apply attributes to a given event, or globally. 95 PERFMON_CTL_SET_ATTR = _IOW('P', 6, struct perfmon_attr), 96 97 // Control the state of the PMU, only allowed when open for writing. 98 99 // Configure the monitor, no more settings can be adjusted after this is 100 // called, one time only. 101 PERFMON_CTL_CONFIGURE = _IO('P', 7), 102 // Start counting, only allowed after configuration and counting stopped. 103 PERFMON_CTL_START = _IO('P', 8), 104 // Stop counting, only allowed with counting started. 105 PERFMON_CTL_STOP = _IO('P', 9), 106 107 // Query the confguration, only allowed when open for writing. 108 PERFMON_CTL_SPECIFY = _IOWR('P', 10, struct perfmon_spec), 109 }; 110 111 #if XNU_KERNEL_PRIVATE 112 113 // Called from the pseudo-device initializer in config/MASTER. 114 int perfmon_dev_init(void); 115 116 #endif // XNU_KERNEL_PRIVATE 117 118 #endif // !MACH_KERNEL_PRIVATE 119 120 __END_DECLS 121 122 #endif // !defined(BSD_PERFMON_PRIVATE_H) 123