-
Notifications
You must be signed in to change notification settings - Fork 1
/
miniprof.h
126 lines (107 loc) · 3.4 KB
/
miniprof.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright (C) 2012
Fabien Gaud <fgaud@sfu.ca>, Baptiste Lepers <baptiste.lepers@inria.fr>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROFILER_H_
#define PROFILER_H_
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include <sched.h>
#include <pthread.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/syscall.h>
#define __EXPORTED_HEADERS__
#include <sys/sysinfo.h>
#undef __EXPORTED_HEADERS__
#include <linux/perf_event.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <dirent.h>
#include <numa.h>
#include <sched.h>
#include <linux/unistd.h>
#include <sys/resource.h>
#include <inttypes.h>
#define TIME_SECOND 1000000
#define TIME_MSECOND 1000
#define PAGE_SIZE (4*1024)
#undef __NR_perf_counter_open
#if defined(__x86_64__)
#define __NR_perf_counter_open 298
#elif defined(__i386__)
#define __NR_perf_counter_open 336
#endif
#define die(msg, args...) \
do { \
fprintf(stderr,"(%s,%d) " msg "\n", __FUNCTION__ , __LINE__, ##args); \
exit(-1); \
} while(0)
#define thread_die(msg, args...) \
do { \
fprintf(stderr,"(%s,%d) " msg "\n", __FUNCTION__ , __LINE__, ##args); \
pthread_exit(NULL); \
} while(0)
typedef struct _event {
uint64_t type;
/* Value describing the chosen event and unitmask (see README). */
uint64_t config;
/* Boolean indicating if kernel-level events must be monitored */
uint64_t exclude_kernel;
/* Boolean indicating if user-level events must be monitored */
uint64_t exclude_user;
const char* name;
char per_node;
int32_t cpu_filter;
/** Only meaningful for hardware events **/
/* Id of the MSR control register that will be used to monitor the event */
uint64_t msr_select;
/* Id of the MSR counter register that will be used to monitor the event */
uint64_t msr_value;
} event_t;
struct perf_read_ev {
uint64_t value;
uint64_t time_enabled;
uint64_t time_running;
};
#ifdef __x86_64__
#define rdtscll(val) { \
unsigned int __a,__d; \
asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \
(val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
}
#else
#define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
#endif
typedef struct pdata {
int core;
int tid; /* Tid to observe */
} pdata_t;
struct msr {
int id;
uint64_t select;
uint64_t value;
int (*can_be_used)(struct msr*, uint64_t);
};
struct msr* get_msr(uint64_t evt, uint64_t cpu_filter);
void reserve_msr(int msr_id, uint64_t evt, int cpu_filter);
#endif /* PROFILER_H_ */