Lines Matching full:oe

18 static void queue_event(struct ordered_events *oe, struct ordered_event *new)  in queue_event()  argument
20 struct ordered_event *last = oe->last; in queue_event()
24 ++oe->nr_events; in queue_event()
25 oe->last = new; in queue_event()
27 pr_oe_time2(timestamp, "queue_event nr_events %u\n", oe->nr_events); in queue_event()
30 list_add(&new->list, &oe->events); in queue_event()
31 oe->max_timestamp = timestamp; in queue_event()
43 if (p == &oe->events) { in queue_event()
44 list_add_tail(&new->list, &oe->events); in queue_event()
45 oe->max_timestamp = timestamp; in queue_event()
54 if (p == &oe->events) { in queue_event()
55 list_add(&new->list, &oe->events); in queue_event()
64 static union perf_event *__dup_event(struct ordered_events *oe, in __dup_event() argument
69 if (oe->cur_alloc_size < oe->max_alloc_size) { in __dup_event()
72 oe->cur_alloc_size += event->header.size; in __dup_event()
78 static union perf_event *dup_event(struct ordered_events *oe, in dup_event() argument
81 return oe->copy_on_queue ? __dup_event(oe, event) : event; in dup_event()
84 static void __free_dup_event(struct ordered_events *oe, union perf_event *event) in __free_dup_event() argument
87 oe->cur_alloc_size -= event->header.size; in __free_dup_event()
92 static void free_dup_event(struct ordered_events *oe, union perf_event *event) in free_dup_event() argument
94 if (oe->copy_on_queue) in free_dup_event()
95 __free_dup_event(oe, event); in free_dup_event()
99 static struct ordered_event *alloc_event(struct ordered_events *oe, in alloc_event() argument
102 struct list_head *cache = &oe->cache; in alloc_event()
107 new_event = dup_event(oe, event); in alloc_event()
138 size = sizeof(*oe->buffer) + MAX_SAMPLE_BUFFER * sizeof(*new); in alloc_event()
143 } else if (oe->buffer) { in alloc_event()
144 new = &oe->buffer->event[oe->buffer_idx]; in alloc_event()
145 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER) in alloc_event()
146 oe->buffer = NULL; in alloc_event()
147 } else if ((oe->cur_alloc_size + size) < oe->max_alloc_size) { in alloc_event()
148 oe->buffer = malloc(size); in alloc_event()
149 if (!oe->buffer) { in alloc_event()
150 free_dup_event(oe, new_event); in alloc_event()
155 oe->cur_alloc_size, size, oe->max_alloc_size); in alloc_event()
157 oe->cur_alloc_size += size; in alloc_event()
158 list_add(&oe->buffer->list, &oe->to_free); in alloc_event()
160 oe->buffer_idx = 1; in alloc_event()
161 new = &oe->buffer->event[0]; in alloc_event()
163 pr("allocation limit reached %" PRIu64 "B\n", oe->max_alloc_size); in alloc_event()
172 ordered_events__new_event(struct ordered_events *oe, u64 timestamp, in ordered_events__new_event() argument
177 new = alloc_event(oe, event); in ordered_events__new_event()
180 queue_event(oe, new); in ordered_events__new_event()
186 void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event) in ordered_events__delete() argument
188 list_move(&event->list, &oe->cache); in ordered_events__delete()
189 oe->nr_events--; in ordered_events__delete()
190 free_dup_event(oe, event->event); in ordered_events__delete()
194 int ordered_events__queue(struct ordered_events *oe, union perf_event *event, in ordered_events__queue() argument
202 if (timestamp < oe->last_flush) { in ordered_events__queue()
204 pr_oe_time(oe->last_flush, "last flush, last_flush_type %d\n", in ordered_events__queue()
205 oe->last_flush_type); in ordered_events__queue()
207 oe->nr_unordered_events++; in ordered_events__queue()
210 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
212 ordered_events__flush(oe, OE_FLUSH__HALF); in ordered_events__queue()
213 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
224 static int do_flush(struct ordered_events *oe, bool show_progress) in do_flush() argument
226 struct list_head *head = &oe->events; in do_flush()
228 u64 limit = oe->next_flush; in do_flush()
229 u64 last_ts = oe->last ? oe->last->timestamp : 0ULL; in do_flush()
237 ui_progress__init(&prog, oe->nr_events, "Processing time ordered events..."); in do_flush()
245 ret = oe->deliver(oe, iter); in do_flush()
249 ordered_events__delete(oe, iter); in do_flush()
250 oe->last_flush = iter->timestamp; in do_flush()
257 oe->last = NULL; in do_flush()
259 oe->last = list_entry(head->prev, struct ordered_event, list); in do_flush()
267 static int __ordered_events__flush(struct ordered_events *oe, enum oe_flush how, in __ordered_events__flush() argument
281 if (oe->nr_events == 0) in __ordered_events__flush()
289 oe->next_flush = ULLONG_MAX; in __ordered_events__flush()
295 struct list_head *head = &oe->events; in __ordered_events__flush()
298 last = oe->last; in __ordered_events__flush()
304 oe->next_flush = first->timestamp; in __ordered_events__flush()
305 oe->next_flush += (last->timestamp - first->timestamp) / 2; in __ordered_events__flush()
310 oe->next_flush = timestamp; in __ordered_events__flush()
320 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush PRE %s, nr_events %u\n", in __ordered_events__flush()
321 str[how], oe->nr_events); in __ordered_events__flush()
322 pr_oe_time(oe->max_timestamp, "max_timestamp\n"); in __ordered_events__flush()
324 err = do_flush(oe, show_progress); in __ordered_events__flush()
328 oe->next_flush = oe->max_timestamp; in __ordered_events__flush()
330 oe->last_flush_type = how; in __ordered_events__flush()
333 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush POST %s, nr_events %u\n", in __ordered_events__flush()
334 str[how], oe->nr_events); in __ordered_events__flush()
335 pr_oe_time(oe->last_flush, "last_flush\n"); in __ordered_events__flush()
340 int ordered_events__flush(struct ordered_events *oe, enum oe_flush how) in ordered_events__flush() argument
342 return __ordered_events__flush(oe, how, 0); in ordered_events__flush()
345 int ordered_events__flush_time(struct ordered_events *oe, u64 timestamp) in ordered_events__flush_time() argument
347 return __ordered_events__flush(oe, OE_FLUSH__TIME, timestamp); in ordered_events__flush_time()
350 u64 ordered_events__first_time(struct ordered_events *oe) in ordered_events__first_time() argument
354 if (list_empty(&oe->events)) in ordered_events__first_time()
357 event = list_first_entry(&oe->events, struct ordered_event, list); in ordered_events__first_time()
361 void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver, in ordered_events__init() argument
364 INIT_LIST_HEAD(&oe->events); in ordered_events__init()
365 INIT_LIST_HEAD(&oe->cache); in ordered_events__init()
366 INIT_LIST_HEAD(&oe->to_free); in ordered_events__init()
367 oe->max_alloc_size = (u64) -1; in ordered_events__init()
368 oe->cur_alloc_size = 0; in ordered_events__init()
369 oe->deliver = deliver; in ordered_events__init()
370 oe->data = data; in ordered_events__init()
375 unsigned int max, struct ordered_events *oe) in ordered_events_buffer__free() argument
377 if (oe->copy_on_queue) { in ordered_events_buffer__free()
381 __free_dup_event(oe, buffer->event[i].event); in ordered_events_buffer__free()
387 void ordered_events__free(struct ordered_events *oe) in ordered_events__free() argument
391 if (list_empty(&oe->to_free)) in ordered_events__free()
398 if (oe->buffer) { in ordered_events__free()
399 list_del_init(&oe->buffer->list); in ordered_events__free()
400 ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe); in ordered_events__free()
404 list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) { in ordered_events__free()
406 ordered_events_buffer__free(buffer, MAX_SAMPLE_BUFFER, oe); in ordered_events__free()
410 void ordered_events__reinit(struct ordered_events *oe) in ordered_events__reinit() argument
412 ordered_events__deliver_t old_deliver = oe->deliver; in ordered_events__reinit()
414 ordered_events__free(oe); in ordered_events__reinit()
415 memset(oe, '\0', sizeof(*oe)); in ordered_events__reinit()
416 ordered_events__init(oe, old_deliver, oe->data); in ordered_events__reinit()