ordered-events.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. };
  18. struct ordered_events;
  19. typedef int (*ordered_events__deliver_t)(struct ordered_events *oe,
  20. struct ordered_event *event);
  21. struct ordered_events_buffer {
  22. struct list_head list;
  23. struct ordered_event event[0];
  24. };
  25. struct ordered_events {
  26. u64 last_flush;
  27. u64 next_flush;
  28. u64 max_timestamp;
  29. u64 max_alloc_size;
  30. u64 cur_alloc_size;
  31. struct list_head events;
  32. struct list_head cache;
  33. struct list_head to_free;
  34. struct ordered_events_buffer *buffer;
  35. struct ordered_event *last;
  36. ordered_events__deliver_t deliver;
  37. int buffer_idx;
  38. unsigned int nr_events;
  39. enum oe_flush last_flush_type;
  40. u32 nr_unordered_events;
  41. bool copy_on_queue;
  42. };
  43. int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
  44. u64 timestamp, u64 file_offset);
  45. void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event);
  46. int ordered_events__flush(struct ordered_events *oe, enum oe_flush how);
  47. void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver);
  48. void ordered_events__free(struct ordered_events *oe);
  49. void ordered_events__reinit(struct ordered_events *oe);
  50. static inline
  51. void ordered_events__set_alloc_size(struct ordered_events *oe, u64 size)
  52. {
  53. oe->max_alloc_size = size;
  54. }
  55. static inline
  56. void ordered_events__set_copy_on_queue(struct ordered_events *oe, bool copy)
  57. {
  58. oe->copy_on_queue = copy;
  59. }
  60. #endif /* __ORDERED_EVENTS_H */