10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*11389SAlexander.Kolbasov@Sun.COM * Common Development and Distribution License (the "License"). 6*11389SAlexander.Kolbasov@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*11389SAlexander.Kolbasov@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * CPC Performance Counter Backend 280Sstevel@tonic-gate * 290Sstevel@tonic-gate * To utilize the performance counters on a given CPU, a pcbe (Performance 300Sstevel@tonic-gate * Counter Backend) must be implemented for that CPU. 310Sstevel@tonic-gate * 320Sstevel@tonic-gate * This file defines the API which the kernel CPC implementation will call into. 330Sstevel@tonic-gate * 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifndef _SYS_CPC_PCBE_H 370Sstevel@tonic-gate #define _SYS_CPC_PCBE_H 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <sys/inttypes.h> 400Sstevel@tonic-gate #include <sys/cpc_impl.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate #ifdef __cplusplus 430Sstevel@tonic-gate extern "C" { 440Sstevel@tonic-gate #endif 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * All PCBEs must use PCBE_VER_1. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate #define PCBE_VER_1 1 500Sstevel@tonic-gate 51*11389SAlexander.Kolbasov@Sun.COM #define PCBE_IMPL_NAME_P4HT "Pentium 4 with HyperThreading" 52*11389SAlexander.Kolbasov@Sun.COM 530Sstevel@tonic-gate typedef struct __pcbe_ops { 540Sstevel@tonic-gate uint_t pcbe_ver; 550Sstevel@tonic-gate uint_t pcbe_caps; 560Sstevel@tonic-gate uint_t (*pcbe_ncounters)(void); 570Sstevel@tonic-gate const char *(*pcbe_impl_name)(void); 580Sstevel@tonic-gate const char *(*pcbe_cpuref)(void); 590Sstevel@tonic-gate char *(*pcbe_list_events)(uint_t picnum); 600Sstevel@tonic-gate char *(*pcbe_list_attrs)(void); 610Sstevel@tonic-gate uint64_t (*pcbe_event_coverage)(char *event); 620Sstevel@tonic-gate uint64_t (*pcbe_overflow_bitmap)(void); 630Sstevel@tonic-gate int (*pcbe_configure)(uint_t, char *, uint64_t, uint_t, 640Sstevel@tonic-gate uint_t, kcpc_attr_t *, void **, void *); 650Sstevel@tonic-gate void (*pcbe_program)(void *); 660Sstevel@tonic-gate void (*pcbe_allstop)(void); 670Sstevel@tonic-gate void (*pcbe_sample)(void *); 680Sstevel@tonic-gate void (*pcbe_free)(void *); 690Sstevel@tonic-gate } pcbe_ops_t; 700Sstevel@tonic-gate 710Sstevel@tonic-gate extern pcbe_ops_t *pcbe_ops; 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * uint_t pcbe_ver; 750Sstevel@tonic-gate * 760Sstevel@tonic-gate * Must always be set to PCBE_VER_1. 770Sstevel@tonic-gate * 780Sstevel@tonic-gate * uint_t pcbe_caps; 790Sstevel@tonic-gate * 800Sstevel@tonic-gate * Bitmask of capability flags which define the processor's capabilities: 810Sstevel@tonic-gate * CPC_CAP_OVERFLOW_INTERRUPT: 820Sstevel@tonic-gate * This processor can generate an interrupt when a counter 830Sstevel@tonic-gate * overflows. 840Sstevel@tonic-gate * 850Sstevel@tonic-gate * CPC_CAP_OVERFLOW_PRECISE: 860Sstevel@tonic-gate * When an overflow interrupt occurs, the backend can 870Sstevel@tonic-gate * determine programmatically exactly which counter 880Sstevel@tonic-gate * overflowed. 890Sstevel@tonic-gate * 900Sstevel@tonic-gate * uint_t (*pcbe_ncounters)(void); 910Sstevel@tonic-gate * 920Sstevel@tonic-gate * Returns the number of counters on the processor. 930Sstevel@tonic-gate * 940Sstevel@tonic-gate * const char *(*pcbe_impl_name)(void); 950Sstevel@tonic-gate * 960Sstevel@tonic-gate * Returns a pointer to a string which uniquely identifies the CPC 970Sstevel@tonic-gate * capabilities of the processor. 980Sstevel@tonic-gate * 990Sstevel@tonic-gate * const char *(*pcbe_cpuref)(void); 1000Sstevel@tonic-gate * 1010Sstevel@tonic-gate * Returns a pointer to a string which points to a reference manual of 1020Sstevel@tonic-gate * some sort which should be consulted to understand the performance 1030Sstevel@tonic-gate * counters. 1040Sstevel@tonic-gate * 1050Sstevel@tonic-gate * char *(*pcbe_list_events)(uint_t picnum); 1060Sstevel@tonic-gate * 1070Sstevel@tonic-gate * Returns a pointer to a comma-separated list of events which the given 1080Sstevel@tonic-gate * counter number is capable of counting. picnum starts at 0 and goes as 1090Sstevel@tonic-gate * high as (ncounters - 1). 1100Sstevel@tonic-gate * 1110Sstevel@tonic-gate * char *(*pcbe_list_attrs)(void); 1120Sstevel@tonic-gate * 1130Sstevel@tonic-gate * Returns a pointer to a comma-separated list of attribute names which 1140Sstevel@tonic-gate * the PCBE supports. 1150Sstevel@tonic-gate * 1160Sstevel@tonic-gate * uint64_t (*pcbe_event_coverage)(char *event); 1170Sstevel@tonic-gate * 1180Sstevel@tonic-gate * Returns a bitmask indicating which counters are capable of counting the 1190Sstevel@tonic-gate * named event. Counter n is deemed capable if bit (1 << n) is turned on, 1200Sstevel@tonic-gate * where counters range from 0 to (ncounters - 1). 1210Sstevel@tonic-gate * 1220Sstevel@tonic-gate * uint64_t (*pcbe_overflow_bitmap)(void); 1230Sstevel@tonic-gate * 1240Sstevel@tonic-gate * Called by the kernel when a performance counter interrupt is received. 1250Sstevel@tonic-gate * This routine must return a bitmap of counters indicating which ones have 1260Sstevel@tonic-gate * overflowed. If the platform cannot determine this, it must act as if 1270Sstevel@tonic-gate * _all_ of its counters have overflowed. 1280Sstevel@tonic-gate * 1290Sstevel@tonic-gate * int (*pcbe_configure)(uint_t picnum, char *event, uint64_t preset, 1300Sstevel@tonic-gate * uint_t flags, uint_t nattrs, kcpc_attr_t *attrp, 1310Sstevel@tonic-gate * void **configp, void *token); 1320Sstevel@tonic-gate * 1330Sstevel@tonic-gate * Returns a pointer to a PCBE-private data structure which can later be 1340Sstevel@tonic-gate * used to program the indicated picnum according to the arguments. 1350Sstevel@tonic-gate * token may be passed to kcpc_next_config() in order to walk the list of 1360Sstevel@tonic-gate * configurations which will be programmed together. 1370Sstevel@tonic-gate * 1380Sstevel@tonic-gate * void (*pcbe_program)(void *token); 1390Sstevel@tonic-gate * 1400Sstevel@tonic-gate * Collects all configurations which will be programmed together, via 1410Sstevel@tonic-gate * kcpc_next_config(), programs them onto the hardware, and starts the 1420Sstevel@tonic-gate * performance counters. 1430Sstevel@tonic-gate * 1440Sstevel@tonic-gate * void (*pcbe_allstop)(void); 1450Sstevel@tonic-gate * 1460Sstevel@tonic-gate * Stops all hardware performance counters. 1470Sstevel@tonic-gate * 1480Sstevel@tonic-gate * void (*pcbe_sample)(void *token); 1490Sstevel@tonic-gate * 1500Sstevel@tonic-gate * Samples the values in the performance couters and updates the locations 1510Sstevel@tonic-gate * returned by kcpc_next_config() with the delta since the last sample. 1520Sstevel@tonic-gate * 1530Sstevel@tonic-gate * void (*pcbe_free)(void *config); 1540Sstevel@tonic-gate * 1550Sstevel@tonic-gate * Frees the given configuration. 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate #ifdef __cplusplus 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate #endif 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate #endif /* _SYS_CPC_PCBE_H */ 163