xref: /onnv-gate/usr/src/uts/common/sys/cpc_pcbe.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate  * CPC Performance Counter Backend
29*0Sstevel@tonic-gate  *
30*0Sstevel@tonic-gate  * To utilize the performance counters on a given CPU, a pcbe (Performance
31*0Sstevel@tonic-gate  * Counter Backend) must be implemented for that CPU.
32*0Sstevel@tonic-gate  *
33*0Sstevel@tonic-gate  * This file defines the API which the kernel CPC implementation will call into.
34*0Sstevel@tonic-gate  *
35*0Sstevel@tonic-gate  */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #ifndef _SYS_CPC_PCBE_H
38*0Sstevel@tonic-gate #define	_SYS_CPC_PCBE_H
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #include <sys/inttypes.h>
43*0Sstevel@tonic-gate #include <sys/cpc_impl.h>
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #ifdef	__cplusplus
46*0Sstevel@tonic-gate extern "C" {
47*0Sstevel@tonic-gate #endif
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /*
50*0Sstevel@tonic-gate  * All PCBEs must use PCBE_VER_1.
51*0Sstevel@tonic-gate  */
52*0Sstevel@tonic-gate #define	PCBE_VER_1	1
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate typedef struct __pcbe_ops {
55*0Sstevel@tonic-gate 	uint_t		pcbe_ver;
56*0Sstevel@tonic-gate 	uint_t		pcbe_caps;
57*0Sstevel@tonic-gate 	uint_t		(*pcbe_ncounters)(void);
58*0Sstevel@tonic-gate 	const char	*(*pcbe_impl_name)(void);
59*0Sstevel@tonic-gate 	const char	*(*pcbe_cpuref)(void);
60*0Sstevel@tonic-gate 	char		*(*pcbe_list_events)(uint_t picnum);
61*0Sstevel@tonic-gate 	char		*(*pcbe_list_attrs)(void);
62*0Sstevel@tonic-gate 	uint64_t	(*pcbe_event_coverage)(char *event);
63*0Sstevel@tonic-gate 	uint64_t	(*pcbe_overflow_bitmap)(void);
64*0Sstevel@tonic-gate 	int		(*pcbe_configure)(uint_t, char *, uint64_t, uint_t,
65*0Sstevel@tonic-gate 				uint_t, kcpc_attr_t *, void **, void *);
66*0Sstevel@tonic-gate 	void		(*pcbe_program)(void *);
67*0Sstevel@tonic-gate 	void		(*pcbe_allstop)(void);
68*0Sstevel@tonic-gate 	void		(*pcbe_sample)(void *);
69*0Sstevel@tonic-gate 	void		(*pcbe_free)(void *);
70*0Sstevel@tonic-gate } pcbe_ops_t;
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate extern pcbe_ops_t *pcbe_ops;
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate  * uint_t pcbe_ver;
76*0Sstevel@tonic-gate  *
77*0Sstevel@tonic-gate  *	Must always be set to PCBE_VER_1.
78*0Sstevel@tonic-gate  *
79*0Sstevel@tonic-gate  * uint_t pcbe_caps;
80*0Sstevel@tonic-gate  *
81*0Sstevel@tonic-gate  *	Bitmask of capability flags which define the processor's capabilities:
82*0Sstevel@tonic-gate  *		CPC_CAP_OVERFLOW_INTERRUPT:
83*0Sstevel@tonic-gate  *			This processor can generate an interrupt when a counter
84*0Sstevel@tonic-gate  *			overflows.
85*0Sstevel@tonic-gate  *
86*0Sstevel@tonic-gate  *		CPC_CAP_OVERFLOW_PRECISE:
87*0Sstevel@tonic-gate  *			When an overflow interrupt occurs, the backend can
88*0Sstevel@tonic-gate  *			determine programmatically exactly which counter
89*0Sstevel@tonic-gate  *			overflowed.
90*0Sstevel@tonic-gate  *
91*0Sstevel@tonic-gate  * uint_t (*pcbe_ncounters)(void);
92*0Sstevel@tonic-gate  *
93*0Sstevel@tonic-gate  *	Returns the number of counters on the processor.
94*0Sstevel@tonic-gate  *
95*0Sstevel@tonic-gate  * const char *(*pcbe_impl_name)(void);
96*0Sstevel@tonic-gate  *
97*0Sstevel@tonic-gate  *	Returns a pointer to a string which uniquely identifies the CPC
98*0Sstevel@tonic-gate  *	capabilities of the processor.
99*0Sstevel@tonic-gate  *
100*0Sstevel@tonic-gate  * const char *(*pcbe_cpuref)(void);
101*0Sstevel@tonic-gate  *
102*0Sstevel@tonic-gate  *	Returns a pointer to a string which points to a reference manual of
103*0Sstevel@tonic-gate  *	some sort which should be consulted to understand the performance
104*0Sstevel@tonic-gate  *	counters.
105*0Sstevel@tonic-gate  *
106*0Sstevel@tonic-gate  * char	*(*pcbe_list_events)(uint_t picnum);
107*0Sstevel@tonic-gate  *
108*0Sstevel@tonic-gate  *	Returns a pointer to a comma-separated list of events which the given
109*0Sstevel@tonic-gate  *	counter number is capable of counting. picnum starts at 0 and goes as
110*0Sstevel@tonic-gate  *	high as (ncounters - 1).
111*0Sstevel@tonic-gate  *
112*0Sstevel@tonic-gate  * char *(*pcbe_list_attrs)(void);
113*0Sstevel@tonic-gate  *
114*0Sstevel@tonic-gate  *	Returns a pointer to a comma-separated list of attribute names which
115*0Sstevel@tonic-gate  *	the PCBE supports.
116*0Sstevel@tonic-gate  *
117*0Sstevel@tonic-gate  * uint64_t (*pcbe_event_coverage)(char *event);
118*0Sstevel@tonic-gate  *
119*0Sstevel@tonic-gate  *	Returns a bitmask indicating which counters are capable of counting the
120*0Sstevel@tonic-gate  *	named event. Counter n is deemed capable if bit (1 << n) is turned on,
121*0Sstevel@tonic-gate  *	where counters range from 0 to (ncounters - 1).
122*0Sstevel@tonic-gate  *
123*0Sstevel@tonic-gate  * uint64_t (*pcbe_overflow_bitmap)(void);
124*0Sstevel@tonic-gate  *
125*0Sstevel@tonic-gate  *	Called by the kernel when a performance counter interrupt is received.
126*0Sstevel@tonic-gate  *	This routine must return a bitmap of counters indicating which ones have
127*0Sstevel@tonic-gate  *	overflowed. If the platform cannot determine this, it must act as if
128*0Sstevel@tonic-gate  *	_all_ of its counters have overflowed.
129*0Sstevel@tonic-gate  *
130*0Sstevel@tonic-gate  * int (*pcbe_configure)(uint_t picnum, char *event, uint64_t preset,
131*0Sstevel@tonic-gate  *				uint_t flags, uint_t nattrs, kcpc_attr_t *attrp,
132*0Sstevel@tonic-gate  *				void **configp, void *token);
133*0Sstevel@tonic-gate  *
134*0Sstevel@tonic-gate  *	Returns a pointer to a PCBE-private data structure which can later be
135*0Sstevel@tonic-gate  *	used to program the indicated picnum according to the arguments.
136*0Sstevel@tonic-gate  *	token may be passed to kcpc_next_config() in order to walk the list of
137*0Sstevel@tonic-gate  *	configurations which will be programmed together.
138*0Sstevel@tonic-gate  *
139*0Sstevel@tonic-gate  * void	(*pcbe_program)(void *token);
140*0Sstevel@tonic-gate  *
141*0Sstevel@tonic-gate  *	Collects all configurations which will be programmed together, via
142*0Sstevel@tonic-gate  *	kcpc_next_config(), programs them onto the hardware, and starts the
143*0Sstevel@tonic-gate  *	performance counters.
144*0Sstevel@tonic-gate  *
145*0Sstevel@tonic-gate  * void	(*pcbe_allstop)(void);
146*0Sstevel@tonic-gate  *
147*0Sstevel@tonic-gate  *	Stops all hardware performance counters.
148*0Sstevel@tonic-gate  *
149*0Sstevel@tonic-gate  * void	(*pcbe_sample)(void *token);
150*0Sstevel@tonic-gate  *
151*0Sstevel@tonic-gate  *	Samples the values in the performance couters and updates the locations
152*0Sstevel@tonic-gate  *	returned by kcpc_next_config() with the delta since the last sample.
153*0Sstevel@tonic-gate  *
154*0Sstevel@tonic-gate  * void	(*pcbe_free)(void *config);
155*0Sstevel@tonic-gate  *
156*0Sstevel@tonic-gate  *	Frees the given configuration.
157*0Sstevel@tonic-gate  */
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate #ifdef	__cplusplus
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate #endif
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate #endif /* _SYS_CPC_PCBE_H */
164