cpu_buffer.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @file cpu_buffer.h
  3. *
  4. * @remark Copyright 2002 OProfile authors
  5. * @remark Read the file COPYING
  6. *
  7. * @author John Levon <levon@movementarian.org>
  8. */
  9. #ifndef OPROFILE_CPU_BUFFER_H
  10. #define OPROFILE_CPU_BUFFER_H
  11. #include <linux/types.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/cache.h>
  15. #include <linux/sched.h>
  16. #include <linux/ring_buffer.h>
  17. struct task_struct;
  18. int alloc_cpu_buffers(void);
  19. void free_cpu_buffers(void);
  20. void start_cpu_work(void);
  21. void end_cpu_work(void);
  22. /* CPU buffer is composed of such entries (which are
  23. * also used for context switch notes)
  24. */
  25. struct op_sample {
  26. unsigned long eip;
  27. unsigned long event;
  28. };
  29. struct op_entry {
  30. struct ring_buffer_event *event;
  31. struct op_sample *sample;
  32. unsigned long irq_flags;
  33. };
  34. struct oprofile_cpu_buffer {
  35. unsigned long buffer_size;
  36. struct task_struct *last_task;
  37. int last_is_kernel;
  38. int tracing;
  39. unsigned long sample_received;
  40. unsigned long sample_lost_overflow;
  41. unsigned long backtrace_aborted;
  42. unsigned long sample_invalid_eip;
  43. int cpu;
  44. struct delayed_work work;
  45. };
  46. DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
  47. /*
  48. * Resets the cpu buffer to a sane state.
  49. *
  50. * reset these to invalid values; the next sample collected will
  51. * populate the buffer with proper values to initialize the buffer
  52. */
  53. static inline void op_cpu_buffer_reset(int cpu)
  54. {
  55. struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
  56. cpu_buf->last_is_kernel = -1;
  57. cpu_buf->last_task = NULL;
  58. }
  59. int op_cpu_buffer_write_entry(struct op_entry *entry);
  60. int op_cpu_buffer_write_commit(struct op_entry *entry);
  61. struct op_sample *op_cpu_buffer_read_entry(int cpu);
  62. unsigned long op_cpu_buffer_entries(int cpu);
  63. /* transient events for the CPU buffer -> event buffer */
  64. #define CPU_IS_KERNEL 1
  65. #define CPU_TRACE_BEGIN 2
  66. #define IBS_FETCH_BEGIN 3
  67. #define IBS_OP_BEGIN 4
  68. #endif /* OPROFILE_CPU_BUFFER_H */