diff options
author | Jerome Glisse <jglisse@redhat.com> | 2010-04-23 20:09:12 +0200 |
---|---|---|
committer | Jerome Glisse <jglisse@redhat.com> | 2010-04-23 20:09:12 +0200 |
commit | 17150fac6c9ea4b9bb22893211cd900bc2601d74 (patch) | |
tree | 4fdc757efe5ef7dd05fbccb87e40ee8f401713de | |
parent | be0747685c8be6b7557d63b7505d8ce0333f6132 (diff) |
radeondb: add benchmark helper
allow to benchmark how much time it takes the GPU
to execute a CS.
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
-rw-r--r-- | src/radeon_ctx.c | 2 | ||||
-rw-r--r-- | src/radeondb.c | 117 |
2 files changed, 97 insertions, 22 deletions
diff --git a/src/radeon_ctx.c b/src/radeon_ctx.c index 2df0645..09a5eca 100644 --- a/src/radeon_ctx.c +++ b/src/radeon_ctx.c @@ -232,8 +232,8 @@ int radeon_ctx_submit(struct radeon_ctx *ctx) uint64_t chunk_array[2]; int r = 0; - fprintf(stderr, "[0x%04X %d %d]\n", ctx->radeon->device, ctx->cpm4, ctx->nreloc); #if 0 + fprintf(stderr, "[0x%04X %d %d]\n", ctx->radeon->device, ctx->cpm4, ctx->nreloc); for (r = 0; r < ctx->cpm4; r++) { fprintf(stderr, "0x%08X\n", ctx->pm4[r]); } diff --git a/src/radeondb.c b/src/radeondb.c index 3e2b6e1..427b529 100644 --- a/src/radeondb.c +++ b/src/radeondb.c @@ -27,6 +27,8 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <time.h> +#include <sys/timeb.h> #include <getopt.h> #include <jansson.h> #include "radeon_priv.h" @@ -41,11 +43,25 @@ void usage(void) } static int conv(const char *file); -static int json(const char *file); -static int play(const char *file); +static int json(const char *file, int bench); +static int play(const char *file, int bench); static int dump(const char *file); void radeon_register_dump(const char *bname); +struct param { + char file_json[256]; + char file_play[256]; + char file_conv[256]; + char file_dump[256]; + char block[256]; + int bench; + int json; + int play; + int conv; + int dump; + int reg; +}; + int main(int argc, char *argv[]) { static struct option options[] = { @@ -57,24 +73,38 @@ int main(int argc, char *argv[]) {0, 0, 0, 0} }; int option_id; + struct param p; int c; + memset(&p, 0, sizeof(struct param)); while (1) { - c = getopt_long(argc, argv, "p:d:j:c:r:", options, &option_id); + c = getopt_long(argc, argv, "p:d:j:c:r:b", options, &option_id); if (c == -1) break; switch (c) { case 'd': - return dump(optarg); + strcpy(p.file_dump, optarg); + p.dump = 1; + break; + case 'b': + p.bench = 1; + break; case 'j': - return json(optarg); + strcpy(p.file_json, optarg); + p.json = 1; + break; case 'c': - return conv(optarg); + strcpy(p.file_conv, optarg); + p.conv = 1; + break; case 'p': - return play(optarg); + strcpy(p.file_play, optarg); + p.play = 1; + break; case 'r': - radeon_register_dump(optarg); - return 0; + strcpy(p.block, optarg); + p.reg = 1; + break; case '?': /* getopt_long already printed an error message. */ break; @@ -82,16 +112,38 @@ int main(int argc, char *argv[]) abort (); } } + if (p.reg) { + radeon_register_dump(p.block); + } + if (p.play) { + return play(p.file_play, p.bench); + } + if (p.dump) { + return dump(p.file_dump); + } + if (p.json) { + return json(p.file_json, p.bench); + } + if (p.conv) { + return conv(p.file_conv); + } } -static int play(const char *file) +static int play(const char *file, int bench) { struct radeon *radeon; struct radeon_ctx *ctx = NULL; struct radeon_surface dst; struct radeon_surface src; - int r, fd; + struct timeb fstart, fend; + double time_elapsed; + int r, fd, i; + if (bench) { + bench = 10000; + } else { + bench = 1; + } fd = radeon_open_fd(); if (fd < 0) { fprintf(stderr, "failed to open radeon drm device\n"); @@ -103,7 +155,6 @@ static int play(const char *file) return -1; } /* setup framebuffer surface */ -// memset_bo(radeon->mode.bo, 0x000000FF); dst.bo = radeon->mode.bo; dst.width = radeon->mode.pitch / 4; dst.pitch = radeon->mode.pitch / 4; @@ -132,9 +183,19 @@ static int play(const char *file) goto out; } radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height); - getchar(); - r = radeon_ctx_submit(ctx); + printf("%d execution of %d dwords\n", bench, ctx->cpm4); + ftime(&fstart); + for (i = 0; i < bench; i++) { + r = radeon_ctx_submit(ctx); + if (r) + goto out; + } radeon_bo_wait(radeon, src.bo); + ftime(&fend); + time_elapsed = fend.time - fstart.time; + time_elapsed += ((double)(fend.millitm - fstart.millitm)) / 1000; + printf("%d runs in %f seconds\n", bench, time_elapsed); + getchar(); radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height); getchar(); out: @@ -167,14 +228,21 @@ static int dump(const char *file) return 0; } -static int json(const char *file) +static int json(const char *file, int bench) { struct radeon *radeon; struct radeon_ctx *ctx = NULL; struct radeon_surface dst; struct radeon_surface src; - int r, fd; + struct timeb fstart, fend; + double time_elapsed; + int r, fd, i, j; + if (bench) { + bench = 10000; + } else { + bench = 1; + } fd = radeon_open_fd(); if (fd < 0) { fprintf(stderr, "failed to open radeon drm device\n"); @@ -186,7 +254,6 @@ static int json(const char *file) return -1; } /* setup framebuffer surface */ -// memset_bo(radeon->mode.bo, 0x000000FF); dst.bo = radeon->mode.bo; dst.width = radeon->mode.pitch / 4; dst.pitch = radeon->mode.pitch / 4; @@ -215,12 +282,20 @@ static int json(const char *file) goto out; } radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height); - if (radeon_ctx_submit(ctx)) { - fprintf(stderr, "failed to flush\n"); - goto out; + printf("%d execution of %d dwords\n", bench, ctx->cpm4); + ftime(&fstart); + for (i = 0; i < bench; i++) { + if (radeon_ctx_submit(ctx)) { + fprintf(stderr, "failed to flush\n"); + goto out; + } } - getchar(); radeon_bo_wait(radeon, src.bo); + ftime(&fend); + time_elapsed = fend.time - fstart.time; + time_elapsed += ((double)(fend.millitm - fstart.millitm)) / 1000; + printf("%d runs in %f seconds\n", bench, time_elapsed); + getchar(); radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height); getchar(); out: |