|
PAPI
5.3.0.0
|
00001 /****************************/ 00002 /* THIS IS OPEN SOURCE CODE */ 00003 /****************************/ 00004 00005 /* 00006 * File: perfctr-ppc64.h 00007 * CVS: $Id$ 00008 * Author: Maynard Johnson 00009 * maynardj@us.ibm.com 00010 * Mods: <your name here> 00011 * <your email address> 00012 */ 00013 00014 #ifndef _PAPI_PERFCTR_PPC64 /* _PAPI_PERFCTR_PPC64 */ 00015 #define _PAPI_PERFCTR_PPC64 00016 00017 #if defined(_POWER5) || defined(_POWER5p) 00018 #define MAX_COUNTERS 6 00019 #define NUM_COUNTER_MASKS 4 00020 /* masks for PMC1-4 should be AND'ed into MMCR1 */ 00021 #define PMC1_SEL_MASK 0xFFFFFFFF00FFFFFFULL 00022 #define PMC2_SEL_MASK 0xFFFFFFFFFF00FFFFULL 00023 #define PMC3_SEL_MASK 0xFFFFFFFFFFFF00FFULL 00024 #define PMC4_SEL_MASK 0xFFFFFFFFFFFFFF00ULL 00025 /* PMC5_6_FREEZE should be OR'ed into MMCR0 */ 00026 #define PMC5_PMC6_FREEZE 0x00000010UL 00027 #else 00028 #define MAX_COUNTERS 8 00029 #define NUM_COUNTER_MASKS MAX_COUNTERS+1 00030 /* assume ppc970 for now */ 00031 #define PMC1_SEL_MASK 0xFFFFF0FFUL 00032 #define PMC2_SEL_MASK 0xFFFFFFE1UL 00033 #define PMC3_SEL_MASK 0xFFFFFFFF87FFFFFFULL 00034 #define PMC4_SEL_MASK 0xFFFFFFFFFC3FFFFFULL 00035 #define PMC5_SEL_MASK 0xFFFFFFFFFFE1FFFFULL 00036 #define PMC6_SEL_MASK 0xFFFFFFFFFFFF0FFFULL 00037 #define PMC7_SEL_MASK 0xFFFFFFFFFFFFF87FULL 00038 #define PMC8_SEL_MASK 0xFFFFFFFFFFFFFFC3ULL 00039 #define PMC8a_SEL_MASK 0xFFFDFFFFUL 00040 #endif 00041 00042 00043 00044 #include "papi.h" 00045 #include "ppc64_events.h" 00046 #include "linux-ppc64.h" 00047 #include "papi_preset.h" 00048 #include "libperfctr.h" 00049 00050 #define HW_OVERFLOW 1 00051 //#define PAPI_MAX_STR_LEN 129 00052 00053 // control bits MMCR0 00054 #define PERF_INT_ENABLE 0x0000C000 // enables interrupts on PMC1 as well as PMC2-PMCj (2<=j<=MAX_COUNTERS) 00055 #define PMC_OVFL 0x80000000 00056 #define PERF_KERNEL 0x40000000 00057 #define PERF_USER 0x20000000 00058 #define PERF_HYPERVISOR 0x00000001 00059 #define PERF_CONTROL_MASK 0xFFFFE001 00060 00061 00062 #define AI_ERROR "No support for a-mode counters after adding an i-mode counter" 00063 #define VOPEN_ERROR "vperfctr_open() returned NULL, please run perfex -i to verify your perfctr installation" 00064 #define GOPEN_ERROR "gperfctr_open() returned NULL" 00065 #define VINFO_ERROR "vperfctr_info() returned < 0" 00066 #define VCNTRL_ERROR "vperfctr_control() returned < 0" 00067 #define RCNTRL_ERROR "rvperfctr_control() returned < 0" 00068 #define GCNTRL_ERROR "gperfctr_control() returned < 0" 00069 #define FOPEN_ERROR "fopen(%s) returned NULL" 00070 #define STATE_MAL_ERROR "Error allocating perfctr structures" 00071 #define MODEL_ERROR "This is not a PowerPC" 00072 #define EVENT_INFO_FILE_ERROR "Event info file error" 00073 00074 #define MUTEX_LOCKED 1 00075 #define MUTEX_OPEN 0 00076 00077 extern volatile unsigned int lock[]; 00078 00079 #include <unistd.h> 00080 00081 // similar to __arch_compare_and_exchange_val_32_acq() from libc's atomic.h 00082 static inline unsigned long 00083 _papi_hwd_trylock( unsigned int *lock ) 00084 { 00085 unsigned long tmp, tmp2; 00086 __asm__ volatile ( " li %1,%3\n" 00087 "1: lwarx %0,0,%2\n" 00088 " cmpwi 0,%0,%4\n" 00089 " bne- 2f\n" 00090 " stwcx. %1,0,%2\n" 00091 " bne- 1b\n" 00092 " isync\n" "2:":"=&r" ( tmp ), "=&r"( tmp2 ) 00093 :"b"( lock ), "i"( MUTEX_LOCKED ), "i"( MUTEX_OPEN ) 00094 :"cr0", "memory" ); 00095 return tmp; 00096 } 00097 00098 #define _papi_hwd_lock(locknum) \ 00099 do { } while (_papi_hwd_trylock((unsigned int *)(&(lock[(locknum)]))) != MUTEX_OPEN) 00100 00101 #define _papi_hwd_unlock(locknum) \ 00102 do { \ 00103 __asm__ volatile("lwsync": : :"memory"); \ 00104 lock[(locknum)] = MUTEX_OPEN; \ 00105 } while(0) 00106 00107 00108 // prototypes 00109 int setup_ppc64_native_table( void ); 00110 00111 typedef struct hwd_native 00112 { 00113 /* index in the native table, required */ 00114 int index; 00115 /* Which counters can be used? */ 00116 unsigned int selector; 00117 /* Rank determines how many counters carry each metric */ 00118 unsigned char rank; 00119 /* which counter this native event stays */ 00120 int position; 00121 int mod; 00122 int link; 00123 } hwd_native_t; 00124 00125 typedef struct ppc64_reg_alloc 00126 { 00127 int ra_position; 00128 unsigned int ra_group[GROUP_INTS]; 00129 int ra_counter_cmd[MAX_COUNTERS]; 00130 } ppc64_reg_alloc_t; 00131 00132 00133 /* typedefs to conform to hardware independent PAPI code. */ 00134 typedef ppc64_reg_alloc_t hwd_reg_alloc_t; 00135 00136 typedef struct ppc64_perfctr_control 00137 { 00138 /* Buffer to pass to the kernel to control the counters */ 00139 int group_id; 00140 /* Interrupt interval */ 00141 int timer_ms; 00142 00143 // the members below are from perfctr-p3.h 00144 hwd_native_t native[MAX_COUNTERS]; 00145 int native_idx; 00146 unsigned char master_selector; 00147 hwd_register_t allocated_registers; 00148 struct vperfctr_control control; 00149 struct perfctr_sum_ctrs state; 00150 /* Allow attach to be per-eventset. */ 00151 struct rvperfctr *rvperfctr; 00152 } ppc64_perfctr_control_t; 00153 00154 typedef struct ppc64_perfctr_context 00155 { 00156 struct vperfctr *perfctr; 00157 } ppc64_perfctr_context_t; 00158 00159 /* typedefs to conform to hardware independent PAPI code. */ 00160 typedef ppc64_perfctr_control_t hwd_control_state_t; 00161 typedef ppc64_perfctr_context_t hwd_context_t; 00162 #define hwd_pmc_control vperfctr_control 00163 00164 typedef struct ntv_event 00165 { 00166 char symbol[PAPI_MAX_STR_LEN]; 00167 unsigned int event_num; 00168 char *short_description; 00169 char *description; 00170 } ntv_event_t; 00171 00172 typedef struct ntv_event_info 00173 { 00174 int maxevents[MAX_COUNTERS]; 00175 int maxpmcs; 00176 ntv_event_t *wev[MAX_COUNTERS]; 00177 } ntv_event_info_t; 00178 00179 00180 typedef struct event_group 00181 { 00182 int group_id; 00183 unsigned int mmcr0; 00184 unsigned int mmcr1L; 00185 unsigned int mmcr1U; 00186 unsigned int mmcra; 00187 unsigned int events[MAX_COUNTERS]; 00188 } event_group_t; 00189 00190 typedef struct ntv_event_group_info 00191 { 00192 int maxgroups; 00193 event_group_t *event_groups[MAX_GROUPS]; 00194 } ntv_event_group_info_t; 00195 00196 00197 // prototypes 00198 ntv_event_info_t *perfctr_get_native_evt_info( void ); 00199 ntv_event_group_info_t *perfctr_get_native_group_info( void ); 00200 00201 #endif /* _PAPI_PERFCTR_PPC64 */