On 16 December 2014 at 12:21, Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> wrote: > Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> > --- > tests/.gitignore | 1 + > tests/Makefile.am | 2 + > tests/Makefile.sources | 1 + > tests/gem_ctx_thrash.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 156 insertions(+) > create mode 100644 tests/gem_ctx_thrash.c > > diff --git a/tests/.gitignore b/tests/.gitignore > index 38f6f96..88a6405 100644 > --- a/tests/.gitignore > +++ b/tests/.gitignore > @@ -29,6 +29,7 @@ gem_ctx_bad_exec > gem_ctx_basic > gem_ctx_create > gem_ctx_exec > +gem_ctx_thrash > gem_double_irq_loop > gem_dummy_reloc_loop > gem_evict_alignment > diff --git a/tests/Makefile.am b/tests/Makefile.am > index 78cbe04..ec2bd30 100644 > --- a/tests/Makefile.am > +++ b/tests/Makefile.am > @@ -50,6 +50,8 @@ gem_close_race_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) > gem_close_race_LDADD = $(LDADD) -lpthread > gem_ctx_basic_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) > gem_ctx_basic_LDADD = $(LDADD) -lpthread > +gem_ctx_thrash_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) > +gem_ctx_thrash_LDADD = $(LDADD) -lpthread > gem_fence_thrash_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) > gem_fence_thrash_LDADD = $(LDADD) -lpthread > gem_fence_upload_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) > diff --git a/tests/Makefile.sources b/tests/Makefile.sources > index da9e742..74deec3 100644 > --- a/tests/Makefile.sources > +++ b/tests/Makefile.sources > @@ -101,6 +101,7 @@ TESTS_progs = \ > gem_ctx_bad_destroy \ > gem_ctx_basic \ > gem_ctx_create \ > + gem_ctx_thrash \ > gem_double_irq_loop \ > gem_exec_big \ > gem_exec_blt \ > diff --git a/tests/gem_ctx_thrash.c b/tests/gem_ctx_thrash.c > new file mode 100644 > index 0000000..8242f47 > --- /dev/null > +++ b/tests/gem_ctx_thrash.c > @@ -0,0 +1,152 @@ > +/* > + * Copyright © 2014 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. > + * > + */ > + > +#include <stdio.h> > +#include <string.h> > +#include <errno.h> > +#include <pthread.h> > + > +#include "ioctl_wrappers.h" > +#include "igt_aux.h" > +#include "intel_chipset.h" > +#include "drmtest.h" Could you add a small description of the test, ideally with the IGT_TEST_DESCRIPTION macro? > + > +#define WIDTH 512 > +#define HEIGHT 512 > +#define STRIDE (4 * WIDTH) > +#define OBJECT_SIZE (STRIDE * HEIGHT) > +#define NUM_THREADS 8 > + > +static int fd; > +static unsigned devid; > +static igt_render_copyfunc_t render_copy; > + > +static dri_bo **all_bo; > +static int num_bo; > +static int bo_per_ctx; > + > +static drm_intel_context **all_ctx; > +static int num_ctx; > +static int ctx_per_thread; > + > +static void xchg_ptr(void *array, unsigned i, unsigned j) > +{ > + void **A = array; > + swap(A[i], A[j]); > +} > + > +static void *thread(void *bufmgr) > +{ > + struct intel_batchbuffer *batch; > + dri_bo **bo; > + drm_intel_context **ctx; > + int c, b; > + > + batch = intel_batchbuffer_alloc(bufmgr, devid); > + > + bo = malloc(num_bo * sizeof(dri_bo *)); > + igt_assert(bo); > + memcpy(bo, all_bo, num_bo * sizeof(dri_bo *)); > + igt_permute_array(bo, num_bo, xchg_ptr); > + > + ctx = malloc(num_ctx * sizeof(drm_intel_context *)); > + igt_assert(ctx); > + memcpy(ctx, all_ctx, num_ctx * sizeof(drm_intel_context *)); > + igt_permute_array(ctx, num_ctx, xchg_ptr); > + > + for (c = 0; c < ctx_per_thread; c++) { > + for (b = 0; b < bo_per_ctx; b++) { > + struct igt_buf src, dst; > + > + src.bo = bo[b % num_bo]; > + src.stride = STRIDE; > + src.size = OBJECT_SIZE; > + src.tiling = I915_TILING_X; > + > + dst.bo = bo[(b+1) % num_bo]; > + dst.stride = STRIDE; > + dst.size = OBJECT_SIZE; > + dst.tiling = I915_TILING_X; > + > + render_copy(batch, ctx[c], > + &src, 0, 0, WIDTH, HEIGHT, > + &dst, WIDTH / 2, HEIGHT / 2); > + } > + } > + > + return NULL; > +} > + > +igt_simple_main > +{ > + pthread_t threads[NUM_THREADS]; > + drm_intel_bufmgr *bufmgr; > + uint64_t aperture; > + int ctx_size; > + int n; > + > + igt_skip_on_simulation(); > + > + fd = drm_open_any_render(); > + devid = intel_get_drm_devid(fd); > + aperture = gem_aperture_size(fd); > + > + render_copy = igt_get_render_copyfunc(devid); > + igt_require_f(render_copy, "no render-copy function\n"); > + > + bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); > + igt_assert(bufmgr); > + > + ctx_size = aperture >> 10; > + num_ctx = 3 * (aperture / ctx_size) / 2; > + igt_info("Creating %d contexts (assuming of size %d)\n", > + num_ctx, ctx_size); > + intel_require_memory(num_ctx, ctx_size, CHECK_RAM | CHECK_SWAP); > + all_ctx = malloc(num_ctx * sizeof(drm_intel_context *)); > + igt_assert(all_ctx); > + for (n = 0; n < num_ctx; n++) { > + all_ctx[n] = drm_intel_gem_context_create(bufmgr); > + igt_assert(all_ctx[n]); > + } > + > + num_bo = 3 * (aperture / OBJECT_SIZE) / 2; > + igt_info("Creating %d surfaces (of size %d)\n", num_bo, OBJECT_SIZE); > + intel_require_memory(num_bo, OBJECT_SIZE, CHECK_RAM); > + all_bo = malloc(num_bo * sizeof(dri_bo *)); > + igt_assert(all_bo); > + > + for (n = 0; n < num_bo; n++) { > + all_bo[n] = drm_intel_bo_alloc(bufmgr, "", OBJECT_SIZE, 0); > + igt_assert(all_bo[n]); > + } > + > + bo_per_ctx = aperture / OBJECT_SIZE / 2; > + ctx_per_thread = 2 * num_ctx / NUM_THREADS; > + > + for (n = 0; n < NUM_THREADS; n++) > + pthread_create(&threads[n], NULL, thread, bufmgr); > + > + for (n = 0; n < NUM_THREADS; n++) > + pthread_join(threads[n], NULL); > +} > -- > 2.1.3 > > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@xxxxxxxxxxxxxxxxxxxxx > http://lists.freedesktop.org/mailman/listinfo/intel-gfx _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/intel-gfx