Lines Matching refs:oe

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