blob: 81a737444c8ff075260325803ca1c6463fc01e7d [file] [log] [blame]
Thomas Gleixner6eda5832009-05-01 18:29:57 +02001#ifndef _PERF_PERF_H
2#define _PERF_PERF_H
3
4/*
5 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
6 * counters in the current task.
7 */
8#define PR_TASK_PERF_COUNTERS_DISABLE 31
9#define PR_TASK_PERF_COUNTERS_ENABLE 32
10
Thomas Gleixnera92e702372009-05-01 18:39:47 +020011#ifndef NSEC_PER_SEC
12# define NSEC_PER_SEC 1000000000ULL
13#endif
14
15static inline unsigned long long rdclock(void)
16{
17 struct timespec ts;
18
19 clock_gettime(CLOCK_MONOTONIC, &ts);
20 return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
21}
Thomas Gleixner6eda5832009-05-01 18:29:57 +020022
23/*
24 * Pick up some kernel type conventions:
25 */
26#define __user
27#define asmlinkage
28
Thomas Gleixner4ba67c12009-05-01 18:48:06 +020029#if defined(__x86_64__) || defined(__i386__)
30#include "../../arch/x86/include/asm/unistd.h"
Thomas Gleixner6eda5832009-05-01 18:29:57 +020031#define rmb() asm volatile("lfence" ::: "memory")
32#define cpu_relax() asm volatile("rep; nop" ::: "memory");
33#endif
34
35#ifdef __powerpc__
Thomas Gleixner4ba67c12009-05-01 18:48:06 +020036#include "../../arch/powerpc/include/asm/unistd.h"
Thomas Gleixner6eda5832009-05-01 18:29:57 +020037#define rmb() asm volatile ("sync" ::: "memory")
38#define cpu_relax() asm volatile ("" ::: "memory");
39#endif
40
41#define unlikely(x) __builtin_expect(!!(x), 0)
42#define min(x, y) ({ \
43 typeof(x) _min1 = (x); \
44 typeof(y) _min2 = (y); \
45 (void) (&_min1 == &_min2); \
46 _min1 < _min2 ? _min1 : _min2; })
47
48static inline int
49sys_perf_counter_open(struct perf_counter_hw_event *hw_event_uptr,
50 pid_t pid, int cpu, int group_fd,
51 unsigned long flags)
52{
53 return syscall(__NR_perf_counter_open, hw_event_uptr, pid, cpu,
54 group_fd, flags);
55}
56
Ingo Molnarc6eb1382009-05-22 18:18:28 +020057#define MAX_COUNTERS 1024
58#define MAX_NR_CPUS 4096
Thomas Gleixner6eda5832009-05-01 18:29:57 +020059
60#define EID(type, id) (((__u64)(type) << PERF_COUNTER_TYPE_SHIFT) | (id))
61
62#endif