Remove ovni_clock_update()

The clock is now managed by the user, using the ovni_clock_now()
function to sample the current value and ovni_ev_set_clock() to set the
event clock timestamp. This change allows events with custom clock
values.
This commit is contained in:
Rodrigo Arias 2021-11-16 14:35:39 +01:00 committed by Kevin Sala
parent 88d79aec8e
commit d79b887182
4 changed files with 20 additions and 38 deletions

39
ovni.c
View File

@ -313,7 +313,7 @@ uint64_t rdtsc(void)
#endif
uint64_t
ovni_get_clock(void)
ovni_clock_now(void)
{
struct timespec tp;
uint64_t ns = 1000LL * 1000LL * 1000LL;
@ -331,21 +331,12 @@ ovni_get_clock(void)
#endif /* ENABLE_SLOW_CHECKS */
raw = tp.tv_sec * ns + tp.tv_nsec;
rthread.clockvalue = (uint64_t) raw;
#endif /* USE_RDTSC */
return raw;
}
/* Sets the current time so that all subsequent events have the new
* timestamp */
void
ovni_clock_update(void)
{
rthread.clockvalue = ovni_get_clock();
}
//static void
//hexdump(uint8_t *buf, size_t size)
//{
@ -400,10 +391,10 @@ flush_evbuf(void)
return ret;
}
static void
ovni_ev_set_clock(struct ovni_ev *ev)
void
ovni_ev_set_clock(struct ovni_ev *ev, uint64_t clock)
{
ev->header.clock = rthread.clockvalue;
ev->header.clock = clock;
}
uint64_t
@ -483,14 +474,12 @@ ovni_flush(void)
assert(rthread.ready);
assert(rproc.ready);
ovni_clock_update();
ovni_ev_set_clock(&pre);
ovni_ev_set_clock(&pre, ovni_clock_now());
ovni_ev_set_mcv(&pre, "OF[");
ret = flush_evbuf();
ovni_clock_update();
ovni_ev_set_clock(&post);
ovni_ev_set_clock(&post, ovni_clock_now());
ovni_ev_set_mcv(&post, "OF]");
/* Add the two flush events */
@ -534,9 +523,9 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize)
if(rthread.evlen + totalsize >= OVNI_MAX_EV_BUF)
{
/* Measure the flush times */
t0 = ovni_get_clock();
t0 = ovni_clock_now();
flush_evbuf();
t1 = ovni_get_clock();
t1 = ovni_clock_now();
flushed = 1;
}
@ -555,9 +544,6 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize)
{
/* Emit the flush events *after* the user event */
add_flush_events(t0, t1);
/* Set the current clock to the last event */
rthread.clockvalue = t1;
}
}
@ -573,9 +559,9 @@ ovni_ev_add(struct ovni_ev *ev)
if(rthread.evlen + size >= OVNI_MAX_EV_BUF)
{
/* Measure the flush times */
t0 = ovni_get_clock();
t0 = ovni_clock_now();
flush_evbuf();
t1 = ovni_get_clock();
t1 = ovni_clock_now();
flushed = 1;
}
@ -586,22 +572,17 @@ ovni_ev_add(struct ovni_ev *ev)
{
/* 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
ovni_ev_jumbo_emit(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize)
{
ovni_ev_set_clock(ev);
ovni_ev_add_jumbo(ev, buf, bufsize);
}
void
ovni_ev_emit(struct ovni_ev *ev)
{
ovni_ev_set_clock(ev);
ovni_ev_add(ev);
}

15
ovni.h
View File

@ -101,9 +101,6 @@ struct ovni_rthread {
/* Current thread id */
pid_t tid;
/* Clock value of the events being emitted */
uint64_t clockvalue;
/* Stream trace file descriptor */
int streamfd;
@ -143,13 +140,16 @@ void ovni_thread_free(void);
int ovni_thread_isready(void);
void ovni_clock_update(void);
void ovni_ev_set_mcv(struct ovni_ev *ev, const char *mcv);
/* Gets the event clock in ns */
uint64_t ovni_ev_get_clock(const struct ovni_ev *ev);
uint64_t ovni_get_clock(void);
/* Sets the event clock in ns */
void ovni_ev_set_clock(struct ovni_ev *ev, uint64_t clock);
/* Returns the current value of the ovni clock in ns */
uint64_t ovni_clock_now(void);
void ovni_payload_add(struct ovni_ev *ev, const uint8_t *buf, int size);
@ -159,7 +159,8 @@ int ovni_payload_size(const struct ovni_ev *ev);
void ovni_add_cpu(int index, int phyid);
/* Set the current clock in the event and queue it */
/* Adds the event to the events buffer. The buffer is flushed first if the event
* doesn't fit in the buffer. */
void ovni_ev_emit(struct ovni_ev *ev);
void ovni_ev_jumbo_emit(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize);

View File

@ -56,8 +56,8 @@ init(void)
static void emit(uint8_t *buf, size_t size)
{
struct ovni_ev ev = {0};
ovni_clock_update();
ovni_ev_set_mcv(&ev, "O$$");
ovni_ev_set_clock(&ev, ovni_clock_now());
ovni_ev_jumbo_emit(&ev, buf, size);
}

View File

@ -65,7 +65,7 @@ int main(int argc, char *argv[])
for(i=0; i<n; i++)
{
ovni_clock_update();
ovni_ev_set_clock(&ev, ovni_clock_now());
ovni_ev_emit(&ev);
}