perf.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _PERF_PERF_H
  2. #define _PERF_PERF_H
  3. /*
  4. * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
  5. * counters in the current task.
  6. */
  7. #define PR_TASK_PERF_COUNTERS_DISABLE 31
  8. #define PR_TASK_PERF_COUNTERS_ENABLE 32
  9. #ifndef NSEC_PER_SEC
  10. # define NSEC_PER_SEC 1000000000ULL
  11. #endif
  12. static inline unsigned long long rdclock(void)
  13. {
  14. struct timespec ts;
  15. clock_gettime(CLOCK_MONOTONIC, &ts);
  16. return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
  17. }
  18. /*
  19. * Pick up some kernel type conventions:
  20. */
  21. #define __user
  22. #define asmlinkage
  23. #if defined(__x86_64__) || defined(__i386__)
  24. #include "../../arch/x86/include/asm/unistd.h"
  25. #define rmb() asm volatile("lfence" ::: "memory")
  26. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  27. #endif
  28. #ifdef __powerpc__
  29. #include "../../arch/powerpc/include/asm/unistd.h"
  30. #define rmb() asm volatile ("sync" ::: "memory")
  31. #define cpu_relax() asm volatile ("" ::: "memory");
  32. #endif
  33. #define unlikely(x) __builtin_expect(!!(x), 0)
  34. #define min(x, y) ({ \
  35. typeof(x) _min1 = (x); \
  36. typeof(y) _min2 = (y); \
  37. (void) (&_min1 == &_min2); \
  38. _min1 < _min2 ? _min1 : _min2; })
  39. static inline int
  40. sys_perf_counter_open(struct perf_counter_hw_event *hw_event_uptr,
  41. pid_t pid, int cpu, int group_fd,
  42. unsigned long flags)
  43. {
  44. return syscall(__NR_perf_counter_open, hw_event_uptr, pid, cpu,
  45. group_fd, flags);
  46. }
  47. #define MAX_COUNTERS 1024
  48. #define MAX_NR_CPUS 4096
  49. #define EID(type, id) (((__u64)(type) << PERF_COUNTER_TYPE_SHIFT) | (id))
  50. #endif