From 6233cac9c9f264961c62bb1330d8f48b3b6922b5 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 17 Aug 2013 22:22:21 +0100 Subject: overlay: Couple wait begin/end events together to fix accounting Since the events may be processed out of order (due to per-cpu ringbuffers) we need to be careful to associated wait pairs in order to compute the correct elapsed time. Signed-off-by: Chris Wilson --- overlay/gpu-perf.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'overlay/gpu-perf.c') diff --git a/overlay/gpu-perf.c b/overlay/gpu-perf.c index ef170909..653148b8 100644 --- a/overlay/gpu-perf.c +++ b/overlay/gpu-perf.c @@ -229,12 +229,21 @@ static int wait_begin(struct gpu_perf *gp, const void *event) { const struct sample_event *sample = event; struct gpu_perf_comm *comm; + struct gpu_perf_wait *wait; comm = lookup_comm(gp, sample->pid); if (comm == NULL) return 0; - comm->wait_begin = sample->time; + wait = malloc(sizeof(*wait)); + if (wait == NULL) + return 0; + + wait->seqno = sample->raw[3]; + wait->time = sample->time; + wait->next = comm->wait; + comm->wait = wait; + return 0; } @@ -242,12 +251,22 @@ static int wait_end(struct gpu_perf *gp, const void *event) { const struct sample_event *sample = event; struct gpu_perf_comm *comm; + struct gpu_perf_wait *wait, **prev; comm = lookup_comm(gp, sample->pid); if (comm == NULL) return 0; - comm->wait_time += sample->time - comm->wait_begin; + for (prev = &comm->wait; (wait = *prev) != NULL; prev = &wait->next) { + if (wait->seqno != sample->raw[3]) + continue; + + comm->wait_time += sample->time - wait->time; + *prev = wait->next; + free(wait); + return 1; + } + return 0; } -- cgit v1.2.3