ordered-events.h 1.6 KB

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