1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2003,2004 Joseph Koshy 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31#ifndef _PMC_H_ 32#define _PMC_H_ 33 34#include <sys/cdefs.h> 35#include <sys/types.h> 36#include <sys/pmc.h> 37 38/* 39 * Driver statistics. 40 */ 41struct pmc_driverstats { 42 unsigned int pm_intr_ignored; /* #interrupts ignored */ 43 unsigned int pm_intr_processed; /* #interrupts processed */ 44 unsigned int pm_intr_bufferfull; /* #interrupts with ENOSPC */ 45 unsigned int pm_syscalls; /* #syscalls */ 46 unsigned int pm_syscall_errors; /* #syscalls with errors */ 47 unsigned int pm_buffer_requests; /* #buffer requests */ 48 unsigned int pm_buffer_requests_failed; /* #failed buffer requests */ 49 unsigned int pm_log_sweeps; /* #sample buffer processing 50 passes */ 51}; 52 53/* 54 * CPU information. 55 */ 56struct pmc_cpuinfo { 57 enum pmc_cputype pm_cputype; /* the kind of CPU */ 58 uint32_t pm_ncpu; /* number of CPUs */ 59 uint32_t pm_npmc; /* #PMCs per CPU */ 60 uint32_t pm_nclass; /* #classes of PMCs */ 61 struct pmc_classinfo pm_classes[PMC_CLASS_MAX]; 62}; 63 64/* 65 * Current PMC state. 66 */ 67struct pmc_pmcinfo { 68 int32_t pm_cpu; /* CPU number */ 69 struct pmc_info pm_pmcs[]; /* NPMC structs */ 70}; 71 72/* 73 * Prototypes 74 */ 75 76__BEGIN_DECLS 77int pmc_allocate(const char *_ctrspec, enum pmc_mode _mode, uint32_t _flags, 78 int _cpu, pmc_id_t *_pmcid, uint64_t count); 79int pmc_attach(pmc_id_t _pmcid, pid_t _pid); 80int pmc_capabilities(pmc_id_t _pmc, uint32_t *_caps); 81int pmc_configure_logfile(int _fd); 82int pmc_flush_logfile(void); 83int pmc_close_logfile(void); 84int pmc_detach(pmc_id_t _pmcid, pid_t _pid); 85int pmc_disable(int _cpu, int _pmc); 86int pmc_enable(int _cpu, int _pmc); 87int pmc_get_driver_stats(struct pmc_driverstats *_gms); 88int pmc_get_msr(pmc_id_t _pmc, uint32_t *_msr); 89int pmc_init(void); 90int pmc_read(pmc_id_t _pmc, pmc_value_t *_value); 91int pmc_release(pmc_id_t _pmc); 92int pmc_rw(pmc_id_t _pmc, pmc_value_t _newvalue, pmc_value_t *_oldvalue); 93int pmc_set(pmc_id_t _pmc, pmc_value_t _value); 94int pmc_start(pmc_id_t _pmc); 95int pmc_stop(pmc_id_t _pmc); 96int pmc_width(pmc_id_t _pmc, uint32_t *_width); 97int pmc_write(pmc_id_t _pmc, pmc_value_t _value); 98int pmc_writelog(uint32_t _udata); 99 100int pmc_ncpu(void); 101int pmc_npmc(int _cpu); 102int pmc_cpuinfo(const struct pmc_cpuinfo **_cpu_info); 103int pmc_pmcinfo(int _cpu, struct pmc_pmcinfo **_pmc_info); 104 105const char *pmc_name_of_capability(enum pmc_caps _c); 106const char *pmc_name_of_class(enum pmc_class _pc); 107const char *pmc_name_of_cputype(enum pmc_cputype _cp); 108const char *pmc_name_of_disposition(enum pmc_disp _pd); 109const char *pmc_name_of_event(enum pmc_event _pe); 110const char *pmc_name_of_mode(enum pmc_mode _pm); 111const char *pmc_name_of_state(enum pmc_state _ps); 112 113int pmc_event_names_of_class(enum pmc_class _cl, const char ***_eventnames, 114 int *_nevents); 115 116int pmc_pmu_enabled(void); 117void pmc_pmu_print_counters(const char *); 118void pmc_pmu_print_counter_desc(const char *); 119void pmc_pmu_print_counter_desc_long(const char *); 120void pmc_pmu_print_counter_full(const char *); 121uint64_t pmc_pmu_sample_rate_get(const char *); 122int pmc_pmu_pmcallocate(const char *, struct pmc_op_pmcallocate *); 123const char *pmc_pmu_event_get_by_idx(const char *, int idx); 124int pmc_pmu_idx_get_by_event(const char*, const char *); 125int pmc_pmu_stat_mode(const char ***); 126__END_DECLS 127 128#endif 129