Lines Matching refs:oe
14 static void queue_event(struct ordered_events *oe, struct ordered_event *new) in queue_event() argument
16 struct ordered_event *last = oe->last; in queue_event()
20 ++oe->nr_events; in queue_event()
21 oe->last = new; in queue_event()
23 pr_oe_time2(timestamp, "queue_event nr_events %u\n", oe->nr_events); in queue_event()
26 list_add(&new->list, &oe->events); in queue_event()
27 oe->max_timestamp = timestamp; in queue_event()
39 if (p == &oe->events) { in queue_event()
40 list_add_tail(&new->list, &oe->events); in queue_event()
41 oe->max_timestamp = timestamp; in queue_event()
50 if (p == &oe->events) { in queue_event()
51 list_add(&new->list, &oe->events); in queue_event()
60 static union perf_event *__dup_event(struct ordered_events *oe, in __dup_event() argument
65 if (oe->cur_alloc_size < oe->max_alloc_size) { in __dup_event()
68 oe->cur_alloc_size += event->header.size; in __dup_event()
74 static union perf_event *dup_event(struct ordered_events *oe, in dup_event() argument
77 return oe->copy_on_queue ? __dup_event(oe, event) : event; in dup_event()
80 static void free_dup_event(struct ordered_events *oe, union perf_event *event) in free_dup_event() argument
82 if (oe->copy_on_queue) { in free_dup_event()
83 oe->cur_alloc_size -= event->header.size; in free_dup_event()
89 static struct ordered_event *alloc_event(struct ordered_events *oe, in alloc_event() argument
92 struct list_head *cache = &oe->cache; in alloc_event()
96 new_event = dup_event(oe, event); in alloc_event()
103 } else if (oe->buffer) { in alloc_event()
104 new = oe->buffer + oe->buffer_idx; in alloc_event()
105 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER) in alloc_event()
106 oe->buffer = NULL; in alloc_event()
107 } else if (oe->cur_alloc_size < oe->max_alloc_size) { in alloc_event()
110 oe->buffer = malloc(size); in alloc_event()
111 if (!oe->buffer) { in alloc_event()
112 free_dup_event(oe, new_event); in alloc_event()
117 oe->cur_alloc_size, size, oe->max_alloc_size); in alloc_event()
119 oe->cur_alloc_size += size; in alloc_event()
120 list_add(&oe->buffer->list, &oe->to_free); in alloc_event()
123 oe->buffer_idx = 2; in alloc_event()
124 new = oe->buffer + 1; in alloc_event()
126 pr("allocation limit reached %" PRIu64 "B\n", oe->max_alloc_size); in alloc_event()
134 ordered_events__new_event(struct ordered_events *oe, u64 timestamp, in ordered_events__new_event() argument
139 new = alloc_event(oe, event); in ordered_events__new_event()
142 queue_event(oe, new); in ordered_events__new_event()
148 void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event) in ordered_events__delete() argument
150 list_move(&event->list, &oe->cache); in ordered_events__delete()
151 oe->nr_events--; in ordered_events__delete()
152 free_dup_event(oe, event->event); in ordered_events__delete()
155 int ordered_events__queue(struct ordered_events *oe, union perf_event *event, in ordered_events__queue() argument
164 if (timestamp < oe->last_flush) { in ordered_events__queue()
166 pr_oe_time(oe->last_flush, "last flush, last_flush_type %d\n", in ordered_events__queue()
167 oe->last_flush_type); in ordered_events__queue()
169 oe->nr_unordered_events++; in ordered_events__queue()
172 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
174 ordered_events__flush(oe, OE_FLUSH__HALF); in ordered_events__queue()
175 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
185 static int __ordered_events__flush(struct ordered_events *oe) in __ordered_events__flush() argument
187 struct list_head *head = &oe->events; in __ordered_events__flush()
189 u64 limit = oe->next_flush; in __ordered_events__flush()
190 u64 last_ts = oe->last ? oe->last->timestamp : 0ULL; in __ordered_events__flush()
199 ui_progress__init(&prog, oe->nr_events, "Processing time ordered events..."); in __ordered_events__flush()
207 ret = oe->deliver(oe, iter); in __ordered_events__flush()
211 ordered_events__delete(oe, iter); in __ordered_events__flush()
212 oe->last_flush = iter->timestamp; in __ordered_events__flush()
219 oe->last = NULL; in __ordered_events__flush()
221 oe->last = list_entry(head->prev, struct ordered_event, list); in __ordered_events__flush()
226 int ordered_events__flush(struct ordered_events *oe, enum oe_flush how) in ordered_events__flush() argument
236 if (oe->nr_events == 0) in ordered_events__flush()
241 oe->next_flush = ULLONG_MAX; in ordered_events__flush()
247 struct list_head *head = &oe->events; in ordered_events__flush()
250 last = oe->last; in ordered_events__flush()
256 oe->next_flush = first->timestamp; in ordered_events__flush()
257 oe->next_flush += (last->timestamp - first->timestamp) / 2; in ordered_events__flush()
267 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush PRE %s, nr_events %u\n", in ordered_events__flush()
268 str[how], oe->nr_events); in ordered_events__flush()
269 pr_oe_time(oe->max_timestamp, "max_timestamp\n"); in ordered_events__flush()
271 err = __ordered_events__flush(oe); in ordered_events__flush()
275 oe->next_flush = oe->max_timestamp; in ordered_events__flush()
277 oe->last_flush_type = how; in ordered_events__flush()
280 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush POST %s, nr_events %u\n", in ordered_events__flush()
281 str[how], oe->nr_events); in ordered_events__flush()
282 pr_oe_time(oe->last_flush, "last_flush\n"); in ordered_events__flush()
287 void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver) in ordered_events__init() argument
289 INIT_LIST_HEAD(&oe->events); in ordered_events__init()
290 INIT_LIST_HEAD(&oe->cache); in ordered_events__init()
291 INIT_LIST_HEAD(&oe->to_free); in ordered_events__init()
292 oe->max_alloc_size = (u64) -1; in ordered_events__init()
293 oe->cur_alloc_size = 0; in ordered_events__init()
294 oe->deliver = deliver; in ordered_events__init()
297 void ordered_events__free(struct ordered_events *oe) in ordered_events__free() argument
299 while (!list_empty(&oe->to_free)) { in ordered_events__free()
302 event = list_entry(oe->to_free.next, struct ordered_event, list); in ordered_events__free()
304 free_dup_event(oe, event->event); in ordered_events__free()