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