6 #ifndef __NR_perf_event_open 9 #define __NR_perf_event_open 319 10 #elif defined(__x86_64__) 11 #define __NR_perf_event_open 298 12 #elif defined(__i386__) 13 #define __NR_perf_event_open 336 14 #elif defined(__arm__) 15 #define __NR_perf_event_open 364 22 pid_t
pid,
int cpu,
int group_fd,
unsigned long flags )
26 ret = syscall( __NR_perf_event_open,
27 hw_event,
pid,
cpu, group_fd, flags );
32 #if defined(__x86_64__) || defined(__i386__) 35 static inline unsigned long long rdtsc(
void) {
39 __asm__
volatile(
"rdtsc" :
"=a" (
a),
"=d" (d));
41 return ((
unsigned long long)
a) | (((
unsigned long long)d) << 32);
44 static inline unsigned long long rdpmc(
unsigned int counter) {
46 unsigned int low, high;
48 __asm__
volatile(
"rdpmc" :
"=a" (low),
"=d" (high) :
"c" (counter));
50 return (
unsigned long long)low | ((
unsigned long long)high) <<32;
53 #define barrier() __asm__ volatile("" ::: "memory") 57 unsigned long long *en,
58 unsigned long long *ru) {
60 struct perf_event_mmap_page *pc = addr;
62 uint32_t seq, time_mult, time_shift, index, width;
64 uint64_t enabled, running;
65 uint64_t cyc, time_offset;
86 enabled = pc->time_enabled;
88 running = pc->time_running;
93 if ( (pc->cap_user_time) && (enabled != running)) {
95 time_offset = pc->time_offset;
96 time_mult = pc->time_mult;
97 time_shift = pc->time_shift;
99 quot=(cyc>>time_shift);
100 rem = cyc & (((uint64_t)1 << time_shift) - 1);
101 delta = time_offset + (quot * time_mult) +
102 ((rem * time_mult) >> time_shift);
117 width = pc->pmc_width;
127 if (pc->cap_usr_rdpmc && index) {
130 pmc =
rdpmc(index-1);
144 return 0xffffffffffffffffULL;
149 }
while (pc->lock != seq);
159 unsigned long long *en,
160 unsigned long long *ru) {
167 return (
unsigned long long)(-1);
181 struct perf_event_mmap_page *pc = pe->
mmap_buf;
185 PAPIERROR(
"perf_event_mmap_page is NULL" );
189 head = pc->data_head;
198 struct perf_event_mmap_page *pc = pe->
mmap_buf;
201 pc->data_tail = tail;
214 typedef union event_union {
215 struct perf_event_header header;
227 uint64_t old = pe->
tail;
228 unsigned char *data = ((
unsigned char*)pe->
mmap_buf) + getpagesize();
233 SUBDBG(
"WARNING: failed to keep up with mmap data. head = %" PRIu64
234 ", tail = %" PRIu64
". Discarding samples.\n", head, old );
239 for( ; old != head; ) {
242 size_t size = event->
header.size;
246 if ( ( old & pe->
mask ) + size != ( ( old + size ) & pe->
mask ) ) {
248 uint64_t len =
min(
sizeof ( *event ), size ), cpy;
249 void *dst = &event_copy;
255 dst = ((
unsigned char*)dst) + cpy;
263 SUBDBG(
"event->type = %08x\n", event->header.type );
264 SUBDBG(
"event->size = %d\n", event->header.size );
266 switch ( event->header.type ) {
267 case PERF_RECORD_SAMPLE:
269 (
caddr_t ) (
unsigned long ) event->ip.ip,
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 );
280 SUBDBG(
"Error: unexpected header type - %d\n",
281 event->header.type );
struct perf_event_header header
static unsigned long long mmap_read_self(void *addr, unsigned long long *en, unsigned long long *ru)
struct perf_event_header header
struct perf_event_header header
#define SUBDBG(format, args...)
void PAPIERROR(char *format,...)
static long sys_perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
static void mmap_read(int cidx, ThreadInfo_t **thr, pe_event_info_t *pe, int profile_index)
static void mmap_write_tail(pe_event_info_t *pe, uint64_t tail)
static double a[MATRIX_SIZE][MATRIX_SIZE]
static uint64_t mmap_read_head(pe_event_info_t *pe)