Skip to content

Commit d61345f

Browse files
committed
drm/i915/selftests: Exercise all copy engines with the blt routines
Just to remove an obnoxious HAS_ENGINES(), and in the process make the code agnostic to the availabilty of any particular engine by making it exercise any and all such engines declared on the system. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Matthew Auld <matthew.auld@intel.com> Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200604123641.767-1-chris@chris-wilson.co.uk
1 parent 34becfd commit d61345f

File tree

5 files changed

+80
-24
lines changed

5 files changed

+80
-24
lines changed

drivers/gpu/drm/i915/gem/selftests/i915_gem_client_blt.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,5 @@ int i915_gem_client_blt_live_selftests(struct drm_i915_private *i915)
702702
if (intel_gt_is_wedged(&i915->gt))
703703
return 0;
704704

705-
if (!HAS_ENGINE(i915, BCS0))
706-
return 0;
707-
708705
return i915_live_subtests(tests, i915);
709706
}

drivers/gpu/drm/i915/gem/selftests/i915_gem_object_blt.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int perf_copy_blt(void *arg)
193193
}
194194

195195
struct igt_thread_arg {
196-
struct drm_i915_private *i915;
196+
struct intel_engine_cs *engine;
197197
struct i915_gem_context *ctx;
198198
struct file *file;
199199
struct rnd_state prng;
@@ -203,7 +203,7 @@ struct igt_thread_arg {
203203
static int igt_fill_blt_thread(void *arg)
204204
{
205205
struct igt_thread_arg *thread = arg;
206-
struct drm_i915_private *i915 = thread->i915;
206+
struct intel_engine_cs *engine = thread->engine;
207207
struct rnd_state *prng = &thread->prng;
208208
struct drm_i915_gem_object *obj;
209209
struct i915_gem_context *ctx;
@@ -215,15 +215,15 @@ static int igt_fill_blt_thread(void *arg)
215215

216216
ctx = thread->ctx;
217217
if (!ctx) {
218-
ctx = live_context(i915, thread->file);
218+
ctx = live_context_for_engine(engine, thread->file);
219219
if (IS_ERR(ctx))
220220
return PTR_ERR(ctx);
221221

222222
prio = i915_prandom_u32_max_state(I915_PRIORITY_MAX, prng);
223223
ctx->sched.priority = I915_USER_PRIORITY(prio);
224224
}
225225

226-
ce = i915_gem_context_get_engine(ctx, BCS0);
226+
ce = i915_gem_context_get_engine(ctx, 0);
227227
GEM_BUG_ON(IS_ERR(ce));
228228

229229
/*
@@ -256,7 +256,7 @@ static int igt_fill_blt_thread(void *arg)
256256
pr_debug("%s with phys_sz= %x, sz=%x, val=%x\n", __func__,
257257
phys_sz, sz, val);
258258

259-
obj = huge_gem_object(i915, phys_sz, sz);
259+
obj = huge_gem_object(engine->i915, phys_sz, sz);
260260
if (IS_ERR(obj)) {
261261
err = PTR_ERR(obj);
262262
goto err_flush;
@@ -321,7 +321,7 @@ static int igt_fill_blt_thread(void *arg)
321321
static int igt_copy_blt_thread(void *arg)
322322
{
323323
struct igt_thread_arg *thread = arg;
324-
struct drm_i915_private *i915 = thread->i915;
324+
struct intel_engine_cs *engine = thread->engine;
325325
struct rnd_state *prng = &thread->prng;
326326
struct drm_i915_gem_object *src, *dst;
327327
struct i915_gem_context *ctx;
@@ -333,15 +333,15 @@ static int igt_copy_blt_thread(void *arg)
333333

334334
ctx = thread->ctx;
335335
if (!ctx) {
336-
ctx = live_context(i915, thread->file);
336+
ctx = live_context_for_engine(engine, thread->file);
337337
if (IS_ERR(ctx))
338338
return PTR_ERR(ctx);
339339

340340
prio = i915_prandom_u32_max_state(I915_PRIORITY_MAX, prng);
341341
ctx->sched.priority = I915_USER_PRIORITY(prio);
342342
}
343343

344-
ce = i915_gem_context_get_engine(ctx, BCS0);
344+
ce = i915_gem_context_get_engine(ctx, 0);
345345
GEM_BUG_ON(IS_ERR(ce));
346346

347347
/*
@@ -374,7 +374,7 @@ static int igt_copy_blt_thread(void *arg)
374374
pr_debug("%s with phys_sz= %x, sz=%x, val=%x\n", __func__,
375375
phys_sz, sz, val);
376376

377-
src = huge_gem_object(i915, phys_sz, sz);
377+
src = huge_gem_object(engine->i915, phys_sz, sz);
378378
if (IS_ERR(src)) {
379379
err = PTR_ERR(src);
380380
goto err_flush;
@@ -394,7 +394,7 @@ static int igt_copy_blt_thread(void *arg)
394394
if (!(src->cache_coherent & I915_BO_CACHE_COHERENT_FOR_READ))
395395
src->cache_dirty = true;
396396

397-
dst = huge_gem_object(i915, phys_sz, sz);
397+
dst = huge_gem_object(engine->i915, phys_sz, sz);
398398
if (IS_ERR(dst)) {
399399
err = PTR_ERR(dst);
400400
goto err_put_src;
@@ -456,7 +456,7 @@ static int igt_copy_blt_thread(void *arg)
456456
return err;
457457
}
458458

459-
static int igt_threaded_blt(struct drm_i915_private *i915,
459+
static int igt_threaded_blt(struct intel_engine_cs *engine,
460460
int (*blt_fn)(void *arg),
461461
unsigned int flags)
462462
#define SINGLE_CTX BIT(0)
@@ -477,22 +477,22 @@ static int igt_threaded_blt(struct drm_i915_private *i915,
477477
if (!thread)
478478
goto out_tsk;
479479

480-
thread[0].file = mock_file(i915);
480+
thread[0].file = mock_file(engine->i915);
481481
if (IS_ERR(thread[0].file)) {
482482
err = PTR_ERR(thread[0].file);
483483
goto out_thread;
484484
}
485485

486486
if (flags & SINGLE_CTX) {
487-
thread[0].ctx = live_context(i915, thread[0].file);
487+
thread[0].ctx = live_context_for_engine(engine, thread[0].file);
488488
if (IS_ERR(thread[0].ctx)) {
489489
err = PTR_ERR(thread[0].ctx);
490490
goto out_file;
491491
}
492492
}
493493

494494
for (i = 0; i < n_cpus; ++i) {
495-
thread[i].i915 = i915;
495+
thread[i].engine = engine;
496496
thread[i].file = thread[0].file;
497497
thread[i].ctx = thread[0].ctx;
498498
thread[i].n_cpus = n_cpus;
@@ -532,24 +532,40 @@ static int igt_threaded_blt(struct drm_i915_private *i915,
532532
return err;
533533
}
534534

535+
static int test_copy_engines(struct drm_i915_private *i915,
536+
int (*fn)(void *arg),
537+
unsigned int flags)
538+
{
539+
struct intel_engine_cs *engine;
540+
int ret;
541+
542+
for_each_uabi_class_engine(engine, I915_ENGINE_CLASS_COPY, i915) {
543+
ret = igt_threaded_blt(engine, fn, flags);
544+
if (ret)
545+
return ret;
546+
}
547+
548+
return 0;
549+
}
550+
535551
static int igt_fill_blt(void *arg)
536552
{
537-
return igt_threaded_blt(arg, igt_fill_blt_thread, 0);
553+
return test_copy_engines(arg, igt_fill_blt_thread, 0);
538554
}
539555

540556
static int igt_fill_blt_ctx0(void *arg)
541557
{
542-
return igt_threaded_blt(arg, igt_fill_blt_thread, SINGLE_CTX);
558+
return test_copy_engines(arg, igt_fill_blt_thread, SINGLE_CTX);
543559
}
544560

545561
static int igt_copy_blt(void *arg)
546562
{
547-
return igt_threaded_blt(arg, igt_copy_blt_thread, 0);
563+
return test_copy_engines(arg, igt_copy_blt_thread, 0);
548564
}
549565

550566
static int igt_copy_blt_ctx0(void *arg)
551567
{
552-
return igt_threaded_blt(arg, igt_copy_blt_thread, SINGLE_CTX);
568+
return test_copy_engines(arg, igt_copy_blt_thread, SINGLE_CTX);
553569
}
554570

555571
int i915_gem_object_blt_live_selftests(struct drm_i915_private *i915)
@@ -564,9 +580,6 @@ int i915_gem_object_blt_live_selftests(struct drm_i915_private *i915)
564580
if (intel_gt_is_wedged(&i915->gt))
565581
return 0;
566582

567-
if (!HAS_ENGINE(i915, BCS0))
568-
return 0;
569-
570583
return i915_live_subtests(tests, i915);
571584
}
572585

drivers/gpu/drm/i915/gem/selftests/mock_context.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,43 @@ live_context(struct drm_i915_private *i915, struct file *file)
9999
return ERR_PTR(err);
100100
}
101101

102+
struct i915_gem_context *
103+
live_context_for_engine(struct intel_engine_cs *engine, struct file *file)
104+
{
105+
struct i915_gem_engines *engines;
106+
struct i915_gem_context *ctx;
107+
struct intel_context *ce;
108+
109+
engines = alloc_engines(1);
110+
if (!engines)
111+
return ERR_PTR(-ENOMEM);
112+
113+
ctx = live_context(engine->i915, file);
114+
if (IS_ERR(ctx)) {
115+
__free_engines(engines, 0);
116+
return ctx;
117+
}
118+
119+
ce = intel_context_create(engine);
120+
if (IS_ERR(ce)) {
121+
__free_engines(engines, 0);
122+
return ERR_CAST(ce);
123+
}
124+
125+
intel_context_set_gem(ce, ctx);
126+
engines->engines[0] = ce;
127+
engines->num_engines = 1;
128+
129+
mutex_lock(&ctx->engines_mutex);
130+
i915_gem_context_set_user_engines(ctx);
131+
engines = rcu_replace_pointer(ctx->engines, engines, 1);
132+
mutex_unlock(&ctx->engines_mutex);
133+
134+
engines_idle_release(ctx, engines);
135+
136+
return ctx;
137+
}
138+
102139
struct i915_gem_context *
103140
kernel_context(struct drm_i915_private *i915)
104141
{

drivers/gpu/drm/i915/gem/selftests/mock_context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
struct file;
1111
struct drm_i915_private;
12+
struct intel_engine_cs;
1213

1314
void mock_init_contexts(struct drm_i915_private *i915);
1415

@@ -21,6 +22,9 @@ void mock_context_close(struct i915_gem_context *ctx);
2122
struct i915_gem_context *
2223
live_context(struct drm_i915_private *i915, struct file *file);
2324

25+
struct i915_gem_context *
26+
live_context_for_engine(struct intel_engine_cs *engine, struct file *file);
27+
2428
struct i915_gem_context *kernel_context(struct drm_i915_private *i915);
2529
void kernel_context_close(struct i915_gem_context *ctx);
2630

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,11 @@ static inline struct drm_i915_private *pdev_to_i915(struct pci_dev *pdev)
12611261
(engine__); \
12621262
(engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))
12631263

1264+
#define for_each_uabi_class_engine(engine__, class__, i915__) \
1265+
for ((engine__) = intel_engine_lookup_user((i915__), (class__), 0); \
1266+
(engine__) && (engine__)->uabi_class == (class__); \
1267+
(engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))
1268+
12641269
#define I915_GTT_OFFSET_NONE ((u32)-1)
12651270

12661271
/*

0 commit comments

Comments
 (0)