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