Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Widawsky <widawsky@gmail.com>
To: intel-gfx@lists.freedesktop.org
Cc: benjamin.widawsky@linux.intel.com
Subject: [RFC] drm/i915: context support unit test
Date: Sat, 25 Dec 2010 14:53:04 -0800	[thread overview]
Message-ID: <20101225225303.GA5311@snipes.kumite> (raw)

[-- Attachment #1: Type: text/plain, Size: 607 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gem_ctx_basic.c --]
[-- Type: text/x-c; charset=unknown-8bit, Size: 4169 bytes --]

/*
 * 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 <benjamin.widawsky@linux.intel.com>
 *
 */

#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;
}

[-- Attachment #3: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

             reply	other threads:[~2010-12-25 22:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-25 22:53 Ben Widawsky [this message]
2010-12-28 22:36 ` [RFC] drm/i915: context support unit test Daniel Vetter
2010-12-29  4:03   ` Ben Widawsky
2010-12-30 10:07     ` Daniel Vetter
2010-12-30 11:13       ` Chris Wilson
2010-12-30 12:48         ` Daniel Vetter
2010-12-30 20:21           ` Ben Widawsky
2010-12-31  0:48             ` Ben Widawsky
2010-12-31  9:31               ` Chris Wilson
2011-01-04 20:10                 ` Daniel Vetter
2011-01-04 20:21                   ` Ben Widawsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101225225303.GA5311@snipes.kumite \
    --to=widawsky@gmail.com \
    --cc=benjamin.widawsky@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox