From a7b742092700b68d049597d1f25574cac41bb63a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 20 Aug 2013 23:19:45 +0100 Subject: overlay: Fix sampling of i915 perf event Signed-off-by: Chris Wilson --- overlay/gpu-top.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'overlay/gpu-top.c') diff --git a/overlay/gpu-top.c b/overlay/gpu-top.c index e7729779..d613553e 100644 --- a/overlay/gpu-top.c +++ b/overlay/gpu-top.c @@ -72,10 +72,12 @@ static uint64_t i915_type_id(void) int fd, n; fd = open("/sys/bus/event_source/devices/i915/type", 0); - if (fd < 0) - return 0; - n = read(fd, buf, sizeof(buf)-1); - close(fd); + if (fd < 0) { + n = -1; + } else { + n = read(fd, buf, sizeof(buf)-1); + close(fd); + } if (n < 0) return 0; @@ -310,7 +312,7 @@ int gpu_top_update(struct gpu_top *gt) struct gpu_top_stat *s = >->stat[gt->count++&1]; struct gpu_top_stat *d = >->stat[gt->count&1]; uint64_t *sample, d_time; - int n; + int n, m; len = read(gt->fd, data, sizeof(data)); if (len < 0) @@ -319,12 +321,12 @@ int gpu_top_update(struct gpu_top *gt) sample = (uint64_t *)data + 1; s->time = *sample++; - for (n = 0; n < gt->num_rings; n++) { - s->busy[n] = sample[n]; + for (n = m = 0; n < gt->num_rings; n++) { + s->busy[n] = sample[m++]; if (gt->have_wait) - s->wait[n] = sample[n]; + s->wait[n] = sample[m++]; if (gt->have_sema) - s->sema[n] = sample[n]; + s->sema[n] = sample[m++]; } if (gt->count == 1) -- cgit v1.2.3