From: Chris Wilson Date: Wed, 8 May 2019 06:23:13 +0000 (-0700) Subject: iris: Add helpers to clone a hardware context. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7402564c076a06c00fa71f880246775fa631b640;p=mesa.git iris: Add helpers to clone a hardware context. (Chris Wilson wrote this code in a patch titled "i965: Be resilient in the face of GPU hangs"; Ken fixed a bug and copied it to iris.) --- diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 808f20d537d..2d960574705 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -1437,6 +1437,17 @@ iris_create_hw_context(struct iris_bufmgr *bufmgr) return create.ctx_id; } +static int +iris_hw_context_get_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id) +{ + struct drm_i915_gem_context_param p = { + .ctx_id = ctx_id, + .param = I915_CONTEXT_PARAM_PRIORITY, + }; + drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p); + return p.value; /* on error, return 0 i.e. default priority */ +} + int iris_hw_context_set_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id, @@ -1456,6 +1467,19 @@ iris_hw_context_set_priority(struct iris_bufmgr *bufmgr, return err; } +uint32_t +iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id) +{ + uint32_t new_ctx = iris_create_hw_context(bufmgr); + + if (new_ctx) { + int priority = iris_hw_context_get_priority(bufmgr, ctx_id); + iris_hw_context_set_priority(bufmgr, new_ctx, priority); + } + + return new_ctx; +} + void iris_destroy_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id) { diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h index 0e82d577519..5676a35e106 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.h +++ b/src/gallium/drivers/iris/iris_bufmgr.h @@ -331,6 +331,7 @@ void iris_bufmgr_enable_reuse(struct iris_bufmgr *bufmgr); int iris_bo_wait(struct iris_bo *bo, int64_t timeout_ns); uint32_t iris_create_hw_context(struct iris_bufmgr *bufmgr); +uint32_t iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id); #define IRIS_CONTEXT_LOW_PRIORITY ((I915_CONTEXT_MIN_USER_PRIORITY-1)/2) #define IRIS_CONTEXT_MEDIUM_PRIORITY (I915_CONTEXT_DEFAULT_PRIORITY)