-
Notifications
You must be signed in to change notification settings - Fork 0
/
shim.h
66 lines (59 loc) · 1.54 KB
/
shim.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
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* See feature_test_macros(7) */
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <errno.h>
#include <sched.h>
#include <sys/sysinfo.h>
#include <perfmon/pfmlib_perf_event.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <time.h>
#include <assert.h>
#include <pthread.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <getopt.h>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <poll.h>
#include <sys/time.h>
#include <sys/resource.h>
#define debug_print(...) fprintf (stderr, __VA_ARGS__)
//routines for creating the hadware performance counter
typedef struct {
int index;
int fd;
struct perf_event_attr perf_attr;
struct perf_event_mmap_page *buf;
char * name;
}hw_event_t;
static unsigned long __inline__ rdtsc(void)
{
unsigned int tickl, tickh;
__asm__ __volatile__("rdtscp":"=a"(tickl),"=d"(tickh)::"%ecx");
return ((uint64_t)tickh << 32)|tickl;
}
static void __inline__ bind_processor(int cpu)
{
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
}
int grab_os_signals(int cpu, unsigned long ** ppid, int ** syscall);
hw_event_t * shim_create_hw_events(int nr_hw_events, char **hw_event_names);
int read_counters(unsigned long *p, hw_event_t *events, int nr_events);