1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
/*
* Copyright © 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/**
* TEST: kms busy
* Category: Display
* Description: Basic check of KMS ABI with busy framebuffers.
*/
#include <sys/poll.h>
#include <signal.h>
#include <time.h>
#include "i915/gem.h"
#include "igt.h"
IGT_TEST_DESCRIPTION("Basic check of KMS ABI with busy framebuffers.");
static bool all_pipes = false;
static void
set_fb_on_crtc(igt_display_t *dpy, int pipe,
igt_output_t *output, struct igt_fb *fb)
{
drmModeModeInfoPtr mode;
igt_plane_t *primary;
igt_output_set_pipe(output, pipe);
mode = igt_output_get_mode(output);
igt_create_pattern_fb(dpy->drm_fd, mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888,
I915_FORMAT_MOD_X_TILED, fb);
primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
igt_plane_set_fb(primary, fb);
}
static void do_cleanup_display(igt_display_t *dpy)
{
enum pipe pipe;
igt_output_t *output;
igt_plane_t *plane;
for_each_pipe(dpy, pipe)
for_each_plane_on_pipe(dpy, pipe, plane)
igt_plane_set_fb(plane, NULL);
for_each_connected_output(dpy, output)
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit2(dpy, dpy->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
}
static void flip_to_fb(igt_display_t *dpy, int pipe,
igt_output_t *output,
struct igt_fb *fb, int timeout,
const char *name, bool modeset)
{
struct pollfd pfd = { .fd = dpy->drm_fd, .events = POLLIN };
struct drm_event_vblank ev;
IGT_CORK_FENCE(cork);
uint64_t ahnd = get_reloc_ahnd(dpy->drm_fd, 0);
igt_spin_t *t;
int fence;
fence = igt_cork_plug(&cork, dpy->drm_fd);
t = igt_spin_new(dpy->drm_fd,
.ahnd = ahnd,
.fence = fence,
.dependency = fb->gem_handle,
.flags = IGT_SPIN_FENCE_IN);
close(fence);
igt_fork(child, 1) {
igt_assert(gem_bo_busy(dpy->drm_fd, fb->gem_handle));
if (!modeset)
do_or_die(drmModePageFlip(dpy->drm_fd,
dpy->pipes[pipe].crtc_id, fb->fb_id,
DRM_MODE_PAGE_FLIP_EVENT, fb));
else {
igt_plane_set_fb(igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY), fb);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit_atomic(dpy,
DRM_MODE_ATOMIC_NONBLOCK |
DRM_MODE_PAGE_FLIP_EVENT |
DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
}
igt_assert_f(poll(&pfd, 1, timeout) == 0,
"flip completed whilst %s was busy [%d]\n",
name, gem_bo_busy(dpy->drm_fd, fb->gem_handle));
igt_assert(gem_bo_busy(dpy->drm_fd, fb->gem_handle));
igt_cork_unplug(&cork);
}
igt_waitchildren_timeout(5 * timeout,
"flip blocked waiting for busy bo\n");
igt_spin_end(t);
igt_cork_unplug(&cork);
igt_assert(read(dpy->drm_fd, &ev, sizeof(ev)) == sizeof(ev));
igt_assert(poll(&pfd, 1, 0) == 0);
if (modeset) {
gem_quiescent_gpu(dpy->drm_fd);
/* Clear old mode blob. */
igt_pipe_refresh(dpy, pipe, true);
igt_output_set_pipe(output, pipe);
igt_display_commit2(dpy, COMMIT_ATOMIC);
}
igt_spin_free(dpy->drm_fd, t);
put_ahnd(ahnd);
}
/**
* SUBTEST: basic
* Description: Test for basic check of KMS ABI with busy framebuffers.
* Driver requirement: i915
* Functionality: kms_core
* Mega feature: General Display Features
* Test category: functionality test
*
* SUBTEST: basic-hang
* Description: Test for basic check of KMS ABI with busy framebuffers.
* Driver requirement: i915
* Functionality: kms_core, hang
* Mega feature: General Display Features
* Test category: functionality test
*/
static void test_flip(igt_display_t *dpy, int pipe,
igt_output_t *output, bool modeset)
{
struct igt_fb fb[2];
int warmup[] = { 0, 1, 0, -1 };
struct timespec tv = {};
int timeout;
if (modeset)
igt_require(dpy->is_atomic);
igt_info("Using (pipe %s + %s) to run the subtest.\n",
kmstest_pipe_name(pipe), igt_output_name(output));
igt_display_reset(dpy);
set_fb_on_crtc(dpy, pipe, output, &fb[0]);
igt_display_commit2(dpy, COMMIT_LEGACY);
igt_create_pattern_fb(dpy->drm_fd,
fb[0].width, fb[0].height,
DRM_FORMAT_XRGB8888,
I915_FORMAT_MOD_X_TILED,
&fb[1]);
/* Bind both fb to the display (such that they are ready for future
* flips without stalling for the bind) leaving fb[0] as bound.
*/
igt_nsec_elapsed(&tv);
for (int i = 0; warmup[i] != -1; i++) {
struct drm_event_vblank ev;
do_or_die(drmModePageFlip(dpy->drm_fd,
dpy->pipes[pipe].crtc_id,
fb[warmup[i]].fb_id,
DRM_MODE_PAGE_FLIP_EVENT,
&fb[warmup[i]]));
igt_assert(read(dpy->drm_fd, &ev, sizeof(ev)) == sizeof(ev));
}
timeout = igt_nsec_elapsed(&tv) / 1000 / 1000;
igt_info("Using timeout of %dms\n", timeout);
/* Make the frontbuffer busy and try to flip to itself */
flip_to_fb(dpy, pipe, output, &fb[0], timeout, "fb[0]", modeset);
/* Repeat for flip to second buffer */
flip_to_fb(dpy, pipe, output, &fb[1], timeout, "fb[1]", modeset);
do_cleanup_display(dpy);
igt_remove_fb(dpy->drm_fd, &fb[1]);
igt_remove_fb(dpy->drm_fd, &fb[0]);
}
static void test_atomic_commit_hang(igt_display_t *dpy, igt_plane_t *primary,
struct igt_fb *busy_fb)
{
uint64_t ahnd = get_reloc_ahnd(dpy->drm_fd, 0);
igt_spin_t *t = igt_spin_new(dpy->drm_fd,
.ahnd = ahnd,
.dependency = busy_fb->gem_handle,
.flags = IGT_SPIN_NO_PREEMPTION);
struct pollfd pfd = { .fd = dpy->drm_fd, .events = POLLIN };
unsigned flags = 0;
struct drm_event_vblank ev;
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
flags |= DRM_MODE_ATOMIC_NONBLOCK;
flags |= DRM_MODE_PAGE_FLIP_EVENT;
igt_display_commit_atomic(dpy, flags, NULL);
igt_fork(child, 1) {
/*
* bit of a hack, just set atomic commit to NULL fb to make sure
* that we don't wait for the new update to complete.
*/
igt_plane_set_fb(primary, NULL);
igt_display_commit_atomic(dpy, 0, NULL);
igt_assert_f(poll(&pfd, 1, 1) > 0,
"nonblocking update completed whilst fb[%d] was still busy [%d]\n",
busy_fb->fb_id, gem_bo_busy(dpy->drm_fd, busy_fb->gem_handle));
}
igt_waitchildren();
igt_assert(read(dpy->drm_fd, &ev, sizeof(ev)) == sizeof(ev));
igt_spin_free(dpy->drm_fd, t);
put_ahnd(ahnd);
}
/**
* SUBTEST: extended-modeset-hang-%s
* Description: Test for basic check of KMS ABI with busy framebuffers.
* Driver requirement: i915
* Functionality: kms_core, hang
* Mega feature: General Display Features
* Test category: functionality test
*
* arg[1]:
*
* @newfb: New framebuffer
* @oldfb: Old framebuffer
* @newfb-with-reset: New framebuffer with reset
* @oldfb-with-reset: Old framebuffer with reset
*/
/**
* SUBTEST: extended-pageflip-hang-%s
* Description: Test for basic check of KMS ABI with busy framebuffers.
* Driver requirement: i915
* Functionality: kms_core, hang
* Mega feature: General Display Features
* Test category: functionality test
*
* arg[1]:
*
* @newfb: New framebuffer
* @oldfb: Old framebuffer
*/
static void test_hang(igt_display_t *dpy,
enum pipe pipe, igt_output_t *output,
bool modeset, bool hang_newfb)
{
struct igt_fb fb[2];
igt_plane_t *primary;
igt_info("Using (pipe %s + %s) to run the subtest.\n",
kmstest_pipe_name(pipe), igt_output_name(output));
igt_display_reset(dpy);
set_fb_on_crtc(dpy, pipe, output, &fb[0]);
igt_display_commit2(dpy, COMMIT_ATOMIC);
primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
igt_create_pattern_fb(dpy->drm_fd,
fb[0].width, fb[0].height,
DRM_FORMAT_XRGB8888,
I915_FORMAT_MOD_X_TILED,
&fb[1]);
if (modeset) {
/* Test modeset disable with hang */
igt_output_set_pipe(output, PIPE_NONE);
igt_plane_set_fb(primary, &fb[1]);
test_atomic_commit_hang(dpy, primary, &fb[hang_newfb]);
/* Test modeset enable with hang */
igt_plane_set_fb(primary, &fb[0]);
igt_output_set_pipe(output, pipe);
test_atomic_commit_hang(dpy, primary, &fb[!hang_newfb]);
} else {
/*
* Test what happens with a single hanging pageflip.
* This always completes early, because we have some
* timeouts taking care of it.
*/
igt_plane_set_fb(primary, &fb[1]);
test_atomic_commit_hang(dpy, primary, &fb[hang_newfb]);
}
do_cleanup_display(dpy);
igt_remove_fb(dpy->drm_fd, &fb[1]);
igt_remove_fb(dpy->drm_fd, &fb[0]);
}
/**
* SUBTEST: extended-pageflip-modeset-hang-oldfb
* Description: Test for basic check of KMS ABI with busy framebuffers.
* Driver requirement: i915
* Functionality: kms_core, hang
* Mega feature: General Display Features
* Test category: functionality test
*/
static void
test_pageflip_modeset_hang(igt_display_t *dpy,
igt_output_t *output, enum pipe pipe)
{
struct igt_fb fb;
struct drm_event_vblank ev;
igt_plane_t *primary;
igt_spin_t *t;
uint64_t ahnd = get_reloc_ahnd(dpy->drm_fd, 0);
igt_info("Using (pipe %s + %s) to run the subtest.\n",
kmstest_pipe_name(pipe), igt_output_name(output));
igt_display_reset(dpy);
set_fb_on_crtc(dpy, pipe, output, &fb);
primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
igt_display_commit2(dpy, dpy->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
t = igt_spin_new(dpy->drm_fd,
.ahnd = ahnd,
.dependency = fb.gem_handle,
.flags = IGT_SPIN_NO_PREEMPTION);
do_or_die(drmModePageFlip(dpy->drm_fd, dpy->pipes[pipe].crtc_id, fb.fb_id, DRM_MODE_PAGE_FLIP_EVENT, &fb));
/* Kill crtc with hung fb */
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit2(dpy, dpy->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
igt_assert(read(dpy->drm_fd, &ev, sizeof(ev)) == sizeof(ev));
igt_spin_free(dpy->drm_fd, t);
put_ahnd(ahnd);
igt_remove_fb(dpy->drm_fd, &fb);
}
static bool
pipe_output_combo_valid(igt_display_t *dpy,
igt_output_t *output, enum pipe pipe)
{
bool ret = true;
igt_display_reset(dpy);
igt_output_set_pipe(output, pipe);
if (!i915_pipe_output_combo_valid(dpy))
ret = false;
igt_output_set_pipe(output, PIPE_NONE);
return ret;
}
static int opt_handler(int opt, int opt_index, void *data)
{
switch (opt) {
case 'e':
all_pipes = true;
break;
default:
return IGT_OPT_HANDLER_ERROR;
}
return IGT_OPT_HANDLER_SUCCESS;
}
static void gpu_engines_init_timeouts(int fd, int max_engines,
int *num_engines, struct gem_engine_properties *props)
{
const struct intel_execution_engine2 *e;
*num_engines = 0;
for_each_physical_engine(fd, e) {
igt_assert(*num_engines < max_engines);
props[*num_engines].engine = e;
props[*num_engines].preempt_timeout = 0;
props[*num_engines].heartbeat_interval = 250;
gem_engine_properties_configure(fd, &props[*num_engines]);
(*num_engines)++;
}
}
static void gpu_engines_restore_timeouts(int fd, int num_engines, const struct gem_engine_properties *props)
{
int i;
for (i = 0; i < num_engines; i++)
gem_engine_properties_restore(fd, &props[i]);
}
const char *help_str =
" -e \tRun on all pipes. (By default subtests will run on two pipes)\n";
igt_main_args("e", NULL, help_str, opt_handler, NULL)
{
igt_display_t display = { .drm_fd = -1, .n_pipes = IGT_MAX_PIPES };
enum pipe pipe, active_pipes[IGT_MAX_PIPES];
igt_output_t *output;
uint32_t last_pipe = 0;
int i;
struct {
const char *name;
bool modeset;
bool hang_newfb;
bool reset;
} tests[] = {
{ "extended-pageflip-hang-oldfb", false, false, false },
{ "extended-pageflip-hang-newfb", false, true, false },
{ "extended-modeset-hang-oldfb", true, false, false },
{ "extended-modeset-hang-newfb", true, true, false },
{ "extended-modeset-hang-oldfb-with-reset", true, false, true },
{ "extended-modeset-hang-newfb-with-reset", true, true, true },
};
int fd;
igt_fixture {
fd = drm_open_driver_master(DRIVER_INTEL);
igt_require_gem(fd);
gem_require_mmap_device_coherent(fd);
igt_require(gem_has_ring(fd, I915_EXEC_DEFAULT));
kmstest_set_vt_graphics_mode();
igt_display_require(&display, fd);
igt_display_require_output(&display);
/* Get active pipes. */
for_each_pipe(&display, pipe)
active_pipes[last_pipe++] = pipe;
last_pipe--;
}
/* XXX Extend to cover atomic rendering tests to all planes + legacy */
igt_describe("Test for basic check of KMS ABI with busy framebuffers.");
igt_subtest_with_dynamic("basic") { /* just run on the first pipe */
for_each_pipe_with_single_output(&display, pipe, output) {
if (!pipe_output_combo_valid(&display, output, pipe))
continue;
igt_dynamic("flip")
test_flip(&display, pipe, output, false);
igt_dynamic("modeset")
test_flip(&display, pipe, output, true);
break;
}
}
igt_subtest_with_dynamic("basic-hang") {
igt_hang_t hang = igt_allow_hang(display.drm_fd, 0, 0);
errno = 0;
for_each_pipe_with_single_output(&display, pipe, output) {
if (!pipe_output_combo_valid(&display, output, pipe))
continue;
if (!all_pipes && pipe != active_pipes[0] &&
pipe != active_pipes[last_pipe])
continue;
igt_dynamic_f("flip-pipe-%s", kmstest_pipe_name(pipe))
test_flip(&display, pipe, output, false);
igt_dynamic_f("modeset-pipe-%s", kmstest_pipe_name(pipe))
test_flip(&display, pipe, output, true);
}
igt_disallow_hang(display.drm_fd, hang);
}
igt_subtest_with_dynamic("extended-pageflip-modeset-hang-oldfb") {
igt_hang_t hang = igt_allow_hang(display.drm_fd, 0, 0);
errno = 0;
for_each_pipe_with_single_output(&display, pipe, output) {
if (!pipe_output_combo_valid(&display, output, pipe))
continue;
if (!all_pipes && pipe != active_pipes[0] &&
pipe != active_pipes[last_pipe])
continue;
igt_dynamic_f("pipe-%s", kmstest_pipe_name(pipe))
test_pageflip_modeset_hang(&display, output, pipe);
}
igt_disallow_hang(display.drm_fd, hang);
}
for (i = 0; i < sizeof(tests) / sizeof (tests[0]); i++) {
struct gem_engine_properties saved_gpu_timeouts[GEM_MAX_ENGINES];
int num_engines;
igt_fixture {
igt_require(display.is_atomic);
if (tests[i].reset)
gpu_engines_init_timeouts(display.drm_fd,
ARRAY_SIZE(saved_gpu_timeouts),
&num_engines, saved_gpu_timeouts);
}
igt_subtest_with_dynamic(tests[i].name) {
igt_hang_t hang;
errno = 0;
hang = igt_allow_hang(display.drm_fd, 0, 0);
for_each_pipe_with_single_output(&display, pipe, output) {
if (!pipe_output_combo_valid(&display, output, pipe))
continue;
if (!all_pipes && pipe != active_pipes[0] &&
pipe != active_pipes[last_pipe])
continue;
igt_dynamic_f("pipe-%s", kmstest_pipe_name(pipe)) {
if (tests[i].reset)
igt_set_module_param_int(display.drm_fd, "force_reset_modeset_test", 1);
test_hang(&display, pipe, output,
tests[i].modeset, tests[i].hang_newfb);
if (tests[i].reset)
igt_set_module_param_int(display.drm_fd, "force_reset_modeset_test", 0);
}
}
igt_disallow_hang(display.drm_fd, hang);
}
igt_fixture {
if (tests[i].reset)
gpu_engines_restore_timeouts(display.drm_fd, num_engines, saved_gpu_timeouts);
}
}
igt_fixture {
igt_display_fini(&display);
drm_close_driver(display.drm_fd);
}
}
|