[PATH i-g-t 06/13] gem_wsim: Context priority support

Tvrtko Ursulin
2018-09-05T13:49:52Z

A new workload command ('P') is added which enables per context dynamic
priority control.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
benchmarks/gem_wsim.c | 48 +++++++++++++++++++++++++++++++++++++++++-
benchmarks/wsim/README | 18 ++++++++++++++++
2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index fe9535df75c6..0c52ec567430 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -82,7 +82,8 @@ enum w_type
THROTTLE,
QD_THROTTLE,
SW_FENCE,
- SW_FENCE_SIGNAL
+ SW_FENCE_SIGNAL,
+ CTX_PRIORITY
};

struct deps
@@ -114,6 +115,7 @@ struct w_step
int target;
int throttle;
int fence_signal;
+ int priority;
};

/* Implementation details */
@@ -162,6 +164,7 @@ struct workload
unsigned int nr_ctxs;
struct {
uint32_t id;
+ int priority;
unsigned int static_vcs;
} *ctx_list;

@@ -342,6 +345,36 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w)
step.period = tmp;
goto add_step;
}
+ } else if (!strcmp(field, "P")) {
+ unsigned int nr = 0;
+ while ((field = strtok_r(fstart, ".", &fctx)) !=
+ NULL) {
+ tmp = atoi(field);
+ if (tmp <= 0 && nr == 0) {
+ if (verbose)
+ fprintf(stderr,
+ "Invalid context at step %u!\n",
+ nr_steps);
+ return NULL;
+ }
+
+ if (nr == 0) {
+ step.context = tmp;
+ } else if (nr == 1) {
+ step.priority = tmp;
+ } else {
+ if (verbose)
+ fprintf(stderr,
+ "Invalid priority format at step %u!\n",
+ nr_steps);
+ return NULL;
+ }
+
+ nr++;
+ }
+
+ step.type = CTX_PRIORITY;
+ goto add_step;
} else if (!strcmp(field, "s")) {
if ((field = strtok_r(fstart, ".", &fctx)) !=
NULL) {
@@ -1806,6 +1839,19 @@ static void *run_workload(void *data)
inc = cur_seqno - wrk->sync_seqno;
sw_sync_timeline_inc(wrk->sync_timeline, inc);
continue;
+ } else if (w->type == CTX_PRIORITY) {
+ if (w->priority != wrk->ctx_list[w->context].priority) {
+ struct drm_i915_gem_context_param param = {
+ .ctx_id = wrk->ctx_list[w->context].id,
+ .param = I915_CONTEXT_PARAM_PRIORITY,
+ .value = w->priority,
+ };
+
+ gem_context_set_param(fd, &param);
+ wrk->ctx_list[w->context].priority =
+ w->priority;
+ }
+ continue;
}

if (do_sleep || w->type == PERIOD) {
diff --git a/benchmarks/wsim/README b/benchmarks/wsim/README
index 01766d37564f..fd9bff3401af 100644
--- a/benchmarks/wsim/README
+++ b/benchmarks/wsim/README
@@ -3,6 +3,7 @@ Workload descriptor format

ctx.engine.duration_us.dependency.wait,...
<uint>.<str>.<uint>[-<uint>].<int <= 0>[/<int <= 0>][...].<0|1>,...
+P.<uint>.<int>
d|p|s|t|q|a.<int>,...
f

@@ -22,6 +23,7 @@ Additional workload steps are also supported:
'q' - Throttle to n max queue depth.
'f' - Create a sync fence.
'a' - Advance the previously created sync fence.
+ 'P' - Context priority.

Engine ids: RCS, BCS, VCS, VCS1, VCS2, VECS

@@ -110,3 +112,19 @@ created at the second step. They are submitted ahead of time while still not
runnable. When the second RCS batch completes the standalone fence is signaled
which allows the two VCS batches to be executed. Finally we wait until the both
VCS batches have completed before starting the (optional) next iteration.
+
+Context priority
+----------------
+
+ P.1.-1
+ 1.RCS.1000.0.0
+ P.2.1
+ 2.BCS.1000.-2.0
+
+Context 1 is marked as low priority (-1) and then a batch buffer is submitted
+against it. Context 2 is marked as high priority (1) and then a batch buffer
+is submitted against it which depends on the batch from context 1.
+
+Context priority command is executed at workload runtime and is valid until
+overriden by another (optional) same context priority change. Actual driver
+ioctls are executed only if the priority level has changed for the context.