niagara_perfctr.c revision a588362c0375ebed265afad9dd5a60b5739820df
/*
* 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
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/ddi_impldefs.h>
#include <sys/machsystm.h>
#include <sys/hypervisor_api.h>
#if defined(NIAGARA_IMPL)
#include <sys/niagararegs.h>
#include <sys/niagara2regs.h>
#endif
extern char cpu_module_name[];
/*
* Data structure used to build array of event-names and pcr-mask values
*/
typedef struct ni_kev_mask {
char *event_name;
/*
* Kstat data structure for DRAM and JBUS performance counters
*
* Note that these performance counters are only 31 bits wide. Since
* the "busstat" command assumes a 32-bit counter, we emulate a 32-bit
* counter by detecting overflow on read of these performance counters
* and using the least significant bit of the overflow count as the
* most significant bit (i.e. bit# 31) of the DRAM and JBUS performance
* counters.
*/
#define NUM_OF_PICS 2
typedef struct ni_ksinfo {
} ni_ksinfo_t;
#if defined(NIAGARA_IMPL)
static ni_ksinfo_t *ni_jbus_kstat;
#endif
typedef struct ni_perf_regs {
static ni_perf_regs_t dram_perf_regs[] = {
#ifdef VFALLS_IMPL
#endif
};
#ifdef VFALLS_IMPL
/*
* Kstat data structure for Zambezi performance counters
* These performance counters are 64 bits wide.
*/
typedef struct zam_perf_regs {
static zam_perf_regs_t lpu_perf_regs[] = {
};
static zam_perf_regs_t gpd_perf_regs[] = {
};
static zam_perf_regs_t asu_perf_regs[] = {
};
static int zam_cntr_kstat_update(kstat_t *, int);
#endif
static void ni_delete_name_kstat(ni_ksinfo_t *);
static kstat_t *ni_create_cntr_kstat(char *, int,
static int ni_cntr_kstat_update(kstat_t *, int);
static kstat_t *ni_create_picN_kstat(char *, int, int, int,
ni_kev_mask_t *);
#ifdef DEBUG
static int ni_perf_debug;
#endif
/*
* Niagara, Niagara2 and VFalls DRAM Performance Events
*/
static ni_kev_mask_t
niagara_dram_events[] = {
{"mem_reads", 0x0},
{"mem_writes", 0x1},
{"mem_read_write", 0x2},
#if defined(NIAGARA_IMPL)
{"bank_busy_stalls", 0x3},
#endif
{"rd_queue_latency", 0x4},
{"wr_queue_latency", 0x5},
{"rw_queue_latency", 0x6},
{"wb_buf_hits", 0x7},
{"clear_pic", 0xf}
};
#if defined(VFALLS_IMPL)
/*
* Zambezi Performance Events
*/
static ni_kev_mask_t
zam_lpu_perf_events[] = {
{"none", 0x0},
{"clock_cycles", 0x1},
{"cycles_c2c_portX", 0x2},
{"cycles_mem_portX", 0x3},
{"cycles_WB_portX", 0x4},
{"cycles_NC_portX", 0x5},
{"cycles_c2c_portY", 0x6},
{"cycles_mem_portY", 0x7},
{"cycles_WB_portY", 0x8},
{"cycles_NC_portY", 0x9},
{"cycles_c2c_portZ", 0xa},
{"cycles_mem_portZ", 0xb},
{"cycles_WB_portZ", 0xc},
{"cycles_NC_portZ", 0xd},
{"cycles_TID_WB", 0xe},
{"cycles_TID_INV", 0xf},
{"cycles_TID_RTD", 0x10},
{"cycles_TID_RTO", 0x11},
{"cycles_TID_RTS", 0x12},
{"cycles_IO_WRM", 0x13},
{"cycles_IO_RD", 0x14},
{"cycles_WB_egress", 0x15},
{"cycles_INV_egress", 0x16},
{"cycles_RTO_egress", 0x17},
{"cycles_RTD_egress", 0x18},
{"cycles_RTS_egress", 0x19},
{"cycles_no_WB", 0x1a},
{"cycles_no_read/inv", 0x1b},
{"cycles_HIT_M", 0x1c},
{"cycles_HIT_O", 0x1d},
{"cycles_HIT_S", 0x1e},
{"cycles_WB_HIT", 0x1f},
{"cycles_MISS", 0x20},
{"cycles_READ_or_INV", 0x21},
{"cycles_WB", 0x22},
{"cycles_NDR", 0x23},
{"cycles_cache_miss", 0x24},
{"cycles_cache_hit", 0x25},
{"cycles_CRC_errors", 0x26},
{"cycles_replys_sent", 0x27},
{"cycles_replys_recev", 0x28},
{"cycles_link_retrain", 0x29},
{"clear_pic", 0xff}
};
static ni_kev_mask_t
zam_gpd_perf_events[] = {
{"none", 0x0},
{"clock_cycles", 0x1},
{"clear_pic", 0xf}
};
static ni_kev_mask_t
zam_asu_perf_events[] = {
{"none", 0x0},
{"clock_cycles", 0x1},
{"asu_in_pck", 0x2},
{"asu_out_pck", 0x3},
{"asu_CAM_hit", 0x4},
{"asu_wakeup", 0x5},
{"clear_pic", 0xf}
};
#endif
#if defined(NIAGARA_IMPL)
/*
* Niagara JBUS Performance Events
*/
static ni_kev_mask_t
niagara_jbus_events[] = {
{"jbus_cycles", 0x1},
{"dma_reads", 0x2},
{"dma_read_latency", 0x3},
{"dma_writes", 0x4},
{"dma_write8", 0x5},
{"ordering_waits", 0x6},
{"pio_reads", 0x8},
{"pio_read_latency", 0x9},
{"aok_dok_off_cycles", 0xc},
{"aok_off_cycles", 0xd},
{"dok_off_cycles", 0xe},
{"clear_pic", 0xf}
};
#endif
/*
* Create the picN kstats for DRAM, JBUS and Zambezi events
*/
void
{
int i;
#ifdef VFALLS_IMPL
#endif
#ifdef DEBUG
if (ni_perf_debug)
printf("ni_kstat_init called\n");
#endif
/*
* Create DRAM perf events kstat
*/
for (i = 0; i < NIAGARA_DRAM_BANKS; i++) {
#ifdef VFALLS_IMPL
/* check if this dram instance is enabled in the HW */
#endif
sizeof (ni_ksinfo_t), KM_NOSLEEP);
"%s: no space for dram kstat\n",
break;
}
sizeof (niagara_dram_events) /
sizeof (ni_kev_mask_t);
ni_dram_kstats[i] = ksinfop;
if (i == 0)
/* create counter kstats */
#ifdef VFALLS_IMPL
}
#endif
}
#ifdef VFALLS_IMPL
/*
* Create Zambezi LPU perf events kstat
*/
for (i = 0; i < ZAMBEZI_LPU_COUNTERS; i++) {
/* check if this Zambezi LPU instance is enabled in the HW */
sizeof (ni_ksinfo_t), KM_NOSLEEP);
"%s: no space for zambezi lpu kstat\n",
break;
}
sizeof (zam_lpu_perf_events) /
sizeof (ni_kev_mask_t);
zam_lpu_kstats[i] = ksinfop;
if (i == 0)
/* create counter kstats */
}
}
/*
* Create Zambezi GPD perf events kstat
*/
for (i = 0; i < ZAMBEZI_GPD_COUNTERS; i++) {
/* check if this Zambezi GPD instance is enabled in the HW */
sizeof (ni_ksinfo_t), KM_NOSLEEP);
"%s: no space for zambezi gpd kstat\n",
break;
}
sizeof (zam_gpd_perf_events) /
sizeof (ni_kev_mask_t);
zam_gpd_kstats[i] = ksinfop;
if (i == 0)
/* create counter kstats */
}
}
/*
* Create Zambezi ASU perf events kstat
*/
for (i = 0; i < ZAMBEZI_ASU_COUNTERS; i++) {
/* check if this Zambezi ASU instance is enabled in the HW */
sizeof (ni_ksinfo_t), KM_NOSLEEP);
"%s: no space for zambezi asu kstat\n",
break;
}
sizeof (zam_asu_perf_events) /
sizeof (ni_kev_mask_t);
zam_asu_kstats[i] = ksinfop;
if (i == 0)
/* create counter kstats */
}
}
#endif
#if defined(NIAGARA_IMPL)
/*
* Create JBUS perf events kstat
*/
if (ni_jbus_kstat == NULL) {
} else {
sizeof (niagara_jbus_events) / sizeof (ni_kev_mask_t);
}
#endif
}
void
{
int i;
#ifdef DEBUG
if (ni_perf_debug)
printf("ni_kstat_fini called\n");
#endif
for (i = 0; i < NIAGARA_DRAM_BANKS; i++) {
if (ni_dram_kstats[i] != NULL) {
ni_dram_kstats[i] = NULL;
}
}
#if defined(VFALLS_IMPL)
for (i = 0; i < ZAMBEZI_LPU_COUNTERS; i++) {
if (zam_lpu_kstats[i] != NULL) {
zam_lpu_kstats[i] = NULL;
}
}
for (i = 0; i < ZAMBEZI_GPD_COUNTERS; i++) {
if (zam_gpd_kstats[i] != NULL) {
zam_gpd_kstats[i] = NULL;
}
}
for (i = 0; i < ZAMBEZI_ASU_COUNTERS; i++) {
if (zam_asu_kstats[i] != NULL) {
zam_asu_kstats[i] = NULL;
}
}
#endif
#if defined(NIAGARA_IMPL)
if (ni_jbus_kstat != NULL) {
}
#endif
}
static void
{
int i;
#ifdef DEBUG
if (ni_perf_debug > 1)
#endif
for (i = 0; i < NUM_OF_PICS; i++) {
}
}
}
static void
{
int i;
for (i = 0; i < NUM_OF_PICS; i++) {
}
}
}
/*
* Create the picN kstat. Returns a pointer to the
* kstat which the driver must store to allow it
* to be deleted when necessary.
*/
static kstat_t *
{
struct kstat_named *pic_named_data;
int inst = 0;
int event;
char pic_name[30];
/*
* It is up to the calling function to delete any kstats
* that may have been created already. We just
* return NULL to indicate an error has occured.
*/
return (NULL);
}
pic_named_data = (struct kstat_named *)
/*
* Write event names and their associated pcr masks. The
* last entry in the array (clear_pic) is added seperately
* below as the pic value must be inverted.
*/
}
/*
* add the clear_pic entry.
*/
return (picN_ksp);
}
/*
* Create the "counters" kstat.
*/
static kstat_t *
void *ksinfop)
{
struct kstat *counters_ksp;
struct kstat_named *counters_named_data;
char pic_str[10];
int i;
int num_pics = NUM_OF_PICS;
#ifdef DEBUG
if (ni_perf_debug > 1)
printf("ni_create_cntr_kstat: name: %s instance: %d\n",
#endif
/*
* Size of kstat is num_pics + 1 as it
* also contains the %pcr
*/
"%s: kstat_create for %s%d failed", cpu_module_name,
return (NULL);
}
/*
* Iinitialize the named kstats
*/
for (i = 0; i < num_pics; i++) {
}
/*
* Store the register offset's in the kstat's
* private field so that they are available
* to the update function.
*/
return (counters_ksp);
}
#if defined(VFALLS_IMPL)
/*
*/
static int
{
struct kstat_named *data_p;
int stat = 0;
if (rw == KSTAT_WRITE) {
#ifdef DEBUG
if (ni_perf_debug)
printf("zam_cntr_kstat_update: wr pcr-%d: %lx\n",
#endif
} else {
do {
&pic0);
} while (pic0_stat == H_EWOULDBLOCK);
do {
&pic1);
} while (pic1_stat == H_EWOULDBLOCK);
do {
&pcr);
} while (pcr_stat == H_EWOULDBLOCK);
else {
}
#ifdef DEBUG
if (ni_perf_debug)
printf("zam_cntr_kstat_update: rd pcr%d: %lx "
"pic0: %16lx pic1: %16lx\n",
#endif
}
return (stat);
}
#endif
/*
*/
static int
{
struct kstat_named *data_p;
int stat = 0;
if (rw == KSTAT_WRITE) {
#ifdef DEBUG
if (ni_perf_debug)
printf("ni_cntr_kstat_update: wr pcr-%d: %lx\n",
#endif
} else {
else {
/*
* Generate a 32-bit PIC0 value by detecting overflow
*/
ksinfop->pic_overflow[0]++;
/*
* Generate a 32-bit PIC1 value by detecting overflow
*/
}
#ifdef DEBUG
if (ni_perf_debug)
printf("ni_cntr_kstat_update: rd pcr%d: %lx "
"pic%d: %16lx pic0: %8lx pic1: %8lx\n",
#endif
}
return (stat);
}