[Intel-gfx] [PATCH 1/1] drm/i915: Add wrapper for context priority interface

John.C.Harrison at Intel.com John.C.Harrison at Intel.com
Wed Apr 20 17:13:53 UTC 2016


From: John Harrison <John.C.Harrison at Intel.com>

There is an EGL extension to set execution priority per context. This
can be implemented via the i915 per context priority parameter. This
patch adds a wrapper to connect the two together in a way that can be
updated as necessary without breaking one side or the other.

Signed-off-by: John Harrison <John.C.Harrison at Intel.com>
---
 include/drm/i915_drm.h   |  1 +
 intel/intel_bufmgr.h     |  5 ++++
 intel/intel_bufmgr_gem.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)

diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h
index c4ce6b2..8d9f063 100644
--- a/include/drm/i915_drm.h
+++ b/include/drm/i915_drm.h
@@ -1167,6 +1167,7 @@ struct drm_i915_gem_context_param {
 #define I915_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define I915_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define I915_CONTEXT_PARAM_GTT_SIZE	0x3
+#define I915_CONTEXT_PARAM_PRIORITY	0x4
 	__u64 value;
 };
 
diff --git a/intel/intel_bufmgr.h b/intel/intel_bufmgr.h
index a1abbcd..49d4125 100644
--- a/intel/intel_bufmgr.h
+++ b/intel/intel_bufmgr.h
@@ -209,6 +209,11 @@ int drm_intel_gem_bo_wait(drm_intel_bo *bo, int64_t timeout_ns);
 
 drm_intel_context *drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr);
 void drm_intel_gem_context_destroy(drm_intel_context *ctx);
+int drm_intel_gem_context_get_priority(drm_intel_context *ctx, int *priority);
+#define DRM_INTEL_CTX_SET_PRIORITY_EGL_LOW		(0x10001)
+#define DRM_INTEL_CTX_SET_PRIORITY_EGL_MEDIUM		(0x10002)
+#define DRM_INTEL_CTX_SET_PRIORITY_EGL_HIGH		(0x10003)
+int drm_intel_gem_context_set_priority(drm_intel_context *ctx, int priority);
 int drm_intel_gem_bo_context_exec(drm_intel_bo *bo, drm_intel_context *ctx,
 				  int used, unsigned int flags);
 
diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
index 0a4012b..591ccd5 100644
--- a/intel/intel_bufmgr_gem.c
+++ b/intel/intel_bufmgr_gem.c
@@ -3154,6 +3154,76 @@ drm_intel_gem_context_destroy(drm_intel_context *ctx)
 }
 
 int
+drm_intel_gem_context_get_priority(drm_intel_context *ctx, int *priority)
+{
+	drm_intel_bufmgr_gem *bufmgr_gem;
+	struct drm_i915_gem_context_param ctxparam;
+	int ret;
+
+	if ((ctx == NULL) || (priority == NULL))
+		return -EINVAL;
+
+	memclear(ctxparam);
+
+	bufmgr_gem = (drm_intel_bufmgr_gem *)ctx->bufmgr;
+	ctxparam.ctx_id = ctx->ctx_id;
+	ctxparam.param = I915_CONTEXT_PARAM_PRIORITY;
+	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM,
+		       &ctxparam);
+	if (ret != 0) {
+		int err = errno;
+		*priority = 0;
+		fprintf(stderr, "DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM failed: %s\n",
+			strerror(err));
+		return -err;
+	}
+
+	*priority = (int) ctxparam.value;
+
+	return 0;
+}
+
+int
+drm_intel_gem_context_set_priority(drm_intel_context *ctx, int priority)
+{
+	drm_intel_bufmgr_gem *bufmgr_gem;
+	struct drm_i915_gem_context_param ctxparam;
+	int ret;
+
+	if (ctx == NULL)
+		return -EINVAL;
+
+	memclear(ctxparam);
+
+	switch (priority) {
+	case DRM_INTEL_CTX_SET_PRIORITY_EGL_LOW:
+		priority = -500;
+		break;
+	case DRM_INTEL_CTX_SET_PRIORITY_EGL_MEDIUM:
+		priority = -0;
+		break;
+	case DRM_INTEL_CTX_SET_PRIORITY_EGL_HIGH:
+		priority = 500;
+		break;
+	}
+
+	bufmgr_gem = (drm_intel_bufmgr_gem *)ctx->bufmgr;
+	ctxparam.ctx_id = ctx->ctx_id;
+	ctxparam.param = I915_CONTEXT_PARAM_PRIORITY;
+	ctxparam.value = priority;
+	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM,
+		       &ctxparam);
+	if (ret != 0) {
+		int err = errno;
+		fprintf(stderr, "DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM failed: %s\n",
+			strerror(err));
+		return -err;
+	}
+
+	return 0;
+}
+
+int
 drm_intel_get_reset_stats(drm_intel_context *ctx,
 			  uint32_t *reset_count,
 			  uint32_t *active,
-- 
1.9.1



More information about the Intel-gfx mailing list