cpu_buffer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(struct op_entry *entry, int cpu);
  67. unsigned long op_cpu_buffer_entries(int cpu);
  68. /* returns the remaining free size of data in the entry */
  69. static inline
  70. int op_cpu_buffer_add_data(struct op_entry *entry, unsigned long val)
  71. {
  72. if (!entry->size)
  73. return 0;
  74. *entry->data = val;
  75. entry->size--;
  76. entry->data++;
  77. return entry->size;
  78. }
  79. /* extra data flags */
  80. #define KERNEL_CTX_SWITCH (1UL << 0)
  81. #define IS_KERNEL (1UL << 1)
  82. #define TRACE_BEGIN (1UL << 2)
  83. #define USER_CTX_SWITCH (1UL << 3)
  84. #define IBS_FETCH_BEGIN (1UL << 4)
  85. #define IBS_OP_BEGIN (1UL << 5)
  86. #endif /* OPROFILE_CPU_BUFFER_H */