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