ordered-events.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ORDERED_EVENTS_H
  3. #define __ORDERED_EVENTS_H
  4. #include <linux/types.h>
  5. struct perf_sample;
  6. struct ordered_event {
  7. u64 timestamp;
  8. u64 file_offset;
  9. union perf_event *event;
  10. struct list_head list;
  11. };
  12. enum oe_flush {
  13. OE_FLUSH__NONE,
  14. OE_FLUSH__FINAL,
  15. OE_FLUSH__ROUND,
  16. OE_FLUSH__HALF,
  17. OE_FLUSH__TOP,
  18. OE_FLUSH__TIME,
  19. };
  20. struct ordered_events;
  21. typedef int (*ordered_events__deliver_t)(struct ordered_events *oe,
  22. struct ordered_event *event);
  23. struct ordered_events_buffer {
  24. struct list_head list;
  25. struct ordered_event event[0];
  26. };
  27. struct ordered_events {
  28. u64 last_flush;
  29. u64 next_flush;
  30. u64 max_timestamp;
  31. u64 max_alloc_size;
  32. u64 cur_alloc_size;
  33. struct list_head events;
  34. struct list_head cache;
  35. struct list_head to_free;
  36. struct ordered_events_buffer *buffer;
  37. struct ordered_event *last;
  38. ordered_events__deliver_t deliver;
  39. int buffer_idx;
  40. unsigned int nr_events;
  41. enum oe_flush last_flush_type;
  42. u32 nr_unordered_events;
  43. bool copy_on_queue;
  44. void *data;
  45. };
  46. int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
  47. u64 timestamp, u64 file_offset);
  48. void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event);
  49. int ordered_events__flush(struct ordered_events *oe, enum oe_flush how);
  50. int ordered_events__flush_time(struct ordered_events *oe, u64 timestamp);
  51. void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver,
  52. void *data);
  53. void ordered_events__free(struct ordered_events *oe);
  54. void ordered_events__reinit(struct ordered_events *oe);
  55. u64 ordered_events__first_time(struct ordered_events *oe);
  56. static inline
  57. void ordered_events__set_alloc_size(struct ordered_events *oe, u64 size)
  58. {
  59. oe->max_alloc_size = size;
  60. }
  61. static inline
  62. void ordered_events__set_copy_on_queue(struct ordered_events *oe, bool copy)
  63. {
  64. oe->copy_on_queue = copy;
  65. }
  66. #endif /* __ORDERED_EVENTS_H */