xref: /illumos-gate/usr/src/uts/common/sys/cpc_pcbe.h (revision b885580b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*b885580bSAlexander Kolbasov  * Common Development and Distribution License (the "License").
6*b885580bSAlexander Kolbasov  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*b885580bSAlexander Kolbasov  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * CPC Performance Counter Backend
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * To utilize the performance counters on a given CPU, a pcbe (Performance
307c478bd9Sstevel@tonic-gate  * Counter Backend) must be implemented for that CPU.
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * This file defines the API which the kernel CPC implementation will call into.
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifndef _SYS_CPC_PCBE_H
377c478bd9Sstevel@tonic-gate #define	_SYS_CPC_PCBE_H
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
407c478bd9Sstevel@tonic-gate #include <sys/cpc_impl.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
437c478bd9Sstevel@tonic-gate extern "C" {
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * All PCBEs must use PCBE_VER_1.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate #define	PCBE_VER_1	1
507c478bd9Sstevel@tonic-gate 
51*b885580bSAlexander Kolbasov #define	PCBE_IMPL_NAME_P4HT	"Pentium 4 with HyperThreading"
52*b885580bSAlexander Kolbasov 
537c478bd9Sstevel@tonic-gate typedef struct __pcbe_ops {
547c478bd9Sstevel@tonic-gate 	uint_t		pcbe_ver;
557c478bd9Sstevel@tonic-gate 	uint_t		pcbe_caps;
567c478bd9Sstevel@tonic-gate 	uint_t		(*pcbe_ncounters)(void);
577c478bd9Sstevel@tonic-gate 	const char	*(*pcbe_impl_name)(void);
587c478bd9Sstevel@tonic-gate 	const char	*(*pcbe_cpuref)(void);
597c478bd9Sstevel@tonic-gate 	char		*(*pcbe_list_events)(uint_t picnum);
607c478bd9Sstevel@tonic-gate 	char		*(*pcbe_list_attrs)(void);
617c478bd9Sstevel@tonic-gate 	uint64_t	(*pcbe_event_coverage)(char *event);
627c478bd9Sstevel@tonic-gate 	uint64_t	(*pcbe_overflow_bitmap)(void);
637c478bd9Sstevel@tonic-gate 	int		(*pcbe_configure)(uint_t, char *, uint64_t, uint_t,
647c478bd9Sstevel@tonic-gate 				uint_t, kcpc_attr_t *, void **, void *);
657c478bd9Sstevel@tonic-gate 	void		(*pcbe_program)(void *);
667c478bd9Sstevel@tonic-gate 	void		(*pcbe_allstop)(void);
677c478bd9Sstevel@tonic-gate 	void		(*pcbe_sample)(void *);
687c478bd9Sstevel@tonic-gate 	void		(*pcbe_free)(void *);
697c478bd9Sstevel@tonic-gate } pcbe_ops_t;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate extern pcbe_ops_t *pcbe_ops;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * uint_t pcbe_ver;
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  *	Must always be set to PCBE_VER_1.
777c478bd9Sstevel@tonic-gate  *
787c478bd9Sstevel@tonic-gate  * uint_t pcbe_caps;
797c478bd9Sstevel@tonic-gate  *
807c478bd9Sstevel@tonic-gate  *	Bitmask of capability flags which define the processor's capabilities:
817c478bd9Sstevel@tonic-gate  *		CPC_CAP_OVERFLOW_INTERRUPT:
827c478bd9Sstevel@tonic-gate  *			This processor can generate an interrupt when a counter
837c478bd9Sstevel@tonic-gate  *			overflows.
847c478bd9Sstevel@tonic-gate  *
857c478bd9Sstevel@tonic-gate  *		CPC_CAP_OVERFLOW_PRECISE:
867c478bd9Sstevel@tonic-gate  *			When an overflow interrupt occurs, the backend can
877c478bd9Sstevel@tonic-gate  *			determine programmatically exactly which counter
887c478bd9Sstevel@tonic-gate  *			overflowed.
897c478bd9Sstevel@tonic-gate  *
907c478bd9Sstevel@tonic-gate  * uint_t (*pcbe_ncounters)(void);
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  *	Returns the number of counters on the processor.
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  * const char *(*pcbe_impl_name)(void);
957c478bd9Sstevel@tonic-gate  *
967c478bd9Sstevel@tonic-gate  *	Returns a pointer to a string which uniquely identifies the CPC
977c478bd9Sstevel@tonic-gate  *	capabilities of the processor.
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  * const char *(*pcbe_cpuref)(void);
1007c478bd9Sstevel@tonic-gate  *
1017c478bd9Sstevel@tonic-gate  *	Returns a pointer to a string which points to a reference manual of
1027c478bd9Sstevel@tonic-gate  *	some sort which should be consulted to understand the performance
1037c478bd9Sstevel@tonic-gate  *	counters.
1047c478bd9Sstevel@tonic-gate  *
1057c478bd9Sstevel@tonic-gate  * char	*(*pcbe_list_events)(uint_t picnum);
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  *	Returns a pointer to a comma-separated list of events which the given
1087c478bd9Sstevel@tonic-gate  *	counter number is capable of counting. picnum starts at 0 and goes as
1097c478bd9Sstevel@tonic-gate  *	high as (ncounters - 1).
1107c478bd9Sstevel@tonic-gate  *
1117c478bd9Sstevel@tonic-gate  * char *(*pcbe_list_attrs)(void);
1127c478bd9Sstevel@tonic-gate  *
1137c478bd9Sstevel@tonic-gate  *	Returns a pointer to a comma-separated list of attribute names which
1147c478bd9Sstevel@tonic-gate  *	the PCBE supports.
1157c478bd9Sstevel@tonic-gate  *
1167c478bd9Sstevel@tonic-gate  * uint64_t (*pcbe_event_coverage)(char *event);
1177c478bd9Sstevel@tonic-gate  *
1187c478bd9Sstevel@tonic-gate  *	Returns a bitmask indicating which counters are capable of counting the
1197c478bd9Sstevel@tonic-gate  *	named event. Counter n is deemed capable if bit (1 << n) is turned on,
1207c478bd9Sstevel@tonic-gate  *	where counters range from 0 to (ncounters - 1).
1217c478bd9Sstevel@tonic-gate  *
1227c478bd9Sstevel@tonic-gate  * uint64_t (*pcbe_overflow_bitmap)(void);
1237c478bd9Sstevel@tonic-gate  *
1247c478bd9Sstevel@tonic-gate  *	Called by the kernel when a performance counter interrupt is received.
1257c478bd9Sstevel@tonic-gate  *	This routine must return a bitmap of counters indicating which ones have
1267c478bd9Sstevel@tonic-gate  *	overflowed. If the platform cannot determine this, it must act as if
1277c478bd9Sstevel@tonic-gate  *	_all_ of its counters have overflowed.
1287c478bd9Sstevel@tonic-gate  *
1297c478bd9Sstevel@tonic-gate  * int (*pcbe_configure)(uint_t picnum, char *event, uint64_t preset,
1307c478bd9Sstevel@tonic-gate  *				uint_t flags, uint_t nattrs, kcpc_attr_t *attrp,
1317c478bd9Sstevel@tonic-gate  *				void **configp, void *token);
1327c478bd9Sstevel@tonic-gate  *
1337c478bd9Sstevel@tonic-gate  *	Returns a pointer to a PCBE-private data structure which can later be
1347c478bd9Sstevel@tonic-gate  *	used to program the indicated picnum according to the arguments.
1357c478bd9Sstevel@tonic-gate  *	token may be passed to kcpc_next_config() in order to walk the list of
1367c478bd9Sstevel@tonic-gate  *	configurations which will be programmed together.
1377c478bd9Sstevel@tonic-gate  *
1387c478bd9Sstevel@tonic-gate  * void	(*pcbe_program)(void *token);
1397c478bd9Sstevel@tonic-gate  *
1407c478bd9Sstevel@tonic-gate  *	Collects all configurations which will be programmed together, via
1417c478bd9Sstevel@tonic-gate  *	kcpc_next_config(), programs them onto the hardware, and starts the
1427c478bd9Sstevel@tonic-gate  *	performance counters.
1437c478bd9Sstevel@tonic-gate  *
1447c478bd9Sstevel@tonic-gate  * void	(*pcbe_allstop)(void);
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  *	Stops all hardware performance counters.
1477c478bd9Sstevel@tonic-gate  *
1487c478bd9Sstevel@tonic-gate  * void	(*pcbe_sample)(void *token);
1497c478bd9Sstevel@tonic-gate  *
1507c478bd9Sstevel@tonic-gate  *	Samples the values in the performance couters and updates the locations
1517c478bd9Sstevel@tonic-gate  *	returned by kcpc_next_config() with the delta since the last sample.
1527c478bd9Sstevel@tonic-gate  *
1537c478bd9Sstevel@tonic-gate  * void	(*pcbe_free)(void *config);
1547c478bd9Sstevel@tonic-gate  *
1557c478bd9Sstevel@tonic-gate  *	Frees the given configuration.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #endif /* _SYS_CPC_PCBE_H */
163