perf_counter.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Performance counters:
  3. *
  4. * Copyright(C) 2008, Thomas Gleixner <tglx@linutronix.de>
  5. * Copyright(C) 2008, Red Hat, Inc., Ingo Molnar
  6. *
  7. * Data type definitions, declarations, prototypes.
  8. *
  9. * Started by: Thomas Gleixner and Ingo Molnar
  10. *
  11. * For licencing details see kernel-base/COPYING
  12. */
  13. #ifndef _LINUX_PERF_COUNTER_H
  14. #define _LINUX_PERF_COUNTER_H
  15. #include <asm/atomic.h>
  16. #include <linux/list.h>
  17. #include <linux/mutex.h>
  18. #include <linux/rculist.h>
  19. #include <linux/rcupdate.h>
  20. #include <linux/spinlock.h>
  21. struct task_struct;
  22. /*
  23. * Generalized hardware event types, used by the hw_event_type parameter
  24. * of the sys_perf_counter_open() syscall:
  25. */
  26. enum hw_event_types {
  27. PERF_COUNT_CYCLES,
  28. PERF_COUNT_INSTRUCTIONS,
  29. PERF_COUNT_CACHE_REFERENCES,
  30. PERF_COUNT_CACHE_MISSES,
  31. PERF_COUNT_BRANCH_INSTRUCTIONS,
  32. PERF_COUNT_BRANCH_MISSES,
  33. /*
  34. * If this bit is set in the type, then trigger NMI sampling:
  35. */
  36. PERF_COUNT_NMI = (1 << 30),
  37. };
  38. /*
  39. * IRQ-notification data record type:
  40. */
  41. enum perf_record_type {
  42. PERF_RECORD_SIMPLE,
  43. PERF_RECORD_IRQ,
  44. PERF_RECORD_GROUP,
  45. };
  46. /**
  47. * struct hw_perf_counter - performance counter hardware details
  48. */
  49. struct hw_perf_counter {
  50. u64 config;
  51. unsigned long config_base;
  52. unsigned long counter_base;
  53. int nmi;
  54. unsigned int idx;
  55. u64 prev_count;
  56. s32 next_count;
  57. u64 irq_period;
  58. };
  59. /*
  60. * Hardcoded buffer length limit for now, for IRQ-fed events:
  61. */
  62. #define PERF_DATA_BUFLEN 2048
  63. /**
  64. * struct perf_data - performance counter IRQ data sampling ...
  65. */
  66. struct perf_data {
  67. int len;
  68. int rd_idx;
  69. int overrun;
  70. u8 data[PERF_DATA_BUFLEN];
  71. };
  72. /**
  73. * struct perf_counter - performance counter kernel representation:
  74. */
  75. struct perf_counter {
  76. struct list_head list;
  77. int active;
  78. #if BITS_PER_LONG == 64
  79. atomic64_t count;
  80. #else
  81. atomic_t count32[2];
  82. #endif
  83. u64 __irq_period;
  84. struct hw_perf_counter hw;
  85. struct perf_counter_context *ctx;
  86. struct task_struct *task;
  87. /*
  88. * Protect attach/detach:
  89. */
  90. struct mutex mutex;
  91. int oncpu;
  92. int cpu;
  93. s32 hw_event_type;
  94. enum perf_record_type record_type;
  95. /* read() / irq related data */
  96. wait_queue_head_t waitq;
  97. /* optional: for NMIs */
  98. int wakeup_pending;
  99. struct perf_data *irqdata;
  100. struct perf_data *usrdata;
  101. struct perf_data data[2];
  102. };
  103. /**
  104. * struct perf_counter_context - counter context structure
  105. *
  106. * Used as a container for task counters and CPU counters as well:
  107. */
  108. struct perf_counter_context {
  109. #ifdef CONFIG_PERF_COUNTERS
  110. /*
  111. * Protect the list of counters:
  112. */
  113. spinlock_t lock;
  114. struct list_head counters;
  115. int nr_counters;
  116. int nr_active;
  117. struct task_struct *task;
  118. #endif
  119. };
  120. /**
  121. * struct perf_counter_cpu_context - per cpu counter context structure
  122. */
  123. struct perf_cpu_context {
  124. struct perf_counter_context ctx;
  125. struct perf_counter_context *task_ctx;
  126. int active_oncpu;
  127. int max_pertask;
  128. };
  129. /*
  130. * Set by architecture code:
  131. */
  132. extern int perf_max_counters;
  133. #ifdef CONFIG_PERF_COUNTERS
  134. extern void perf_counter_task_sched_in(struct task_struct *task, int cpu);
  135. extern void perf_counter_task_sched_out(struct task_struct *task, int cpu);
  136. extern void perf_counter_task_tick(struct task_struct *task, int cpu);
  137. extern void perf_counter_init_task(struct task_struct *task);
  138. extern void perf_counter_notify(struct pt_regs *regs);
  139. extern void perf_counter_print_debug(void);
  140. #else
  141. static inline void
  142. perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
  143. static inline void
  144. perf_counter_task_sched_out(struct task_struct *task, int cpu) { }
  145. static inline void
  146. perf_counter_task_tick(struct task_struct *task, int cpu) { }
  147. static inline void perf_counter_init_task(struct task_struct *task) { }
  148. static inline void perf_counter_notify(struct pt_regs *regs) { }
  149. static inline void perf_counter_print_debug(void) { }
  150. #endif
  151. #endif /* _LINUX_PERF_COUNTER_H */