1145256Sjkoshy/*- 2145256Sjkoshy * Copyright (c) 2003,2004 Joseph Koshy 3145256Sjkoshy * All rights reserved. 4145256Sjkoshy * 5145256Sjkoshy * Redistribution and use in source and binary forms, with or without 6145256Sjkoshy * modification, are permitted provided that the following conditions 7145256Sjkoshy * are met: 8145256Sjkoshy * 1. Redistributions of source code must retain the above copyright 9145256Sjkoshy * notice, this list of conditions and the following disclaimer. 10145256Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright 11145256Sjkoshy * notice, this list of conditions and the following disclaimer in the 12145256Sjkoshy * documentation and/or other materials provided with the distribution. 13145256Sjkoshy * 14145256Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15145256Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16145256Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17145256Sjkoshy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18145256Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19145256Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20145256Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21145256Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22145256Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23145256Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24145256Sjkoshy * SUCH DAMAGE. 25145256Sjkoshy * 26145256Sjkoshy * $FreeBSD: releng/11.0/lib/libpmc/pmc.h 290929 2015-11-16 15:16:09Z jtl $ 27145256Sjkoshy */ 28145256Sjkoshy 29145256Sjkoshy#ifndef _PMC_H_ 30145256Sjkoshy#define _PMC_H_ 31145256Sjkoshy 32190395Sfabient#include <sys/cdefs.h> 33258572Srstone#include <sys/types.h> 34145256Sjkoshy#include <sys/pmc.h> 35145256Sjkoshy 36145256Sjkoshy/* 37147191Sjkoshy * Driver statistics. 38147191Sjkoshy */ 39147191Sjkoshystruct pmc_driverstats { 40290929Sjtl unsigned int pm_intr_ignored; /* #interrupts ignored */ 41290929Sjtl unsigned int pm_intr_processed; /* #interrupts processed */ 42290929Sjtl unsigned int pm_intr_bufferfull; /* #interrupts with ENOSPC */ 43290929Sjtl unsigned int pm_syscalls; /* #syscalls */ 44290929Sjtl unsigned int pm_syscall_errors; /* #syscalls with errors */ 45290929Sjtl unsigned int pm_buffer_requests; /* #buffer requests */ 46290929Sjtl unsigned int pm_buffer_requests_failed; /* #failed buffer requests */ 47290929Sjtl unsigned int pm_log_sweeps; /* #sample buffer processing 48290929Sjtl passes */ 49147191Sjkoshy}; 50147191Sjkoshy 51147191Sjkoshy/* 52147191Sjkoshy * CPU information. 53147191Sjkoshy */ 54147191Sjkoshystruct pmc_cpuinfo { 55147191Sjkoshy enum pmc_cputype pm_cputype; /* the kind of CPU */ 56147191Sjkoshy uint32_t pm_ncpu; /* number of CPUs */ 57147191Sjkoshy uint32_t pm_npmc; /* #PMCs per CPU */ 58147191Sjkoshy uint32_t pm_nclass; /* #classes of PMCs */ 59147191Sjkoshy struct pmc_classinfo pm_classes[PMC_CLASS_MAX]; 60147191Sjkoshy}; 61147191Sjkoshy 62147191Sjkoshy/* 63147191Sjkoshy * Current PMC state. 64147191Sjkoshy */ 65147191Sjkoshystruct pmc_pmcinfo { 66147191Sjkoshy int32_t pm_cpu; /* CPU number */ 67147191Sjkoshy struct pmc_info pm_pmcs[]; /* NPMC structs */ 68147191Sjkoshy}; 69147191Sjkoshy 70147191Sjkoshy/* 71145256Sjkoshy * Prototypes 72145256Sjkoshy */ 73145256Sjkoshy 74190395Sfabient__BEGIN_DECLS 75145256Sjkoshyint pmc_allocate(const char *_ctrspec, enum pmc_mode _mode, uint32_t _flags, 76145256Sjkoshy int _cpu, pmc_id_t *_pmcid); 77145256Sjkoshyint pmc_attach(pmc_id_t _pmcid, pid_t _pid); 78145774Sjkoshyint pmc_capabilities(pmc_id_t _pmc, uint32_t *_caps); 79145256Sjkoshyint pmc_configure_logfile(int _fd); 80147191Sjkoshyint pmc_flush_logfile(void); 81226514Sfabientint pmc_close_logfile(void); 82145256Sjkoshyint pmc_detach(pmc_id_t _pmcid, pid_t _pid); 83145256Sjkoshyint pmc_disable(int _cpu, int _pmc); 84145256Sjkoshyint pmc_enable(int _cpu, int _pmc); 85147191Sjkoshyint pmc_get_driver_stats(struct pmc_driverstats *_gms); 86147191Sjkoshyint pmc_get_msr(pmc_id_t _pmc, uint32_t *_msr); 87145256Sjkoshyint pmc_init(void); 88145256Sjkoshyint pmc_read(pmc_id_t _pmc, pmc_value_t *_value); 89145256Sjkoshyint pmc_release(pmc_id_t _pmc); 90145256Sjkoshyint pmc_rw(pmc_id_t _pmc, pmc_value_t _newvalue, pmc_value_t *_oldvalue); 91145256Sjkoshyint pmc_set(pmc_id_t _pmc, pmc_value_t _value); 92145256Sjkoshyint pmc_start(pmc_id_t _pmc); 93145256Sjkoshyint pmc_stop(pmc_id_t _pmc); 94145774Sjkoshyint pmc_width(pmc_id_t _pmc, uint32_t *_width); 95145256Sjkoshyint pmc_write(pmc_id_t _pmc, pmc_value_t _value); 96147191Sjkoshyint pmc_writelog(uint32_t _udata); 97145256Sjkoshy 98145256Sjkoshyint pmc_ncpu(void); 99145256Sjkoshyint pmc_npmc(int _cpu); 100147191Sjkoshyint pmc_cpuinfo(const struct pmc_cpuinfo **_cpu_info); 101147191Sjkoshyint pmc_pmcinfo(int _cpu, struct pmc_pmcinfo **_pmc_info); 102145256Sjkoshy 103233321Sjkoshyconst char *pmc_name_of_capability(enum pmc_caps _c); 104145256Sjkoshyconst char *pmc_name_of_class(enum pmc_class _pc); 105145256Sjkoshyconst char *pmc_name_of_cputype(enum pmc_cputype _cp); 106145256Sjkoshyconst char *pmc_name_of_disposition(enum pmc_disp _pd); 107145256Sjkoshyconst char *pmc_name_of_event(enum pmc_event _pe); 108145256Sjkoshyconst char *pmc_name_of_mode(enum pmc_mode _pm); 109145256Sjkoshyconst char *pmc_name_of_state(enum pmc_state _ps); 110145256Sjkoshy 111145256Sjkoshyint pmc_event_names_of_class(enum pmc_class _cl, const char ***_eventnames, 112145256Sjkoshy int *_nevents); 113190395Sfabient__END_DECLS 114145256Sjkoshy 115145256Sjkoshy#endif 116