Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 2 | #ifndef __ORDERED_EVENTS_H |
| 3 | #define __ORDERED_EVENTS_H |
| 4 | |
| 5 | #include <linux/types.h> |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 6 | |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 7 | struct perf_sample; |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 8 | |
| 9 | struct ordered_event { |
| 10 | u64 timestamp; |
| 11 | u64 file_offset; |
| 12 | union perf_event *event; |
| 13 | struct list_head list; |
| 14 | }; |
| 15 | |
| 16 | enum oe_flush { |
Jiri Olsa | b0a4520 | 2014-06-12 09:50:11 +0200 | [diff] [blame] | 17 | OE_FLUSH__NONE, |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 18 | OE_FLUSH__FINAL, |
| 19 | OE_FLUSH__ROUND, |
| 20 | OE_FLUSH__HALF, |
Jiri Olsa | 16c66bc | 2018-11-05 13:24:55 +0100 | [diff] [blame] | 21 | OE_FLUSH__TOP, |
Jiri Olsa | 68ca5d0 | 2018-12-05 17:05:07 +0100 | [diff] [blame] | 22 | OE_FLUSH__TIME, |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 23 | }; |
| 24 | |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 25 | struct ordered_events; |
| 26 | |
| 27 | typedef int (*ordered_events__deliver_t)(struct ordered_events *oe, |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 28 | struct ordered_event *event); |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 29 | |
Jiri Olsa | d5ceb62 | 2018-09-07 12:24:54 +0200 | [diff] [blame] | 30 | struct ordered_events_buffer { |
| 31 | struct list_head list; |
Gustavo A. R. Silva | 6549a8c | 2020-05-15 12:29:26 -0500 | [diff] [blame] | 32 | struct ordered_event event[]; |
Jiri Olsa | d5ceb62 | 2018-09-07 12:24:54 +0200 | [diff] [blame] | 33 | }; |
| 34 | |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 35 | struct ordered_events { |
Jiri Olsa | d5ceb62 | 2018-09-07 12:24:54 +0200 | [diff] [blame] | 36 | u64 last_flush; |
| 37 | u64 next_flush; |
| 38 | u64 max_timestamp; |
| 39 | u64 max_alloc_size; |
| 40 | u64 cur_alloc_size; |
| 41 | struct list_head events; |
| 42 | struct list_head cache; |
| 43 | struct list_head to_free; |
| 44 | struct ordered_events_buffer *buffer; |
| 45 | struct ordered_event *last; |
| 46 | ordered_events__deliver_t deliver; |
| 47 | int buffer_idx; |
| 48 | unsigned int nr_events; |
| 49 | enum oe_flush last_flush_type; |
| 50 | u32 nr_unordered_events; |
| 51 | bool copy_on_queue; |
Jiri Olsa | a4a6668 | 2018-11-07 16:58:36 +0100 | [diff] [blame] | 52 | void *data; |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 53 | }; |
| 54 | |
Arnaldo Carvalho de Melo | 4a6b362 | 2015-03-03 13:02:24 -0300 | [diff] [blame] | 55 | int ordered_events__queue(struct ordered_events *oe, union perf_event *event, |
Jiri Olsa | dc83e13 | 2017-08-03 13:24:33 +0200 | [diff] [blame] | 56 | u64 timestamp, u64 file_offset); |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 57 | void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event); |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 58 | int ordered_events__flush(struct ordered_events *oe, enum oe_flush how); |
Jiri Olsa | 68ca5d0 | 2018-12-05 17:05:07 +0100 | [diff] [blame] | 59 | int ordered_events__flush_time(struct ordered_events *oe, u64 timestamp); |
Jiri Olsa | a4a6668 | 2018-11-07 16:58:36 +0100 | [diff] [blame] | 60 | void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver, |
| 61 | void *data); |
Jiri Olsa | adc56ed | 2014-06-10 22:50:03 +0200 | [diff] [blame] | 62 | void ordered_events__free(struct ordered_events *oe); |
Wang Nan | 4532f64 | 2016-04-13 08:21:04 +0000 | [diff] [blame] | 63 | void ordered_events__reinit(struct ordered_events *oe); |
Jiri Olsa | 83356b3 | 2018-12-06 14:38:52 -0300 | [diff] [blame] | 64 | u64 ordered_events__first_time(struct ordered_events *oe); |
Jiri Olsa | 94786b6 | 2014-06-05 11:00:20 +0200 | [diff] [blame] | 65 | |
| 66 | static inline |
| 67 | void ordered_events__set_alloc_size(struct ordered_events *oe, u64 size) |
| 68 | { |
| 69 | oe->max_alloc_size = size; |
| 70 | } |
Alexander Yarygin | 54bf53b | 2014-10-03 18:40:11 +0400 | [diff] [blame] | 71 | |
| 72 | static inline |
| 73 | void ordered_events__set_copy_on_queue(struct ordered_events *oe, bool copy) |
| 74 | { |
| 75 | oe->copy_on_queue = copy; |
| 76 | } |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 77 | #endif /* __ORDERED_EVENTS_H */ |