summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/cpc_pcbe.h
blob: eb168fcf2c734093153a2a298605f97324956f74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * CPC Performance Counter Backend
 *
 * To utilize the performance counters on a given CPU, a pcbe (Performance
 * Counter Backend) must be implemented for that CPU.
 *
 * This file defines the API which the kernel CPC implementation will call into.
 *
 */

#ifndef _SYS_CPC_PCBE_H
#define	_SYS_CPC_PCBE_H

#include <sys/inttypes.h>
#include <sys/cpc_impl.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * All PCBEs must use PCBE_VER_1.
 */
#define	PCBE_VER_1	1

#define	PCBE_IMPL_NAME_P4HT	"Pentium 4 with HyperThreading"

typedef struct __pcbe_ops {
	uint_t		pcbe_ver;
	uint_t		pcbe_caps;
	uint_t		(*pcbe_ncounters)(void);
	const char	*(*pcbe_impl_name)(void);
	const char	*(*pcbe_cpuref)(void);
	char		*(*pcbe_list_events)(uint_t picnum);
	char		*(*pcbe_list_attrs)(void);
	uint64_t	(*pcbe_event_coverage)(char *event);
	uint64_t	(*pcbe_overflow_bitmap)(void);
	int		(*pcbe_configure)(uint_t, char *, uint64_t, uint_t,
				uint_t, kcpc_attr_t *, void **, void *);
	void		(*pcbe_program)(void *);
	void		(*pcbe_allstop)(void);
	void		(*pcbe_sample)(void *);
	void		(*pcbe_free)(void *);
} pcbe_ops_t;

extern pcbe_ops_t *pcbe_ops;

/*
 * uint_t pcbe_ver;
 *
 *	Must always be set to PCBE_VER_1.
 *
 * uint_t pcbe_caps;
 *
 *	Bitmask of capability flags which define the processor's capabilities:
 *		CPC_CAP_OVERFLOW_INTERRUPT:
 *			This processor can generate an interrupt when a counter
 *			overflows.
 *
 *		CPC_CAP_OVERFLOW_PRECISE:
 *			When an overflow interrupt occurs, the backend can
 *			determine programmatically exactly which counter
 *			overflowed.
 *
 * uint_t (*pcbe_ncounters)(void);
 *
 *	Returns the number of counters on the processor.
 *
 * const char *(*pcbe_impl_name)(void);
 *
 *	Returns a pointer to a string which uniquely identifies the CPC
 *	capabilities of the processor.
 *
 * const char *(*pcbe_cpuref)(void);
 *
 *	Returns a pointer to a string which points to a reference manual of
 *	some sort which should be consulted to understand the performance
 *	counters.
 *
 * char	*(*pcbe_list_events)(uint_t picnum);
 *
 *	Returns a pointer to a comma-separated list of events which the given
 *	counter number is capable of counting. picnum starts at 0 and goes as
 *	high as (ncounters - 1).
 *
 * char *(*pcbe_list_attrs)(void);
 *
 *	Returns a pointer to a comma-separated list of attribute names which
 *	the PCBE supports.
 *
 * uint64_t (*pcbe_event_coverage)(char *event);
 *
 *	Returns a bitmask indicating which counters are capable of counting the
 *	named event. Counter n is deemed capable if bit (1 << n) is turned on,
 *	where counters range from 0 to (ncounters - 1).
 *
 * uint64_t (*pcbe_overflow_bitmap)(void);
 *
 *	Called by the kernel when a performance counter interrupt is received.
 *	This routine must return a bitmap of counters indicating which ones have
 *	overflowed. If the platform cannot determine this, it must act as if
 *	_all_ of its counters have overflowed.
 *
 * int (*pcbe_configure)(uint_t picnum, char *event, uint64_t preset,
 *				uint_t flags, uint_t nattrs, kcpc_attr_t *attrp,
 *				void **configp, void *token);
 *
 *	Returns a pointer to a PCBE-private data structure which can later be
 *	used to program the indicated picnum according to the arguments.
 *	token may be passed to kcpc_next_config() in order to walk the list of
 *	configurations which will be programmed together.
 *
 * void	(*pcbe_program)(void *token);
 *
 *	Collects all configurations which will be programmed together, via
 *	kcpc_next_config(), programs them onto the hardware, and starts the
 *	performance counters.
 *
 * void	(*pcbe_allstop)(void);
 *
 *	Stops all hardware performance counters.
 *
 * void	(*pcbe_sample)(void *token);
 *
 *	Samples the values in the performance couters and updates the locations
 *	returned by kcpc_next_config() with the delta since the last sample.
 *
 * void	(*pcbe_free)(void *config);
 *
 *	Frees the given configuration.
 */

#ifdef	__cplusplus
}
#endif

#endif /* _SYS_CPC_PCBE_H */