cvmx-log.h revision 210286
1231990Smp/***********************license start*************** 259243Sobrien * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights 359243Sobrien * reserved. 459243Sobrien * 559243Sobrien * 659243Sobrien * Redistribution and use in source and binary forms, with or without 759243Sobrien * modification, are permitted provided that the following conditions are 8231990Smp * met: 9231990Smp * 10231990Smp * * Redistributions of source code must retain the above copyright 1159243Sobrien * notice, this list of conditions and the following disclaimer. 1259243Sobrien * 1359243Sobrien * * Redistributions in binary form must reproduce the above 1459243Sobrien * copyright notice, this list of conditions and the following 1559243Sobrien * disclaimer in the documentation and/or other materials provided 1659243Sobrien * with the distribution. 1759243Sobrien * 1859243Sobrien * * Neither the name of Cavium Networks nor the names of 1959243Sobrien * its contributors may be used to endorse or promote products 20231990Smp * derived from this software without specific prior written 2159243Sobrien * permission. 2259243Sobrien * 2359243Sobrien * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 2459243Sobrien * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS 2559243Sobrien * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 2659243Sobrien * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 27231990Smp * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 28231990Smp * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES 2959243Sobrien * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR 3059243Sobrien * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET 3159243Sobrien * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT 3259243Sobrien * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 33231990Smp * 3459243Sobrien * 35231990Smp * For any questions regarding licensing please contact marketing@caviumnetworks.com 3659243Sobrien * 3759243Sobrien ***********************license end**************************************/ 3859243Sobrien 3959243Sobrien 40231990Smp 4159243Sobrien 4259243Sobrien 4359243Sobrien#ifndef __CVMX_LOG_H__ 4459243Sobrien#define __CVMX_LOG_H__ 45231990Smp 4659243Sobrien/** 47231990Smp * @file 48231990Smp * 4959243Sobrien * cvmx-log supplies a fast log buffer implementation. Each core writes 5059243Sobrien * log data to a differnet buffer to avoid synchronization overhead. Function 5159243Sobrien * call logging can be turned on with the GCC option "-pg". 5259243Sobrien * 5359243Sobrien * <hr>$Revision: 41586 $<hr> 5459243Sobrien */ 55231990Smp 5659243Sobrien#ifdef __cplusplus 5759243Sobrienextern "C" { 5859243Sobrien#endif 5959243Sobrien 6059243Sobrien/** 61231990Smp * Enumeration of all supported performance counter types 6259243Sobrien */ 6359243Sobrientypedef enum 6459243Sobrien{ 6559243Sobrien CVMX_LOG_PERF_CNT_NONE = 0, /**< Turn off the performance counter */ 6659243Sobrien CVMX_LOG_PERF_CNT_CLK = 1, /**< Conditionally clocked cycles (as opposed to count/cvm_count which count even with no clocks) */ 67231990Smp CVMX_LOG_PERF_CNT_ISSUE = 2, /**< Instructions issued but not retired */ 6859243Sobrien CVMX_LOG_PERF_CNT_RET = 3, /**< Instructions retired */ 6959243Sobrien CVMX_LOG_PERF_CNT_NISSUE = 4, /**< Cycles no issue */ 7059243Sobrien CVMX_LOG_PERF_CNT_SISSUE = 5, /**< Cycles single issue */ 7159243Sobrien CVMX_LOG_PERF_CNT_DISSUE = 6, /**< Cycles dual issue */ 72231990Smp CVMX_LOG_PERF_CNT_IFI = 7, /**< Cycle ifetch issued (but not necessarily commit to pp_mem) */ 7359243Sobrien CVMX_LOG_PERF_CNT_BR = 8, /**< Branches retired */ 74231990Smp CVMX_LOG_PERF_CNT_BRMIS = 9, /**< Branch mispredicts */ 7559243Sobrien CVMX_LOG_PERF_CNT_J = 10, /**< Jumps retired */ 7659243Sobrien CVMX_LOG_PERF_CNT_JMIS = 11, /**< Jumps mispredicted */ 7759243Sobrien CVMX_LOG_PERF_CNT_REPLAY = 12, /**< Mem Replays */ 7859243Sobrien CVMX_LOG_PERF_CNT_IUNA = 13, /**< Cycles idle due to unaligned_replays */ 7959243Sobrien CVMX_LOG_PERF_CNT_TRAP = 14, /**< trap_6a signal */ 8059243Sobrien CVMX_LOG_PERF_CNT_UULOAD = 16, /**< Unexpected unaligned loads (REPUN=1) */ 8159243Sobrien CVMX_LOG_PERF_CNT_UUSTORE = 17, /**< Unexpected unaligned store (REPUN=1) */ 8259243Sobrien CVMX_LOG_PERF_CNT_ULOAD = 18, /**< Unaligned loads (REPUN=1 or USEUN=1) */ 8359243Sobrien CVMX_LOG_PERF_CNT_USTORE = 19, /**< Unaligned store (REPUN=1 or USEUN=1) */ 8459243Sobrien CVMX_LOG_PERF_CNT_EC = 20, /**< Exec clocks(must set CvmCtl[DISCE] for accurate timing) */ 8559243Sobrien CVMX_LOG_PERF_CNT_MC = 21, /**< Mul clocks(must set CvmCtl[DISCE] for accurate timing) */ 8659243Sobrien CVMX_LOG_PERF_CNT_CC = 22, /**< Crypto clocks(must set CvmCtl[DISCE] for accurate timing) */ 87231990Smp CVMX_LOG_PERF_CNT_CSRC = 23, /**< Issue_csr clocks(must set CvmCtl[DISCE] for accurate timing) */ 8859243Sobrien CVMX_LOG_PERF_CNT_CFETCH = 24, /**< Icache committed fetches (demand+prefetch) */ 89231990Smp CVMX_LOG_PERF_CNT_CPREF = 25, /**< Icache committed prefetches */ 9059243Sobrien CVMX_LOG_PERF_CNT_ICA = 26, /**< Icache aliases */ 9159243Sobrien CVMX_LOG_PERF_CNT_II = 27, /**< Icache invalidates */ 9259243Sobrien CVMX_LOG_PERF_CNT_IP = 28, /**< Icache parity error */ 9359243Sobrien CVMX_LOG_PERF_CNT_CIMISS = 29, /**< Cycles idle due to imiss (must set CvmCtl[DISCE] for accurate timing) */ 9459243Sobrien CVMX_LOG_PERF_CNT_WBUF = 32, /**< Number of write buffer entries created */ 9559243Sobrien CVMX_LOG_PERF_CNT_WDAT = 33, /**< Number of write buffer data cycles used (may need to set CvmCtl[DISCE] for accurate counts) */ 9659243Sobrien CVMX_LOG_PERF_CNT_WBUFLD = 34, /**< Number of write buffer entries forced out by loads */ 9759243Sobrien CVMX_LOG_PERF_CNT_WBUFFL = 35, /**< Number of cycles that there was no available write buffer entry (may need to set CvmCtl[DISCE] and CvmMemCtl[MCLK] for accurate counts) */ 98231990Smp CVMX_LOG_PERF_CNT_WBUFTR = 36, /**< Number of stores that found no available write buffer entries */ 9959243Sobrien CVMX_LOG_PERF_CNT_BADD = 37, /**< Number of address bus cycles used (may need to set CvmCtl[DISCE] for accurate counts) */ 10059243Sobrien CVMX_LOG_PERF_CNT_BADDL2 = 38, /**< Number of address bus cycles not reflected (i.e. destined for L2) (may need to set CvmCtl[DISCE] for accurate counts) */ 10159243Sobrien CVMX_LOG_PERF_CNT_BFILL = 39, /**< Number of fill bus cycles used (may need to set CvmCtl[DISCE] for accurate counts) */ 10259243Sobrien CVMX_LOG_PERF_CNT_DDIDS = 40, /**< Number of Dstream DIDs created */ 10359243Sobrien CVMX_LOG_PERF_CNT_IDIDS = 41, /**< Number of Istream DIDs created */ 10459243Sobrien CVMX_LOG_PERF_CNT_DIDNA = 42, /**< Number of cycles that no DIDs were available (may need to set CvmCtl[DISCE] and CvmMemCtl[MCLK] for accurate counts) */ 105231990Smp CVMX_LOG_PERF_CNT_LDS = 43, /**< Number of load issues */ 10659243Sobrien CVMX_LOG_PERF_CNT_LMLDS = 44, /**< Number of local memory load */ 10759243Sobrien CVMX_LOG_PERF_CNT_IOLDS = 45, /**< Number of I/O load issues */ 10859243Sobrien CVMX_LOG_PERF_CNT_DMLDS = 46, /**< Number of loads that were not prefetches and missed in the cache */ 10959243Sobrien CVMX_LOG_PERF_CNT_STS = 48, /**< Number of store issues */ 11059243Sobrien CVMX_LOG_PERF_CNT_LMSTS = 49, /**< Number of local memory store issues */ 11159243Sobrien CVMX_LOG_PERF_CNT_IOSTS = 50, /**< Number of I/O store issues */ 11259243Sobrien CVMX_LOG_PERF_CNT_IOBDMA = 51, /**< Number of IOBDMAs */ 11359243Sobrien CVMX_LOG_PERF_CNT_DTLB = 53, /**< Number of dstream TLB refill, invalid, or modified exceptions */ 11459243Sobrien CVMX_LOG_PERF_CNT_DTLBAD = 54, /**< Number of dstream TLB address errors */ 115231990Smp CVMX_LOG_PERF_CNT_ITLB = 55, /**< Number of istream TLB refill, invalid, or address error exceptions */ 116231990Smp CVMX_LOG_PERF_CNT_SYNC = 56, /**< Number of SYNC stall cycles (may need to set CvmCtl[DISCE] for accurate counts) */ 11759243Sobrien CVMX_LOG_PERF_CNT_SYNCIOB = 57, /**< Number of SYNCIOBDMA stall cycles (may need to set CvmCtl[DISCE] for accurate counts) */ 118231990Smp CVMX_LOG_PERF_CNT_SYNCW = 58, /**< Number of SYNCWs */ 11959243Sobrien} cvmx_log_perf_event_t; 120231990Smp 12159243Sobrien/** 122231990Smp * Structure of the performance counter control register 12359243Sobrien */ 124231990Smptypedef union 12559243Sobrien{ 12659243Sobrien uint32_t u32; 12759243Sobrien struct 128231990Smp { 12959243Sobrien uint32_t M : 1; 13059243Sobrien uint32_t W : 1; 13159243Sobrien uint32_t reserved: 19; 132231990Smp cvmx_log_perf_event_t event : 6; 133231990Smp uint32_t IE : 1; 13459243Sobrien uint32_t U : 1; 135231990Smp uint32_t S : 1; 136231990Smp uint32_t K : 1; 13759243Sobrien uint32_t EX : 1; 13859243Sobrien } s; 13959243Sobrien} cvmx_log_perf_control_t; 14059243Sobrien 141/* 142 * Add CVMX_LOG_DISABLE_PC_LOGGING as an attribute to and function prototype 143 * that you don't want logged when the gcc option "-pg" is supplied. We 144 * use it on the cvmx-log functions since it is pointless to log the 145 * calling of a function than in itself writes to the log. 146 */ 147#define CVMX_LOG_DISABLE_PC_LOGGING __attribute__((no_instrument_function)) 148 149/** 150 * Log a constant printf style format string with 0 to 4 151 * arguments. The string must persist until the log is read, 152 * but the parameters are copied into the log. 153 * 154 * @param format Constant printf style format string. 155 * @param numberx 64bit argument to the printf format string 156 */ 157void cvmx_log_printf0(const char *format) CVMX_LOG_DISABLE_PC_LOGGING; 158void cvmx_log_printf1(const char *format, uint64_t number1) CVMX_LOG_DISABLE_PC_LOGGING; 159void cvmx_log_printf2(const char *format, uint64_t number1, uint64_t number2) CVMX_LOG_DISABLE_PC_LOGGING; 160void cvmx_log_printf3(const char *format, uint64_t number1, uint64_t number2, uint64_t number3) CVMX_LOG_DISABLE_PC_LOGGING; 161void cvmx_log_printf4(const char *format, uint64_t number1, uint64_t number2, uint64_t number3, uint64_t number4) CVMX_LOG_DISABLE_PC_LOGGING; 162 163/** 164 * Log an arbitrary block of 64bit words. At most 255 64bit 165 * words can be logged. The words are copied into the log. 166 * 167 * @param size_in_dwords 168 * Number of 64bit dwords to copy into the log. 169 * @param data Array of 64bit dwords to copy 170 */ 171void cvmx_log_data(uint64_t size_in_dwords, const uint64_t *data) CVMX_LOG_DISABLE_PC_LOGGING; 172 173/** 174 * Log a structured data object. Post processing will use the 175 * debugging information in the ELF file to determine how to 176 * display the structure. Max of 2032 bytes. 177 * 178 * Example: 179 * cvmx_log_structure("cvmx_wqe_t", work, sizeof(*work)); 180 * 181 * @param type C typedef expressed as a string. This will be used to 182 * lookup the structure in the debugging infirmation. 183 * @param data Data to be written to the log. 184 * @param size_in_bytes 185 * Size if the data in bytes. Normally you'll use the 186 * sizeof() operator here. 187 */ 188void cvmx_log_structure(const char *type, void *data, int size_in_bytes) CVMX_LOG_DISABLE_PC_LOGGING; 189 190/** 191 * Setup the mips performance counters 192 * 193 * @param counter1 Event type for counter 1 194 * @param counter2 Event type for counter 2 195 */ 196void cvmx_log_perf_setup(cvmx_log_perf_event_t counter1, cvmx_log_perf_event_t counter2); 197 198/** 199 * Log the performance counters 200 */ 201void cvmx_log_perf(void) CVMX_LOG_DISABLE_PC_LOGGING; 202 203/** 204 * Display the current log in a human readable format. 205 */ 206void cvmx_log_display(void); 207 208#ifdef __cplusplus 209} 210#endif 211 212#endif 213