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