linux/tools/perf/perf.h
<<
>>
Prefs
   1#ifndef _PERF_PERF_H
   2#define _PERF_PERF_H
   3
   4struct winsize;
   5
   6void get_term_dimensions(struct winsize *ws);
   7
   8#include <asm/unistd.h>
   9
  10#if defined(__i386__)
  11#define rmb()           asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
  12#define cpu_relax()     asm volatile("rep; nop" ::: "memory");
  13#define CPUINFO_PROC    "model name"
  14#ifndef __NR_perf_event_open
  15# define __NR_perf_event_open 336
  16#endif
  17#endif
  18
  19#if defined(__x86_64__)
  20#define rmb()           asm volatile("lfence" ::: "memory")
  21#define cpu_relax()     asm volatile("rep; nop" ::: "memory");
  22#define CPUINFO_PROC    "model name"
  23#ifndef __NR_perf_event_open
  24# define __NR_perf_event_open 298
  25#endif
  26#endif
  27
  28#ifdef __powerpc__
  29#define rmb()           asm volatile ("sync" ::: "memory")
  30#define cpu_relax()     asm volatile ("" ::: "memory");
  31#define CPUINFO_PROC    "cpu"
  32#endif
  33
  34#ifdef __s390__
  35#define rmb()           asm volatile("bcr 15,0" ::: "memory")
  36#define cpu_relax()     asm volatile("" ::: "memory");
  37#endif
  38
  39#ifdef __sh__
  40#if defined(__SH4A__) || defined(__SH5__)
  41# define rmb()          asm volatile("synco" ::: "memory")
  42#else
  43# define rmb()          asm volatile("" ::: "memory")
  44#endif
  45#define cpu_relax()     asm volatile("" ::: "memory")
  46#define CPUINFO_PROC    "cpu type"
  47#endif
  48
  49#ifdef __hppa__
  50#define rmb()           asm volatile("" ::: "memory")
  51#define cpu_relax()     asm volatile("" ::: "memory");
  52#define CPUINFO_PROC    "cpu"
  53#endif
  54
  55#ifdef __sparc__
  56#define rmb()           asm volatile("":::"memory")
  57#define cpu_relax()     asm volatile("":::"memory")
  58#define CPUINFO_PROC    "cpu"
  59#endif
  60
  61#ifdef __alpha__
  62#define rmb()           asm volatile("mb" ::: "memory")
  63#define cpu_relax()     asm volatile("" ::: "memory")
  64#define CPUINFO_PROC    "cpu model"
  65#endif
  66
  67#ifdef __ia64__
  68#define rmb()           asm volatile ("mf" ::: "memory")
  69#define cpu_relax()     asm volatile ("hint @pause" ::: "memory")
  70#define CPUINFO_PROC    "model name"
  71#endif
  72
  73#ifdef __arm__
  74/*
  75 * Use the __kuser_memory_barrier helper in the CPU helper page. See
  76 * arch/arm/kernel/entry-armv.S in the kernel source for details.
  77 */
  78#define rmb()           ((void(*)(void))0xffff0fa0)()
  79#define cpu_relax()     asm volatile("":::"memory")
  80#define CPUINFO_PROC    "Processor"
  81#endif
  82
  83#ifdef __aarch64__
  84#define rmb()           asm volatile("dmb ld" ::: "memory")
  85#define cpu_relax()     asm volatile("yield" ::: "memory")
  86#endif
  87
  88#ifdef __mips__
  89#define rmb()           asm volatile(                                   \
  90                                ".set   mips2\n\t"                      \
  91                                "sync\n\t"                              \
  92                                ".set   mips0"                          \
  93                                : /* no output */                       \
  94                                : /* no input */                        \
  95                                : "memory")
  96#define cpu_relax()     asm volatile("" ::: "memory")
  97#define CPUINFO_PROC    "cpu model"
  98#endif
  99
 100#include <time.h>
 101#include <unistd.h>
 102#include <sys/types.h>
 103#include <sys/syscall.h>
 104
 105#include <linux/perf_event.h>
 106#include "util/types.h"
 107#include <stdbool.h>
 108
 109struct perf_mmap {
 110        void                    *base;
 111        int                     mask;
 112        unsigned int            prev;
 113};
 114
 115static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm)
 116{
 117        struct perf_event_mmap_page *pc = mm->base;
 118        int head = pc->data_head;
 119        rmb();
 120        return head;
 121}
 122
 123static inline void perf_mmap__write_tail(struct perf_mmap *md,
 124                                         unsigned long tail)
 125{
 126        struct perf_event_mmap_page *pc = md->base;
 127
 128        /*
 129         * ensure all reads are done before we write the tail out.
 130         */
 131        /* mb(); */
 132        pc->data_tail = tail;
 133}
 134
 135/*
 136 * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
 137 * counters in the current task.
 138 */
 139#define PR_TASK_PERF_EVENTS_DISABLE   31
 140#define PR_TASK_PERF_EVENTS_ENABLE    32
 141
 142#ifndef NSEC_PER_SEC
 143# define NSEC_PER_SEC                   1000000000ULL
 144#endif
 145
 146static inline unsigned long long rdclock(void)
 147{
 148        struct timespec ts;
 149
 150        clock_gettime(CLOCK_MONOTONIC, &ts);
 151        return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
 152}
 153
 154/*
 155 * Pick up some kernel type conventions:
 156 */
 157#define __user
 158#define asmlinkage
 159
 160#define unlikely(x)     __builtin_expect(!!(x), 0)
 161#define min(x, y) ({                            \
 162        typeof(x) _min1 = (x);                  \
 163        typeof(y) _min2 = (y);                  \
 164        (void) (&_min1 == &_min2);              \
 165        _min1 < _min2 ? _min1 : _min2; })
 166
 167static inline int
 168sys_perf_event_open(struct perf_event_attr *attr,
 169                      pid_t pid, int cpu, int group_fd,
 170                      unsigned long flags)
 171{
 172        return syscall(__NR_perf_event_open, attr, pid, cpu,
 173                       group_fd, flags);
 174}
 175
 176#define MAX_COUNTERS                    256
 177#define MAX_NR_CPUS                     256
 178
 179struct ip_callchain {
 180        u64 nr;
 181        u64 ips[0];
 182};
 183
 184struct branch_flags {
 185        u64 mispred:1;
 186        u64 predicted:1;
 187        u64 reserved:62;
 188};
 189
 190struct branch_entry {
 191        u64                             from;
 192        u64                             to;
 193        struct branch_flags flags;
 194};
 195
 196struct branch_stack {
 197        u64                             nr;
 198        struct branch_entry     entries[0];
 199};
 200
 201extern bool perf_host, perf_guest;
 202extern const char perf_version_string[];
 203
 204void pthread__unblock_sigwinch(void);
 205
 206#include "util/target.h"
 207
 208enum perf_call_graph_mode {
 209        CALLCHAIN_NONE,
 210        CALLCHAIN_FP,
 211        CALLCHAIN_DWARF
 212};
 213
 214struct perf_record_opts {
 215        struct perf_target target;
 216        int          call_graph;
 217        bool         group;
 218        bool         inherit_stat;
 219        bool         no_delay;
 220        bool         no_inherit;
 221        bool         no_samples;
 222        bool         pipe_output;
 223        bool         raw_samples;
 224        bool         sample_address;
 225        bool         sample_time;
 226        bool         sample_id_all_missing;
 227        bool         exclude_guest_missing;
 228        bool         period;
 229        unsigned int freq;
 230        unsigned int mmap_pages;
 231        unsigned int user_freq;
 232        u64          branch_stack;
 233        u64          default_interval;
 234        u64          user_interval;
 235        u16          stack_dump_size;
 236};
 237
 238#endif
 239
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.