I am requesting comments on the unit test for the context support I will be adding. Attached is the unit test. I intend to create wrappers for the create and destroy Ioctls in libdrm, unless someone has a better solution to reuse the existing API. For the time being, I plan to use the rsvd1 field in the exec2 structure to store the context.
In summary, you'll see two new Ioctls in this test, and one new DRM API, but once it's cleaned up, it will probably be 3 new Ioctls, and 3 new DRM APIs. Also I realize this test doesn't cover a lot of the bad cases, but that will be included later. Thanks. Ben
/* * Copyright ?? 2010 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 <[email protected]> * */ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <assert.h> #include <fcntl.h> #include <inttypes.h> #include <errno.h> #include <sys/stat.h> #include <sys/ioctl.h> #include "drm.h" #include "i915_drm.h" #include "intel_bufmgr.h" #include "drmtest.h" #define MAX_CONTEXTS 100 static int ctxs[MAX_CONTEXTS]; #define MI_INSTR(opcode, flags) (((opcode) << 23) | (flags)) #define MI_NOOP(id) MI_INSTR(0, (1 << 22) | id) #define MI_BATCH_BUFFER_END MI_INSTR(0xa, 0) static void create_ctxs(const int fd, const int count) { struct drm_i915_gem_ctx_create ctx_create; int ret, i; printf("Testing context creation (%d).\n", count); for (i = 0; i < count; i++) { memset(&ctx_create, 0, sizeof(ctx_create)); ret = ioctl(fd, DRM_IOCTL_I915_GEM_CTX_CREATE, &ctx_create); if (ret != 0) { printf("%d ", i); perror("ctx_create"); ctxs[i] = -1; } else { ctxs[i] = ctx_create.ctx_id; printf("Got back id #%d\n", ctx_create.ctx_id); } } } static int create_and_submit_batches(const int fd, const int count) { drm_intel_bufmgr *bufmgr; drm_intel_bo *bo; uint32_t *data; int ret, i = 1; /* Create the bufmgr */ bufmgr = drm_intel_bufmgr_gem_init(fd, 16 * 4096); drm_intel_bufmgr_set_debug(bufmgr, 1); /* Allocate a BO */ bo = drm_intel_bo_alloc(bufmgr, "test", 4 * 1024, 4); assert(bo != NULL); for (i = 0; i < count; i++) { /* Put the commands in the batch buffer */ ret = drm_intel_bo_map(bo, 1); assert(ret == 0); data = (uint32_t *)bo->virtual; *data++ = MI_NOOP(i); *data = MI_BATCH_BUFFER_END; ret = drm_intel_bo_unmap(bo); assert(ret == 0); /* Execute the batch buffer */ ret = drm_intel_bo_mrb_exec_ctx(bo, 8, NULL, 0, 0, I915_EXEC_DEFAULT, ctxs[i]); if (ret != 0) { perror("drm_intel_bo_mrb_exec"); return i; } /* Wait for completion */ drm_intel_bo_wait_rendering(bo); } return count; } static void destroy_ctxs(const int fd, const int count) { int ret, i; struct drm_i915_gem_ctx_destroy destroy; printf("Testing context destruction (%d)\n", count); for (i = 0; i < count; i++) { memset(&destroy, 0, sizeof(destroy)); if (ctxs[i] == -1) continue; destroy.ctx_id = ctxs[i]; ret = ioctl(fd, DRM_IOCTL_I915_GEM_CTX_DESTROY, &destroy); if (ret != 0) { printf("%d ", i); perror("destroy"); } else { printf("destroyed context %d\n", ctxs[i]); } } } int main(int argc, char *argv[]) { int fd, count, ret; if (argc != 2) { printf("usage: %s <number of contexts>\n", argv[0]); exit(-1); } fd = drm_open_any(); count = strtol(argv[1], NULL, 0); memset(ctxs, 0, sizeof(*ctxs)); create_ctxs(fd, count); ret = create_and_submit_batches(fd, count); destroy_ctxs(fd, count); assert(ret == count); close(fd); return 0; }
_______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
