cvmx-log.h revision 210286
1159764Sobrien/***********************license start*************** 268349Sobrien * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights 3159764Sobrien * reserved. 4159764Sobrien * 5133359Sobrien * 6133359Sobrien * Redistribution and use in source and binary forms, with or without 7133359Sobrien * modification, are permitted provided that the following conditions are 868349Sobrien * met: 9133359Sobrien * 10133359Sobrien * * Redistributions of source code must retain the above copyright 11133359Sobrien * notice, this list of conditions and the following disclaimer. 12133359Sobrien * 1368349Sobrien * * Redistributions in binary form must reproduce the above 14159764Sobrien * copyright notice, this list of conditions and the following 1568349Sobrien * disclaimer in the documentation and/or other materials provided 16159764Sobrien * with the distribution. 1784685Sobrien * 1884685Sobrien * * Neither the name of Cavium Networks nor the names of 19159764Sobrien * its contributors may be used to endorse or promote products 20159764Sobrien * derived from this software without specific prior written 21159764Sobrien * permission. 22159764Sobrien * 23159764Sobrien * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 24159764Sobrien * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS 25159764Sobrien * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 26159764Sobrien * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 2784685Sobrien * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 28103373Sobrien * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES 29159764Sobrien * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR 30133359Sobrien * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET 31159764Sobrien * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT 32159764Sobrien * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 33159764Sobrien * 34159764Sobrien * 35159764Sobrien * For any questions regarding licensing please contact marketing@caviumnetworks.com 36159764Sobrien * 37159764Sobrien ***********************license end**************************************/ 38159764Sobrien 39159764Sobrien 40159764Sobrien 41159764Sobrien 42159764Sobrien 43159764Sobrien#ifndef __CVMX_LOG_H__ 4468349Sobrien#define __CVMX_LOG_H__ 45159764Sobrien 46159764Sobrien/** 47159764Sobrien * @file 48159764Sobrien * 49159764Sobrien * cvmx-log supplies a fast log buffer implementation. Each core writes 50159764Sobrien * log data to a differnet buffer to avoid synchronization overhead. Function 51159764Sobrien * call logging can be turned on with the GCC option "-pg". 52159764Sobrien * 53159764Sobrien * <hr>$Revision: 41586 $<hr> 54159764Sobrien */ 55159764Sobrien 56159764Sobrien#ifdef __cplusplus 57159764Sobrienextern "C" { 58159764Sobrien#endif 59159764Sobrien 60159764Sobrien/** 61159764Sobrien * Enumeration of all supported performance counter types 6268349Sobrien */ 6368349Sobrientypedef enum 64159764Sobrien{ 65159764Sobrien CVMX_LOG_PERF_CNT_NONE = 0, /**< Turn off the performance counter */ 66159764Sobrien CVMX_LOG_PERF_CNT_CLK = 1, /**< Conditionally clocked cycles (as opposed to count/cvm_count which count even with no clocks) */ 67133359Sobrien CVMX_LOG_PERF_CNT_ISSUE = 2, /**< Instructions issued but not retired */ 68159764Sobrien CVMX_LOG_PERF_CNT_RET = 3, /**< Instructions retired */ 69159764Sobrien CVMX_LOG_PERF_CNT_NISSUE = 4, /**< Cycles no issue */ 70159764Sobrien CVMX_LOG_PERF_CNT_SISSUE = 5, /**< Cycles single issue */ 71133359Sobrien CVMX_LOG_PERF_CNT_DISSUE = 6, /**< Cycles dual issue */ 72133359Sobrien CVMX_LOG_PERF_CNT_IFI = 7, /**< Cycle ifetch issued (but not necessarily commit to pp_mem) */ 73139368Sobrien CVMX_LOG_PERF_CNT_BR = 8, /**< Branches retired */ 74133359Sobrien CVMX_LOG_PERF_CNT_BRMIS = 9, /**< Branch mispredicts */ 75133359Sobrien CVMX_LOG_PERF_CNT_J = 10, /**< Jumps retired */ 76133359Sobrien CVMX_LOG_PERF_CNT_JMIS = 11, /**< Jumps mispredicted */ 77133359Sobrien CVMX_LOG_PERF_CNT_REPLAY = 12, /**< Mem Replays */ 78133359Sobrien CVMX_LOG_PERF_CNT_IUNA = 13, /**< Cycles idle due to unaligned_replays */ 79139368Sobrien CVMX_LOG_PERF_CNT_TRAP = 14, /**< trap_6a signal */ 80139368Sobrien CVMX_LOG_PERF_CNT_UULOAD = 16, /**< Unexpected unaligned loads (REPUN=1) */ 81159764Sobrien CVMX_LOG_PERF_CNT_UUSTORE = 17, /**< Unexpected unaligned store (REPUN=1) */ 82133359Sobrien CVMX_LOG_PERF_CNT_ULOAD = 18, /**< Unaligned loads (REPUN=1 or USEUN=1) */ 83159764Sobrien CVMX_LOG_PERF_CNT_USTORE = 19, /**< Unaligned store (REPUN=1 or USEUN=1) */ 84159764Sobrien CVMX_LOG_PERF_CNT_EC = 20, /**< Exec clocks(must set CvmCtl[DISCE] for accurate timing) */ 85159764Sobrien CVMX_LOG_PERF_CNT_MC = 21, /**< Mul clocks(must set CvmCtl[DISCE] for accurate timing) */ 86133359Sobrien CVMX_LOG_PERF_CNT_CC = 22, /**< Crypto clocks(must set CvmCtl[DISCE] for accurate timing) */ 87159764Sobrien CVMX_LOG_PERF_CNT_CSRC = 23, /**< Issue_csr clocks(must set CvmCtl[DISCE] for accurate timing) */ 88133359Sobrien CVMX_LOG_PERF_CNT_CFETCH = 24, /**< Icache committed fetches (demand+prefetch) */ 89133359Sobrien CVMX_LOG_PERF_CNT_CPREF = 25, /**< Icache committed prefetches */ 90133359Sobrien CVMX_LOG_PERF_CNT_ICA = 26, /**< Icache aliases */ 91133359Sobrien CVMX_LOG_PERF_CNT_II = 27, /**< Icache invalidates */ 92133359Sobrien CVMX_LOG_PERF_CNT_IP = 28, /**< Icache parity error */ 93133359Sobrien CVMX_LOG_PERF_CNT_CIMISS = 29, /**< Cycles idle due to imiss (must set CvmCtl[DISCE] for accurate timing) */ 94133359Sobrien CVMX_LOG_PERF_CNT_WBUF = 32, /**< Number of write buffer entries created */ 95133359Sobrien CVMX_LOG_PERF_CNT_WDAT = 33, /**< Number of write buffer data cycles used (may need to set CvmCtl[DISCE] for accurate counts) */ 96133359Sobrien CVMX_LOG_PERF_CNT_WBUFLD = 34, /**< Number of write buffer entries forced out by loads */ 97159764Sobrien 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) */ 98133359Sobrien CVMX_LOG_PERF_CNT_WBUFTR = 36, /**< Number of stores that found no available write buffer entries */ 99133359Sobrien CVMX_LOG_PERF_CNT_BADD = 37, /**< Number of address bus cycles used (may need to set CvmCtl[DISCE] for accurate counts) */ 100159764Sobrien 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) */ 101133359Sobrien CVMX_LOG_PERF_CNT_BFILL = 39, /**< Number of fill bus cycles used (may need to set CvmCtl[DISCE] for accurate counts) */ 102133359Sobrien CVMX_LOG_PERF_CNT_DDIDS = 40, /**< Number of Dstream DIDs created */ 103133359Sobrien CVMX_LOG_PERF_CNT_IDIDS = 41, /**< Number of Istream DIDs created */ 104133359Sobrien 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) */ 105159764Sobrien CVMX_LOG_PERF_CNT_LDS = 43, /**< Number of load issues */ 106159764Sobrien CVMX_LOG_PERF_CNT_LMLDS = 44, /**< Number of local memory load */ 107159764Sobrien CVMX_LOG_PERF_CNT_IOLDS = 45, /**< Number of I/O load issues */ 108159764Sobrien CVMX_LOG_PERF_CNT_DMLDS = 46, /**< Number of loads that were not prefetches and missed in the cache */ 109159764Sobrien CVMX_LOG_PERF_CNT_STS = 48, /**< Number of store issues */ 110139368Sobrien CVMX_LOG_PERF_CNT_LMSTS = 49, /**< Number of local memory store issues */ 111159764Sobrien CVMX_LOG_PERF_CNT_IOSTS = 50, /**< Number of I/O store issues */ 112159764Sobrien CVMX_LOG_PERF_CNT_IOBDMA = 51, /**< Number of IOBDMAs */ 113159764Sobrien CVMX_LOG_PERF_CNT_DTLB = 53, /**< Number of dstream TLB refill, invalid, or modified exceptions */ 114159764Sobrien CVMX_LOG_PERF_CNT_DTLBAD = 54, /**< Number of dstream TLB address errors */ 115159764Sobrien CVMX_LOG_PERF_CNT_ITLB = 55, /**< Number of istream TLB refill, invalid, or address error exceptions */ 116159764Sobrien CVMX_LOG_PERF_CNT_SYNC = 56, /**< Number of SYNC stall cycles (may need to set CvmCtl[DISCE] for accurate counts) */ 117159764Sobrien CVMX_LOG_PERF_CNT_SYNCIOB = 57, /**< Number of SYNCIOBDMA stall cycles (may need to set CvmCtl[DISCE] for accurate counts) */ 118159764Sobrien CVMX_LOG_PERF_CNT_SYNCW = 58, /**< Number of SYNCWs */ 119159764Sobrien} cvmx_log_perf_event_t; 120133359Sobrien 121133359Sobrien/** 122133359Sobrien * Structure of the performance counter control register 123133359Sobrien */ 124159764Sobrientypedef union 125159764Sobrien{ 126159764Sobrien uint32_t u32; 127159764Sobrien struct 128133359Sobrien { 129159764Sobrien uint32_t M : 1; 130159764Sobrien uint32_t W : 1; 131139368Sobrien uint32_t reserved: 19; 132159764Sobrien cvmx_log_perf_event_t event : 6; 133159764Sobrien uint32_t IE : 1; 134159764Sobrien uint32_t U : 1; 135133359Sobrien uint32_t S : 1; 136159764Sobrien uint32_t K : 1; 137159764Sobrien uint32_t EX : 1; 138133359Sobrien } s; 139159764Sobrien} cvmx_log_perf_control_t; 140159764Sobrien 141133359Sobrien/* 142159764Sobrien * Add CVMX_LOG_DISABLE_PC_LOGGING as an attribute to and function prototype 143159764Sobrien * that you don't want logged when the gcc option "-pg" is supplied. We 144159764Sobrien * use it on the cvmx-log functions since it is pointless to log the 145133359Sobrien * calling of a function than in itself writes to the log. 146159764Sobrien */ 147159764Sobrien#define CVMX_LOG_DISABLE_PC_LOGGING __attribute__((no_instrument_function)) 148159764Sobrien 149159764Sobrien/** 150159764Sobrien * Log a constant printf style format string with 0 to 4 151159764Sobrien * arguments. The string must persist until the log is read, 152133359Sobrien * but the parameters are copied into the log. 153159764Sobrien * 154159764Sobrien * @param format Constant printf style format string. 155159764Sobrien * @param numberx 64bit argument to the printf format string 156139368Sobrien */ 157159764Sobrienvoid cvmx_log_printf0(const char *format) CVMX_LOG_DISABLE_PC_LOGGING; 158159764Sobrienvoid cvmx_log_printf1(const char *format, uint64_t number1) CVMX_LOG_DISABLE_PC_LOGGING; 159139368Sobrienvoid cvmx_log_printf2(const char *format, uint64_t number1, uint64_t number2) CVMX_LOG_DISABLE_PC_LOGGING; 160159764Sobrienvoid cvmx_log_printf3(const char *format, uint64_t number1, uint64_t number2, uint64_t number3) CVMX_LOG_DISABLE_PC_LOGGING; 161159764Sobrienvoid cvmx_log_printf4(const char *format, uint64_t number1, uint64_t number2, uint64_t number3, uint64_t number4) CVMX_LOG_DISABLE_PC_LOGGING; 162159764Sobrien 163159764Sobrien/** 164159764Sobrien * Log an arbitrary block of 64bit words. At most 255 64bit 165159764Sobrien * words can be logged. The words are copied into the log. 166159764Sobrien * 167159764Sobrien * @param size_in_dwords 168159764Sobrien * Number of 64bit dwords to copy into the log. 169159764Sobrien * @param data Array of 64bit dwords to copy 170159764Sobrien */ 171159764Sobrienvoid cvmx_log_data(uint64_t size_in_dwords, const uint64_t *data) CVMX_LOG_DISABLE_PC_LOGGING; 172159764Sobrien 173159764Sobrien/** 174159764Sobrien * Log a structured data object. Post processing will use the 175159764Sobrien * debugging information in the ELF file to determine how to 176133359Sobrien * display the structure. Max of 2032 bytes. 177159764Sobrien * 178159764Sobrien * Example: 179159764Sobrien * cvmx_log_structure("cvmx_wqe_t", work, sizeof(*work)); 180159764Sobrien * 181139368Sobrien * @param type C typedef expressed as a string. This will be used to 182159764Sobrien * lookup the structure in the debugging infirmation. 183159764Sobrien * @param data Data to be written to the log. 184159764Sobrien * @param size_in_bytes 185159764Sobrien * Size if the data in bytes. Normally you'll use the 186159764Sobrien * sizeof() operator here. 187159764Sobrien */ 188159764Sobrienvoid cvmx_log_structure(const char *type, void *data, int size_in_bytes) CVMX_LOG_DISABLE_PC_LOGGING; 189159764Sobrien 190159764Sobrien/** 191159764Sobrien * Setup the mips performance counters 192139368Sobrien * 193139368Sobrien * @param counter1 Event type for counter 1 194159764Sobrien * @param counter2 Event type for counter 2 195139368Sobrien */ 196159764Sobrienvoid cvmx_log_perf_setup(cvmx_log_perf_event_t counter1, cvmx_log_perf_event_t counter2); 197159764Sobrien 198159764Sobrien/** 199159764Sobrien * Log the performance counters 200159764Sobrien */ 201159764Sobrienvoid cvmx_log_perf(void) CVMX_LOG_DISABLE_PC_LOGGING; 202159764Sobrien 203159764Sobrien/** 204139368Sobrien * Display the current log in a human readable format. 205159764Sobrien */ 206159764Sobrienvoid cvmx_log_display(void); 207159764Sobrien 208139368Sobrien#ifdef __cplusplus 209159764Sobrien} 210159764Sobrien#endif 211159764Sobrien 212159764Sobrien#endif 213139368Sobrien