1153838Sdfr/*-
2153838Sdfr * Copyright (c) 2003,2004 Joseph Koshy
3153838Sdfr * All rights reserved.
4153838Sdfr *
5153838Sdfr * Redistribution and use in source and binary forms, with or without
6153838Sdfr * modification, are permitted provided that the following conditions
7153838Sdfr * are met:
8153838Sdfr * 1. Redistributions of source code must retain the above copyright
9153838Sdfr *    notice, this list of conditions and the following disclaimer.
10153838Sdfr * 2. Redistributions in binary form must reproduce the above copyright
11153838Sdfr *    notice, this list of conditions and the following disclaimer in the
12153838Sdfr *    documentation and/or other materials provided with the distribution.
13153838Sdfr *
14153838Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15153838Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16153838Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17153838Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18153838Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19153838Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20153838Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21153838Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22153838Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23153838Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24153838Sdfr * SUCH DAMAGE.
25153838Sdfr *
26153838Sdfr * $FreeBSD: releng/10.3/lib/libpmc/pmc.h 294046 2016-01-14 22:02:21Z jtl $
27153838Sdfr */
28153838Sdfr
29153838Sdfr#ifndef _PMC_H_
30153838Sdfr#define _PMC_H_
31168340Skan
32153838Sdfr#include <sys/cdefs.h>
33153838Sdfr#include <sys/pmc.h>
34153838Sdfr
35153838Sdfr/*
36178828Sdfr * Driver statistics.
37153838Sdfr */
38153838Sdfrstruct pmc_driverstats {
39153838Sdfr	unsigned int	pm_intr_ignored;	/* #interrupts ignored */
40153838Sdfr	unsigned int	pm_intr_processed;	/* #interrupts processed */
41153838Sdfr	unsigned int	pm_intr_bufferfull;	/* #interrupts with ENOSPC */
42153838Sdfr	unsigned int	pm_syscalls;		/* #syscalls */
43153838Sdfr	unsigned int	pm_syscall_errors;	/* #syscalls with errors */
44153838Sdfr	unsigned int	pm_buffer_requests;	/* #buffer requests */
45153838Sdfr	unsigned int	pm_buffer_requests_failed; /* #failed buffer requests */
46153838Sdfr	unsigned int	pm_log_sweeps;		/* #sample buffer processing
47153838Sdfr						   passes */
48153838Sdfr};
49153838Sdfr
50178828Sdfr/*
51153838Sdfr * CPU information.
52153838Sdfr */
53153838Sdfrstruct pmc_cpuinfo {
54153838Sdfr	enum pmc_cputype pm_cputype;	/* the kind of CPU */
55153838Sdfr	uint32_t	pm_ncpu;	/* number of CPUs */
56153838Sdfr	uint32_t	pm_npmc;	/* #PMCs per CPU */
57153838Sdfr	uint32_t	pm_nclass;	/* #classes of PMCs */
58153838Sdfr	struct pmc_classinfo pm_classes[PMC_CLASS_MAX];
59153838Sdfr};
60153838Sdfr
61153838Sdfr/*
62153838Sdfr * Current PMC state.
63153838Sdfr */
64153838Sdfrstruct pmc_pmcinfo {
65178828Sdfr	int32_t		pm_cpu;		/* CPU number */
66153838Sdfr	struct pmc_info	pm_pmcs[];	/* NPMC structs */
67153838Sdfr};
68153838Sdfr
69153838Sdfr/*
70153838Sdfr * Prototypes
71153838Sdfr */
72153838Sdfr
73153838Sdfr__BEGIN_DECLS
74153838Sdfrint	pmc_allocate(const char *_ctrspec, enum pmc_mode _mode, uint32_t _flags,
75153838Sdfr    int _cpu, pmc_id_t *_pmcid);
76153838Sdfrint	pmc_attach(pmc_id_t _pmcid, pid_t _pid);
77153838Sdfrint	pmc_capabilities(pmc_id_t _pmc, uint32_t *_caps);
78153838Sdfrint	pmc_configure_logfile(int _fd);
79153838Sdfrint	pmc_flush_logfile(void);
80178828Sdfrint	pmc_close_logfile(void);
81153838Sdfrint	pmc_detach(pmc_id_t _pmcid, pid_t _pid);
82153838Sdfrint	pmc_disable(int _cpu, int _pmc);
83153838Sdfrint	pmc_enable(int _cpu, int _pmc);
84153838Sdfrint	pmc_get_driver_stats(struct pmc_driverstats *_gms);
85153838Sdfrint	pmc_get_msr(pmc_id_t _pmc, uint32_t *_msr);
86153838Sdfrint	pmc_init(void);
87153838Sdfrint	pmc_read(pmc_id_t _pmc, pmc_value_t *_value);
88153838Sdfrint	pmc_release(pmc_id_t _pmc);
89153838Sdfrint	pmc_rw(pmc_id_t _pmc, pmc_value_t _newvalue, pmc_value_t *_oldvalue);
90153838Sdfrint	pmc_set(pmc_id_t _pmc, pmc_value_t _value);
91153838Sdfrint	pmc_start(pmc_id_t _pmc);
92153838Sdfrint	pmc_stop(pmc_id_t _pmc);
93153838Sdfrint	pmc_width(pmc_id_t _pmc, uint32_t *_width);
94153838Sdfrint	pmc_write(pmc_id_t _pmc, pmc_value_t _value);
95153838Sdfrint	pmc_writelog(uint32_t _udata);
96153838Sdfr
97153838Sdfrint	pmc_ncpu(void);
98153838Sdfrint	pmc_npmc(int _cpu);
99153838Sdfrint	pmc_cpuinfo(const struct pmc_cpuinfo **_cpu_info);
100153838Sdfrint	pmc_pmcinfo(int _cpu, struct pmc_pmcinfo **_pmc_info);
101178828Sdfr
102153838Sdfrconst char	*pmc_name_of_capability(enum pmc_caps _c);
103153838Sdfrconst char	*pmc_name_of_class(enum pmc_class _pc);
104153838Sdfrconst char	*pmc_name_of_cputype(enum pmc_cputype _cp);
105153838Sdfrconst char	*pmc_name_of_disposition(enum pmc_disp _pd);
106153838Sdfrconst char	*pmc_name_of_event(enum pmc_event _pe);
107153838Sdfrconst char	*pmc_name_of_mode(enum pmc_mode _pm);
108153838Sdfrconst char	*pmc_name_of_state(enum pmc_state _ps);
109153838Sdfr
110153838Sdfrint	pmc_event_names_of_class(enum pmc_class _cl, const char ***_eventnames,
111153838Sdfr    int *_nevents);
112153838Sdfr__END_DECLS
113153838Sdfr
114153838Sdfr#endif
115153838Sdfr