From 29ea26e871b3132794281ae7b7460006d5952f15 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Wed, 3 Nov 2021 11:08:29 +0100 Subject: [PATCH] Emit flush events in order, after the user event Fixes the backwards jump in time warnings each 2 MB of buffer, caused by the flush events being written out of order. --- ovni.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/ovni.c b/ovni.c index afb7c04..6e34990 100644 --- a/ovni.c +++ b/ovni.c @@ -498,10 +498,28 @@ ovni_flush(void) return ret; } +static void +add_flush_events(uint64_t t0, uint64_t t1) +{ + struct ovni_ev pre={0}, post={0}; + + pre.header.clock = t0; + ovni_ev_set_mcv(&pre, "OF["); + + post.header.clock = t1; + ovni_ev_set_mcv(&post, "OF]"); + + /* Add the two flush events */ + ovni_ev_add(&pre); + ovni_ev_add(&post); +} + static void ovni_ev_add_jumbo(struct ovni_ev *ev, uint8_t *buf, uint32_t bufsize) { size_t evsize, totalsize; + int flushed = 0; + uint64_t t0, t1; assert(ovni_payload_size(ev) == 0); @@ -512,7 +530,13 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, uint8_t *buf, uint32_t bufsize) /* Check if the event fits or flush first otherwise */ if(rthread.evlen + totalsize >= OVNI_MAX_EV_BUF) - ovni_flush(); + { + /* Measure the flush times */ + t0 = ovni_get_clock(); + flush_evbuf(); + t1 = ovni_get_clock(); + flushed = 1; + } /* Se the jumbo flag here, so we capture the previous evsize * properly, ignoring the jumbo buffer */ @@ -524,22 +548,46 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, uint8_t *buf, uint32_t bufsize) rthread.evlen += bufsize; assert(rthread.evlen < OVNI_MAX_EV_BUF); -} + if(flushed) + { + /* Emit the flush events *after* the user event */ + add_flush_events(t0, t1); + + /* Set the current clock to the last event */ + rthread.clockvalue = t1; + } +} static void ovni_ev_add(struct ovni_ev *ev) { - int size; + int size, flushed = 0; + uint64_t t0, t1; size = ovni_ev_size(ev); /* Check if the event fits or flush first otherwise */ if(rthread.evlen + size >= OVNI_MAX_EV_BUF) - ovni_flush(); + { + /* Measure the flush times */ + t0 = ovni_get_clock(); + flush_evbuf(); + t1 = ovni_get_clock(); + flushed = 1; + } memcpy(&rthread.evbuf[rthread.evlen], ev, size); rthread.evlen += size; + + if(flushed) + { + /* Emit the flush events *after* the user event */ + add_flush_events(t0, t1); + + /* Set the current clock to the last event */ + rthread.clockvalue = t1; + } } void