blob: 75345946c4b9ec187eb49825a7d4638ad1f23b5d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jiri Olsa5f86b802014-08-01 13:02:58 -03002#ifndef __ORDERED_EVENTS_H
3#define __ORDERED_EVENTS_H
4
5#include <linux/types.h>
Jiri Olsa5f86b802014-08-01 13:02:58 -03006
Arnaldo Carvalho de Melod10eb1e2015-03-03 12:20:38 -03007struct perf_sample;
Jiri Olsa5f86b802014-08-01 13:02:58 -03008
9struct ordered_event {
10 u64 timestamp;
11 u64 file_offset;
12 union perf_event *event;
13 struct list_head list;
14};
15
16enum oe_flush {
Jiri Olsab0a45202014-06-12 09:50:11 +020017 OE_FLUSH__NONE,
Jiri Olsa5f86b802014-08-01 13:02:58 -030018 OE_FLUSH__FINAL,
19 OE_FLUSH__ROUND,
20 OE_FLUSH__HALF,
Jiri Olsa16c66bc2018-11-05 13:24:55 +010021 OE_FLUSH__TOP,
Jiri Olsa68ca5d02018-12-05 17:05:07 +010022 OE_FLUSH__TIME,
Jiri Olsa5f86b802014-08-01 13:02:58 -030023};
24
Arnaldo Carvalho de Melod10eb1e2015-03-03 12:20:38 -030025struct ordered_events;
26
27typedef int (*ordered_events__deliver_t)(struct ordered_events *oe,
Arnaldo Carvalho de Melo9870d782015-03-31 12:48:16 -030028 struct ordered_event *event);
Arnaldo Carvalho de Melod10eb1e2015-03-03 12:20:38 -030029
Jiri Olsad5ceb622018-09-07 12:24:54 +020030struct ordered_events_buffer {
31 struct list_head list;
Gustavo A. R. Silva6549a8c2020-05-15 12:29:26 -050032 struct ordered_event event[];
Jiri Olsad5ceb622018-09-07 12:24:54 +020033};
34
Jiri Olsa5f86b802014-08-01 13:02:58 -030035struct ordered_events {
Jiri Olsad5ceb622018-09-07 12:24:54 +020036 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 Olsaa4a66682018-11-07 16:58:36 +010052 void *data;
Jiri Olsa5f86b802014-08-01 13:02:58 -030053};
54
Arnaldo Carvalho de Melo4a6b3622015-03-03 13:02:24 -030055int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
Jiri Olsadc83e132017-08-03 13:24:33 +020056 u64 timestamp, u64 file_offset);
Jiri Olsa5f86b802014-08-01 13:02:58 -030057void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event);
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -030058int ordered_events__flush(struct ordered_events *oe, enum oe_flush how);
Jiri Olsa68ca5d02018-12-05 17:05:07 +010059int ordered_events__flush_time(struct ordered_events *oe, u64 timestamp);
Jiri Olsaa4a66682018-11-07 16:58:36 +010060void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver,
61 void *data);
Jiri Olsaadc56ed2014-06-10 22:50:03 +020062void ordered_events__free(struct ordered_events *oe);
Wang Nan4532f642016-04-13 08:21:04 +000063void ordered_events__reinit(struct ordered_events *oe);
Jiri Olsa83356b32018-12-06 14:38:52 -030064u64 ordered_events__first_time(struct ordered_events *oe);
Jiri Olsa94786b62014-06-05 11:00:20 +020065
66static inline
67void ordered_events__set_alloc_size(struct ordered_events *oe, u64 size)
68{
69 oe->max_alloc_size = size;
70}
Alexander Yarygin54bf53b2014-10-03 18:40:11 +040071
72static inline
73void ordered_events__set_copy_on_queue(struct ordered_events *oe, bool copy)
74{
75 oe->copy_on_queue = copy;
76}
Jiri Olsa5f86b802014-08-01 13:02:58 -030077#endif /* __ORDERED_EVENTS_H */