Skip to content

Commit c9d08cc

Browse files
committed
drm/i915/selftests: Mark up rpm wakerefs
Track the temporary wakerefs used within the selftests so that leaks are clear. v2: Add a couple of coarse annotations for mock selftests as we now loudly warn about the errors. Signed-off-by: Chris Wilson <[email protected]> Cc: Jani Nikula <[email protected]> Reviewed-by: Mika Kuoppala <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 2cb2cb5 commit c9d08cc

File tree

12 files changed

+138
-78
lines changed

12 files changed

+138
-78
lines changed

drivers/gpu/drm/i915/selftests/huge_pages.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,7 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *dev_priv)
17561756
};
17571757
struct drm_file *file;
17581758
struct i915_gem_context *ctx;
1759+
intel_wakeref_t wakeref;
17591760
int err;
17601761

17611762
if (!HAS_PPGTT(dev_priv)) {
@@ -1771,7 +1772,7 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *dev_priv)
17711772
return PTR_ERR(file);
17721773

17731774
mutex_lock(&dev_priv->drm.struct_mutex);
1774-
intel_runtime_pm_get(dev_priv);
1775+
wakeref = intel_runtime_pm_get(dev_priv);
17751776

17761777
ctx = live_context(dev_priv, file);
17771778
if (IS_ERR(ctx)) {
@@ -1785,7 +1786,7 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *dev_priv)
17851786
err = i915_subtests(tests, ctx);
17861787

17871788
out_unlock:
1788-
intel_runtime_pm_put_unchecked(dev_priv);
1789+
intel_runtime_pm_put(dev_priv, wakeref);
17891790
mutex_unlock(&dev_priv->drm.struct_mutex);
17901791

17911792
mock_file_free(dev_priv, file);

drivers/gpu/drm/i915/selftests/i915_gem.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ static int switch_to_context(struct drm_i915_private *i915,
1616
{
1717
struct intel_engine_cs *engine;
1818
enum intel_engine_id id;
19+
intel_wakeref_t wakeref;
1920
int err = 0;
2021

21-
intel_runtime_pm_get(i915);
22+
wakeref = intel_runtime_pm_get(i915);
2223

2324
for_each_engine(engine, i915, id) {
2425
struct i915_request *rq;
@@ -32,7 +33,7 @@ static int switch_to_context(struct drm_i915_private *i915,
3233
i915_request_add(rq);
3334
}
3435

35-
intel_runtime_pm_put_unchecked(i915);
36+
intel_runtime_pm_put(i915, wakeref);
3637

3738
return err;
3839
}
@@ -65,7 +66,9 @@ static void trash_stolen(struct drm_i915_private *i915)
6566

6667
static void simulate_hibernate(struct drm_i915_private *i915)
6768
{
68-
intel_runtime_pm_get(i915);
69+
intel_wakeref_t wakeref;
70+
71+
wakeref = intel_runtime_pm_get(i915);
6972

7073
/*
7174
* As a final sting in the tail, invalidate stolen. Under a real S4,
@@ -76,7 +79,7 @@ static void simulate_hibernate(struct drm_i915_private *i915)
7679
*/
7780
trash_stolen(i915);
7881

79-
intel_runtime_pm_put_unchecked(i915);
82+
intel_runtime_pm_put(i915, wakeref);
8083
}
8184

8285
static int pm_prepare(struct drm_i915_private *i915)
@@ -93,39 +96,45 @@ static int pm_prepare(struct drm_i915_private *i915)
9396

9497
static void pm_suspend(struct drm_i915_private *i915)
9598
{
96-
intel_runtime_pm_get(i915);
99+
intel_wakeref_t wakeref;
100+
101+
wakeref = intel_runtime_pm_get(i915);
97102

98103
i915_gem_suspend_gtt_mappings(i915);
99104
i915_gem_suspend_late(i915);
100105

101-
intel_runtime_pm_put_unchecked(i915);
106+
intel_runtime_pm_put(i915, wakeref);
102107
}
103108

104109
static void pm_hibernate(struct drm_i915_private *i915)
105110
{
106-
intel_runtime_pm_get(i915);
111+
intel_wakeref_t wakeref;
112+
113+
wakeref = intel_runtime_pm_get(i915);
107114

108115
i915_gem_suspend_gtt_mappings(i915);
109116

110117
i915_gem_freeze(i915);
111118
i915_gem_freeze_late(i915);
112119

113-
intel_runtime_pm_put_unchecked(i915);
120+
intel_runtime_pm_put(i915, wakeref);
114121
}
115122

116123
static void pm_resume(struct drm_i915_private *i915)
117124
{
125+
intel_wakeref_t wakeref;
126+
118127
/*
119128
* Both suspend and hibernate follow the same wakeup path and assume
120129
* that runtime-pm just works.
121130
*/
122-
intel_runtime_pm_get(i915);
131+
wakeref = intel_runtime_pm_get(i915);
123132

124133
intel_engines_sanitize(i915, false);
125134
i915_gem_sanitize(i915);
126135
i915_gem_resume(i915);
127136

128-
intel_runtime_pm_put_unchecked(i915);
137+
intel_runtime_pm_put(i915, wakeref);
129138
}
130139

131140
static int igt_gem_suspend(void *arg)

drivers/gpu/drm/i915/selftests/i915_gem_coherency.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ static int igt_gem_coherency(void *arg)
279279
struct drm_i915_private *i915 = arg;
280280
const struct igt_coherency_mode *read, *write, *over;
281281
struct drm_i915_gem_object *obj;
282+
intel_wakeref_t wakeref;
282283
unsigned long count, n;
283284
u32 *offsets, *values;
284285
int err = 0;
@@ -298,7 +299,7 @@ static int igt_gem_coherency(void *arg)
298299
values = offsets + ncachelines;
299300

300301
mutex_lock(&i915->drm.struct_mutex);
301-
intel_runtime_pm_get(i915);
302+
wakeref = intel_runtime_pm_get(i915);
302303
for (over = igt_coherency_mode; over->name; over++) {
303304
if (!over->set)
304305
continue;
@@ -376,7 +377,7 @@ static int igt_gem_coherency(void *arg)
376377
}
377378
}
378379
unlock:
379-
intel_runtime_pm_put_unchecked(i915);
380+
intel_runtime_pm_put(i915, wakeref);
380381
mutex_unlock(&i915->drm.struct_mutex);
381382
kfree(offsets);
382383
return err;

drivers/gpu/drm/i915/selftests/i915_gem_context.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ static int live_nop_switch(void *arg)
119119
struct intel_engine_cs *engine;
120120
struct i915_gem_context **ctx;
121121
enum intel_engine_id id;
122+
intel_wakeref_t wakeref;
122123
struct drm_file *file;
123124
struct live_test t;
124125
unsigned long n;
@@ -140,7 +141,7 @@ static int live_nop_switch(void *arg)
140141
return PTR_ERR(file);
141142

142143
mutex_lock(&i915->drm.struct_mutex);
143-
intel_runtime_pm_get(i915);
144+
wakeref = intel_runtime_pm_get(i915);
144145

145146
ctx = kcalloc(nctx, sizeof(*ctx), GFP_KERNEL);
146147
if (!ctx) {
@@ -243,7 +244,7 @@ static int live_nop_switch(void *arg)
243244
}
244245

245246
out_unlock:
246-
intel_runtime_pm_put_unchecked(i915);
247+
intel_runtime_pm_put(i915, wakeref);
247248
mutex_unlock(&i915->drm.struct_mutex);
248249
mock_file_free(i915, file);
249250
return err;
@@ -593,6 +594,8 @@ static int igt_ctx_exec(void *arg)
593594
}
594595

595596
for_each_engine(engine, i915, id) {
597+
intel_wakeref_t wakeref;
598+
596599
if (!engine->context_size)
597600
continue; /* No logical context support in HW */
598601

@@ -607,9 +610,9 @@ static int igt_ctx_exec(void *arg)
607610
}
608611
}
609612

610-
intel_runtime_pm_get(i915);
613+
wakeref = intel_runtime_pm_get(i915);
611614
err = gpu_fill(obj, ctx, engine, dw);
612-
intel_runtime_pm_put_unchecked(i915);
615+
intel_runtime_pm_put(i915, wakeref);
613616
if (err) {
614617
pr_err("Failed to fill dword %lu [%lu/%lu] with gpu (%s) in ctx %u [full-ppgtt? %s], err=%d\n",
615618
ndwords, dw, max_dwords(obj),
@@ -699,6 +702,8 @@ static int igt_ctx_readonly(void *arg)
699702
unsigned int id;
700703

701704
for_each_engine(engine, i915, id) {
705+
intel_wakeref_t wakeref;
706+
702707
if (!intel_engine_can_store_dword(engine))
703708
continue;
704709

@@ -713,9 +718,9 @@ static int igt_ctx_readonly(void *arg)
713718
i915_gem_object_set_readonly(obj);
714719
}
715720

716-
intel_runtime_pm_get(i915);
721+
wakeref = intel_runtime_pm_get(i915);
717722
err = gpu_fill(obj, ctx, engine, dw);
718-
intel_runtime_pm_put_unchecked(i915);
723+
intel_runtime_pm_put(i915, wakeref);
719724
if (err) {
720725
pr_err("Failed to fill dword %lu [%lu/%lu] with gpu (%s) in ctx %u [full-ppgtt? %s], err=%d\n",
721726
ndwords, dw, max_dwords(obj),
@@ -976,6 +981,7 @@ static int igt_vm_isolation(void *arg)
976981
struct drm_i915_private *i915 = arg;
977982
struct i915_gem_context *ctx_a, *ctx_b;
978983
struct intel_engine_cs *engine;
984+
intel_wakeref_t wakeref;
979985
struct drm_file *file;
980986
I915_RND_STATE(prng);
981987
unsigned long count;
@@ -1022,7 +1028,7 @@ static int igt_vm_isolation(void *arg)
10221028
GEM_BUG_ON(ctx_b->ppgtt->vm.total != vm_total);
10231029
vm_total -= I915_GTT_PAGE_SIZE;
10241030

1025-
intel_runtime_pm_get(i915);
1031+
wakeref = intel_runtime_pm_get(i915);
10261032

10271033
count = 0;
10281034
for_each_engine(engine, i915, id) {
@@ -1067,7 +1073,7 @@ static int igt_vm_isolation(void *arg)
10671073
count, RUNTIME_INFO(i915)->num_rings);
10681074

10691075
out_rpm:
1070-
intel_runtime_pm_put_unchecked(i915);
1076+
intel_runtime_pm_put(i915, wakeref);
10711077
out_unlock:
10721078
if (end_live_test(&t))
10731079
err = -EIO;
@@ -1165,6 +1171,7 @@ static int igt_switch_to_kernel_context(void *arg)
11651171
struct intel_engine_cs *engine;
11661172
struct i915_gem_context *ctx;
11671173
enum intel_engine_id id;
1174+
intel_wakeref_t wakeref;
11681175
int err;
11691176

11701177
/*
@@ -1175,7 +1182,7 @@ static int igt_switch_to_kernel_context(void *arg)
11751182
*/
11761183

11771184
mutex_lock(&i915->drm.struct_mutex);
1178-
intel_runtime_pm_get(i915);
1185+
wakeref = intel_runtime_pm_get(i915);
11791186

11801187
ctx = kernel_context(i915);
11811188
if (IS_ERR(ctx)) {
@@ -1200,7 +1207,7 @@ static int igt_switch_to_kernel_context(void *arg)
12001207
if (igt_flush_test(i915, I915_WAIT_LOCKED))
12011208
err = -EIO;
12021209

1203-
intel_runtime_pm_put_unchecked(i915);
1210+
intel_runtime_pm_put(i915, wakeref);
12041211
mutex_unlock(&i915->drm.struct_mutex);
12051212

12061213
kernel_context_close(ctx);

drivers/gpu/drm/i915/selftests/i915_gem_evict.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ static int igt_evict_contexts(void *arg)
336336
struct drm_mm_node node;
337337
struct reserved *next;
338338
} *reserved = NULL;
339+
intel_wakeref_t wakeref;
339340
struct drm_mm_node hole;
340341
unsigned long count;
341342
int err;
@@ -355,7 +356,7 @@ static int igt_evict_contexts(void *arg)
355356
return 0;
356357

357358
mutex_lock(&i915->drm.struct_mutex);
358-
intel_runtime_pm_get(i915);
359+
wakeref = intel_runtime_pm_get(i915);
359360

360361
/* Reserve a block so that we know we have enough to fit a few rq */
361362
memset(&hole, 0, sizeof(hole));
@@ -400,8 +401,10 @@ static int igt_evict_contexts(void *arg)
400401
struct drm_file *file;
401402

402403
file = mock_file(i915);
403-
if (IS_ERR(file))
404-
return PTR_ERR(file);
404+
if (IS_ERR(file)) {
405+
err = PTR_ERR(file);
406+
break;
407+
}
405408

406409
count = 0;
407410
mutex_lock(&i915->drm.struct_mutex);
@@ -464,7 +467,7 @@ static int igt_evict_contexts(void *arg)
464467
}
465468
if (drm_mm_node_allocated(&hole))
466469
drm_mm_remove_node(&hole);
467-
intel_runtime_pm_put_unchecked(i915);
470+
intel_runtime_pm_put(i915, wakeref);
468471
mutex_unlock(&i915->drm.struct_mutex);
469472

470473
return err;
@@ -480,14 +483,19 @@ int i915_gem_evict_mock_selftests(void)
480483
SUBTEST(igt_overcommit),
481484
};
482485
struct drm_i915_private *i915;
486+
intel_wakeref_t wakeref;
483487
int err;
484488

485489
i915 = mock_gem_device();
486490
if (!i915)
487491
return -ENOMEM;
488492

489493
mutex_lock(&i915->drm.struct_mutex);
494+
wakeref = intel_runtime_pm_get(i915);
495+
490496
err = i915_subtests(tests, i915);
497+
498+
intel_runtime_pm_put(i915, wakeref);
491499
mutex_unlock(&i915->drm.struct_mutex);
492500

493501
drm_dev_put(&i915->drm);

drivers/gpu/drm/i915/selftests/i915_gem_gtt.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ static int lowlevel_hole(struct drm_i915_private *i915,
275275

276276
for (n = 0; n < count; n++) {
277277
u64 addr = hole_start + order[n] * BIT_ULL(size);
278+
intel_wakeref_t wakeref;
278279

279280
GEM_BUG_ON(addr + BIT_ULL(size) > vm->total);
280281

@@ -293,9 +294,9 @@ static int lowlevel_hole(struct drm_i915_private *i915,
293294
mock_vma.node.size = BIT_ULL(size);
294295
mock_vma.node.start = addr;
295296

296-
intel_runtime_pm_get(i915);
297+
wakeref = intel_runtime_pm_get(i915);
297298
vm->insert_entries(vm, &mock_vma, I915_CACHE_NONE, 0);
298-
intel_runtime_pm_put_unchecked(i915);
299+
intel_runtime_pm_put(i915, wakeref);
299300
}
300301
count = n;
301302

@@ -1144,6 +1145,7 @@ static int igt_ggtt_page(void *arg)
11441145
struct drm_i915_private *i915 = arg;
11451146
struct i915_ggtt *ggtt = &i915->ggtt;
11461147
struct drm_i915_gem_object *obj;
1148+
intel_wakeref_t wakeref;
11471149
struct drm_mm_node tmp;
11481150
unsigned int *order, n;
11491151
int err;
@@ -1169,7 +1171,7 @@ static int igt_ggtt_page(void *arg)
11691171
if (err)
11701172
goto out_unpin;
11711173

1172-
intel_runtime_pm_get(i915);
1174+
wakeref = intel_runtime_pm_get(i915);
11731175

11741176
for (n = 0; n < count; n++) {
11751177
u64 offset = tmp.start + n * PAGE_SIZE;
@@ -1216,7 +1218,7 @@ static int igt_ggtt_page(void *arg)
12161218
kfree(order);
12171219
out_remove:
12181220
ggtt->vm.clear_range(&ggtt->vm, tmp.start, tmp.size);
1219-
intel_runtime_pm_put_unchecked(i915);
1221+
intel_runtime_pm_put(i915, wakeref);
12201222
drm_mm_remove_node(&tmp);
12211223
out_unpin:
12221224
i915_gem_object_unpin_pages(obj);

0 commit comments

Comments
 (0)