PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
perfctr-ppc64.h
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
5 /*
6 * File: perfctr-ppc64.h
7 * CVS: $Id$
8 * Author: Maynard Johnson
9 * maynardj@us.ibm.com
10 * Mods: <your name here>
11 * <your email address>
12 */
13 
14 #ifndef _PAPI_PERFCTR_PPC64 /* _PAPI_PERFCTR_PPC64 */
15 #define _PAPI_PERFCTR_PPC64
16 
17 #if defined(_POWER5) || defined(_POWER5p)
18 #define MAX_COUNTERS 6
19 #define NUM_COUNTER_MASKS 4
20 /* masks for PMC1-4 should be AND'ed into MMCR1 */
21 #define PMC1_SEL_MASK 0xFFFFFFFF00FFFFFFULL
22 #define PMC2_SEL_MASK 0xFFFFFFFFFF00FFFFULL
23 #define PMC3_SEL_MASK 0xFFFFFFFFFFFF00FFULL
24 #define PMC4_SEL_MASK 0xFFFFFFFFFFFFFF00ULL
25 /* PMC5_6_FREEZE should be OR'ed into MMCR0 */
26 #define PMC5_PMC6_FREEZE 0x00000010UL
27 #else
28 #define MAX_COUNTERS 8
29 #define NUM_COUNTER_MASKS MAX_COUNTERS+1
30 /* assume ppc970 for now */
31 #define PMC1_SEL_MASK 0xFFFFF0FFUL
32 #define PMC2_SEL_MASK 0xFFFFFFE1UL
33 #define PMC3_SEL_MASK 0xFFFFFFFF87FFFFFFULL
34 #define PMC4_SEL_MASK 0xFFFFFFFFFC3FFFFFULL
35 #define PMC5_SEL_MASK 0xFFFFFFFFFFE1FFFFULL
36 #define PMC6_SEL_MASK 0xFFFFFFFFFFFF0FFFULL
37 #define PMC7_SEL_MASK 0xFFFFFFFFFFFFF87FULL
38 #define PMC8_SEL_MASK 0xFFFFFFFFFFFFFFC3ULL
39 #define PMC8a_SEL_MASK 0xFFFDFFFFUL
40 #endif
41 
42 
43 
44 #include "papi.h"
45 #include "ppc64_events.h"
46 #include "linux-ppc64.h"
47 #include "papi_preset.h"
48 #include "libperfctr.h"
49 
50 #define HW_OVERFLOW 1
51 //#define PAPI_MAX_STR_LEN 129
52 
53 // control bits MMCR0
54 #define PERF_INT_ENABLE 0x0000C000 // enables interrupts on PMC1 as well as PMC2-PMCj (2<=j<=MAX_COUNTERS)
55 #define PMC_OVFL 0x80000000
56 #define PERF_KERNEL 0x40000000
57 #define PERF_USER 0x20000000
58 #define PERF_HYPERVISOR 0x00000001
59 #define PERF_CONTROL_MASK 0xFFFFE001
60 
61 
62 #define AI_ERROR "No support for a-mode counters after adding an i-mode counter"
63 #define VOPEN_ERROR "vperfctr_open() returned NULL, please run perfex -i to verify your perfctr installation"
64 #define GOPEN_ERROR "gperfctr_open() returned NULL"
65 #define VINFO_ERROR "vperfctr_info() returned < 0"
66 #define VCNTRL_ERROR "vperfctr_control() returned < 0"
67 #define RCNTRL_ERROR "rvperfctr_control() returned < 0"
68 #define GCNTRL_ERROR "gperfctr_control() returned < 0"
69 #define FOPEN_ERROR "fopen(%s) returned NULL"
70 #define STATE_MAL_ERROR "Error allocating perfctr structures"
71 #define MODEL_ERROR "This is not a PowerPC"
72 #define EVENT_INFO_FILE_ERROR "Event info file error"
73 
74 #define MUTEX_LOCKED 1
75 #define MUTEX_OPEN 0
76 
77 extern volatile unsigned int lock[];
78 
79 #include <unistd.h>
80 
81 // similar to __arch_compare_and_exchange_val_32_acq() from libc's atomic.h
82 static inline unsigned long
83 _papi_hwd_trylock( unsigned int *lock )
84 {
85  unsigned long tmp, tmp2;
86  __asm__ volatile ( " li %1,%3\n"
87  "1: lwarx %0,0,%2\n"
88  " cmpwi 0,%0,%4\n"
89  " bne- 2f\n"
90  " stwcx. %1,0,%2\n"
91  " bne- 1b\n"
92  " isync\n" "2:":"=&r" ( tmp ), "=&r"( tmp2 )
93  :"b"( lock ), "i"( MUTEX_LOCKED ), "i"( MUTEX_OPEN )
94  :"cr0", "memory" );
95  return tmp;
96 }
97 
98 #define _papi_hwd_lock(locknum) \
99  do { } while (_papi_hwd_trylock((unsigned int *)(&(lock[(locknum)]))) != MUTEX_OPEN)
100 
101 #define _papi_hwd_unlock(locknum) \
102  do { \
103  __asm__ volatile("lwsync": : :"memory"); \
104  lock[(locknum)] = MUTEX_OPEN; \
105  } while(0)
106 
107 
108 // prototypes
109 int setup_ppc64_native_table( void );
110 
111 typedef struct hwd_native
112 {
113  /* index in the native table, required */
114  int index;
115  /* Which counters can be used? */
116  unsigned int selector;
117  /* Rank determines how many counters carry each metric */
118  unsigned char rank;
119  /* which counter this native event stays */
120  int position;
121  int mod;
122  int link;
123 } hwd_native_t;
124 
125 typedef struct ppc64_reg_alloc
126 {
127  int ra_position;
128  unsigned int ra_group[GROUP_INTS];
129  int ra_counter_cmd[MAX_COUNTERS];
131 
132 
133 /* typedefs to conform to hardware independent PAPI code. */
135 
136 typedef struct ppc64_perfctr_control
137 {
138  /* Buffer to pass to the kernel to control the counters */
139  int group_id;
140  /* Interrupt interval */
141  int timer_ms;
142 
143 // the members below are from perfctr-p3.h
146  unsigned char master_selector;
148  struct vperfctr_control control;
149  struct perfctr_sum_ctrs state;
150  /* Allow attach to be per-eventset. */
151  struct rvperfctr *rvperfctr;
153 
154 typedef struct ppc64_perfctr_context
155 {
156  struct vperfctr *perfctr;
158 
159 /* typedefs to conform to hardware independent PAPI code. */
162 #define hwd_pmc_control vperfctr_control
163 
164 typedef struct ntv_event
165 {
166  char symbol[PAPI_MAX_STR_LEN];
167  unsigned int event_num;
169  char *description;
170 } ntv_event_t;
171 
172 typedef struct ntv_event_info
173 {
174  int maxevents[MAX_COUNTERS];
175  int maxpmcs;
178 
179 
180 typedef struct event_group
181 {
182  int group_id;
183  unsigned int mmcr0;
184  unsigned int mmcr1L;
185  unsigned int mmcr1U;
186  unsigned int mmcra;
187  unsigned int events[MAX_COUNTERS];
188 } event_group_t;
189 
190 typedef struct ntv_event_group_info
191 {
193  event_group_t *event_groups[MAX_GROUPS];
195 
196 
197 // prototypes
200 
201 #endif /* _PAPI_PERFCTR_PPC64 */
#define hwd_control_state_t
#define hwd_reg_alloc_t
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
long long tmp2
Definition: iozone.c:19604
#define MUTEX_LOCKED
Definition: perfctr-ppc64.h:74
unsigned int mmcra
#define MAX_GROUPS
ntv_event_info_t * perfctr_get_native_evt_info(void)
Definition: ppc64_events.c:483
unsigned char master_selector
ntv_event_group_info_t * perfctr_get_native_group_info(void)
Definition: ppc64_events.c:495
Return codes and api definitions.
unsigned int mmcr0
struct vperfctr * perfctr
#define hwd_context_t
static int native
Definition: event_info.c:39
hwd_register_t allocated_registers
#define MAX_COUNTERS
Definition: perfctr-ppc64.h:28
char events[MAX_EVENTS][BUFSIZ]
#define GROUP_INTS
atomic_p lock[]
Definition: aix.c:25
unsigned int mmcr1U
#define MUTEX_OPEN
Definition: perfctr-ppc64.h:75
child_idents[x-1] state
Definition: iozone.c:21341
static unsigned long _papi_hwd_trylock(unsigned int *lock)
Definition: perfctr-ppc64.h:83
unsigned int mmcr1L
char * short_description
unsigned int event_num
long long tmp
Definition: iozone.c:12031
struct rvperfctr * rvperfctr
int setup_ppc64_native_table(void)
char * description