cpu_buffer.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. struct task_struct;
  17. int alloc_cpu_buffers(void);
  18. void free_cpu_buffers(void);
  19. void start_cpu_work(void);
  20. void end_cpu_work(void);
  21. /* CPU buffer is composed of such entries (which are
  22. * also used for context switch notes)
  23. */
  24. struct op_sample {
  25. unsigned long eip;
  26. unsigned long event;
  27. };
  28. struct oprofile_cpu_buffer {
  29. volatile unsigned long head_pos;
  30. volatile unsigned long tail_pos;
  31. unsigned long buffer_size;
  32. struct task_struct *last_task;
  33. int last_is_kernel;
  34. int tracing;
  35. struct op_sample *buffer;
  36. unsigned long sample_received;
  37. unsigned long sample_lost_overflow;
  38. unsigned long backtrace_aborted;
  39. unsigned long sample_invalid_eip;
  40. int cpu;
  41. struct delayed_work work;
  42. };
  43. DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
  44. void cpu_buffer_reset(struct oprofile_cpu_buffer *cpu_buf);
  45. static inline
  46. struct op_sample *cpu_buffer_write_entry(struct oprofile_cpu_buffer *cpu_buf)
  47. {
  48. return &cpu_buf->buffer[cpu_buf->head_pos];
  49. }
  50. static inline
  51. struct op_sample *cpu_buffer_read_entry(struct oprofile_cpu_buffer *cpu_buf)
  52. {
  53. return &cpu_buf->buffer[cpu_buf->tail_pos];
  54. }
  55. /* transient events for the CPU buffer -> event buffer */
  56. #define CPU_IS_KERNEL 1
  57. #define CPU_TRACE_BEGIN 2
  58. #define IBS_FETCH_BEGIN 3
  59. #define IBS_OP_BEGIN 4
  60. #endif /* OPROFILE_CPU_BUFFER_H */