blob: 95aaf565c704fb6ea67cee78d49e177f0ba8f595 [file] [log] [blame]
Thomas Gleixner6eda5832009-05-01 18:29:57 +02001#ifndef _PERF_PERF_H
2#define _PERF_PERF_H
3
Arnaldo Carvalho de Melo895f0ed2010-03-11 20:12:41 -03004struct winsize;
5
6void get_term_dimensions(struct winsize *ws);
7
Vince Weaver11d15782009-07-08 17:46:14 -04008#if defined(__i386__)
9#include "../../arch/x86/include/asm/unistd.h"
10#define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
11#define cpu_relax() asm volatile("rep; nop" ::: "memory");
12#endif
13
14#if defined(__x86_64__)
Peter Zijlstra1a482f32009-05-23 18:28:58 +020015#include "../../arch/x86/include/asm/unistd.h"
16#define rmb() asm volatile("lfence" ::: "memory")
17#define cpu_relax() asm volatile("rep; nop" ::: "memory");
18#endif
19
20#ifdef __powerpc__
21#include "../../arch/powerpc/include/asm/unistd.h"
22#define rmb() asm volatile ("sync" ::: "memory")
23#define cpu_relax() asm volatile ("" ::: "memory");
24#endif
25
Martin Schwidefsky12310e92009-06-22 12:08:22 +020026#ifdef __s390__
27#include "../../arch/s390/include/asm/unistd.h"
28#define rmb() asm volatile("bcr 15,0" ::: "memory")
29#define cpu_relax() asm volatile("" ::: "memory");
30#endif
31
Paul Mundtfebe8342009-06-25 14:41:57 +090032#ifdef __sh__
33#include "../../arch/sh/include/asm/unistd.h"
34#if defined(__SH4A__) || defined(__SH5__)
35# define rmb() asm volatile("synco" ::: "memory")
36#else
37# define rmb() asm volatile("" ::: "memory")
38#endif
39#define cpu_relax() asm volatile("" ::: "memory")
40#endif
41
Kyle McMartin2d4618d2009-06-23 21:38:49 -040042#ifdef __hppa__
43#include "../../arch/parisc/include/asm/unistd.h"
44#define rmb() asm volatile("" ::: "memory")
45#define cpu_relax() asm volatile("" ::: "memory");
46#endif
47
Jens Axboe825c9fb2009-09-04 02:56:22 -070048#ifdef __sparc__
49#include "../../arch/sparc/include/asm/unistd.h"
50#define rmb() asm volatile("":::"memory")
51#define cpu_relax() asm volatile("":::"memory")
52#endif
53
Michael Creefcd14b32009-10-26 21:32:06 +130054#ifdef __alpha__
55#include "../../arch/alpha/include/asm/unistd.h"
56#define rmb() asm volatile("mb" ::: "memory")
57#define cpu_relax() asm volatile("" ::: "memory")
58#endif
59
Luck, Tony11ada262009-11-17 09:05:56 -080060#ifdef __ia64__
61#include "../../arch/ia64/include/asm/unistd.h"
62#define rmb() asm volatile ("mf" ::: "memory")
63#define cpu_relax() asm volatile ("hint @pause" ::: "memory")
64#endif
65
Jamie Iles58e9f942009-12-11 12:20:09 +000066#ifdef __arm__
67#include "../../arch/arm/include/asm/unistd.h"
68/*
69 * Use the __kuser_memory_barrier helper in the CPU helper page. See
70 * arch/arm/kernel/entry-armv.S in the kernel source for details.
71 */
Will Deaconda7196e2010-03-03 11:47:58 +000072#define rmb() ((void(*)(void))0xffff0fa0)()
Jamie Iles58e9f942009-12-11 12:20:09 +000073#define cpu_relax() asm volatile("":::"memory")
74#endif
75
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +080076#ifdef __mips__
77#include "../../arch/mips/include/asm/unistd.h"
78#define rmb() asm volatile( \
79 ".set mips2\n\t" \
80 "sync\n\t" \
81 ".set mips0" \
82 : /* no output */ \
83 : /* no input */ \
84 : "memory")
85#define cpu_relax() asm volatile("" ::: "memory")
86#endif
87
Peter Zijlstra1a482f32009-05-23 18:28:58 +020088#include <time.h>
89#include <unistd.h>
90#include <sys/types.h>
91#include <sys/syscall.h>
92
Ingo Molnarcdd6c482009-09-21 12:02:48 +020093#include "../../include/linux/perf_event.h"
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020094#include "util/types.h"
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -030095#include <stdbool.h>
Peter Zijlstra1a482f32009-05-23 18:28:58 +020096
Thomas Gleixner6eda5832009-05-01 18:29:57 +020097/*
Ingo Molnarcdd6c482009-09-21 12:02:48 +020098 * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
Thomas Gleixner6eda5832009-05-01 18:29:57 +020099 * counters in the current task.
100 */
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200101#define PR_TASK_PERF_EVENTS_DISABLE 31
102#define PR_TASK_PERF_EVENTS_ENABLE 32
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200103
Thomas Gleixnera92e702372009-05-01 18:39:47 +0200104#ifndef NSEC_PER_SEC
105# define NSEC_PER_SEC 1000000000ULL
106#endif
107
108static inline unsigned long long rdclock(void)
109{
110 struct timespec ts;
111
112 clock_gettime(CLOCK_MONOTONIC, &ts);
113 return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
114}
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200115
116/*
117 * Pick up some kernel type conventions:
118 */
119#define __user
120#define asmlinkage
121
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200122#define unlikely(x) __builtin_expect(!!(x), 0)
123#define min(x, y) ({ \
124 typeof(x) _min1 = (x); \
125 typeof(y) _min2 = (y); \
126 (void) (&_min1 == &_min2); \
127 _min1 < _min2 ? _min1 : _min2; })
128
129static inline int
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200130sys_perf_event_open(struct perf_event_attr *attr,
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200131 pid_t pid, int cpu, int group_fd,
132 unsigned long flags)
133{
Peter Zijlstra974802e2009-06-12 12:46:55 +0200134 attr->size = sizeof(*attr);
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200135 return syscall(__NR_perf_event_open, attr, pid, cpu,
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200136 group_fd, flags);
137}
138
Ingo Molnar85a9f922009-05-25 09:59:50 +0200139#define MAX_COUNTERS 256
140#define MAX_NR_CPUS 256
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200141
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +0200142struct ip_callchain {
143 u64 nr;
144 u64 ips[0];
Peter Zijlstraf5970552009-06-18 23:22:55 +0200145};
146
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300147extern bool perf_host, perf_guest;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800148
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200149#endif