internal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef _KERNEL_EVENTS_INTERNAL_H
  2. #define _KERNEL_EVENTS_INTERNAL_H
  3. #include <linux/hardirq.h>
  4. #include <linux/uaccess.h>
  5. /* Buffer handling */
  6. #define RING_BUFFER_WRITABLE 0x01
  7. struct ring_buffer {
  8. atomic_t refcount;
  9. struct rcu_head rcu_head;
  10. #ifdef CONFIG_PERF_USE_VMALLOC
  11. struct work_struct work;
  12. int page_order; /* allocation order */
  13. #endif
  14. int nr_pages; /* nr of data pages */
  15. int writable; /* are we writable */
  16. atomic_t poll; /* POLL_ for wakeups */
  17. local_t head; /* write position */
  18. local_t nest; /* nested writers */
  19. local_t events; /* event limit */
  20. local_t wakeup; /* wakeup stamp */
  21. local_t lost; /* nr records lost */
  22. long watermark; /* wakeup watermark */
  23. /* poll crap */
  24. spinlock_t event_lock;
  25. struct list_head event_list;
  26. struct perf_event_mmap_page *user_page;
  27. void *data_pages[0];
  28. };
  29. extern void rb_free(struct ring_buffer *rb);
  30. extern struct ring_buffer *
  31. rb_alloc(int nr_pages, long watermark, int cpu, int flags);
  32. extern void perf_event_wakeup(struct perf_event *event);
  33. extern void
  34. perf_event_header__init_id(struct perf_event_header *header,
  35. struct perf_sample_data *data,
  36. struct perf_event *event);
  37. extern void
  38. perf_event__output_id_sample(struct perf_event *event,
  39. struct perf_output_handle *handle,
  40. struct perf_sample_data *sample);
  41. extern struct page *
  42. perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff);
  43. #ifdef CONFIG_PERF_USE_VMALLOC
  44. /*
  45. * Back perf_mmap() with vmalloc memory.
  46. *
  47. * Required for architectures that have d-cache aliasing issues.
  48. */
  49. static inline int page_order(struct ring_buffer *rb)
  50. {
  51. return rb->page_order;
  52. }
  53. #else
  54. static inline int page_order(struct ring_buffer *rb)
  55. {
  56. return 0;
  57. }
  58. #endif
  59. static inline unsigned long perf_data_size(struct ring_buffer *rb)
  60. {
  61. return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
  62. }
  63. #define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
  64. static inline unsigned int \
  65. func_name(struct perf_output_handle *handle, \
  66. const void *buf, unsigned int len) \
  67. { \
  68. unsigned long size, written; \
  69. \
  70. do { \
  71. size = min_t(unsigned long, handle->size, len); \
  72. \
  73. written = memcpy_func(handle->addr, buf, size); \
  74. \
  75. len -= written; \
  76. handle->addr += written; \
  77. buf += written; \
  78. handle->size -= written; \
  79. if (!handle->size) { \
  80. struct ring_buffer *rb = handle->rb; \
  81. \
  82. handle->page++; \
  83. handle->page &= rb->nr_pages - 1; \
  84. handle->addr = rb->data_pages[handle->page]; \
  85. handle->size = PAGE_SIZE << page_order(rb); \
  86. } \
  87. } while (len && written == size); \
  88. \
  89. return len; \
  90. }
  91. static inline int memcpy_common(void *dst, const void *src, size_t n)
  92. {
  93. memcpy(dst, src, n);
  94. return n;
  95. }
  96. DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
  97. #define MEMCPY_SKIP(dst, src, n) (n)
  98. DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
  99. #ifndef arch_perf_out_copy_user
  100. #define arch_perf_out_copy_user __copy_from_user_inatomic
  101. #endif
  102. DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
  103. /* Callchain handling */
  104. extern struct perf_callchain_entry *
  105. perf_callchain(struct perf_event *event, struct pt_regs *regs);
  106. extern int get_callchain_buffers(void);
  107. extern void put_callchain_buffers(void);
  108. static inline int get_recursion_context(int *recursion)
  109. {
  110. int rctx;
  111. if (in_nmi())
  112. rctx = 3;
  113. else if (in_irq())
  114. rctx = 2;
  115. else if (in_softirq())
  116. rctx = 1;
  117. else
  118. rctx = 0;
  119. if (recursion[rctx])
  120. return -1;
  121. recursion[rctx]++;
  122. barrier();
  123. return rctx;
  124. }
  125. static inline void put_recursion_context(int *recursion, int rctx)
  126. {
  127. barrier();
  128. recursion[rctx]--;
  129. }
  130. #ifdef CONFIG_HAVE_PERF_USER_STACK_DUMP
  131. static inline bool arch_perf_have_user_stack_dump(void)
  132. {
  133. return true;
  134. }
  135. #define perf_user_stack_pointer(regs) user_stack_pointer(regs)
  136. #else
  137. static inline bool arch_perf_have_user_stack_dump(void)
  138. {
  139. return false;
  140. }
  141. #define perf_user_stack_pointer(regs) 0
  142. #endif /* CONFIG_HAVE_PERF_USER_STACK_DUMP */
  143. #endif /* _KERNEL_EVENTS_INTERNAL_H */