<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 18, 2017 at 2:46 AM, Chris Wilson <span dir="ltr"><<a href="mailto:chris@chris-wilson.co.uk" target="_blank">chris@chris-wilson.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Use a priority stored in the context as the initial value when<br>
submitting a request. This allows us to change the default priority on a<br>
per-context basis, allowing different contexts to be favoured with GPU<br>
time at the expense of lower importance work. The user can adjust the<br>
context's priority via I915_CONTEXT_PARAM_PRIORITY, with more positive<br>
values being higher priority (they will be serviced earlier, after their<br>
dependencies have been resolved). Any prerequisite work for an execbuf<br>
will have its priority raised to match the new request as required.<br>
<br>
Normal users can specify any value in the range of -1023 to 0 [default],<br>
i.e. they can reduce the priority of their workloads (and temporarily<br>
boost it back to normal if so desired).<br>
<br>
Privileged users can specify any value in the range of -1023 to 1023,<br>
[default is 0], i.e. they can raise their priority above all overs and<br>
so potentially starve the system.<br></blockquote><div><br></div><div>How is "priviledged" defined? These days, X11 and/or your Wayland compositor run as the logged in user. One thought (thanks to Rafael) would be DRM master on the current VT. Also, is there some mechanism whereby a "priviledged" app can make another app "priviledged"? I.e. X11 making your compositor privileged.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Note that the existing schedulers are not fair, nor load balancing, the<br>
execution is strictly by priority on a first-come, first-served basis,<br>
and the driver may choose to boost some requests above the range<br>
available to users.<br>
<br>
This priority was originally based around nice(2), but evolved to allow<br>
clients to adjust their priority within a small range, and allow for a<br>
privileged high priority range.<br>
<br>
For example, this can be used to implement EGL_IMG_context_priority<br>
<a href="https://www.khronos.org/registry/egl/extensions/IMG/EGL_IMG_context_priority.txt" rel="noreferrer" target="_blank">https://www.khronos.org/<wbr>registry/egl/extensions/IMG/<wbr>EGL_IMG_context_priority.txt</a><br>
<br>
EGL_CONTEXT_PRIORITY_LEVEL_IMG determines the priority level of<br>
the context to be created. This attribute is a hint, as an<br>
implementation may not support multiple contexts at some<br>
priority levels and system policy may limit access to high<br>
priority contexts to appropriate system privilege level. The<br>
default value for EGL_CONTEXT_PRIORITY_LEVEL_IMG is<br>
EGL_CONTEXT_PRIORITY_MEDIUM_<wbr>IMG."<br>
<br>
so we can map<br>
<br>
PRIORITY_HIGH -> 1023 [privileged, will failback to 0]<br>
PRIORITY_MED -> 0 [default]<br>
PRIORITY_LOW -> -1023<br>
<br>
They also map onto the priorities used by VkQueue (and a VkQueue is<br>
essentially a timeline, our i915_gem_context under full-ppgtt).<br></blockquote><div><br></div><div>Not really. VkQueue priorities are a long and complicated story and were *not* well thought-out in the API. Many hours of meetings have been wasted trying to figure out what they mean. Whey they *don't* mean is a global context priority.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
v2: s/CAP_SYS_ADMIN/CAP_SYS_NICE/<br>
v3: Report min/max user priorities as defines in the uapi, and rebase<br>
internal priorities on the exposed values.<br>
<br>
Testcase: igt/gem_exec_schedule<br>
Signed-off-by: Chris Wilson <<a href="mailto:chris@chris-wilson.co.uk">chris@chris-wilson.co.uk</a>><br>
Reviewed-by: Tvrtko Ursulin <<a href="mailto:tvrtko.ursulin@intel.com">tvrtko.ursulin@intel.com</a>><br>
---<br>
drivers/gpu/drm/i915/i915_gem_<wbr>context.c | 23 +++++++++++++++++++++++<br>
drivers/gpu/drm/i915/i915_gem_<wbr>request.h | 11 ++++++++---<br>
include/uapi/drm/i915_drm.h | 9 ++++++++-<br>
3 files changed, 39 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/i915/i915_<wbr>gem_context.c b/drivers/gpu/drm/i915/i915_<wbr>gem_context.c<br>
index c62e17a68f5b..0735d624ef07 100644<br>
--- a/drivers/gpu/drm/i915/i915_<wbr>gem_context.c<br>
+++ b/drivers/gpu/drm/i915/i915_<wbr>gem_context.c<br>
@@ -1038,6 +1038,9 @@ int i915_gem_context_getparam_<wbr>ioctl(struct drm_device *dev, void *data,<br>
case I915_CONTEXT_PARAM_BANNABLE:<br>
args->value = i915_gem_context_is_bannable(<wbr>ctx);<br>
break;<br>
+ case I915_CONTEXT_PARAM_PRIORITY:<br>
+ args->value = ctx->priority;<br>
+ break;<br>
default:<br>
ret = -EINVAL;<br>
break;<br>
@@ -1095,6 +1098,26 @@ int i915_gem_context_setparam_<wbr>ioctl(struct drm_device *dev, void *data,<br>
else<br>
i915_gem_context_clear_<wbr>bannable(ctx);<br>
break;<br>
+<br>
+ case I915_CONTEXT_PARAM_PRIORITY:<br>
+ {<br>
+ int priority = args->value;<br>
+<br>
+ if (args->size)<br>
+ ret = -EINVAL;<br>
+ else if (!to_i915(dev)->engine[RCS]-><wbr>schedule)<br>
+ ret = -ENODEV;<br>
+ else if (priority > I915_CONTEXT_MAX_USER_PRIORITY ||<br>
+ priority < I915_CONTEXT_MIN_USER_<wbr>PRIORITY)<br>
+ ret = -EINVAL;<br>
+ else if (priority > I915_CONTEXT_DEFAULT_PRIORITY &&<br>
+ !capable(CAP_SYS_NICE))<br>
+ ret = -EPERM;<br>
+ else<br>
+ ctx->priority = priority;<br>
+ }<br>
+ break;<br>
+<br>
default:<br>
ret = -EINVAL;<br>
break;<br>
diff --git a/drivers/gpu/drm/i915/i915_<wbr>gem_request.h b/drivers/gpu/drm/i915/i915_<wbr>gem_request.h<br>
index 7b7c84369d78..d34d8adba9e9 100644<br>
--- a/drivers/gpu/drm/i915/i915_<wbr>gem_request.h<br>
+++ b/drivers/gpu/drm/i915/i915_<wbr>gem_request.h<br>
@@ -30,6 +30,8 @@<br>
#include "i915_gem.h"<br>
#include "i915_sw_fence.h"<br>
<br>
+#include <uapi/drm/i915_drm.h><br>
+<br>
struct drm_file;<br>
struct drm_i915_gem_object;<br>
struct drm_i915_gem_request;<br>
@@ -69,9 +71,12 @@ struct i915_priotree {<br>
struct list_head waiters_list; /* those after us, they depend upon us */<br>
struct list_head link;<br>
int priority;<br>
-#define I915_PRIORITY_MAX 1024<br>
-#define I915_PRIORITY_NORMAL 0<br>
-#define I915_PRIORITY_MIN (-I915_PRIORITY_MAX)<br>
+};<br>
+<br>
+enum {<br>
+ I915_PRIORITY_MIN = I915_CONTEXT_MIN_USER_PRIORITY - 1,<br>
+ I915_PRIORITY_NORMAL = I915_CONTEXT_DEFAULT_PRIORITY,<br>
+ I915_PRIORITY_MAX = I915_CONTEXT_MAX_USER_PRIORITY + 1,<br>
};<br>
<br>
struct i915_gem_capture_list {<br>
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h<br>
index 4adf3e5f5c71..34ee011f08ac 100644<br>
--- a/include/uapi/drm/i915_drm.h<br>
+++ b/include/uapi/drm/i915_drm.h<br>
@@ -393,8 +393,11 @@ typedef struct drm_i915_irq_wait {<br>
#define I915_PARAM_MIN_EU_IN_POOL 39<br>
#define I915_PARAM_MMAP_GTT_VERSION 40<br>
<br>
-/* Query whether DRM_I915_GEM_EXECBUFFER2 supports user defined execution<br>
+/*<br>
+ * Query whether DRM_I915_GEM_EXECBUFFER2 supports user defined execution<br>
* priorities and the driver will attempt to execute batches in priority order.<br>
+ * The initial priority for each batch is supplied by the context and is<br>
+ * controlled via I915_CONTEXT_PARAM_PRIORITY.<br>
*/<br>
#define I915_PARAM_HAS_SCHEDULER 41<br>
#define I915_PARAM_HUC_STATUS 42<br>
@@ -1320,6 +1323,10 @@ struct drm_i915_gem_context_param {<br>
#define I915_CONTEXT_PARAM_GTT_SIZE 0x3<br>
#define I915_CONTEXT_PARAM_NO_ERROR_<wbr>CAPTURE 0x4<br>
#define I915_CONTEXT_PARAM_BANNABLE 0x5<br>
+#define I915_CONTEXT_PARAM_PRIORITY 0x6<br>
+#define I915_CONTEXT_MAX_USER_PRIORITY 1023 /* inclusive */<br>
+#define I915_CONTEXT_DEFAULT_PRIORITY 0<br>
+#define I915_CONTEXT_MIN_USER_PRIORITY -1023 /* inclusive */<br>
__u64 value;<br>
};<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
Intel-gfx mailing list<br>
<a href="mailto:Intel-gfx@lists.freedesktop.org">Intel-gfx@lists.freedesktop.<wbr>org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/intel-gfx" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/intel-gfx</a><br>
</font></span></blockquote></div><br></div></div>