Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 1 | #ifndef _PERF_PERF_H |
| 2 | #define _PERF_PERF_H |
| 3 | |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 4 | #if defined(__x86_64__) || defined(__i386__) |
| 5 | #include "../../arch/x86/include/asm/unistd.h" |
| 6 | #define rmb() asm volatile("lfence" ::: "memory") |
| 7 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
| 8 | #endif |
| 9 | |
| 10 | #ifdef __powerpc__ |
| 11 | #include "../../arch/powerpc/include/asm/unistd.h" |
| 12 | #define rmb() asm volatile ("sync" ::: "memory") |
| 13 | #define cpu_relax() asm volatile ("" ::: "memory"); |
| 14 | #endif |
| 15 | |
Martin Schwidefsky | 12310e9 | 2009-06-22 12:08:22 +0200 | [diff] [blame] | 16 | #ifdef __s390__ |
| 17 | #include "../../arch/s390/include/asm/unistd.h" |
| 18 | #define rmb() asm volatile("bcr 15,0" ::: "memory") |
| 19 | #define cpu_relax() asm volatile("" ::: "memory"); |
| 20 | #endif |
| 21 | |
Paul Mundt | febe834 | 2009-06-25 14:41:57 +0900 | [diff] [blame] | 22 | #ifdef __sh__ |
| 23 | #include "../../arch/sh/include/asm/unistd.h" |
| 24 | #if defined(__SH4A__) || defined(__SH5__) |
| 25 | # define rmb() asm volatile("synco" ::: "memory") |
| 26 | #else |
| 27 | # define rmb() asm volatile("" ::: "memory") |
| 28 | #endif |
| 29 | #define cpu_relax() asm volatile("" ::: "memory") |
| 30 | #endif |
| 31 | |
Kyle McMartin | 2d4618d | 2009-06-23 21:38:49 -0400 | [diff] [blame] | 32 | #ifdef __hppa__ |
| 33 | #include "../../arch/parisc/include/asm/unistd.h" |
| 34 | #define rmb() asm volatile("" ::: "memory") |
| 35 | #define cpu_relax() asm volatile("" ::: "memory"); |
| 36 | #endif |
| 37 | |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 38 | #include <time.h> |
| 39 | #include <unistd.h> |
| 40 | #include <sys/types.h> |
| 41 | #include <sys/syscall.h> |
| 42 | |
| 43 | #include "../../include/linux/perf_counter.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 44 | #include "util/types.h" |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 45 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 46 | /* |
| 47 | * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all |
| 48 | * counters in the current task. |
| 49 | */ |
| 50 | #define PR_TASK_PERF_COUNTERS_DISABLE 31 |
| 51 | #define PR_TASK_PERF_COUNTERS_ENABLE 32 |
| 52 | |
Thomas Gleixner | a92e70237 | 2009-05-01 18:39:47 +0200 | [diff] [blame] | 53 | #ifndef NSEC_PER_SEC |
| 54 | # define NSEC_PER_SEC 1000000000ULL |
| 55 | #endif |
| 56 | |
| 57 | static inline unsigned long long rdclock(void) |
| 58 | { |
| 59 | struct timespec ts; |
| 60 | |
| 61 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 62 | return ts.tv_sec * 1000000000ULL + ts.tv_nsec; |
| 63 | } |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Pick up some kernel type conventions: |
| 67 | */ |
| 68 | #define __user |
| 69 | #define asmlinkage |
| 70 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 71 | #define unlikely(x) __builtin_expect(!!(x), 0) |
| 72 | #define min(x, y) ({ \ |
| 73 | typeof(x) _min1 = (x); \ |
| 74 | typeof(y) _min2 = (y); \ |
| 75 | (void) (&_min1 == &_min2); \ |
| 76 | _min1 < _min2 ? _min1 : _min2; }) |
| 77 | |
| 78 | static inline int |
Peter Zijlstra | 974802e | 2009-06-12 12:46:55 +0200 | [diff] [blame] | 79 | sys_perf_counter_open(struct perf_counter_attr *attr, |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 80 | pid_t pid, int cpu, int group_fd, |
| 81 | unsigned long flags) |
| 82 | { |
Peter Zijlstra | 974802e | 2009-06-12 12:46:55 +0200 | [diff] [blame] | 83 | attr->size = sizeof(*attr); |
| 84 | return syscall(__NR_perf_counter_open, attr, pid, cpu, |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 85 | group_fd, flags); |
| 86 | } |
| 87 | |
Ingo Molnar | 85a9f92 | 2009-05-25 09:59:50 +0200 | [diff] [blame] | 88 | #define MAX_COUNTERS 256 |
| 89 | #define MAX_NR_CPUS 256 |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 90 | |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 91 | struct ip_callchain { |
| 92 | u64 nr; |
| 93 | u64 ips[0]; |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 96 | #endif |