[Mesa-dev] [RFC 3/3] i965: Implement context priorities

Chris Wilson chris at chris-wilson.co.uk
Fri Oct 28 08:10:49 UTC 2016


Pass along the context priority provided through eglCreateContext to the
kernel, where it will be used for priority sorting of batches.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 src/mesa/drivers/dri/i965/brw_batch.c   | 43 ++++++++++++++++++++++++++++++++-
 src/mesa/drivers/dri/i965/brw_batch.h   |  3 ++-
 src/mesa/drivers/dri/i965/brw_context.c |  2 +-
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_batch.c b/src/mesa/drivers/dri/i965/brw_batch.c
index 40e3ec4..4c95c57 100644
--- a/src/mesa/drivers/dri/i965/brw_batch.c
+++ b/src/mesa/drivers/dri/i965/brw_batch.c
@@ -620,6 +620,44 @@ static uint64_t get_max_aperture(int fd, int gen)
    return max_aperture;
 }
 
+static unsigned batch_set_priority(struct brw_batch *batch, unsigned priority)
+{
+   struct drm_i915_gem_context_param param;
+
+   if (!batch->hw_ctx)
+      return __DRI_CTX_PRIORITY_MEDIUM;
+
+#ifndef I915_CONTEXT_PARAM_PRIORITY
+#define I915_CONTEXT_PARAM_PRIORITY 0x5
+#endif
+
+   memset(&param, 0, sizeof(param));
+   param.ctx_id = batch->hw_ctx;
+   param.param = I915_CONTEXT_PARAM_PRIORITY;
+   switch (priority) {
+   case __DRI_CTX_PRIORITY_HIGH:
+      param.value = 1023;
+      break;
+
+   case __DRI_CTX_PRIORITY_LOW:
+      param.value = -1023;
+      break;
+
+   case __DRI_CTX_PRIORITY_MEDIUM:
+      return __DRI_CTX_PRIORITY_MEDIUM;
+   }
+   drmIoctl(batch->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &param);
+
+   drmIoctl(batch->fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &param);
+   if ((int)param.value < 0)
+      priority = __DRI_CTX_PRIORITY_LOW;
+   else if ((int)param.value > 0)
+      priority = __DRI_CTX_PRIORITY_HIGH;
+   else
+      priority = __DRI_CTX_PRIORITY_MEDIUM;
+   return priority;
+}
+
 /*
  * Initialise the batch-manager for the context.
  *
@@ -629,7 +667,8 @@ static uint64_t get_max_aperture(int fd, int gen)
  * all contexts.)
  */
 int brw_batch_init(struct brw_batch *batch,
-                   struct intel_screen *screen)
+                   struct intel_screen *screen,
+                   unsigned *priority)
 {
    const struct gen_device_info *devinfo = &screen->devinfo;
    struct drm_i915_gem_context_create create;
@@ -704,6 +743,8 @@ int brw_batch_init(struct brw_batch *batch,
       }
    }
 
+   *priority = batch_set_priority(batch, *priority);
+
    ret = __brw_batch_reset(batch);
    if (ret)
       goto err;
diff --git a/src/mesa/drivers/dri/i965/brw_batch.h b/src/mesa/drivers/dri/i965/brw_batch.h
index ffc9d91..4a188cf 100644
--- a/src/mesa/drivers/dri/i965/brw_batch.h
+++ b/src/mesa/drivers/dri/i965/brw_batch.h
@@ -191,7 +191,8 @@ typedef struct brw_batch {
 } brw_batch;
 
 int brw_batch_init(struct brw_batch *batch,
-                   struct intel_screen *screen);
+                   struct intel_screen *screen,
+                   unsigned *priority);
 
 inline static uint64_t
 __brw_reloc_address(brw_bo *bo, uint64_t offset)
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 1d3ee1d..0382000 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -957,7 +957,7 @@ brwCreateContext(gl_api api,
    brw->driContext = driContextPriv;
    brw->screen = screen;
 
-   if (brw_batch_init(&brw->batch, screen)) {
+   if (brw_batch_init(&brw->batch, screen, &priority)) {
       fprintf(stderr, "%s: failed to alloc batch\n", __func__);
       *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
       return false;
-- 
2.10.1



More information about the mesa-dev mailing list