summaryrefslogtreecommitdiff
path: root/overlay/gpu-perf.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-08-17 22:07:49 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-08-17 22:07:49 +0100
commite1d8d774f331ba4e515cad4e5efa91ddc18efad6 (patch)
tree8ea5b9b53738085aeff6caa0ddb7a75f43661aed /overlay/gpu-perf.c
parenteed59eac47bae095513a5b1b6286fdd556d8a760 (diff)
overlay: Perf output redirection must be done after mmap()
Effectively you choose to redirect the output of an event instead of mmapping it directly - but the target must already be mmapped. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'overlay/gpu-perf.c')
-rw-r--r--overlay/gpu-perf.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/overlay/gpu-perf.c b/overlay/gpu-perf.c
index 78d1756c..ef170909 100644
--- a/overlay/gpu-perf.c
+++ b/overlay/gpu-perf.c
@@ -113,12 +113,10 @@ static int perf_tracepoint_open(struct gpu_perf *gp,
return errno;
/* read back the event to establish id->tracepoint */
- read(fd[n], track, sizeof(track));
+ if (read(fd[n], track, sizeof(track)) < 0)
+ return errno;
sample[n].id = track[1];
sample[n].func = func;
-
- if (gp->nr_events)
- ioctl(fd[n], PERF_EVENT_IOC_SET_OUTPUT, gp->fd[n]);
}
gp->nr_events++;
@@ -128,23 +126,29 @@ static int perf_tracepoint_open(struct gpu_perf *gp,
static int perf_mmap(struct gpu_perf *gp)
{
int size = (1 + N_PAGES) * gp->page_size;
- int n;
+ int *fd, i, j;
gp->map = malloc(sizeof(void *)*gp->nr_cpus);
if (gp->map == NULL)
return ENOMEM;
- for (n = 0; n < gp->nr_cpus; n++) {
- gp->map[n] = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, gp->fd[n], 0);
- if (gp->map[n] == (void *)-1)
+ fd = gp->fd;
+ for (j = 0; j < gp->nr_cpus; j++) {
+ gp->map[j] = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, *fd++, 0);
+ if (gp->map[j] == (void *)-1)
goto err;
}
+ for (i = 1; i < gp->nr_events; i++) {
+ for (j = 0; j < gp->nr_cpus; j++)
+ ioctl(*fd++, PERF_EVENT_IOC_SET_OUTPUT, gp->fd[j]);
+ }
+
return 0;
err:
- while (--n > 0)
- munmap(gp->map[n], size);
+ while (--j > 0)
+ munmap(gp->map[j], size);
free(gp->map);
gp->map = NULL;
return EINVAL;
@@ -207,7 +211,6 @@ static int request_add(struct gpu_perf *gp, const void *event)
static int seqno_start(struct gpu_perf *gp, const void *event)
{
- printf ("seqno_start\n");
return 0;
}