niagara2_pcbe.c revision c4c6ba57afa115b6a7e20afa6a2da6c99f521616
/*
* 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
*/
/*
*/
/*
* This file contains preset event names from the Performance Application
* Programming Interface v3.5 which included the following notice:
*
* Copyright (c) 2005,6
* Innovative Computing Labs
* Computer Science Department,
* University of Tennessee,
* Knoxville, TN.
* All Rights Reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* * Neither the name of the University of Tennessee nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* This open source software license conforms to the BSD License template.
*/
/*
* Niagara2 Performance Counter Backend
*/
#include <sys/archsystm.h>
#include <sys/cpc_impl.h>
#include <sys/cpc_pcbe.h>
#include <sys/machsystm.h>
#include <sys/niagara2regs.h>
#include <sys/hypervisor_api.h>
/*LINTLIBRARY*/
static int ni2_pcbe_init(void);
static uint_t ni2_pcbe_ncounters(void);
static const char *ni2_pcbe_impl_name(void);
static const char *ni2_pcbe_cpuref(void);
static char *ni2_pcbe_list_attrs(void);
static uint64_t ni2_pcbe_overflow_bitmap(void);
void *token);
static void ni2_pcbe_program(void *token);
static void ni2_pcbe_allstop(void);
static void ni2_pcbe_sample(void *token);
static void ni2_pcbe_free(void *config);
extern void ultra_setpcr(uint64_t);
extern uint64_t ultra_getpcr(void);
extern void ultra_setpic(uint64_t);
extern uint64_t ultra_getpic(void);
extern uint64_t ultra_gettick(void);
extern char cpu_module_name[];
#define L2_dmiss_ld_event 0x320
int pcbe_l2dmiss_ovtrap_enable = 0;
};
typedef struct _ni2_pcbe_config {
typedef struct _ni2_event {
const char *name;
} ni2_event_t;
typedef struct _ni2_generic_event {
char *name;
char *event;
/*
* We update this array in the program and allstop routine. The array
* is checked in the sample routine to allow us to only perform the
* PCR.ht bit check when counting is in progress.
*/
static ni2_event_t ni2_events[] = {
{ "Idle_strands", 0x000, 0x00 },
{ "Br_completed", 0x201, 0xff },
{ "Br_taken", 0x202, 0xff },
{ "Instr_FGU_arithmetic", 0x204, 0xff },
{ "Instr_ld", 0x208, 0xff },
{ "Instr_st", 0x210, 0xff },
{ "Instr_sw", 0x220, 0xff },
{ "Instr_other", 0x240, 0xff },
{ "Atomics", 0x280, 0xff },
{ "Instr_cnt", 0x2fd, 0xff },
{ "IC_miss", 0x301, 0x33 },
{ "DC_miss", 0x302, 0x33 },
{ "L2_imiss", 0x310, 0x33 },
{ "L2_dmiss_ld", 0x320, 0x33 },
{ "ITLB_HWTW_ref_L2", 0x404, 0x3c },
{ "DTLB_HWTW_ref_L2", 0x408, 0x3c },
{ "ITLB_HWTW_miss_L2", 0x410, 0x3c },
{ "DTLB_HWTW_miss_L2", 0x420, 0x3c },
{ "Stream_ld_to_PCX", 0x501, 0x3f },
{ "Stream_st_to_PCX", 0x502, 0x3f },
{ "CPU_ld_to_PCX", 0x504, 0x3f },
{ "CPU_ifetch_to_PCX", 0x508, 0x3f },
{ "CPU_st_to_PCX", 0x510, 0x3f },
{ "MMU_ld_to_PCX", 0x520, 0x3f },
#ifdef KT_IMPL
{ "DES_3DES_op", 0x601, 0xff },
{ "AES_op", 0x602, 0xff },
{ "Kasumi_op", 0x604, 0xff },
{ "MD5_SHA-1_SHA-256_op", 0x608, 0xff },
{ "MA_op", 0x610, 0xff },
{ "CRC_TCPIP_cksum", 0x620, 0xff },
{ "DES_3DES_busy_cycle", 0x701, 0xff },
{ "AES_busy_cycle", 0x702, 0xff },
{ "Kasumi_busy_cycle", 0x704, 0xff },
{ "MD5_SHA-1_SHA-256_busy_cycle", 0x708, 0xff },
{ "MA_busy_cycle", 0x710, 0xff },
{ "CRC_MPA_cksum", 0x720, 0xff },
#else
{ "DES_3DES_op", 0x601, 0x3f },
{ "AES_op", 0x602, 0x3f },
{ "RC4_op", 0x604, 0x3f },
{ "MD5_SHA-1_SHA-256_op", 0x608, 0x3f },
{ "MA_op", 0x610, 0x3f },
{ "CRC_TCPIP_cksum", 0x620, 0x3f },
{ "DES_3DES_busy_cycle", 0x701, 0x3f },
{ "AES_busy_cycle", 0x702, 0x3f },
{ "RC4_busy_cycle", 0x704, 0x3f },
{ "MD5_SHA-1_SHA-256_busy_cycle", 0x708, 0x3f },
{ "MA_busy_cycle", 0x710, 0x3f },
{ "CRC_MPA_cksum", 0x720, 0x3f },
#endif
{ "ITLB_miss", 0xb04, 0x0c },
{ "DTLB_miss", 0xb08, 0x0c },
{ "TLB_miss", 0xb0c, 0x0c },
};
static ni2_generic_event_t ni2_generic_events[] = {
{ "PAPI_tot_ins", "Instr_cnt" },
{ "PAPI_l1_dcm", "DC_miss" },
{ "PAPI_l1_icm", "IC_miss" },
{ "PAPI_l2_icm", "L2_imiss" },
{ "PAPI_l2_ldm", "L2_dmiss_ld" },
{ "PAPI_tlb_dm", "DTLB_miss" },
{ "PAPI_tlb_im", "ITLB_miss" },
{ "PAPI_tlb_tm", "TLB_miss" },
{ "PAPI_br_tkn", "Br_taken" },
{ "PAPI_br_ins", "Br_completed" },
{ "PAPI_ld_ins", "Instr_ld" },
{ "PAPI_sr_ins", "Instr_st" },
{ "PAPI_fp_ops", "Instr_FGU_arithmetic" },
{ "PAPI_fp_ins", "Instr_FGU_arithmetic" },
};
static char *evlist;
static uint16_t pcr_pic0_mask;
static uint16_t pcr_pic1_mask;
#define CPU_REF_URL " Documentation for Sun processors can be found at: " \
#if defined(NIAGARA2_IMPL)
static const char *cpu_impl_name = "UltraSPARC T2";
static const char *cpu_pcbe_ref = "See the \"UltraSPARC T2 User's Manual\" "
"for descriptions of these events." CPU_REF_URL;
#elif defined(VFALLS_IMPL)
static const char *cpu_impl_name = "UltraSPARC T2+";
static const char *cpu_pcbe_ref = "See the \"UltraSPARC T2+ User's Manual\" "
"for descriptions of these events." CPU_REF_URL;
static const char *cpu_impl_name = "SPARC T3";
static const char *cpu_pcbe_ref = "See the \"SPARC T3 User's Manual\" "
"for descriptions of these events." CPU_REF_URL;
#endif
static int
ni2_pcbe_init(void)
{
int status;
#if defined(NIAGARA2_IMPL)
#elif defined(VFALLS_IMPL)
#endif
/*
* Validate API version for Niagara2 specific hypervisor services
*/
"or unsupported major number: group: 0x%lx major: 0x%lx "
"minor: 0x%lx errno: %d", hsvc_cpu_group,
}
/*
* Construct event list.
*
* First pass: Calculate size needed. We'll need an additional byte
* for the NULL pointer during the last strcat.
*
* Second pass: Copy strings.
*/
evlist[0] = '\0';
}
}
/*
* Remove trailing comma.
*/
return (0);
}
static uint_t
ni2_pcbe_ncounters(void)
{
return (2);
}
static const char *
ni2_pcbe_impl_name(void)
{
return (cpu_impl_name);
}
static const char *
ni2_pcbe_cpuref(void)
{
return (cpu_pcbe_ref);
}
static char *
{
return (evlist);
}
static char *
ni2_pcbe_list_attrs(void)
{
if (cpu_hsvc_available == B_TRUE)
#if defined(NIAGARA2_IMPL)
return ("hpriv,emask");
#elif defined(VFALLS_IMPL)
return ("hpriv,l2ctl,emask");
return ("hpriv,l2ctl,emask,sample");
#endif
else
#if defined(KT_IMPL)
return ("emask,sample");
#else
return ("emask");
#endif
}
static ni2_generic_event_t *
find_generic_event(char *name)
{
return (gevp);
}
return (NULL);
}
static ni2_event_t *
find_event(char *name)
{
return (evp);
return (NULL);
}
/*ARGSUSED*/
static uint64_t
ni2_pcbe_event_coverage(char *event)
{
/*
* Check whether counter event is supported
*/
return (0);
/*
* Fortunately, both pic0 and pic1 can count all events.
*/
return (0x3);
}
static uint64_t
ni2_pcbe_overflow_bitmap(void)
{
pcr = ultra_getpcr();
pic = ultra_getpic();
if (overflow & 0x1) {
pcr &= ~(CPC_PCR_OV0_MASK |
#if defined(KT_IMPL)
if (pcr & CPC_PCR_SAMPLE_MODE_MASK)
#endif
if (pic_inrange) {
pic0 = 0;
update_pic = B_TRUE;
}
}
if (overflow & 0x2) {
pcr &= ~(CPC_PCR_OV1_MASK |
#if defined(KT_IMPL)
if (pcr & CPC_PCR_SAMPLE_MODE_MASK)
#endif
if (pic_inrange) {
pic1 = 0;
update_pic = B_TRUE;
}
}
if (update_pic)
/*
* The HV interface does not need to be used here because we are
* only resetting the OV bits and do not need to set the HT bit.
*/
return (overflow);
}
/*ARGSUSED*/
static int
{
int i;
#if defined(VFALLS_IMPL) || defined(KT_IMPL)
#endif
/*
* If we've been handed an existing configuration, we need only preset
* the counter value.
*/
return (0);
}
if (picnum > 1)
return (CPC_INVALID_PICNUM);
if (nattrs > 0)
return (CPC_ATTRIBUTE_OUT_OF_RANGE);
} else {
return (CPC_INVALID_EVENT);
}
}
for (i = 0; i < nattrs; i++) {
flags |= CPC_COUNT_HV;
return (CPC_ATTRIBUTE_OUT_OF_RANGE);
#if defined(VFALLS_IMPL) || defined(KT_IMPL)
return (CPC_ATTRIBUTE_OUT_OF_RANGE);
else
#endif
#if defined(KT_IMPL)
#endif
} else
return (CPC_INVALID_ATTRIBUTE);
}
#if defined(VFALLS_IMPL) || defined(KT_IMPL)
/*
* Set PERF_CONTROL bits in L2_CONTROL_REG only when events have
* SL bits equal to 3.
*/
return (CPC_HV_NO_ACCESS);
}
#endif
/*
* Find other requests that will be programmed with this one, and ensure
* the flags don't conflict.
*/
return (CPC_CONFLICTING_REQS);
/*
* If the hpriv attribute is present, make sure we have
* access to hyperprivileged events before continuing with
* this configuration. If we can set the ht bit in the PCR
* successfully, we must have access to hyperprivileged
* events.
*
* If this is a static per-CPU configuration, the CPC
* driver ensures there can not be more than one for this
* CPU. If this is a per-LWP configuration, the driver
* ensures no static per-CPU counting is ongoing and that
* the target LWP is not already being monitored.
*/
if (flags & CPC_COUNT_HV) {
allstopped | CPC_PCR_HT);
return (CPC_HV_NO_ACCESS);
}
}
return (0);
}
static void
ni2_pcbe_program(void *token)
{
/* enable trap-on-event for pic0 and pic1 */
NULL)
}
if (pic0->pcbe_picno != 0) {
/*
* pic0 is counter 1, so if we need the null config it should
* be counter 0.
*/
nullcfg.pcbe_picno = 0;
}
/*
* UltraSPARC does not allow pic0 to be configured differently
* from pic1. If the flags on these two configurations are
* different, they are incompatible. This condition should be
* caught at configure time.
*/
#if defined(KT_IMPL)
#endif
if (pcbe_l2dmiss_ovtrap_enable == 0) {
/*
* SW workaround for HW Erratum 108.
* Disable overflow interrupts when L2_dmiss_ld event is
* selected.
*/
toe &= ~CPC_PCR_TOE0;
toe &= ~CPC_PCR_TOE1;
}
/*
* The ht bit in the PCR is only writable in
* hyperprivileged mode. So if we are counting
* hpriv events, we must use the HV interface
* hv_niagara_setperf to set the PCR. If this
* fails, assume we no longer have access to
* hpriv events.
*/
return;
}
} else
/* Set the PCR with no hpriv event counting enabled. */
/*
* On UltraSPARC, only read-to-read counts are accurate. We cannot
* expect the value we wrote into the PIC, above, to be there after
* starting the counter. We must sample the counter value now and use
* that as the baseline for future samples.
*/
curpic = ultra_getpic();
}
static void
ni2_pcbe_allstop(void)
{
/*
* We use the HV interface here because if we were counting
* hyperprivileged events, we must reset the PCR.ht bit to stop
* the counting. In the event that this HV call fails, we fall
* back on ultra_setpcr which does not have write access to the
* ht bit.
*/
}
static void
ni2_pcbe_sample(void *token)
{
curpic = ultra_getpic();
}
if (pic0->pcbe_picno != 0) {
nullcfg.pcbe_picno = 0;
}
/*
* If the hpriv attribute is present, but the HT bit
* is not set in the PCR, access to hyperprivileged
* events must have been revoked. Only perform this
* check if counting is not stopped.
*/
pcr = ultra_getpcr();
!(pcr & CPC_PCR_HT)) {
return;
}
}
if (diff < 0)
if (diff < 0)
}
static void
ni2_pcbe_free(void *config)
{
}
#if defined(NIAGARA2_IMPL)
"UltraSPARC T2 Performance Counters",
#elif defined(VFALLS_IMPL)
"UltraSPARC T2+ Performance Counters",
"SPARC T3 Performance Counters",
#endif
};
static struct modlinkage modl = {
&modlpcbe,
};
int
_init(void)
{
if (ni2_pcbe_init() != 0)
return (ENOTSUP);
return (mod_install(&modl));
}
int
_fini(void)
{
return (mod_remove(&modl));
}
int
{
}