Merge tag 'for-linus-20181115' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / tools / perf / util / ordered-events.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ORDERED_EVENTS_H
3 #define __ORDERED_EVENTS_H
4
5 #include <linux/types.h>
6
7 struct perf_sample;
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 {
17         OE_FLUSH__NONE,
18         OE_FLUSH__FINAL,
19         OE_FLUSH__ROUND,
20         OE_FLUSH__HALF,
21 };
22
23 struct ordered_events;
24
25 typedef int (*ordered_events__deliver_t)(struct ordered_events *oe,
26                                          struct ordered_event *event);
27
28 struct ordered_events_buffer {
29         struct list_head        list;
30         struct ordered_event    event[0];
31 };
32
33 struct ordered_events {
34         u64                              last_flush;
35         u64                              next_flush;
36         u64                              max_timestamp;
37         u64                              max_alloc_size;
38         u64                              cur_alloc_size;
39         struct list_head                 events;
40         struct list_head                 cache;
41         struct list_head                 to_free;
42         struct ordered_events_buffer    *buffer;
43         struct ordered_event            *last;
44         ordered_events__deliver_t        deliver;
45         int                              buffer_idx;
46         unsigned int                     nr_events;
47         enum oe_flush                    last_flush_type;
48         u32                              nr_unordered_events;
49         bool                             copy_on_queue;
50 };
51
52 int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
53                           u64 timestamp, u64 file_offset);
54 void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event);
55 int ordered_events__flush(struct ordered_events *oe, enum oe_flush how);
56 void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver);
57 void ordered_events__free(struct ordered_events *oe);
58 void ordered_events__reinit(struct ordered_events *oe);
59
60 static inline
61 void ordered_events__set_alloc_size(struct ordered_events *oe, u64 size)
62 {
63         oe->max_alloc_size = size;
64 }
65
66 static inline
67 void ordered_events__set_copy_on_queue(struct ordered_events *oe, bool copy)
68 {
69         oe->copy_on_queue = copy;
70 }
71 #endif /* __ORDERED_EVENTS_H */