Lines Matching full:gp

202 static int perf_tracepoint_open(struct gpu_perf *gp, int tp_id,  in perf_tracepoint_open()  argument
222 n = gp->nr_cpus * (gp->nr_events+1); in perf_tracepoint_open()
223 fd = realloc(gp->fd, n*sizeof(int)); in perf_tracepoint_open()
224 sample = realloc(gp->sample, n*sizeof(*gp->sample)); in perf_tracepoint_open()
227 gp->fd = fd; in perf_tracepoint_open()
228 gp->sample = sample; in perf_tracepoint_open()
230 fd += gp->nr_events * gp->nr_cpus; in perf_tracepoint_open()
231 sample += gp->nr_events * gp->nr_cpus; in perf_tracepoint_open()
232 for (n = 0; n < gp->nr_cpus; n++) { in perf_tracepoint_open()
246 gp->nr_events++; in perf_tracepoint_open()
250 static int perf_mmap(struct gpu_perf *gp) in perf_mmap() argument
252 int size = (1 + N_PAGES) * gp->page_size; in perf_mmap()
255 gp->map = malloc(sizeof(void *)*gp->nr_cpus); in perf_mmap()
256 if (gp->map == NULL) in perf_mmap()
259 fd = gp->fd; in perf_mmap()
260 for (j = 0; j < gp->nr_cpus; j++) { in perf_mmap()
261 gp->map[j] = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, *fd++, 0); in perf_mmap()
262 if (gp->map[j] == (void *)-1) in perf_mmap()
266 for (i = 1; i < gp->nr_events; i++) { in perf_mmap()
267 for (j = 0; j < gp->nr_cpus; j++) in perf_mmap()
268 ioctl(*fd++, PERF_EVENT_IOC_SET_OUTPUT, gp->fd[j]); in perf_mmap()
275 munmap(gp->map[j], size); in perf_mmap()
276 free(gp->map); in perf_mmap()
277 gp->map = NULL; in perf_mmap()
302 lookup_comm(struct gpu_perf *gp, pid_t pid) in lookup_comm() argument
309 for (comm = gp->comm; comm != NULL; comm = comm->next) { in lookup_comm()
324 comm->next = gp->comm; in lookup_comm()
325 gp->comm = comm; in lookup_comm()
331 static int request_add(struct gpu_perf *gp, const void *event) in request_add() argument
336 comm = lookup_comm(gp, sample->pid); in request_add()
344 static int flip_complete(struct gpu_perf *gp, const void *event) in flip_complete() argument
348 gp->flip_complete[READ_TP_FIELD_U32(sample, TP_FLIP_COMPLETE, plane)]++; in flip_complete()
352 static int ctx_switch(struct gpu_perf *gp, const void *event) in ctx_switch() argument
356 gp->ctx_switch[GET_RING_ID(sample, TP_GEM_RING_SWITCH_CONTEXT)]++; in ctx_switch()
360 static int ring_sync(struct gpu_perf *gp, const void *event) in ring_sync() argument
365 comm = lookup_comm(gp, sample->pid); in ring_sync()
373 static int wait_begin(struct gpu_perf *gp, const void *event) in wait_begin() argument
379 comm = lookup_comm(gp, sample->pid); in wait_begin()
394 wait->next = gp->wait[GET_RING_ID(sample, TP_GEM_REQUEST_WAIT_BEGIN)]; in wait_begin()
395 gp->wait[GET_RING_ID(sample, TP_GEM_REQUEST_WAIT_BEGIN)] = wait; in wait_begin()
400 static int wait_end(struct gpu_perf *gp, const void *event) in wait_end() argument
408 for (prev = &gp->wait[engine]; (wait = *prev) != NULL; prev = &wait->next) { in wait_end()
423 void gpu_perf_init(struct gpu_perf *gp, unsigned flags) in gpu_perf_init() argument
425 memset(gp, 0, sizeof(*gp)); in gpu_perf_init()
426 gp->nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); in gpu_perf_init()
427 gp->page_size = getpagesize(); in gpu_perf_init()
429 perf_tracepoint_open(gp, TP_GEM_REQUEST_ADD, request_add); in gpu_perf_init()
430 if (perf_tracepoint_open(gp, TP_GEM_REQUEST_WAIT_BEGIN, wait_begin) == 0) in gpu_perf_init()
431 perf_tracepoint_open(gp, TP_GEM_REQUEST_WAIT_END, wait_end); in gpu_perf_init()
432 perf_tracepoint_open(gp, TP_FLIP_COMPLETE, flip_complete); in gpu_perf_init()
433 perf_tracepoint_open(gp, TP_GEM_RING_SYNC_TO, ring_sync); in gpu_perf_init()
434 perf_tracepoint_open(gp, TP_GEM_RING_SWITCH_CONTEXT, ctx_switch); in gpu_perf_init()
436 if (gp->nr_events == 0) { in gpu_perf_init()
437 gp->error = "i915.ko tracepoints not available"; in gpu_perf_init()
441 if (perf_mmap(gp)) in gpu_perf_init()
445 static int process_sample(struct gpu_perf *gp, int cpu, in process_sample() argument
452 for (n = 0; n < gp->nr_events; n++) { in process_sample()
453 int m = n * gp->nr_cpus + cpu; in process_sample()
454 if (gp->sample[m].id != sample->id) in process_sample()
457 update = gp->sample[m].func(gp, sample); in process_sample()
464 int gpu_perf_update(struct gpu_perf *gp) in gpu_perf_update() argument
466 const int size = N_PAGES * gp->page_size; in gpu_perf_update()
472 if (gp->map == NULL) in gpu_perf_update()
475 for (n = 0; n < gp->nr_cpus; n++) { in gpu_perf_update()
476 struct perf_event_mmap_page *mmap = gp->map[n]; in gpu_perf_update()
492 data = (uint8_t *)mmap + gp->page_size; in gpu_perf_update()
522 update += process_sample(gp, n, header); in gpu_perf_update()