Skip to content

Commit e5e3217

Browse files
mbrost05johnharr-intel
authored andcommitted
drm/i915/guc: Connect UAPI to GuC multi-lrc interface
Introduce 'set parallel submit' extension to connect UAPI to GuC multi-lrc interface. Kernel doc in new uAPI should explain it all. IGT: https://patchwork.freedesktop.org/patch/447008/?series=93071&rev=1 media UMD: intel/media-driver#1252 v2: (Daniel Vetter) - Add IGT link and placeholder for media UMD link v3: (Kernel test robot) - Fix warning in unpin engines call (John Harrison) - Reword a bunch of the kernel doc v4: (John Harrison) - Add comment why perma-pin is done after setting gem context - Update some comments / docs for proto contexts v5: (John Harrison) - Rework perma-pin comment - Add BUG_IN if context is pinned when setting gem context Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Reviewed-by: John Harrison <John.C.Harrison@Intel.com> Signed-off-by: John Harrison <John.C.Harrison@Intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20211014172005.27155-17-matthew.brost@intel.com
1 parent d38a929 commit e5e3217

9 files changed

Lines changed: 505 additions & 31 deletions

File tree

‎drivers/gpu/drm/i915/gem/i915_gem_context.c‎

Lines changed: 228 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,150 @@ set_proto_ctx_engines_bond(struct i915_user_extension __user *base, void *data)
556556
return 0;
557557
}
558558

559+
static int
560+
set_proto_ctx_engines_parallel_submit(struct i915_user_extension __user *base,
561+
void *data)
562+
{
563+
struct i915_context_engines_parallel_submit __user *ext =
564+
container_of_user(base, typeof(*ext), base);
565+
const struct set_proto_ctx_engines *set = data;
566+
struct drm_i915_private *i915 = set->i915;
567+
u64 flags;
568+
int err = 0, n, i, j;
569+
u16 slot, width, num_siblings;
570+
struct intel_engine_cs **siblings = NULL;
571+
intel_engine_mask_t prev_mask;
572+
573+
/* Disabling for now */
574+
return -ENODEV;
575+
576+
/* FIXME: This is NIY for execlists */
577+
if (!(intel_uc_uses_guc_submission(&i915->gt.uc)))
578+
return -ENODEV;
579+
580+
if (get_user(slot, &ext->engine_index))
581+
return -EFAULT;
582+
583+
if (get_user(width, &ext->width))
584+
return -EFAULT;
585+
586+
if (get_user(num_siblings, &ext->num_siblings))
587+
return -EFAULT;
588+
589+
if (slot >= set->num_engines) {
590+
drm_dbg(&i915->drm, "Invalid placement value, %d >= %d\n",
591+
slot, set->num_engines);
592+
return -EINVAL;
593+
}
594+
595+
if (set->engines[slot].type != I915_GEM_ENGINE_TYPE_INVALID) {
596+
drm_dbg(&i915->drm,
597+
"Invalid placement[%d], already occupied\n", slot);
598+
return -EINVAL;
599+
}
600+
601+
if (get_user(flags, &ext->flags))
602+
return -EFAULT;
603+
604+
if (flags) {
605+
drm_dbg(&i915->drm, "Unknown flags 0x%02llx", flags);
606+
return -EINVAL;
607+
}
608+
609+
for (n = 0; n < ARRAY_SIZE(ext->mbz64); n++) {
610+
err = check_user_mbz(&ext->mbz64[n]);
611+
if (err)
612+
return err;
613+
}
614+
615+
if (width < 2) {
616+
drm_dbg(&i915->drm, "Width (%d) < 2\n", width);
617+
return -EINVAL;
618+
}
619+
620+
if (num_siblings < 1) {
621+
drm_dbg(&i915->drm, "Number siblings (%d) < 1\n",
622+
num_siblings);
623+
return -EINVAL;
624+
}
625+
626+
siblings = kmalloc_array(num_siblings * width,
627+
sizeof(*siblings),
628+
GFP_KERNEL);
629+
if (!siblings)
630+
return -ENOMEM;
631+
632+
/* Create contexts / engines */
633+
for (i = 0; i < width; ++i) {
634+
intel_engine_mask_t current_mask = 0;
635+
struct i915_engine_class_instance prev_engine;
636+
637+
for (j = 0; j < num_siblings; ++j) {
638+
struct i915_engine_class_instance ci;
639+
640+
n = i * num_siblings + j;
641+
if (copy_from_user(&ci, &ext->engines[n], sizeof(ci))) {
642+
err = -EFAULT;
643+
goto out_err;
644+
}
645+
646+
siblings[n] =
647+
intel_engine_lookup_user(i915, ci.engine_class,
648+
ci.engine_instance);
649+
if (!siblings[n]) {
650+
drm_dbg(&i915->drm,
651+
"Invalid sibling[%d]: { class:%d, inst:%d }\n",
652+
n, ci.engine_class, ci.engine_instance);
653+
err = -EINVAL;
654+
goto out_err;
655+
}
656+
657+
if (n) {
658+
if (prev_engine.engine_class !=
659+
ci.engine_class) {
660+
drm_dbg(&i915->drm,
661+
"Mismatched class %d, %d\n",
662+
prev_engine.engine_class,
663+
ci.engine_class);
664+
err = -EINVAL;
665+
goto out_err;
666+
}
667+
}
668+
669+
prev_engine = ci;
670+
current_mask |= siblings[n]->logical_mask;
671+
}
672+
673+
if (i > 0) {
674+
if (current_mask != prev_mask << 1) {
675+
drm_dbg(&i915->drm,
676+
"Non contiguous logical mask 0x%x, 0x%x\n",
677+
prev_mask, current_mask);
678+
err = -EINVAL;
679+
goto out_err;
680+
}
681+
}
682+
prev_mask = current_mask;
683+
}
684+
685+
set->engines[slot].type = I915_GEM_ENGINE_TYPE_PARALLEL;
686+
set->engines[slot].num_siblings = num_siblings;
687+
set->engines[slot].width = width;
688+
set->engines[slot].siblings = siblings;
689+
690+
return 0;
691+
692+
out_err:
693+
kfree(siblings);
694+
695+
return err;
696+
}
697+
559698
static const i915_user_extension_fn set_proto_ctx_engines_extensions[] = {
560699
[I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE] = set_proto_ctx_engines_balance,
561700
[I915_CONTEXT_ENGINES_EXT_BOND] = set_proto_ctx_engines_bond,
701+
[I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT] =
702+
set_proto_ctx_engines_parallel_submit,
562703
};
563704

564705
static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
@@ -794,6 +935,7 @@ static int intel_context_set_gem(struct intel_context *ce,
794935
GEM_BUG_ON(rcu_access_pointer(ce->gem_context));
795936
RCU_INIT_POINTER(ce->gem_context, ctx);
796937

938+
GEM_BUG_ON(intel_context_is_pinned(ce));
797939
ce->ring_size = SZ_16K;
798940

799941
i915_vm_put(ce->vm);
@@ -818,6 +960,25 @@ static int intel_context_set_gem(struct intel_context *ce,
818960
return ret;
819961
}
820962

963+
static void __unpin_engines(struct i915_gem_engines *e, unsigned int count)
964+
{
965+
while (count--) {
966+
struct intel_context *ce = e->engines[count], *child;
967+
968+
if (!ce || !test_bit(CONTEXT_PERMA_PIN, &ce->flags))
969+
continue;
970+
971+
for_each_child(ce, child)
972+
intel_context_unpin(child);
973+
intel_context_unpin(ce);
974+
}
975+
}
976+
977+
static void unpin_engines(struct i915_gem_engines *e)
978+
{
979+
__unpin_engines(e, e->num_engines);
980+
}
981+
821982
static void __free_engines(struct i915_gem_engines *e, unsigned int count)
822983
{
823984
while (count--) {
@@ -933,6 +1094,40 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx,
9331094
return err;
9341095
}
9351096

1097+
static int perma_pin_contexts(struct intel_context *ce)
1098+
{
1099+
struct intel_context *child;
1100+
int i = 0, j = 0, ret;
1101+
1102+
GEM_BUG_ON(!intel_context_is_parent(ce));
1103+
1104+
ret = intel_context_pin(ce);
1105+
if (unlikely(ret))
1106+
return ret;
1107+
1108+
for_each_child(ce, child) {
1109+
ret = intel_context_pin(child);
1110+
if (unlikely(ret))
1111+
goto unwind;
1112+
++i;
1113+
}
1114+
1115+
set_bit(CONTEXT_PERMA_PIN, &ce->flags);
1116+
1117+
return 0;
1118+
1119+
unwind:
1120+
intel_context_unpin(ce);
1121+
for_each_child(ce, child) {
1122+
if (j++ < i)
1123+
intel_context_unpin(child);
1124+
else
1125+
break;
1126+
}
1127+
1128+
return ret;
1129+
}
1130+
9361131
static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
9371132
unsigned int num_engines,
9381133
struct i915_gem_proto_engine *pe)
@@ -946,7 +1141,7 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
9461141
e->num_engines = num_engines;
9471142

9481143
for (n = 0; n < num_engines; n++) {
949-
struct intel_context *ce;
1144+
struct intel_context *ce, *child;
9501145
int ret;
9511146

9521147
switch (pe[n].type) {
@@ -956,7 +1151,13 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
9561151

9571152
case I915_GEM_ENGINE_TYPE_BALANCED:
9581153
ce = intel_engine_create_virtual(pe[n].siblings,
959-
pe[n].num_siblings);
1154+
pe[n].num_siblings, 0);
1155+
break;
1156+
1157+
case I915_GEM_ENGINE_TYPE_PARALLEL:
1158+
ce = intel_engine_create_parallel(pe[n].siblings,
1159+
pe[n].num_siblings,
1160+
pe[n].width);
9601161
break;
9611162

9621163
case I915_GEM_ENGINE_TYPE_INVALID:
@@ -977,6 +1178,30 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
9771178
err = ERR_PTR(ret);
9781179
goto free_engines;
9791180
}
1181+
for_each_child(ce, child) {
1182+
ret = intel_context_set_gem(child, ctx, pe->sseu);
1183+
if (ret) {
1184+
err = ERR_PTR(ret);
1185+
goto free_engines;
1186+
}
1187+
}
1188+
1189+
/*
1190+
* XXX: Must be done after calling intel_context_set_gem as that
1191+
* function changes the ring size. The ring is allocated when
1192+
* the context is pinned. If the ring size is changed after
1193+
* allocation we have a mismatch of the ring size and will cause
1194+
* the context to hang. Presumably with a bit of reordering we
1195+
* could move the perma-pin step to the backend function
1196+
* intel_engine_create_parallel.
1197+
*/
1198+
if (pe[n].type == I915_GEM_ENGINE_TYPE_PARALLEL) {
1199+
ret = perma_pin_contexts(ce);
1200+
if (ret) {
1201+
err = ERR_PTR(ret);
1202+
goto free_engines;
1203+
}
1204+
}
9801205
}
9811206

9821207
return e;
@@ -1219,6 +1444,7 @@ static void context_close(struct i915_gem_context *ctx)
12191444

12201445
/* Flush any concurrent set_engines() */
12211446
mutex_lock(&ctx->engines_mutex);
1447+
unpin_engines(__context_engines_static(ctx));
12221448
engines_idle_release(ctx, rcu_replace_pointer(ctx->engines, NULL, 1));
12231449
i915_gem_context_set_closed(ctx);
12241450
mutex_unlock(&ctx->engines_mutex);

‎drivers/gpu/drm/i915/gem/i915_gem_context_types.h‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ enum i915_gem_engine_type {
7878

7979
/** @I915_GEM_ENGINE_TYPE_BALANCED: A load-balanced engine set */
8080
I915_GEM_ENGINE_TYPE_BALANCED,
81+
82+
/** @I915_GEM_ENGINE_TYPE_PARALLEL: A parallel engine set */
83+
I915_GEM_ENGINE_TYPE_PARALLEL,
8184
};
8285

8386
/**
8487
* struct i915_gem_proto_engine - prototype engine
8588
*
8689
* This struct describes an engine that a context may contain. Engines
87-
* have three types:
90+
* have four types:
8891
*
8992
* - I915_GEM_ENGINE_TYPE_INVALID: Invalid engines can be created but they
9093
* show up as a NULL in i915_gem_engines::engines[i] and any attempt to
@@ -97,6 +100,10 @@ enum i915_gem_engine_type {
97100
*
98101
* - I915_GEM_ENGINE_TYPE_BALANCED: A load-balanced engine set, described
99102
* i915_gem_proto_engine::num_siblings and i915_gem_proto_engine::siblings.
103+
*
104+
* - I915_GEM_ENGINE_TYPE_PARALLEL: A parallel submission engine set, described
105+
* i915_gem_proto_engine::width, i915_gem_proto_engine::num_siblings, and
106+
* i915_gem_proto_engine::siblings.
100107
*/
101108
struct i915_gem_proto_engine {
102109
/** @type: Type of this engine */
@@ -105,10 +112,13 @@ struct i915_gem_proto_engine {
105112
/** @engine: Engine, for physical */
106113
struct intel_engine_cs *engine;
107114

108-
/** @num_siblings: Number of balanced siblings */
115+
/** @num_siblings: Number of balanced or parallel siblings */
109116
unsigned int num_siblings;
110117

111-
/** @siblings: Balanced siblings */
118+
/** @width: Width of each sibling */
119+
unsigned int width;
120+
121+
/** @siblings: Balanced siblings or num_siblings * width for parallel */
112122
struct intel_engine_cs **siblings;
113123

114124
/** @sseu: Client-set SSEU parameters */

‎drivers/gpu/drm/i915/gt/intel_context_types.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ struct intel_context_ops {
5555
void (*reset)(struct intel_context *ce);
5656
void (*destroy)(struct kref *kref);
5757

58-
/* virtual engine/context interface */
58+
/* virtual/parallel engine/context interface */
5959
struct intel_context *(*create_virtual)(struct intel_engine_cs **engine,
60-
unsigned int count);
60+
unsigned int count,
61+
unsigned long flags);
62+
struct intel_context *(*create_parallel)(struct intel_engine_cs **engines,
63+
unsigned int num_siblings,
64+
unsigned int width);
6165
struct intel_engine_cs *(*get_sibling)(struct intel_engine_cs *engine,
6266
unsigned int sibling);
6367
};
@@ -113,6 +117,7 @@ struct intel_context {
113117
#define CONTEXT_NOPREEMPT 8
114118
#define CONTEXT_LRCA_DIRTY 9
115119
#define CONTEXT_GUC_INIT 10
120+
#define CONTEXT_PERMA_PIN 11
116121

117122
struct {
118123
u64 timeout_us;

‎drivers/gpu/drm/i915/gt/intel_engine.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,19 @@ intel_engine_has_preempt_reset(const struct intel_engine_cs *engine)
282282
return intel_engine_has_preemption(engine);
283283
}
284284

285+
#define FORCE_VIRTUAL BIT(0)
285286
struct intel_context *
286287
intel_engine_create_virtual(struct intel_engine_cs **siblings,
287-
unsigned int count);
288+
unsigned int count, unsigned long flags);
289+
290+
static inline struct intel_context *
291+
intel_engine_create_parallel(struct intel_engine_cs **engines,
292+
unsigned int num_engines,
293+
unsigned int width)
294+
{
295+
GEM_BUG_ON(!engines[0]->cops->create_parallel);
296+
return engines[0]->cops->create_parallel(engines, num_engines, width);
297+
}
288298

289299
static inline bool
290300
intel_virtual_engine_has_heartbeat(const struct intel_engine_cs *engine)

‎drivers/gpu/drm/i915/gt/intel_engine_cs.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,16 +1953,16 @@ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine, ktime_t *now)
19531953

19541954
struct intel_context *
19551955
intel_engine_create_virtual(struct intel_engine_cs **siblings,
1956-
unsigned int count)
1956+
unsigned int count, unsigned long flags)
19571957
{
19581958
if (count == 0)
19591959
return ERR_PTR(-EINVAL);
19601960

1961-
if (count == 1)
1961+
if (count == 1 && !(flags & FORCE_VIRTUAL))
19621962
return intel_context_create(siblings[0]);
19631963

19641964
GEM_BUG_ON(!siblings[0]->cops->create_virtual);
1965-
return siblings[0]->cops->create_virtual(siblings, count);
1965+
return siblings[0]->cops->create_virtual(siblings, count, flags);
19661966
}
19671967

19681968
struct i915_request *

0 commit comments

Comments
 (0)