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 (event && 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()
156 int ordered_events__queue(struct ordered_events *oe, union perf_event *event, in ordered_events__queue() argument
165 if (timestamp < oe->last_flush) { in ordered_events__queue()
167 pr_oe_time(oe->last_flush, "last flush, last_flush_type %d\n", in ordered_events__queue()
168 oe->last_flush_type); in ordered_events__queue()
170 oe->nr_unordered_events++; in ordered_events__queue()
173 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
175 ordered_events__flush(oe, OE_FLUSH__HALF); in ordered_events__queue()
176 oevent = ordered_events__new_event(oe, timestamp, event); in ordered_events__queue()
186 static int __ordered_events__flush(struct ordered_events *oe) in __ordered_events__flush() argument
188 struct list_head *head = &oe->events; in __ordered_events__flush()
190 u64 limit = oe->next_flush; in __ordered_events__flush()
191 u64 last_ts = oe->last ? oe->last->timestamp : 0ULL; in __ordered_events__flush()
200 ui_progress__init(&prog, oe->nr_events, "Processing time ordered events..."); in __ordered_events__flush()
208 ret = oe->deliver(oe, iter); in __ordered_events__flush()
212 ordered_events__delete(oe, iter); in __ordered_events__flush()
213 oe->last_flush = iter->timestamp; in __ordered_events__flush()
220 oe->last = NULL; in __ordered_events__flush()
222 oe->last = list_entry(head->prev, struct ordered_event, list); in __ordered_events__flush()
230 int ordered_events__flush(struct ordered_events *oe, enum oe_flush how) in ordered_events__flush() argument
240 if (oe->nr_events == 0) in ordered_events__flush()
245 oe->next_flush = ULLONG_MAX; in ordered_events__flush()
251 struct list_head *head = &oe->events; in ordered_events__flush()
254 last = oe->last; in ordered_events__flush()
260 oe->next_flush = first->timestamp; in ordered_events__flush()
261 oe->next_flush += (last->timestamp - first->timestamp) / 2; in ordered_events__flush()
271 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush PRE %s, nr_events %u\n", in ordered_events__flush()
272 str[how], oe->nr_events); in ordered_events__flush()
273 pr_oe_time(oe->max_timestamp, "max_timestamp\n"); in ordered_events__flush()
275 err = __ordered_events__flush(oe); in ordered_events__flush()
279 oe->next_flush = oe->max_timestamp; in ordered_events__flush()
281 oe->last_flush_type = how; in ordered_events__flush()
284 pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush POST %s, nr_events %u\n", in ordered_events__flush()
285 str[how], oe->nr_events); in ordered_events__flush()
286 pr_oe_time(oe->last_flush, "last_flush\n"); in ordered_events__flush()
291 void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver) in ordered_events__init() argument
293 INIT_LIST_HEAD(&oe->events); in ordered_events__init()
294 INIT_LIST_HEAD(&oe->cache); in ordered_events__init()
295 INIT_LIST_HEAD(&oe->to_free); in ordered_events__init()
296 oe->max_alloc_size = (u64) -1; in ordered_events__init()
297 oe->cur_alloc_size = 0; in ordered_events__init()
298 oe->deliver = deliver; in ordered_events__init()
301 void ordered_events__free(struct ordered_events *oe) in ordered_events__free() argument
303 while (!list_empty(&oe->to_free)) { in ordered_events__free()
306 event = list_entry(oe->to_free.next, struct ordered_event, list); in ordered_events__free()
308 free_dup_event(oe, event->event); in ordered_events__free()
313 void ordered_events__reinit(struct ordered_events *oe) in ordered_events__reinit() argument
315 ordered_events__deliver_t old_deliver = oe->deliver; in ordered_events__reinit()
317 ordered_events__free(oe); in ordered_events__reinit()
318 memset(oe, '\0', sizeof(*oe)); in ordered_events__reinit()
319 ordered_events__init(oe, old_deliver); in ordered_events__reinit()