From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Widawsky Subject: [RFC] drm/i915: context support unit test Date: Sat, 25 Dec 2010 14:53:04 -0800 Message-ID: <20101225225303.GA5311@snipes.kumite> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="fdj2RfSjLxBAspz7" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-iw0-f177.google.com (mail-iw0-f177.google.com [209.85.214.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 4A3E59E748 for ; Sat, 25 Dec 2010 14:53:11 -0800 (PST) Received: by iwn38 with SMTP id 38so8592937iwn.36 for ; Sat, 25 Dec 2010 14:53:10 -0800 (PST) Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org Cc: benjamin.widawsky@linux.intel.com List-Id: intel-gfx@lists.freedesktop.org --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --fdj2RfSjLxBAspz7 Content-Type: text/x-c; charset=unknown-8bit Content-Disposition: attachment; filename="gem_ctx_basic.c" Content-Transfer-Encoding: quoted-printable /* * Copyright =C2=A9 2010 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining = a * copy of this software and associated documentation files (the "Softwar= e"), * to deal in the Software without restriction, including without limitat= ion * the rights to use, copy, modify, merge, publish, distribute, sublicens= e, * 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 n= ext * paragraph) shall be included in all copies or substantial portions of = the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRES= S OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILIT= Y, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHA= LL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR O= THER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISIN= G * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DE= ALINGS * IN THE SOFTWARE. * * Authors: * Ben Widawsky * */ #include #include #include #include #include #include #include #include #include #include #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 =3D 0; i < count; i++) { memset(&ctx_create, 0, sizeof(ctx_create)); ret =3D ioctl(fd, DRM_IOCTL_I915_GEM_CTX_CREATE, &ctx_create); if (ret !=3D 0) { printf("%d ", i); perror("ctx_create"); ctxs[i] =3D -1; } else { ctxs[i] =3D 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 =3D 1; /* Create the bufmgr */ bufmgr =3D drm_intel_bufmgr_gem_init(fd, 16 * 4096); drm_intel_bufmgr_set_debug(bufmgr, 1); /* Allocate a BO */ bo =3D drm_intel_bo_alloc(bufmgr, "test", 4 * 1024, 4); assert(bo !=3D NULL); for (i =3D 0; i < count; i++) { /* Put the commands in the batch buffer */ ret =3D drm_intel_bo_map(bo, 1); assert(ret =3D=3D 0); data =3D (uint32_t *)bo->virtual; *data++ =3D MI_NOOP(i); *data =3D MI_BATCH_BUFFER_END; ret =3D drm_intel_bo_unmap(bo); assert(ret =3D=3D 0); =09 /* Execute the batch buffer */ ret =3D drm_intel_bo_mrb_exec_ctx(bo, 8, NULL, 0, 0, I915_EXEC_DEFAULT,= ctxs[i]); if (ret !=3D 0) { perror("drm_intel_bo_mrb_exec"); return i; } =09 /* 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 =3D 0; i < count; i++) { memset(&destroy, 0, sizeof(destroy)); if (ctxs[i] =3D=3D -1) continue; destroy.ctx_id =3D ctxs[i]; ret =3D ioctl(fd, DRM_IOCTL_I915_GEM_CTX_DESTROY, &destroy); if (ret !=3D 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 !=3D 2) { printf("usage: %s \n", argv[0]); exit(-1); } =09 fd =3D drm_open_any(); count =3D strtol(argv[1], NULL, 0); memset(ctxs, 0, sizeof(*ctxs)); create_ctxs(fd, count); ret =3D create_and_submit_batches(fd, count); destroy_ctxs(fd, count); assert(ret =3D=3D count); close(fd); return 0; } --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/intel-gfx --fdj2RfSjLxBAspz7--