cpu_buffer.h 2.0 KB

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