Lines Matching full:oe
17 static void queue_event(struct ordered_events *oe, struct ordered_event *new) in queue_event() argument
19 struct ordered_event *last = oe->last; in queue_event()
23 ++oe->nr_events; in queue_event()
24 oe->last = new; in queue_event()
26 pr_oe_time2(timestamp, "queue_event nr_events %u\n", oe->nr_events); in queue_event()
29 list_add(&new->list, &oe->events); in queue_event()
30 oe->max_timestamp = timestamp; in queue_event()
42 if (p == &oe->events) { in queue_event()
43 list_add_tail(&new->list, &oe->events); in queue_event()
44 oe->max_timestamp = timestamp; in queue_event()
53 if (p == &oe->events) { in queue_event()
54 list_add(&new->list, &oe->events); in queue_event()
63 static union perf_event *__dup_event(struct ordered_events *oe, in __dup_event() argument
68 if (oe->cur_alloc_size < oe->max_alloc_size) { in __dup_event()
71 oe->cur_alloc_size += event->header.size; in __dup_event()
77 static union perf_event *dup_event(struct ordered_events *oe, in dup_event() argument
80 return oe->copy_on_queue ? __dup_event(oe, event) : event; in dup_event()
83 static void free_dup_event(struct ordered_events *oe, union perf_event *event) in free_dup_event() argument
85 if (event && oe->copy_on_queue) { in free_dup_event()
86 oe->cur_alloc_size -= event->header.size; in free_dup_event()
92 static struct ordered_event *alloc_event(struct ordered_events *oe, in alloc_event() argument
95 struct list_head *cache = &oe->cache; in alloc_event()
99 new_event = dup_event(oe, event); in alloc_event()
106 } else if (oe->buffer) { in alloc_event()
107 new = oe->buffer + oe->buffer_idx; in alloc_event()
108 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER) in alloc_event()
109 oe->buffer = NULL; in alloc_event()
110 } else if (oe->cur_alloc_size < oe->max_alloc_size) { in alloc_event()
113 oe->buffer = malloc(size); in alloc_event()
114 if (!oe->buffer) { in alloc_event()
115 free_dup_event(oe, new_event); in alloc_event()
120 oe->cur_alloc_size, size, oe->max_alloc_size); in alloc_event()
122 oe->cur_alloc_size += size; in alloc_event()
123 list_add(&oe->buffer->list, &oe->to_free); in alloc_event()
126 oe->buffer_idx = 2; in alloc_event()
127 new = oe->buffer + 1; in alloc_event()
129 pr("allocation limit reached %" PRIu64 "B\n", oe->max_alloc_size); in alloc_event()
137 ordered_events__new_event(struct ordered_events *oe, u64 timestamp, in ordered_events__new_event() argument
142 new = alloc_event(oe, event); in ordered_events__new_event()
145 queue_event(oe, new); in ordered_events__new_event()
151 void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event) in ordered_events__delete() argument
153 list_move(&event->list, &oe->cache); in ordered_events__delete()
154 oe->nr_events--; in ordered_events__delete()
155 free_dup_event(oe, event->event); in ordered_events__delete()
159 int ordered_events__queue(struct ordered_events *oe, union perf_event *event, in ordered_events__queue() argument
167 if (timestamp < oe->last_flush) { in ordered_events__queue()
169 pr_oe_time(oe->last_flush, "last flush, last_flush_type %d\n", in ordered_events__queue()
170 oe->last_flush_type); in ordered_events__queue()
172 oe->nr_unordered_events++; in ordered_events__queue()
175 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
177 ordered_events__flush(oe, OE_FLUSH__HALF); in ordered_events__queue()
178 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
188 static int __ordered_events__flush(struct ordered_events *oe) in __ordered_events__flush() argument
190 struct list_head *head = &oe->events; in __ordered_events__flush()
192 u64 limit = oe->next_flush; in __ordered_events__flush()
193 u64 last_ts = oe->last ? oe->last->timestamp : 0ULL; in __ordered_events__flush()
202 ui_progress__init(&prog, oe->nr_events, "Processing time ordered events..."); in __ordered_events__flush()
210 ret = oe->deliver(oe, iter); in __ordered_events__flush()
214 ordered_events__delete(oe, iter); in __ordered_events__flush()
215 oe->last_flush = iter->timestamp; in __ordered_events__flush()
222 oe->last = NULL; in __ordered_events__flush()
224 oe->last = list_entry(head->prev, struct ordered_event, list); in __ordered_events__flush()
232 int ordered_events__flush(struct ordered_events *oe, enum oe_flush how) in ordered_events__flush() argument
242 if (oe->nr_events == 0) in ordered_events__flush()
247 oe->next_flush = ULLONG_MAX; in ordered_events__flush()
253 struct list_head *head = &oe->events; in ordered_events__flush()
256 last = oe->last; in ordered_events__flush()
262 oe->next_flush = first->timestamp; in ordered_events__flush()
263 oe->next_flush += (last->timestamp - first->timestamp) / 2; in ordered_events__flush()
273 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush PRE %s, nr_events %u\n", in ordered_events__flush()
274 str[how], oe->nr_events); in ordered_events__flush()
275 pr_oe_time(oe->max_timestamp, "max_timestamp\n"); in ordered_events__flush()
277 err = __ordered_events__flush(oe); in ordered_events__flush()
281 oe->next_flush = oe->max_timestamp; in ordered_events__flush()
283 oe->last_flush_type = how; in ordered_events__flush()
286 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush POST %s, nr_events %u\n", in ordered_events__flush()
287 str[how], oe->nr_events); in ordered_events__flush()
288 pr_oe_time(oe->last_flush, "last_flush\n"); in ordered_events__flush()
293 void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver) in ordered_events__init() argument
295 INIT_LIST_HEAD(&oe->events); in ordered_events__init()
296 INIT_LIST_HEAD(&oe->cache); in ordered_events__init()
297 INIT_LIST_HEAD(&oe->to_free); in ordered_events__init()
298 oe->max_alloc_size = (u64) -1; in ordered_events__init()
299 oe->cur_alloc_size = 0; in ordered_events__init()
300 oe->deliver = deliver; in ordered_events__init()
303 void ordered_events__free(struct ordered_events *oe) in ordered_events__free() argument
305 while (!list_empty(&oe->to_free)) { in ordered_events__free()
308 event = list_entry(oe->to_free.next, struct ordered_event, list); in ordered_events__free()
310 free_dup_event(oe, event->event); in ordered_events__free()
315 void ordered_events__reinit(struct ordered_events *oe) in ordered_events__reinit() argument
317 ordered_events__deliver_t old_deliver = oe->deliver; in ordered_events__reinit()
319 ordered_events__free(oe); in ordered_events__reinit()
320 memset(oe, '\0', sizeof(*oe)); in ordered_events__reinit()
321 ordered_events__init(oe, old_deliver); in ordered_events__reinit()