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