PAPI  5.7.0.0
perf_helpers.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ip_event
 
struct  lost_event
 
union  perf_sample_event_t
 

Functions

static long sys_perf_event_open (struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
 
static unsigned long long mmap_read_self (void *addr, unsigned long long *en, unsigned long long *ru)
 
static uint64_t mmap_read_head (pe_event_info_t *pe)
 
static void mmap_write_tail (pe_event_info_t *pe, uint64_t tail)
 
static void mmap_read (int cidx, ThreadInfo_t **thr, pe_event_info_t *pe, int profile_index)
 

Function Documentation

◆ mmap_read()

static void mmap_read ( int  cidx,
ThreadInfo_t **  thr,
pe_event_info_t pe,
int  profile_index 
)
static

Definition at line 223 of file perf_helpers.h.

225 {
226  uint64_t head = mmap_read_head( pe );
227  uint64_t old = pe->tail;
228  unsigned char *data = ((unsigned char*)pe->mmap_buf) + getpagesize();
229  int diff;
230 
231  diff = head - old;
232  if ( diff < 0 ) {
233  SUBDBG( "WARNING: failed to keep up with mmap data. head = %" PRIu64
234  ", tail = %" PRIu64 ". Discarding samples.\n", head, old );
235  /* head points to a known good entry, start there. */
236  old = head;
237  }
238 
239  for( ; old != head; ) {
240  perf_sample_event_t *event = ( perf_sample_event_t * )& data[old & pe->mask];
241  perf_sample_event_t event_copy;
242  size_t size = event->header.size;
243 
244  /* Event straddles the mmap boundary -- header should always */
245  /* be inside due to u64 alignment of output. */
246  if ( ( old & pe->mask ) + size != ( ( old + size ) & pe->mask ) ) {
247  uint64_t offset = old;
248  uint64_t len = min( sizeof ( *event ), size ), cpy;
249  void *dst = &event_copy;
250 
251  do {
252  cpy = min( pe->mask + 1 - ( offset & pe->mask ), len );
253  memcpy( dst, &data[offset & pe->mask], cpy );
254  offset += cpy;
255  dst = ((unsigned char*)dst) + cpy;
256  len -= cpy;
257  } while ( len );
258 
259  event = &event_copy;
260  }
261  old += size;
262 
263  SUBDBG( "event->type = %08x\n", event->header.type );
264  SUBDBG( "event->size = %d\n", event->header.size );
265 
266  switch ( event->header.type ) {
267  case PERF_RECORD_SAMPLE:
268  _papi_hwi_dispatch_profile( ( *thr )->running_eventset[cidx],
269  ( caddr_t ) ( unsigned long ) event->ip.ip,
270  0, profile_index );
271  break;
272 
273  case PERF_RECORD_LOST:
274  SUBDBG( "Warning: because of a mmap buffer overrun, %" PRId64
275  " events were lost.\n"
276  "Loss was recorded when counter id %#"PRIx64
277  " overflowed.\n", event->lost.lost, event->lost.id );
278  break;
279  default:
280  SUBDBG( "Error: unexpected header type - %d\n",
281  event->header.type );
282  break;
283  }
284  }
285 
286  pe->tail = old;
287  mmap_write_tail( pe, old );
288 }
struct perf_event_header header
Definition: perf_helpers.h:215
off64_t offset
Definition: iozone.c:1279
if(file==NULL) goto out
static int cidx
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define min(x, y)
Definition: darwin-common.h:4
void _papi_hwi_dispatch_profile(EventSetInfo_t *ESI, caddr_t pc, long long over, int profile_index)
Definition: extras.c:165
char * caddr_t
static void mmap_write_tail(pe_event_info_t *pe, uint64_t tail)
Definition: perf_helpers.h:196
static uint64_t mmap_read_head(pe_event_info_t *pe)
Definition: perf_helpers.h:179
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mmap_read_head()

static uint64_t mmap_read_head ( pe_event_info_t pe)
static

Definition at line 179 of file perf_helpers.h.

180 {
181  struct perf_event_mmap_page *pc = pe->mmap_buf;
182  int head;
183 
184  if ( pc == NULL ) {
185  PAPIERROR( "perf_event_mmap_page is NULL" );
186  return 0;
187  }
188 
189  head = pc->data_head;
190  rmb();
191 
192  return head;
193 }
void PAPIERROR(char *format,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mmap_read_self()

static unsigned long long mmap_read_self ( void *  addr,
unsigned long long *  en,
unsigned long long *  ru 
)
inlinestatic

Definition at line 158 of file perf_helpers.h.

160  {
161 
162  (void)addr;
163 
164  *en=0;
165  *ru=0;
166 
167  return (unsigned long long)(-1);
168 }
Here is the caller graph for this function:

◆ mmap_write_tail()

static void mmap_write_tail ( pe_event_info_t pe,
uint64_t  tail 
)
static

Definition at line 196 of file perf_helpers.h.

197 {
198  struct perf_event_mmap_page *pc = pe->mmap_buf;
199 
200  /* ensure all reads are done before we write the tail out. */
201  pc->data_tail = tail;
202 }
Here is the caller graph for this function:

◆ sys_perf_event_open()

static long sys_perf_event_open ( struct perf_event_attr hw_event,
pid_t  pid,
int  cpu,
int  group_fd,
unsigned long  flags 
)
static

Definition at line 21 of file perf_helpers.h.

23 {
24  int ret;
25 
26  ret = syscall( __NR_perf_event_open,
27  hw_event, pid, cpu, group_fd, flags );
28 
29  return ret;
30 }
static int pid
long long ret
Definition: iozone.c:1346
Here is the caller graph for this function: