operf_utils.h
Go to the documentation of this file.00001
00015 #ifndef OPERF_H_
00016 #define OPERF_H_
00017
00018 #include <linux/perf_event.h>
00019 #include <dirent.h>
00020 #include <vector>
00021 #include "config.h"
00022 #include "op_config.h"
00023 #include "op_types.h"
00024 #include "operf_event.h"
00025 #include <signal.h>
00026
00027 namespace operf_options {
00028 extern bool system_wide;
00029 extern int pid;
00030 extern int mmap_pages_mult;
00031 extern std::string session_dir;
00032 extern bool separate_cpu;
00033 extern bool separate_thread;
00034 }
00035
00036 extern bool no_vmlinux;
00037 extern int kptr_restrict;
00038 extern uid_t my_uid;
00039 extern bool throttled;
00040
00041 #define OP_APPNAME_LEN 1024
00042 #if BITS_PER_LONG == 64
00043 #define MMAP_WINDOW_SZ ULLONG_MAX
00044 #else
00045 #define MMAP_WINDOW_SZ (32 * 1024 * 1024ULL)
00046 #endif
00047
00048 extern unsigned int op_nr_counters;
00049
00050 static inline size_t align_64bit(u64 x)
00051 {
00052 u64 mask = 7ULL;
00053 return (x + mask) & ~mask;
00054 }
00055
00056 class operf_record;
00057 namespace OP_perf_utils {
00058 typedef struct vmlinux_info {
00059 std::string image_name;
00060 u64 start, end;
00061 } vmlinux_info_t;
00062 void op_record_kernel_info(std::string vmlinux_file, u64 start_addr, u64 end_addr,
00063 int output_fd, operf_record * pr);
00064 void op_get_kernel_event_data(struct mmap_data *md, operf_record * pr);
00065 void op_perfrecord_sigusr1_handler(int sig __attribute__((unused)),
00066 siginfo_t * siginfo __attribute__((unused)),
00067 void *u_context __attribute__((unused)));
00068 void op_perfread_sigusr1_handler(int sig __attribute__((unused)),
00069 siginfo_t * siginfo __attribute__((unused)),
00070 void *u_context __attribute__((unused)));
00071 int op_record_process_info(bool system_wide, pid_t pid, operf_record * pr, int output_fd);
00072 int op_write_output(int output, void *buf, size_t size);
00073 void op_write_event(event_t * event, u64 sample_type);
00074 int op_read_from_stream(std::ifstream & is, char * buf, std::streamsize sz);
00075 int op_mmap_trace_file(struct mmap_info & info, bool init);
00076 int op_get_next_online_cpu(DIR * dir, struct dirent *entry);
00077 bool op_convert_event_vals(std::vector<operf_event_t> * evt_vec);
00078 void op_reprocess_unresolved_events(u64 sample_type);
00079 void op_release_resources(void);
00080 }
00081
00082
00083 #if defined(__i386__)
00084 #include <asm/unistd.h>
00085 #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
00086 #define cpu_relax() asm volatile("rep; nop" ::: "memory");
00087 #endif
00088
00089 #if defined(__x86_64__)
00090 #include <asm/unistd.h>
00091 #define rmb() asm volatile("lfence" ::: "memory")
00092 #define cpu_relax() asm volatile("rep; nop" ::: "memory");
00093 #endif
00094
00095 #ifdef __powerpc__
00096 #include <asm/unistd.h>
00097 #define rmb() asm volatile ("sync" ::: "memory")
00098 #define cpu_relax() asm volatile ("" ::: "memory");
00099 #endif
00100
00101 #ifdef __s390__
00102 #include <asm/unistd.h>
00103 #define rmb() asm volatile("bcr 15,0" ::: "memory")
00104 #define cpu_relax() asm volatile("" ::: "memory");
00105 #endif
00106
00107 #ifdef __sh__
00108 #include <asm/unistd.h>
00109 #if defined(__SH4A__) || defined(__SH5__)
00110 # define rmb() asm volatile("synco" ::: "memory")
00111 #else
00112 # define rmb() asm volatile("" ::: "memory")
00113 #endif
00114 #define cpu_relax() asm volatile("" ::: "memory")
00115 #endif
00116
00117 #ifdef __hppa__
00118 #include <asm/unistd.h>
00119 #define rmb() asm volatile("" ::: "memory")
00120 #define cpu_relax() asm volatile("" ::: "memory");
00121 #endif
00122
00123 #ifdef __sparc__
00124 #include <asm/unistd.h>
00125 #define rmb() asm volatile("":::"memory")
00126 #define cpu_relax() asm volatile("":::"memory")
00127 #endif
00128
00129 #ifdef __alpha__
00130 #include <asm/unistd.h>
00131 #define rmb() asm volatile("mb" ::: "memory")
00132 #define cpu_relax() asm volatile("" ::: "memory")
00133 #endif
00134
00135 #ifdef __ia64__
00136 #include <asm/unistd.h>
00137 #define rmb() asm volatile ("mf" ::: "memory")
00138 #define cpu_relax() asm volatile ("hint @pause" ::: "memory")
00139 #endif
00140
00141 #ifdef __arm__
00142 #include <asm/unistd.h>
00143
00144
00145
00146
00147 #define rmb() ((void(*)(void))0xffff0fa0)()
00148 #define cpu_relax() asm volatile("":::"memory")
00149 #endif
00150
00151 #ifdef __mips__
00152 #include <asm/unistd.h>
00153 #define rmb() asm volatile( \
00154 ".set mips2\n\t" \
00155 "sync\n\t" \
00156 ".set mips0" \
00157 : \
00158 : \
00159 : "memory")
00160 #define cpu_relax() asm volatile("" ::: "memory")
00161 #endif
00162
00163 #ifdef __tile__
00164 #include <asm/unistd.h>
00165 #define rmb() __insn_mf()
00166 #define cpu_relax() ({__insn_mfspr(SPR_PASS); barrier();})
00167 #endif
00168
00169 #endif // OPERF_H_