PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
 

Macros

#define ARRAY_SIZE(arr)   (sizeof(arr) / sizeof((arr)[0]))
 

Typedefs

typedef uint64_t u64
 
typedef int64_t s64
 
typedef __u32 u32
 
typedef __s32 s32
 
typedef __u16 u16
 
typedef __s16 s16
 
typedef __u8 u8
 
typedef __s8 s8
 

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 u64 mul_u32_u32 (u32 a, u32 b)
 
static u64 mul_u64_u32_shr (u64 a, u32 b, unsigned int shift)
 
static unsigned long long mmap_read_self (void *addr __attribute__((unused)), int user_reset_flag __attribute__((unused)), unsigned long long reset __attribute__((unused)), unsigned long long *en __attribute__((unused)), unsigned long long *ru __attribute__((unused)))
 
static unsigned long long mmap_read_reset_count (void *addr __attribute__((unused)))
 
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)
 

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   arr)    (sizeof(arr) / sizeof((arr)[0]))

Definition at line 96 of file perf_helpers.h.

Typedef Documentation

◆ s16

typedef __s16 s16

Definition at line 47 of file perf_helpers.h.

◆ s32

typedef __s32 s32

Definition at line 44 of file perf_helpers.h.

◆ s64

typedef int64_t s64

Definition at line 41 of file perf_helpers.h.

◆ s8

typedef __s8 s8

Definition at line 50 of file perf_helpers.h.

◆ u16

typedef __u16 u16

Definition at line 46 of file perf_helpers.h.

◆ u32

typedef __u32 u32

Definition at line 43 of file perf_helpers.h.

◆ u64

typedef uint64_t u64

Definition at line 40 of file perf_helpers.h.

◆ u8

typedef __u8 u8

Definition at line 49 of file perf_helpers.h.

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 465 of file perf_helpers.h.

467{
468 uint64_t head = mmap_read_head( pe );
469 uint64_t old = pe->tail;
470 unsigned char *data = ((unsigned char*)pe->mmap_buf) + getpagesize();
471 int diff;
472
473 diff = head - old;
474 if ( diff < 0 ) {
475 SUBDBG( "WARNING: failed to keep up with mmap data. head = %" PRIu64
476 ", tail = %" PRIu64 ". Discarding samples.\n", head, old );
477 /* head points to a known good entry, start there. */
478 old = head;
479 }
480
481 for( ; old != head; ) {
482 perf_sample_event_t *event = ( perf_sample_event_t * )& data[old & pe->mask];
483 perf_sample_event_t event_copy;
484 size_t size = event->header.size;
485
486 /* Event straddles the mmap boundary -- header should always */
487 /* be inside due to u64 alignment of output. */
488 if ( ( old & pe->mask ) + size != ( ( old + size ) & pe->mask ) ) {
489 uint64_t offset = old;
490 uint64_t len = min( sizeof ( *event ), size ), cpy;
491 void *dst = &event_copy;
492
493 do {
494 cpy = min( pe->mask + 1 - ( offset & pe->mask ), len );
495 memcpy( dst, &data[offset & pe->mask], cpy );
496 offset += cpy;
497 dst = ((unsigned char*)dst) + cpy;
498 len -= cpy;
499 } while ( len );
500
501 event = &event_copy;
502 }
503 old += size;
504
505 SUBDBG( "event->type = %08x\n", event->header.type );
506 SUBDBG( "event->size = %d\n", event->header.size );
507
508 switch ( event->header.type ) {
509 case PERF_RECORD_SAMPLE:
510 _papi_hwi_dispatch_profile( ( *thr )->running_eventset[cidx],
511 ( vptr_t ) ( unsigned long ) event->ip.ip,
512 0, profile_index );
513 break;
514
515 case PERF_RECORD_LOST:
516 SUBDBG( "Warning: because of a mmap buffer overrun, %" PRId64
517 " events were lost.\n"
518 "Loss was recorded when counter id %#"PRIx64
519 " overflowed.\n", event->lost.lost, event->lost.id );
520 break;
521 default:
522 SUBDBG( "Error: unexpected header type - %d\n",
523 event->header.type );
524 break;
525 }
526 }
527
528 pe->tail = old;
529 mmap_write_tail( pe, old );
530}
#define min(x, y)
Definition: darwin-common.h:4
void _papi_hwi_dispatch_profile(EventSetInfo_t *ESI, vptr_t pc, long long over, int profile_index)
Definition: extras.c:165
void * vptr_t
Definition: papi.h:576
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
static int cidx
static uint64_t mmap_read_head(pe_event_info_t *pe)
Definition: perf_helpers.h:421
static void mmap_write_tail(pe_event_info_t *pe, uint64_t tail)
Definition: perf_helpers.h:438
static const pme_power_entry_t * pe
if(file==NULL) goto out
struct perf_event_header header
Definition: perf_helpers.h:457
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 421 of file perf_helpers.h.

422{
423 struct perf_event_mmap_page *pc = pe->mmap_buf;
424 int head;
425
426 if ( pc == NULL ) {
427 PAPIERROR( "perf_event_mmap_page is NULL" );
428 return 0;
429 }
430
431 head = pc->data_head;
432 rmb();
433
434 return head;
435}
void PAPIERROR(char *format,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mmap_read_reset_count()

static unsigned long long mmap_read_reset_count ( void *addr   __attribute__(unused))
inlinestatic

Definition at line 407 of file perf_helpers.h.

407 {
408
409 return (unsigned long long)(-1);
410}
Here is the caller graph for this function:

◆ mmap_read_self()

static unsigned long long mmap_read_self ( void *addr   __attribute__(unused),
int user_reset_flag   __attribute__(unused),
unsigned long long reset   __attribute__(unused),
unsigned long long *en   __attribute__(unused),
unsigned long long *ru   __attribute__(unused) 
)
inlinestatic

Definition at line 398 of file perf_helpers.h.

402 {
403
404 return (unsigned long long)(-1);
405}
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 438 of file perf_helpers.h.

439{
440 struct perf_event_mmap_page *pc = pe->mmap_buf;
441
442 /* ensure all reads are done before we write the tail out. */
443 pc->data_tail = tail;
444}
Here is the caller graph for this function:

◆ mul_u32_u32()

static u64 mul_u32_u32 ( u32  a,
u32  b 
)
inlinestatic

Definition at line 72 of file perf_helpers.h.

73{
74 return (u64)a * b;
75}
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
uint64_t u64
Definition: perf_helpers.h:40
Here is the caller graph for this function:

◆ mul_u64_u32_shr()

static u64 mul_u64_u32_shr ( u64  a,
u32  b,
unsigned int  shift 
)
inlinestatic

Definition at line 78 of file perf_helpers.h.

79{
80 u32 ah, al;
81 u64 ret;
82
83 al = a;
84 ah = a >> 32;
85
86 ret = mul_u32_u32(al, b) >> shift;
87 if (ah)
88 ret += mul_u32_u32(ah, b) << (32 - shift);
89
90 return ret;
91}
static u64 mul_u32_u32(u32 a, u32 b)
Definition: perf_helpers.h:72
__u32 u32
Definition: perf_helpers.h:43
Here is the call 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
Here is the caller graph for this function: