This test probably won't get pushed. It's a very synthetic test to help me benchmark
Signed-off-by: Ben Widawsky <b...@bwidawsk.net> --- tests/Makefile.am | 1 + tests/gem_wo_map.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/test.sh | 10 ++ 3 files changed, 322 insertions(+), 0 deletions(-) create mode 100644 tests/gem_wo_map.c create mode 100755 tests/test.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index 80a9c94..65cf128 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -44,6 +44,7 @@ TESTS = getversion \ gen3_mixed_blits \ gem_storedw_loop \ gem_storedw_batches_loop \ + gem_wo_map \ $(NULL) HANG = \ diff --git a/tests/gem_wo_map.c b/tests/gem_wo_map.c new file mode 100644 index 0000000..5c18e20 --- /dev/null +++ b/tests/gem_wo_map.c @@ -0,0 +1,311 @@ +/* + * Copyright © 2011 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Ben Widawsky <b...@bwidawsk.net> + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> +#include <assert.h> +#include <fcntl.h> +#include <inttypes.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <pthread.h> +#include "drm.h" +#include "i915_drm.h" +#include "drmtest.h" +#include "intel_bufmgr.h" +#include "intel_batchbuffer.h" +#include "intel_gpu_tools.h" + +static drm_intel_bufmgr *bufmgr; +struct intel_batchbuffer *batch; +drm_intel_bo *src, *dst; +int fd; +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +int num_writes = 1; + +#define NUM_MAPS 128 * 1024 +#define NUM_BLITS 128 * 1024 +#define SURFACE_SIZE (1<<20) +#define SURFACE_PAGEES (SURFACE_SIZE >> 12) +#define SURFACE_PAGES (SURFACE_SIZE >> 12) + +bool thread_ret; + +/* acts like a gpu memcpy */ +static void +blit(void) +{ + uint32_t pitch = 4096; + uint32_t lines = SURFACE_SIZE / pitch; + uint32_t line_width = pitch; + + BEGIN_BATCH(8); + OUT_BATCH((2<<29) | (0x43<<22) | (0x3<<20) | 4); + OUT_BATCH((0x3<<24) | (0xcc<<16) | pitch); + OUT_BATCH((lines<<16) | line_width); + OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); + OUT_BATCH(pitch); + OUT_RELOC(src, I915_GEM_DOMAIN_RENDER, 0, 0); + ADVANCE_BATCH(); + + intel_batchbuffer_flush(batch); +} + +static inline int +get_offset(void) +{ + return (rand() % SURFACE_PAGES) * 4096; +} + +static void +touch_page(char * const base) +{ + int i = 0; + for(i = 0; i < num_writes; i++) { + base[get_offset()] = 1; + } +} + +static void * +blits(void *arg) +{ + int i = 0; + for (i = 0; i < NUM_BLITS; i++) { + blit(); + usleep(100); + } + pthread_exit(NULL); +} + +static void * +maps(void *arg) +{ + int i = 0; + for (i = 0; i < NUM_MAPS; i++) { + drm_intel_bo_map(src, 1); + touch_page(src->virtual); + drm_intel_bo_unmap(src); + } + pthread_exit(NULL); +} + +static void * +maps_gtt(void *arg) +{ + int i = 0; + for (i = 0; i < NUM_MAPS; i++) { + drm_intel_gem_bo_map_gtt(src); + touch_page(src->virtual); + drm_intel_bo_unmap(src); + } + pthread_exit(NULL); +} + +static void * +maps_wo(void *arg) +{ + int i = 0; + for (i = 0; i < NUM_MAPS; i++) { + drm_intel_gem_bo_map_wo(src); + touch_page(src->virtual); + drm_intel_bo_unmap(src); + } + + drm_intel_gem_bo_flush_obj(src); + + pthread_exit(NULL); +} + +static void * +maps_gtt_wo(void *arg) +{ + int i = 0; + for (i = 0; i < NUM_MAPS; i++) { + drm_intel_gem_bo_map_gtt_wo(src, 0, 0); + touch_page(src->virtual); + drm_intel_bo_unmap(src); + } + pthread_exit(&thread_ret); +} + +static void * +functional_test_wo(void *arg) +{ + drm_intel_gem_bo_map_wo(src); + touch_page(src->virtual); + ((char *)src->virtual)[1000] = 1; + drm_intel_bo_unmap(src); + blit(); + drm_intel_bo_wait_rendering(batch->bo); + + drm_intel_bo_map(dst, 0); + thread_ret = (((char *)dst->virtual)[1000] == 1); + drm_intel_bo_unmap(dst); + pthread_exit(&thread_ret); +} + +static void * +functional_test_gtt_wo(void *arg) +{ + drm_intel_gem_bo_map_gtt_wo(src, 0, 0); + touch_page(src->virtual); + ((char *)src->virtual)[1000] = 1; + drm_intel_bo_unmap(src); + blit(); + drm_intel_bo_wait_rendering(batch->bo); + + drm_intel_bo_map(dst, 0); + thread_ret = (((char *)dst->virtual)[1000] == 1); + drm_intel_bo_unmap(dst); + pthread_exit(&thread_ret); +} + +static void * +functional_test_gtt(void *arg) +{ + drm_intel_gem_bo_map_gtt(src); + ((char *)src->virtual)[1000] = 1; + drm_intel_bo_unmap(src); + blit(); + drm_intel_bo_wait_rendering(batch->bo); + + drm_intel_bo_map(dst, 0); + thread_ret = (((char *)dst->virtual)[1000] == 1); + drm_intel_bo_unmap(dst); + pthread_exit(&thread_ret); +} + +static void * +functional_test(void *arg) +{ + drm_intel_bo_map(src, 1); + ((char *)src->virtual)[1000] = 1; + drm_intel_bo_unmap(src); + blit(); + drm_intel_bo_wait_rendering(batch->bo); + + drm_intel_bo_map(dst, 0); + thread_ret = (((char *)dst->virtual)[1000] == 1); + drm_intel_bo_unmap(dst); + pthread_exit(&thread_ret); +} + +typedef void * (*thread_function)(void *); + +thread_function ffuncs[2][2] = { + {functional_test, functional_test_gtt}, + {functional_test_wo, functional_test_gtt_wo} +}; + +thread_function sfuncs[2][2] = { + {maps, maps_gtt}, + {maps_wo, maps_gtt_wo} +}; + +static void usage(const char *name) +{ + fprintf(stderr, "Usage: %s -[s|f] [-w write only] [-g gtt]\n", name); +} + +int main(int argc, char **argv) +{ + pthread_t blit_thread; + pthread_t map_thread; + int test = 0; + int write_only = 0; + int gtt = 0; + char opt; + bool ret[1]; + + while ((opt = getopt(argc, argv, "sfwgc:")) != -1) { + switch(opt) { + case 'c': + num_writes = atoi(optarg); + break; + case 's': + test = 1; + break; + case 'f': + test = 2; + break; + case 'w': + write_only = 1; + break; + case 'g': + gtt = 1; + break; + case 'h': + case '?': + default: + usage(argv[0]); + exit(EXIT_FAILURE); + } + } + + srandom(0xdeadbeef); + fd = drm_open_any(); + + bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); + drm_intel_bufmgr_gem_enable_reuse(bufmgr); + batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); + + src = drm_intel_bo_alloc(bufmgr, "src", SURFACE_SIZE, 4096); + dst = drm_intel_bo_alloc(bufmgr, "dst", SURFACE_SIZE, 4096); + + switch (test) { + case 0: + usage(argv[0]); + exit(EXIT_FAILURE); + break; + case 2: + pthread_create(&map_thread, NULL, ffuncs[gtt][write_only], NULL); + pthread_join(map_thread, (void **)&ret); + assert(*ret == true); + break; + default: + pthread_create(&blit_thread, NULL, blits, NULL); + pthread_create(&map_thread, NULL, sfuncs[gtt][write_only], NULL); + pthread_join(map_thread, NULL); + /* We don't want to time blit performance for this benchmark, + * though it is relevant. + */ + pthread_join(blit_thread, NULL); + break; + } + + intel_batchbuffer_free(batch); + drm_intel_bufmgr_destroy(bufmgr); + + close(fd); + + return 0; +} diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..8a03249 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +echo "Map" +time ./gem_wo_map -s -c 50 +echo "Map GTT" +time ./gem_wo_map -sg -c 50 +echo "Map WO" +time ./gem_wo_map -sw -c 50 +echo "Map GTT WO" +time ./gem_wo_map -sgw -c 50 -- 1.7.6.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/intel-gfx