perf.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include "types.h"
  19. /*
  20. * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
  21. * counters in the current task.
  22. */
  23. #define PR_TASK_PERF_COUNTERS_DISABLE 31
  24. #define PR_TASK_PERF_COUNTERS_ENABLE 32
  25. #ifndef NSEC_PER_SEC
  26. # define NSEC_PER_SEC 1000000000ULL
  27. #endif
  28. static inline unsigned long long rdclock(void)
  29. {
  30. struct timespec ts;
  31. clock_gettime(CLOCK_MONOTONIC, &ts);
  32. return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
  33. }
  34. /*
  35. * Pick up some kernel type conventions:
  36. */
  37. #define __user
  38. #define asmlinkage
  39. #define unlikely(x) __builtin_expect(!!(x), 0)
  40. #define min(x, y) ({ \
  41. typeof(x) _min1 = (x); \
  42. typeof(y) _min2 = (y); \
  43. (void) (&_min1 == &_min2); \
  44. _min1 < _min2 ? _min1 : _min2; })
  45. static inline int
  46. sys_perf_counter_open(struct perf_counter_attr *attr,
  47. pid_t pid, int cpu, int group_fd,
  48. unsigned long flags)
  49. {
  50. attr->size = sizeof(*attr);
  51. return syscall(__NR_perf_counter_open, attr, pid, cpu,
  52. group_fd, flags);
  53. }
  54. #define MAX_COUNTERS 256
  55. #define MAX_NR_CPUS 256
  56. struct perf_file_header {
  57. u64 version;
  58. u64 sample_type;
  59. u64 data_size;
  60. };
  61. #endif