From 8cdb5bc5e838665bd8aafde3667a55152196e7f4 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 17 Aug 2013 18:24:39 +0100 Subject: [PATCH] overlay: Constify perf ringbuffer Signed-off-by: Chris Wilson --- overlay/gpu-perf.c | 29 ++++++++++++++--------------- overlay/gpu-perf.h | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/overlay/gpu-perf.c b/overlay/gpu-perf.c index 7751132..4a3bc34 100644 --- a/overlay/gpu-perf.c +++ b/overlay/gpu-perf.c @@ -74,7 +74,7 @@ static uint64_t tracepoint_id(const char *sys, const char *name) static int perf_tracepoint_open(struct gpu_perf *gp, const char *sys, const char *name, - int (*func)(struct gpu_perf *, void *)) + int (*func)(struct gpu_perf *, const void *)) { struct perf_event_attr attr; struct gpu_perf_sample *sample; @@ -151,17 +151,17 @@ err: return EINVAL; } -static int seqno_start(struct gpu_perf *gp, void *event) +static int seqno_start(struct gpu_perf *gp, const void *event) { return 0; } -static int seqno_end(struct gpu_perf *gp, void *event) +static int seqno_end(struct gpu_perf *gp, const void *event) { return 0; } -static int flip_complete(struct gpu_perf *gp, void *event) +static int flip_complete(struct gpu_perf *gp, const void *event) { gp->flip_complete++; return 1; @@ -186,9 +186,9 @@ void gpu_perf_init(struct gpu_perf *gp, unsigned flags) } static int process_sample(struct gpu_perf *gp, - struct perf_event_header *header) + const struct perf_event_header *header) { - struct sample_event *sample = (struct sample_event *)header; + const struct sample_event *sample = (const struct sample_event *)header; int n, update = 0; /* hash me! */ @@ -218,7 +218,7 @@ int gpu_perf_update(struct gpu_perf *gp) for (n = 0; n < gp->nr_cpus; n++) { struct perf_event_mmap_page *mmap = gp->map[n]; - uint8_t *data; + const uint8_t *data; uint64_t head, tail; tail = mmap->data_tail; @@ -230,14 +230,14 @@ int gpu_perf_update(struct gpu_perf *gp) data = (uint8_t *)mmap + gp->page_size; while (head - tail >= sizeof (struct perf_event_header)) { - struct perf_event_header *header; + const struct perf_event_header *header; - header = (struct perf_event_header *)(data + (tail & mask)); + header = (const struct perf_event_header *)(data + (tail & mask)); if (header->size > head - tail) break; - if (data + (tail & mask) + header->size > data + size) { - int before, after; + if ((const uint8_t *)header + header->size > data + size) { + int before; if (header->size > buffer_size) { uint8_t *b = realloc(buffer, header->size); @@ -248,11 +248,10 @@ int gpu_perf_update(struct gpu_perf *gp) buffer_size = header->size; } - after = (tail & mask) + header->size - size; - before = header->size - after; + before = data + size - (const uint8_t *)header; - memcpy(buffer, data + (tail & mask), before); - memcpy(buffer + before, data, after); + memcpy(buffer, header, before); + memcpy(buffer + before, data, header->size - before); header = (struct perf_event_header *)buffer; } diff --git a/overlay/gpu-perf.h b/overlay/gpu-perf.h index 58bf306..6a3e00d 100644 --- a/overlay/gpu-perf.h +++ b/overlay/gpu-perf.h @@ -8,7 +8,7 @@ struct gpu_perf { void **map; struct gpu_perf_sample { uint64_t id; - int (*func)(struct gpu_perf *, void *); + int (*func)(struct gpu_perf *, const void *); } *sample; int flip_complete; -- 2.7.4