perf.h 1.6 KB

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