Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #define _GNU_SOURCE |
| 26 | #include <sched.h> |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 27 | #include <sys/poll.h> |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 28 | |
| 29 | #include "igt.h" |
Chris Wilson | 376b813 | 2016-07-03 09:42:38 +0100 | [diff] [blame] | 30 | #include "igt_rand.h" |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 31 | #include "igt_stats.h" |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 32 | |
Tomeu Vizoso | 047c999 | 2016-06-07 10:18:34 +0200 | [diff] [blame] | 33 | #if defined(__x86_64__) || defined(__i386__) |
| 34 | #define cpu_relax() __builtin_ia32_pause() |
| 35 | #else |
| 36 | #define cpu_relax() asm volatile("": : :"memory") |
| 37 | #endif |
| 38 | |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 39 | #ifndef DRM_CAP_CURSOR_WIDTH |
| 40 | #define DRM_CAP_CURSOR_WIDTH 0x8 |
| 41 | #endif |
| 42 | |
| 43 | #ifndef DRM_CAP_CURSOR_HEIGHT |
| 44 | #define DRM_CAP_CURSOR_HEIGHT 0x9 |
| 45 | #endif |
| 46 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 47 | IGT_TEST_DESCRIPTION("Stress legacy cursor ioctl"); |
| 48 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 49 | static void stress(igt_display_t *display, |
| 50 | int pipe, int num_children, unsigned mode, |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 51 | int timeout) |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 52 | { |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 53 | struct drm_mode_cursor arg; |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 54 | uint64_t *results; |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 55 | bool torture; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 56 | int n; |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 57 | unsigned crtc_id[I915_MAX_PIPES], num_crtcs; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 58 | |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 59 | torture = false; |
| 60 | if (num_children < 0) { |
| 61 | torture = true; |
| 62 | num_children = -num_children; |
| 63 | } |
| 64 | |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 65 | results = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 66 | igt_assert(results != MAP_FAILED); |
| 67 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 68 | memset(&arg, 0, sizeof(arg)); |
| 69 | arg.flags = DRM_MODE_CURSOR_BO; |
| 70 | arg.crtc_id = 0; |
| 71 | arg.width = 64; |
| 72 | arg.height = 64; |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 73 | arg.handle = kmstest_dumb_create(display->drm_fd, 64, 64, 32, NULL, NULL); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 74 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 75 | if (pipe < 0) { |
| 76 | num_crtcs = display->n_pipes; |
| 77 | for_each_pipe(display, n) { |
| 78 | arg.crtc_id = crtc_id[n] = display->pipes[n].crtc_id; |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 79 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg); |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 80 | } |
| 81 | } else { |
| 82 | num_crtcs = 1; |
| 83 | arg.crtc_id = crtc_id[0] = display->pipes[pipe].crtc_id; |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 84 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 85 | } |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 86 | |
| 87 | arg.flags = mode; |
Chris Wilson | dab6b6b | 2016-05-24 16:14:32 +0100 | [diff] [blame] | 88 | igt_fork(child, num_children) { |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 89 | struct sched_param rt = {.sched_priority = 99 }; |
| 90 | cpu_set_t allowed; |
| 91 | unsigned long count = 0; |
| 92 | |
| 93 | sched_setscheduler(getpid(), SCHED_RR, &rt); |
| 94 | |
| 95 | CPU_ZERO(&allowed); |
| 96 | CPU_SET(child, &allowed); |
| 97 | sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed); |
| 98 | |
Chris Wilson | 376b813 | 2016-07-03 09:42:38 +0100 | [diff] [blame] | 99 | hars_petruska_f54_1_random_perturb(child); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 100 | igt_until_timeout(timeout) { |
Chris Wilson | 376b813 | 2016-07-03 09:42:38 +0100 | [diff] [blame] | 101 | arg.crtc_id = crtc_id[hars_petruska_f54_1_random_unsafe() % num_crtcs]; |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 102 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 103 | count++; |
| 104 | } |
| 105 | |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 106 | igt_debug("[%d] count=%lu\n", child, count); |
| 107 | results[child] = count; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 108 | } |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 109 | if (torture) { |
| 110 | igt_fork(child, num_children) { |
| 111 | struct sched_param rt = {.sched_priority = 1 }; |
| 112 | cpu_set_t allowed; |
| 113 | unsigned long long count = 0; |
| 114 | |
| 115 | sched_setscheduler(getpid(), SCHED_RR, &rt); |
| 116 | |
| 117 | CPU_ZERO(&allowed); |
| 118 | CPU_SET(child, &allowed); |
| 119 | sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed); |
| 120 | igt_until_timeout(timeout) { |
| 121 | count++; |
Tomeu Vizoso | 047c999 | 2016-06-07 10:18:34 +0200 | [diff] [blame] | 122 | cpu_relax(); |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 123 | } |
| 124 | igt_debug("[hog:%d] count=%llu\n", child, count); |
| 125 | } |
| 126 | } |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 127 | igt_waitchildren(); |
| 128 | |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 129 | if (num_children > 1) { |
| 130 | igt_stats_t stats; |
| 131 | |
| 132 | igt_stats_init_with_size(&stats, num_children); |
| 133 | results[num_children] = 0; |
| 134 | for (int child = 0; child < num_children; child++) { |
| 135 | igt_stats_push(&stats, results[child]); |
| 136 | results[num_children] += results[child]; |
| 137 | } |
| 138 | igt_info("Total updates %llu (median of %d processes is %.2f)\n", |
| 139 | (long long)results[num_children], |
| 140 | num_children, |
| 141 | igt_stats_get_median(&stats)); |
| 142 | igt_stats_fini(&stats); |
| 143 | } else { |
| 144 | igt_info("Total updates %llu\n", (long long)results[0]); |
| 145 | } |
| 146 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 147 | gem_close(display->drm_fd, arg.handle); |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 148 | munmap(results, 4096); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 149 | } |
| 150 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 151 | static igt_output_t *set_fb_on_crtc(igt_display_t *display, int pipe, struct igt_fb *fb_info) |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 152 | { |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 153 | igt_output_t *output; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 154 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 155 | for_each_valid_output_on_pipe(display, pipe, output) { |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 156 | drmModeModeInfoPtr mode; |
| 157 | igt_plane_t *primary; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 158 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 159 | if (output->pending_crtc_idx_mask) |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 160 | continue; |
| 161 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 162 | igt_output_set_pipe(output, pipe); |
| 163 | mode = igt_output_get_mode(output); |
| 164 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 165 | igt_create_pattern_fb(display->drm_fd, |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 166 | mode->hdisplay, mode->vdisplay, |
| 167 | DRM_FORMAT_XRGB8888, I915_TILING_NONE, fb_info); |
| 168 | |
| 169 | primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
| 170 | igt_plane_set_fb(primary, fb_info); |
| 171 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 172 | return output; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 175 | return NULL; |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void set_cursor_on_pipe(igt_display_t *display, enum pipe pipe, struct igt_fb *fb) |
| 179 | { |
| 180 | igt_plane_t *plane, *cursor = NULL; |
| 181 | |
| 182 | for_each_plane_on_pipe(display, pipe, plane) { |
| 183 | if (!plane->is_cursor) |
| 184 | continue; |
| 185 | |
| 186 | cursor = plane; |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | igt_require(cursor); |
| 191 | igt_plane_set_fb(cursor, fb); |
| 192 | } |
| 193 | |
| 194 | static void populate_cursor_args(igt_display_t *display, enum pipe pipe, |
| 195 | struct drm_mode_cursor *arg, struct igt_fb *fb) |
| 196 | { |
| 197 | arg->crtc_id = display->pipes[pipe].crtc_id; |
| 198 | arg->flags = DRM_MODE_CURSOR_MOVE; |
| 199 | arg->x = 128; |
| 200 | arg->y = 128; |
| 201 | arg->width = fb->width; |
| 202 | arg->height = fb->height; |
| 203 | arg->handle = fb->gem_handle; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 204 | arg[1] = *arg; |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static void do_cleanup_display(igt_display_t *display) |
| 208 | { |
| 209 | enum pipe pipe; |
| 210 | igt_output_t *output; |
| 211 | igt_plane_t *plane; |
| 212 | |
| 213 | for_each_pipe(display, pipe) |
| 214 | for_each_plane_on_pipe(display, pipe, plane) |
| 215 | igt_plane_set_fb(plane, NULL); |
| 216 | |
| 217 | for_each_connected_output(display, output) |
| 218 | igt_output_set_pipe(output, PIPE_NONE); |
| 219 | |
| 220 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 223 | static enum pipe find_connected_pipe(igt_display_t *display, bool second) |
| 224 | { |
| 225 | enum pipe pipe, first = PIPE_NONE; |
| 226 | igt_output_t *output; |
| 227 | igt_output_t *first_output = NULL; |
| 228 | bool found = false; |
| 229 | |
| 230 | for_each_pipe_with_valid_output(display, pipe, output) { |
| 231 | if (first == pipe || output == first_output) |
| 232 | continue; |
| 233 | |
| 234 | if (second) { |
| 235 | first = pipe; |
| 236 | first_output = output; |
| 237 | second = false; |
| 238 | continue; |
| 239 | } |
| 240 | |
| 241 | found = true; |
| 242 | break; |
| 243 | } |
| 244 | |
| 245 | if (first_output) |
| 246 | igt_require_f(found, "No second valid output found\n"); |
| 247 | else |
Chris Wilson | 1105d9f | 2016-08-23 18:03:51 +0100 | [diff] [blame] | 248 | igt_require_f(found, "No valid outputs found\n"); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 249 | |
| 250 | return pipe; |
| 251 | } |
| 252 | |
| 253 | static void flip_nonblocking(igt_display_t *display, enum pipe pipe, bool atomic, struct igt_fb *fb) |
| 254 | { |
| 255 | igt_plane_t *primary = &display->pipes[pipe].planes[IGT_PLANE_PRIMARY]; |
| 256 | |
| 257 | if (!atomic) { |
| 258 | /* Schedule a nonblocking flip for the next vblank */ |
| 259 | do_or_die(drmModePageFlip(display->drm_fd, display->pipes[pipe].crtc_id, fb->fb_id, |
| 260 | DRM_MODE_PAGE_FLIP_EVENT, fb)); |
| 261 | } else { |
| 262 | igt_plane_set_fb(primary, fb); |
| 263 | igt_display_commit_atomic(display, DRM_MODE_ATOMIC_NONBLOCK | DRM_MODE_PAGE_FLIP_EVENT, fb); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | enum flip_test { |
| 268 | flip_test_legacy = 0, |
| 269 | flip_test_varying_size, |
| 270 | flip_test_toggle_visibility, |
| 271 | flip_test_atomic, |
| 272 | flip_test_atomic_transitions, |
| 273 | flip_test_atomic_transitions_varying_size, |
| 274 | flip_test_last = flip_test_atomic_transitions_varying_size |
| 275 | }; |
| 276 | |
| 277 | static void transition_nonblocking(igt_display_t *display, enum pipe pipe, |
| 278 | struct igt_fb *prim_fb, struct igt_fb *argb_fb, |
| 279 | bool hide_sprite) |
| 280 | { |
| 281 | igt_plane_t *primary = &display->pipes[pipe].planes[IGT_PLANE_PRIMARY]; |
| 282 | igt_plane_t *sprite = &display->pipes[pipe].planes[IGT_PLANE_2]; |
| 283 | |
| 284 | if (hide_sprite) { |
| 285 | igt_plane_set_fb(primary, prim_fb); |
| 286 | igt_plane_set_fb(sprite, NULL); |
| 287 | } else { |
| 288 | igt_plane_set_fb(primary, NULL); |
| 289 | igt_plane_set_fb(sprite, argb_fb); |
| 290 | } |
| 291 | |
| 292 | igt_display_commit_atomic(display, DRM_MODE_ATOMIC_NONBLOCK | DRM_MODE_PAGE_FLIP_EVENT, display); |
| 293 | } |
| 294 | |
| 295 | static void prepare_flip_test(igt_display_t *display, |
| 296 | enum flip_test mode, |
| 297 | enum pipe flip_pipe, |
| 298 | enum pipe cursor_pipe, |
| 299 | struct drm_mode_cursor *arg, |
| 300 | const struct igt_fb *prim_fb, |
| 301 | struct igt_fb *argb_fb, |
| 302 | struct igt_fb *cursor_fb2) |
| 303 | { |
| 304 | argb_fb->gem_handle = 0; |
| 305 | cursor_fb2->gem_handle = 0; |
| 306 | |
| 307 | if (mode == flip_test_varying_size || |
| 308 | mode == flip_test_atomic_transitions_varying_size) { |
| 309 | uint64_t width, height; |
| 310 | |
| 311 | do_or_die(drmGetCap(display->drm_fd, DRM_CAP_CURSOR_WIDTH, &width)); |
| 312 | do_or_die(drmGetCap(display->drm_fd, DRM_CAP_CURSOR_HEIGHT, &height)); |
| 313 | |
| 314 | igt_skip_on(width <= 64 && height <= 64); |
| 315 | igt_create_color_fb(display->drm_fd, width, height, |
| 316 | DRM_FORMAT_ARGB8888, 0, 1., 0., .7, cursor_fb2); |
| 317 | |
| 318 | arg[0].flags = arg[1].flags = DRM_MODE_CURSOR_BO; |
| 319 | arg[1].handle = cursor_fb2->gem_handle; |
| 320 | arg[1].width = width; |
| 321 | arg[1].height = height; |
| 322 | } |
| 323 | |
| 324 | if (mode == flip_test_legacy || |
| 325 | mode == flip_test_atomic) { |
| 326 | arg[1].x = 192; |
| 327 | arg[1].y = 192; |
| 328 | } |
| 329 | |
| 330 | if (mode == flip_test_toggle_visibility) { |
| 331 | arg[0].flags = arg[1].flags = DRM_MODE_CURSOR_BO; |
| 332 | arg[1].handle = 0; |
| 333 | arg[1].width = arg[1].height = 0; |
| 334 | } |
| 335 | |
| 336 | if (mode == flip_test_atomic_transitions || |
| 337 | mode == flip_test_atomic_transitions_varying_size) { |
| 338 | igt_require(display->pipes[flip_pipe].n_planes > 1 && |
| 339 | !display->pipes[flip_pipe].planes[IGT_PLANE_2].is_cursor); |
| 340 | |
| 341 | igt_create_color_pattern_fb(display->drm_fd, prim_fb->width, prim_fb->height, |
| 342 | DRM_FORMAT_ARGB8888, 0, .1, .1, .1, argb_fb); |
| 343 | } |
| 344 | } |
| 345 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 346 | static void flip(igt_display_t *display, |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 347 | int cursor_pipe, int flip_pipe, |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 348 | int timeout, enum flip_test mode) |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 349 | { |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 350 | struct drm_mode_cursor arg[2]; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 351 | uint64_t *results; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 352 | struct igt_fb fb_info, fb_info2, argb_fb, cursor_fb, cursor_fb2; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 353 | |
| 354 | results = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 355 | igt_assert(results != MAP_FAILED); |
| 356 | |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 357 | flip_pipe = find_connected_pipe(display, !!flip_pipe); |
| 358 | cursor_pipe = find_connected_pipe(display, !!cursor_pipe); |
| 359 | |
| 360 | igt_info("Using pipe %s for page flip, pipe %s for cursor\n", |
| 361 | kmstest_pipe_name(flip_pipe), kmstest_pipe_name(cursor_pipe)); |
| 362 | |
| 363 | if (mode >= flip_test_atomic) |
| 364 | igt_require(display->is_atomic); |
| 365 | |
| 366 | igt_require(set_fb_on_crtc(display, flip_pipe, &fb_info)); |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 367 | if (flip_pipe != cursor_pipe) |
| 368 | igt_require(set_fb_on_crtc(display, cursor_pipe, &fb_info2)); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 369 | |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 370 | igt_create_color_fb(display->drm_fd, fb_info.width, fb_info.height, DRM_FORMAT_ARGB8888, 0, .5, .5, .5, &cursor_fb); |
| 371 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 372 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
| 373 | set_cursor_on_pipe(display, cursor_pipe, &cursor_fb); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 374 | populate_cursor_args(display, cursor_pipe, arg, &cursor_fb); |
| 375 | |
| 376 | prepare_flip_test(display, mode, flip_pipe, cursor_pipe, arg, &fb_info, &argb_fb, &cursor_fb2); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 377 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 378 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 379 | |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 380 | igt_fork(child, 1) { |
| 381 | unsigned long count = 0; |
| 382 | |
| 383 | igt_until_timeout(timeout) { |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 384 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[(count & 64)/64]); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 385 | count++; |
| 386 | } |
| 387 | |
| 388 | igt_debug("cursor count=%lu\n", count); |
| 389 | results[0] = count; |
| 390 | } |
| 391 | igt_fork(child, 1) { |
| 392 | unsigned long count = 0; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 393 | |
| 394 | igt_until_timeout(timeout) { |
| 395 | char buf[128]; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 396 | |
| 397 | switch (mode) { |
| 398 | default: |
| 399 | flip_nonblocking(display, flip_pipe, mode >= flip_test_atomic, &fb_info); |
| 400 | break; |
| 401 | case flip_test_atomic_transitions: |
| 402 | case flip_test_atomic_transitions_varying_size: |
| 403 | transition_nonblocking(display, flip_pipe, &fb_info, &argb_fb, count & 1); |
| 404 | break; |
| 405 | } |
| 406 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 407 | while (read(display->drm_fd, buf, sizeof(buf)) < 0 && |
Chris Wilson | d86d6eb | 2016-06-23 21:07:36 +0100 | [diff] [blame] | 408 | (errno == EINTR || errno == EAGAIN)) |
| 409 | ; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 410 | count++; |
| 411 | } |
| 412 | |
| 413 | igt_debug("flip count=%lu\n", count); |
| 414 | results[1] = count; |
| 415 | } |
| 416 | igt_waitchildren(); |
| 417 | |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 418 | munmap(results, 4096); |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 419 | |
| 420 | do_cleanup_display(display); |
| 421 | |
| 422 | igt_remove_fb(display->drm_fd, &fb_info); |
| 423 | if (flip_pipe != cursor_pipe) |
| 424 | igt_remove_fb(display->drm_fd, &fb_info2); |
| 425 | igt_remove_fb(display->drm_fd, &cursor_fb); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 426 | if (argb_fb.gem_handle) |
| 427 | igt_remove_fb(display->drm_fd, &argb_fb); |
| 428 | if (cursor_fb2.gem_handle) |
| 429 | igt_remove_fb(display->drm_fd, &cursor_fb2); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static inline uint32_t pipe_select(int pipe) |
| 433 | { |
| 434 | if (pipe > 1) |
| 435 | return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT; |
| 436 | else if (pipe > 0) |
| 437 | return DRM_VBLANK_SECONDARY; |
| 438 | else |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | static unsigned get_vblank(int fd, int pipe, unsigned flags) |
| 443 | { |
| 444 | union drm_wait_vblank vbl; |
| 445 | |
| 446 | memset(&vbl, 0, sizeof(vbl)); |
| 447 | vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe) | flags; |
| 448 | if (drmIoctl(fd, DRM_IOCTL_WAIT_VBLANK, &vbl)) |
| 449 | return 0; |
| 450 | |
| 451 | return vbl.reply.sequence; |
| 452 | } |
| 453 | |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 454 | enum basic_flip_cursor { |
| 455 | FLIP_BEFORE_CURSOR, |
| 456 | FLIP_AFTER_CURSOR |
| 457 | }; |
| 458 | |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 459 | static uint32_t *make_busy(int fd, uint32_t target) |
| 460 | { |
| 461 | const int gen = intel_gen(intel_get_drm_devid(fd)); |
| 462 | struct drm_i915_gem_exec_object2 obj[2]; |
| 463 | struct drm_i915_gem_relocation_entry reloc[2]; |
| 464 | struct drm_i915_gem_execbuffer2 execbuf; |
| 465 | uint32_t *batch; |
| 466 | int i; |
| 467 | |
| 468 | memset(&execbuf, 0, sizeof(execbuf)); |
| 469 | execbuf.buffers_ptr = (uintptr_t)obj; |
| 470 | execbuf.buffer_count = 2; |
| 471 | |
| 472 | memset(obj, 0, sizeof(obj)); |
| 473 | obj[0].handle = target; |
| 474 | obj[1].handle = gem_create(fd, 4096); |
| 475 | batch = gem_mmap__wc(fd, obj[1].handle, 0, 4096, PROT_WRITE); |
| 476 | gem_set_domain(fd, obj[1].handle, |
| 477 | I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 478 | |
| 479 | |
| 480 | obj[1].relocs_ptr = (uintptr_t)reloc; |
| 481 | obj[1].relocation_count = 2; |
| 482 | memset(reloc, 0, sizeof(reloc)); |
| 483 | |
| 484 | reloc[0].target_handle = obj[1].handle; /* recurse */ |
| 485 | reloc[0].presumed_offset = 0; |
| 486 | reloc[0].offset = sizeof(uint32_t); |
| 487 | reloc[0].delta = 0; |
| 488 | reloc[0].read_domains = I915_GEM_DOMAIN_COMMAND; |
| 489 | reloc[0].write_domain = 0; |
| 490 | |
| 491 | reloc[1].target_handle = target; |
| 492 | reloc[1].presumed_offset = 0; |
| 493 | reloc[1].offset = 1024; |
| 494 | reloc[1].delta = 0; |
| 495 | reloc[1].read_domains = I915_GEM_DOMAIN_COMMAND; |
| 496 | reloc[1].write_domain = I915_GEM_DOMAIN_COMMAND; |
| 497 | |
| 498 | i = 0; |
| 499 | batch[i] = MI_BATCH_BUFFER_START; |
| 500 | if (gen >= 8) { |
| 501 | batch[i] |= 1 << 8 | 1; |
| 502 | batch[++i] = 0; |
| 503 | batch[++i] = 0; |
| 504 | } else if (gen >= 6) { |
| 505 | batch[i] |= 1 << 8; |
| 506 | batch[++i] = 0; |
| 507 | } else { |
| 508 | batch[i] |= 2 << 6; |
| 509 | batch[++i] = 0; |
| 510 | if (gen < 4) { |
| 511 | batch[i] |= 1; |
| 512 | reloc[0].delta = 1; |
| 513 | } |
| 514 | } |
| 515 | i++; |
| 516 | |
| 517 | gem_execbuf(fd, &execbuf); |
| 518 | gem_close(fd, obj[1].handle); |
| 519 | |
| 520 | return batch; |
| 521 | } |
| 522 | |
Chris Wilson | 18cd796 | 2016-10-05 19:31:27 +0100 | [diff] [blame] | 523 | static void cancel_busy(uint32_t *busy) |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 524 | { |
| 525 | *busy = MI_BATCH_BUFFER_END; |
| 526 | munmap(busy, 4096); |
| 527 | } |
| 528 | |
Chris Wilson | 18cd796 | 2016-10-05 19:31:27 +0100 | [diff] [blame] | 529 | static uint32_t * |
| 530 | make_fb_busy(int fd, const struct igt_fb *fb) |
| 531 | { |
| 532 | uint32_t *busy; |
| 533 | |
| 534 | busy = make_busy(fd, fb->gem_handle); |
| 535 | igt_assert(gem_bo_busy(fd, fb->gem_handle)); |
| 536 | |
| 537 | return busy; |
| 538 | } |
| 539 | |
| 540 | static void finish_fb_busy(uint32_t *busy) |
| 541 | { |
| 542 | cancel_busy(busy); |
| 543 | } |
| 544 | |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 545 | #define BASIC_BUSY 0x1 |
| 546 | |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 547 | static void basic_flip_cursor(igt_display_t *display, |
| 548 | enum flip_test mode, |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 549 | enum basic_flip_cursor order, |
| 550 | unsigned flags) |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 551 | { |
| 552 | struct drm_mode_cursor arg[2]; |
| 553 | struct drm_event_vblank vbl; |
| 554 | struct igt_fb fb_info, cursor_fb, cursor_fb2, argb_fb; |
| 555 | unsigned vblank_start; |
| 556 | enum pipe pipe = find_connected_pipe(display, false); |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 557 | uint32_t *busy; |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 558 | |
| 559 | if (mode >= flip_test_atomic) |
| 560 | igt_require(display->is_atomic); |
| 561 | |
| 562 | igt_require(set_fb_on_crtc(display, pipe, &fb_info)); |
| 563 | |
| 564 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
| 565 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
| 566 | populate_cursor_args(display, pipe, arg, &cursor_fb); |
| 567 | |
| 568 | prepare_flip_test(display, mode, pipe, pipe, arg, &fb_info, &argb_fb, &cursor_fb2); |
| 569 | |
| 570 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
| 571 | |
| 572 | /* Quick sanity check that we can update a cursor in a single vblank */ |
| 573 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 574 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 575 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 576 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 577 | |
| 578 | /* Bind the cursor first to warm up */ |
| 579 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 580 | |
| 581 | /* Start with a synchronous query to align with the vblank */ |
| 582 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 583 | |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 584 | busy = NULL; |
| 585 | if (flags & BASIC_BUSY) |
Chris Wilson | 18cd796 | 2016-10-05 19:31:27 +0100 | [diff] [blame] | 586 | busy = make_fb_busy(display->drm_fd, &fb_info); |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 587 | |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 588 | switch (order) { |
| 589 | case FLIP_BEFORE_CURSOR: |
| 590 | switch (mode) { |
| 591 | default: |
| 592 | flip_nonblocking(display, pipe, mode >= flip_test_atomic, &fb_info); |
| 593 | break; |
| 594 | case flip_test_atomic_transitions: |
| 595 | case flip_test_atomic_transitions_varying_size: |
| 596 | transition_nonblocking(display, pipe, &fb_info, &argb_fb, 0); |
| 597 | break; |
| 598 | } |
| 599 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 600 | |
| 601 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 602 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 603 | break; |
| 604 | |
| 605 | case FLIP_AFTER_CURSOR: |
| 606 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 607 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 608 | |
| 609 | switch (mode) { |
| 610 | default: |
| 611 | flip_nonblocking(display, pipe, mode >= flip_test_atomic, &fb_info); |
| 612 | break; |
| 613 | case flip_test_atomic_transitions: |
| 614 | case flip_test_atomic_transitions_varying_size: |
| 615 | transition_nonblocking(display, pipe, &fb_info, &argb_fb, 0); |
| 616 | break; |
| 617 | } |
| 618 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 619 | } |
| 620 | |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 621 | if (busy) { |
| 622 | struct pollfd pfd = { display->drm_fd, POLLIN }; |
| 623 | igt_assert(poll(&pfd, 1, 0) == 0); |
Chris Wilson | 18cd796 | 2016-10-05 19:31:27 +0100 | [diff] [blame] | 624 | finish_fb_busy(busy); |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 625 | } |
| 626 | |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 627 | igt_set_timeout(1, "Stuck page flip"); |
| 628 | igt_ignore_warn(read(display->drm_fd, &vbl, sizeof(vbl))); |
| 629 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start + 1); |
| 630 | igt_reset_timeout(); |
| 631 | |
| 632 | do_cleanup_display(display); |
| 633 | igt_remove_fb(display->drm_fd, &fb_info); |
| 634 | igt_remove_fb(display->drm_fd, &cursor_fb); |
| 635 | |
| 636 | if (argb_fb.gem_handle) |
| 637 | igt_remove_fb(display->drm_fd, &argb_fb); |
| 638 | if (cursor_fb2.gem_handle) |
| 639 | igt_remove_fb(display->drm_fd, &cursor_fb2); |
| 640 | } |
| 641 | |
| 642 | static void flip_vs_cursor(igt_display_t *display, enum flip_test mode, int nloops) |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 643 | { |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 644 | struct drm_mode_cursor arg[2]; |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 645 | struct drm_event_vblank vbl; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 646 | struct igt_fb fb_info, cursor_fb, cursor_fb2, argb_fb; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 647 | unsigned vblank_start; |
| 648 | int target; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 649 | enum pipe pipe = find_connected_pipe(display, false); |
| 650 | |
| 651 | if (mode >= flip_test_atomic) |
| 652 | igt_require(display->is_atomic); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 653 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 654 | igt_require(set_fb_on_crtc(display, pipe, &fb_info)); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 655 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 656 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 657 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 658 | populate_cursor_args(display, pipe, arg, &cursor_fb); |
| 659 | |
| 660 | prepare_flip_test(display, mode, pipe, pipe, arg, &fb_info, &argb_fb, &cursor_fb2); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 661 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 662 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 663 | |
Chris Wilson | 3a3c0fa | 2016-08-24 14:55:25 +0100 | [diff] [blame] | 664 | if (nloops) { |
| 665 | target = 4096; |
| 666 | do { |
| 667 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 668 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 669 | for (int n = 0; n < target; n++) |
| 670 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 671 | target /= 2; |
| 672 | if (get_vblank(display->drm_fd, pipe, 0) == vblank_start) |
| 673 | break; |
| 674 | } while (target); |
| 675 | igt_require(target > 1); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 676 | |
Chris Wilson | 3a3c0fa | 2016-08-24 14:55:25 +0100 | [diff] [blame] | 677 | igt_debug("Using a target of %d cursor updates per half-vblank\n", target); |
| 678 | } else |
| 679 | target = 1; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 680 | |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 681 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 682 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 683 | for (int n = 0; n < target; n++) |
| 684 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 685 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 686 | |
Chris Wilson | 3a3c0fa | 2016-08-24 14:55:25 +0100 | [diff] [blame] | 687 | do { |
| 688 | /* Bind the cursor first to warm up */ |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 689 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[nloops & 1]); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 690 | |
Chris Wilson | 3a3c0fa | 2016-08-24 14:55:25 +0100 | [diff] [blame] | 691 | /* Start with a synchronous query to align with the vblank */ |
| 692 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 693 | switch (mode) { |
| 694 | default: |
| 695 | flip_nonblocking(display, pipe, mode >= flip_test_atomic, &fb_info); |
| 696 | break; |
| 697 | case flip_test_atomic_transitions: |
| 698 | case flip_test_atomic_transitions_varying_size: |
| 699 | transition_nonblocking(display, pipe, &fb_info, &argb_fb, (nloops & 2) /2); |
| 700 | break; |
| 701 | } |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 702 | |
Chris Wilson | 3a3c0fa | 2016-08-24 14:55:25 +0100 | [diff] [blame] | 703 | /* The nonblocking flip should not have delayed us */ |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 704 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 705 | for (int n = 0; n < target; n++) |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 706 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[nloops & 1]); |
Chris Wilson | 3a3c0fa | 2016-08-24 14:55:25 +0100 | [diff] [blame] | 707 | /* Nor should it have delayed the following cursor update */ |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 708 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 709 | |
| 710 | igt_set_timeout(1, "Stuck page flip"); |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 711 | igt_ignore_warn(read(display->drm_fd, &vbl, sizeof(vbl))); |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 712 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start + 1); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 713 | igt_reset_timeout(); |
Chris Wilson | 3a3c0fa | 2016-08-24 14:55:25 +0100 | [diff] [blame] | 714 | } while (nloops--); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 715 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 716 | do_cleanup_display(display); |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 717 | igt_remove_fb(display->drm_fd, &fb_info); |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 718 | igt_remove_fb(display->drm_fd, &cursor_fb); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 719 | |
| 720 | if (argb_fb.gem_handle) |
| 721 | igt_remove_fb(display->drm_fd, &argb_fb); |
| 722 | if (cursor_fb2.gem_handle) |
| 723 | igt_remove_fb(display->drm_fd, &cursor_fb2); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 724 | } |
| 725 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 726 | static bool skip_on_unsupported_nonblocking_modeset(igt_display_t *display) |
| 727 | { |
| 728 | enum pipe pipe; |
| 729 | int ret; |
| 730 | |
| 731 | igt_display_commit_atomic(display, DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); |
| 732 | |
| 733 | ret = igt_display_try_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET | DRM_MODE_ATOMIC_NONBLOCK, NULL); |
| 734 | |
| 735 | if (ret == -EINVAL) |
| 736 | return true; |
| 737 | |
| 738 | igt_assert_eq(ret, 0); |
| 739 | |
| 740 | /* Force the next state to update all crtc's, to synchronize with the nonblocking modeset. */ |
| 741 | for_each_pipe(display, pipe) |
| 742 | display->pipes[pipe].mode_changed = true; |
| 743 | |
| 744 | return false; |
| 745 | } |
| 746 | |
Maarten Lankhorst | 59cdcf1 | 2016-11-02 13:38:48 +0100 | [diff] [blame^] | 747 | static void nonblocking_modeset_vs_cursor(igt_display_t *display, int loops) |
| 748 | { |
| 749 | struct igt_fb fb_info, cursor_fb; |
| 750 | igt_output_t *output; |
| 751 | enum pipe pipe = find_connected_pipe(display, false); |
| 752 | struct drm_mode_cursor arg; |
| 753 | bool skip_test; |
| 754 | igt_plane_t *cursor = NULL, *plane; |
| 755 | |
| 756 | igt_require(display->is_atomic); |
| 757 | igt_require((output = set_fb_on_crtc(display, pipe, &fb_info))); |
| 758 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
| 759 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
| 760 | populate_cursor_args(display, pipe, &arg, &cursor_fb); |
| 761 | arg.flags |= DRM_MODE_CURSOR_BO; |
| 762 | |
| 763 | for_each_plane_on_pipe(display, pipe, plane) { |
| 764 | if (!plane->is_cursor) |
| 765 | continue; |
| 766 | |
| 767 | cursor = plane; |
| 768 | break; |
| 769 | } |
| 770 | |
| 771 | igt_skip_on(!cursor); |
| 772 | |
| 773 | if ((skip_test = skip_on_unsupported_nonblocking_modeset(display))) |
| 774 | goto cleanup; |
| 775 | |
| 776 | /* |
| 777 | * Start disabled, because skip_on_unsupported_nonblocking_modeset |
| 778 | * will have enabled this pipe. No way around it, since the first |
| 779 | * atomic commit may be unreliable with amount of events sent. |
| 780 | */ |
| 781 | igt_output_set_pipe(output, PIPE_NONE); |
| 782 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 783 | |
| 784 | while (loops--) { |
| 785 | unsigned flags; |
| 786 | struct pollfd pfd = { display->drm_fd, POLLIN }; |
| 787 | struct drm_event_vblank vbl; |
| 788 | |
| 789 | flags = DRM_MODE_ATOMIC_ALLOW_MODESET; |
| 790 | flags |= DRM_MODE_ATOMIC_NONBLOCK; |
| 791 | flags |= DRM_MODE_PAGE_FLIP_EVENT; |
| 792 | |
| 793 | /* |
| 794 | * Test that a cursor update after a nonblocking modeset |
| 795 | * works as intended. It should block until the modeset completes. |
| 796 | */ |
| 797 | |
| 798 | igt_output_set_pipe(output, pipe); |
| 799 | igt_plane_set_fb(cursor, NULL); |
| 800 | igt_display_commit_atomic(display, flags, NULL); |
| 801 | |
| 802 | igt_assert_eq(0, poll(&pfd, 1, 0)); |
| 803 | igt_assert_eq(0, pfd.revents); |
| 804 | |
| 805 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 806 | |
| 807 | igt_assert_eq(1, poll(&pfd, 1, 0)); |
| 808 | igt_assert_eq(POLLIN, pfd.revents); |
| 809 | |
| 810 | igt_set_timeout(1, "Stuck page flip"); |
| 811 | igt_ignore_warn(read(display->drm_fd, &vbl, sizeof(vbl))); |
| 812 | igt_reset_timeout(); |
| 813 | |
| 814 | igt_output_set_pipe(output, PIPE_NONE); |
| 815 | igt_display_commit_atomic(display, flags, NULL); |
| 816 | |
| 817 | igt_assert_eq(0, poll(&pfd, 1, 0)); |
| 818 | igt_assert_eq(0, pfd.revents); |
| 819 | |
| 820 | /* Same for cursor on disabled crtc. */ |
| 821 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 822 | |
| 823 | igt_assert_eq(1, poll(&pfd, 1, 0)); |
| 824 | igt_assert_eq(POLLIN, pfd.revents); |
| 825 | |
| 826 | igt_set_timeout(1, "Stuck page flip"); |
| 827 | igt_ignore_warn(read(display->drm_fd, &vbl, sizeof(vbl))); |
| 828 | igt_reset_timeout(); |
| 829 | } |
| 830 | |
| 831 | cleanup: |
| 832 | do_cleanup_display(display); |
| 833 | igt_remove_fb(display->drm_fd, &fb_info); |
| 834 | igt_remove_fb(display->drm_fd, &cursor_fb); |
| 835 | |
| 836 | if (skip_test) |
| 837 | igt_skip("Nonblocking modeset is not supported by this kernel\n"); |
| 838 | } |
| 839 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 840 | static void two_screens_flip_vs_cursor(igt_display_t *display, int nloops, bool modeset) |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 841 | { |
| 842 | struct drm_mode_cursor arg[2], arg2[2]; |
| 843 | struct drm_event_vblank vbl; |
| 844 | struct igt_fb fb_info, fb2_info, cursor_fb; |
| 845 | unsigned vblank_start; |
| 846 | enum pipe pipe = find_connected_pipe(display, false); |
| 847 | enum pipe pipe2 = find_connected_pipe(display, true); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 848 | igt_output_t *output2; |
| 849 | bool skip_test = false; |
| 850 | |
| 851 | if (modeset) |
| 852 | igt_require(display->is_atomic); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 853 | |
| 854 | igt_require(set_fb_on_crtc(display, pipe, &fb_info)); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 855 | igt_require((output2 = set_fb_on_crtc(display, pipe2, &fb2_info))); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 856 | |
| 857 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
| 858 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
| 859 | populate_cursor_args(display, pipe, arg, &cursor_fb); |
| 860 | |
| 861 | arg[0].flags = arg[1].flags = DRM_MODE_CURSOR_BO; |
| 862 | arg[1].handle = 0; |
| 863 | arg[1].width = arg[1].height = 0; |
| 864 | |
| 865 | set_cursor_on_pipe(display, pipe2, &cursor_fb); |
| 866 | populate_cursor_args(display, pipe2, arg2, &cursor_fb); |
| 867 | |
| 868 | arg2[0].flags = arg2[1].flags = DRM_MODE_CURSOR_BO; |
| 869 | arg2[0].handle = 0; |
| 870 | arg2[0].width = arg2[0].height = 0; |
| 871 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 872 | if (modeset && (skip_test = skip_on_unsupported_nonblocking_modeset(display))) |
| 873 | goto cleanup; |
| 874 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 875 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
| 876 | |
| 877 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 878 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 879 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 880 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg2[0]); |
| 881 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 882 | |
| 883 | while (nloops--) { |
| 884 | /* Start with a synchronous query to align with the vblank */ |
| 885 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 886 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[nloops & 1]); |
| 887 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 888 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 889 | flip_nonblocking(display, pipe, false, &fb_info); |
| 890 | |
| 891 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 892 | |
| 893 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[nloops & 1]); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 894 | if (!modeset) { |
| 895 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg2[nloops & 1]); |
| 896 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[nloops & 1]); |
| 897 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg2[nloops & 1]); |
| 898 | } else { |
| 899 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[nloops & 1]); |
| 900 | |
| 901 | igt_output_set_pipe(output2, (nloops & 1) ? PIPE_NONE : pipe2); |
| 902 | igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET | DRM_MODE_ATOMIC_NONBLOCK, NULL); |
| 903 | |
| 904 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[nloops & 1]); |
| 905 | } |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 906 | |
| 907 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 908 | |
| 909 | igt_set_timeout(1, "Stuck page flip"); |
| 910 | igt_ignore_warn(read(display->drm_fd, &vbl, sizeof(vbl))); |
| 911 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start + 1); |
| 912 | igt_reset_timeout(); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 913 | |
| 914 | if (modeset) { |
| 915 | /* wait for pending modeset to complete, to prevent -EBUSY */ |
| 916 | display->pipes[pipe2].mode_changed = true; |
| 917 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 918 | } |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 921 | cleanup: |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 922 | do_cleanup_display(display); |
| 923 | igt_remove_fb(display->drm_fd, &fb_info); |
| 924 | igt_remove_fb(display->drm_fd, &fb2_info); |
| 925 | igt_remove_fb(display->drm_fd, &cursor_fb); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 926 | |
| 927 | if (skip_test) |
| 928 | igt_skip("Nonblocking modeset is not supported by this kernel\n"); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 929 | } |
| 930 | |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 931 | static void cursor_vs_flip(igt_display_t *display, enum flip_test mode, int nloops) |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 932 | { |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 933 | struct drm_mode_cursor arg[2]; |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 934 | struct drm_event_vblank vbl; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 935 | struct igt_fb fb_info, cursor_fb, cursor_fb2, argb_fb; |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 936 | unsigned vblank_start, vblank_last; |
| 937 | volatile unsigned long *shared; |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 938 | long target; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 939 | enum pipe pipe = find_connected_pipe(display, false); |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 940 | igt_output_t *output; |
| 941 | uint32_t vrefresh; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 942 | |
| 943 | if (mode >= flip_test_atomic) |
| 944 | igt_require(display->is_atomic); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 945 | |
| 946 | shared = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 947 | igt_assert(shared != MAP_FAILED); |
| 948 | |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 949 | igt_require((output = set_fb_on_crtc(display, pipe, &fb_info))); |
| 950 | vrefresh = igt_output_get_mode(output)->vrefresh; |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 951 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 952 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 953 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 954 | populate_cursor_args(display, pipe, arg, &cursor_fb); |
| 955 | |
| 956 | prepare_flip_test(display, mode, pipe, pipe, arg, &fb_info, &argb_fb, &cursor_fb2); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 957 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 958 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 959 | |
| 960 | target = 4096; |
| 961 | do { |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 962 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 963 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 964 | for (int n = 0; n < target; n++) |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 965 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 966 | target /= 2; |
Maarten Lankhorst | 29516cd | 2016-07-18 11:47:06 +0200 | [diff] [blame] | 967 | if (get_vblank(display->drm_fd, pipe, 0) == vblank_start) |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 968 | break; |
| 969 | } while (target); |
| 970 | igt_require(target > 1); |
| 971 | |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 972 | igt_debug("Using a target of %ld cursor updates per half-vblank (%u)\n", |
| 973 | target, vrefresh); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 974 | |
| 975 | for (int i = 0; i < nloops; i++) { |
| 976 | shared[0] = 0; |
| 977 | igt_fork(child, 1) { |
| 978 | unsigned long count = 0; |
| 979 | while (!shared[0]) { |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 980 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[i & 1]); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 981 | count++; |
| 982 | } |
| 983 | igt_debug("child: %lu cursor updates\n", count); |
| 984 | shared[0] = count; |
| 985 | } |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 986 | |
| 987 | switch (mode) { |
| 988 | default: |
| 989 | flip_nonblocking(display, pipe, mode >= flip_test_atomic, &fb_info); |
| 990 | break; |
| 991 | case flip_test_atomic_transitions: |
| 992 | case flip_test_atomic_transitions_varying_size: |
| 993 | transition_nonblocking(display, pipe, &fb_info, &argb_fb, (i & 2) >> 1); |
| 994 | break; |
| 995 | } |
| 996 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 997 | igt_assert_eq(read(display->drm_fd, &vbl, sizeof(vbl)), sizeof(vbl)); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 998 | vblank_start = vblank_last = vbl.sequence; |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 999 | for (int n = 0; n < vrefresh; n++) { |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 1000 | flip_nonblocking(display, pipe, mode >= flip_test_atomic, &fb_info); |
| 1001 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1002 | igt_assert_eq(read(display->drm_fd, &vbl, sizeof(vbl)), sizeof(vbl)); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 1003 | if (vbl.sequence != vblank_last + 1) { |
| 1004 | igt_warn("page flip %d was delayed, missed %d frames\n", |
| 1005 | n, vbl.sequence - vblank_last - 1); |
| 1006 | } |
| 1007 | vblank_last = vbl.sequence; |
| 1008 | } |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 1009 | |
| 1010 | if (mode != flip_test_atomic_transitions && |
| 1011 | mode != flip_test_atomic_transitions_varying_size) |
| 1012 | igt_assert_eq(vbl.sequence, vblank_start + vrefresh); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 1013 | |
| 1014 | shared[0] = 1; |
| 1015 | igt_waitchildren(); |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 1016 | igt_assert_f(shared[0] > vrefresh*target, |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 1017 | "completed %lu cursor updated in a period of 60 flips, " |
| 1018 | "we expect to complete approximately %lu updateds, " |
| 1019 | "with the threshold set at %lu\n", |
Maarten Lankhorst | aaf46cb | 2016-08-10 13:13:19 +0200 | [diff] [blame] | 1020 | shared[0], 2ul*vrefresh*target, vrefresh*target); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 1023 | do_cleanup_display(display); |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1024 | igt_remove_fb(display->drm_fd, &fb_info); |
Maarten Lankhorst | cf84a94 | 2016-07-18 11:04:27 +0200 | [diff] [blame] | 1025 | igt_remove_fb(display->drm_fd, &cursor_fb); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 1026 | munmap((void *)shared, 4096); |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 1027 | if (argb_fb.gem_handle) |
| 1028 | igt_remove_fb(display->drm_fd, &argb_fb); |
| 1029 | if (cursor_fb2.gem_handle) |
| 1030 | igt_remove_fb(display->drm_fd, &cursor_fb2); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1033 | static void two_screens_cursor_vs_flip(igt_display_t *display, int nloops, bool modeset) |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1034 | { |
| 1035 | struct drm_mode_cursor arg[2], arg2[2]; |
| 1036 | struct drm_event_vblank vbl; |
| 1037 | struct igt_fb fb_info, fb2_info, cursor_fb; |
| 1038 | unsigned vblank_start, vblank_last; |
| 1039 | volatile unsigned long *shared; |
| 1040 | int target; |
| 1041 | enum pipe pipe = find_connected_pipe(display, false); |
| 1042 | enum pipe pipe2 = find_connected_pipe(display, true); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1043 | igt_output_t *output2; |
| 1044 | bool skip_test = false; |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1045 | |
| 1046 | shared = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 1047 | igt_assert(shared != MAP_FAILED); |
| 1048 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1049 | if (modeset) |
| 1050 | igt_require(display->is_atomic); |
| 1051 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1052 | igt_require(set_fb_on_crtc(display, pipe, &fb_info)); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1053 | igt_require((output2 = set_fb_on_crtc(display, pipe2, &fb2_info))); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1054 | |
| 1055 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
| 1056 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
| 1057 | populate_cursor_args(display, pipe, arg, &cursor_fb); |
| 1058 | |
| 1059 | arg[0].flags = arg[1].flags = DRM_MODE_CURSOR_BO; |
| 1060 | arg[1].handle = 0; |
| 1061 | arg[1].width = arg[1].height = 0; |
| 1062 | |
| 1063 | set_cursor_on_pipe(display, pipe2, &cursor_fb); |
| 1064 | populate_cursor_args(display, pipe2, arg2, &cursor_fb); |
| 1065 | |
| 1066 | arg2[0].flags = arg2[1].flags = DRM_MODE_CURSOR_BO; |
| 1067 | arg2[0].handle = 0; |
| 1068 | arg2[0].width = arg2[0].height = 0; |
| 1069 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1070 | if (modeset && (skip_test = skip_on_unsupported_nonblocking_modeset(display))) |
| 1071 | goto cleanup; |
| 1072 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1073 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
| 1074 | |
| 1075 | target = 4096; |
| 1076 | do { |
| 1077 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 1078 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 1079 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1080 | if (!modeset) |
| 1081 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg2[0]); |
| 1082 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1083 | for (int n = 0; n < target; n++) { |
| 1084 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 1085 | } |
| 1086 | target /= 2; |
| 1087 | if (get_vblank(display->drm_fd, pipe, 0) == vblank_start) |
| 1088 | break; |
| 1089 | } while (target); |
| 1090 | igt_require(target > 1); |
| 1091 | |
| 1092 | igt_debug("Using a target of %d cursor updates per half-vblank\n", |
| 1093 | target); |
| 1094 | |
| 1095 | for (int i = 0; i < nloops; i++) { |
| 1096 | shared[0] = 0; |
| 1097 | igt_fork(child, 1) { |
| 1098 | unsigned long count = 0; |
| 1099 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1100 | if (!modeset) |
| 1101 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg2[i & 1]); |
| 1102 | else { |
| 1103 | igt_output_set_pipe(output2, (i & 1) ? pipe2 : PIPE_NONE); |
| 1104 | igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET | |
| 1105 | DRM_MODE_ATOMIC_NONBLOCK, NULL); |
| 1106 | } |
| 1107 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1108 | while (!shared[0]) { |
| 1109 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[i & 1]); |
| 1110 | count++; |
| 1111 | } |
| 1112 | igt_debug("child: %lu cursor updates\n", count); |
| 1113 | shared[0] = count; |
| 1114 | } |
| 1115 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1116 | flip_nonblocking(display, pipe, modeset, &fb_info); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1117 | |
| 1118 | igt_assert_eq(read(display->drm_fd, &vbl, sizeof(vbl)), sizeof(vbl)); |
| 1119 | vblank_start = vblank_last = vbl.sequence; |
| 1120 | for (int n = 0; n < 60; n++) { |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1121 | flip_nonblocking(display, pipe, modeset, &fb_info); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1122 | |
| 1123 | igt_assert_eq(read(display->drm_fd, &vbl, sizeof(vbl)), sizeof(vbl)); |
| 1124 | if (vbl.sequence != vblank_last + 1) { |
| 1125 | igt_warn("page flip %d was delayed, missed %d frames\n", |
| 1126 | n, vbl.sequence - vblank_last - 1); |
| 1127 | } |
| 1128 | vblank_last = vbl.sequence; |
| 1129 | } |
| 1130 | igt_assert_eq(vbl.sequence, vblank_start + 60); |
| 1131 | |
| 1132 | shared[0] = 1; |
| 1133 | igt_waitchildren(); |
| 1134 | igt_assert_f(shared[0] > 60*target, |
| 1135 | "completed %lu cursor updated in a period of 60 flips, " |
| 1136 | "we expect to complete approximately %lu updateds, " |
| 1137 | "with the threshold set at %lu\n", |
| 1138 | shared[0], 2*60ul*target, 60ul*target); |
| 1139 | } |
| 1140 | |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1141 | cleanup: |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1142 | do_cleanup_display(display); |
| 1143 | igt_remove_fb(display->drm_fd, &fb_info); |
| 1144 | igt_remove_fb(display->drm_fd, &fb2_info); |
| 1145 | igt_remove_fb(display->drm_fd, &cursor_fb); |
| 1146 | munmap((void *)shared, 4096); |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1147 | |
| 1148 | if (skip_test) |
| 1149 | igt_skip("Nonblocking modeset is not supported by this kernel\n"); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1152 | static void flip_vs_cursor_crc(igt_display_t *display, bool atomic) |
| 1153 | { |
| 1154 | struct drm_mode_cursor arg[2]; |
| 1155 | struct drm_event_vblank vbl; |
| 1156 | struct igt_fb fb_info, cursor_fb; |
| 1157 | unsigned vblank_start; |
| 1158 | enum pipe pipe = find_connected_pipe(display, false); |
| 1159 | igt_pipe_crc_t *pipe_crc; |
| 1160 | igt_crc_t crcs[3]; |
| 1161 | |
| 1162 | if (atomic) |
| 1163 | igt_require(display->is_atomic); |
| 1164 | |
| 1165 | igt_require(set_fb_on_crtc(display, pipe, &fb_info)); |
| 1166 | |
| 1167 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
| 1168 | populate_cursor_args(display, pipe, arg, &cursor_fb); |
| 1169 | |
| 1170 | arg[0].flags = arg[1].flags |= DRM_MODE_CURSOR_BO; |
| 1171 | arg[1].handle = 0; |
| 1172 | arg[1].width = arg[1].height = 0; |
| 1173 | |
| 1174 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
| 1175 | |
| 1176 | pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO); |
| 1177 | |
| 1178 | /* Collect reference crc with cursor disabled. */ |
| 1179 | igt_pipe_crc_collect_crc(pipe_crc, &crcs[1]); |
| 1180 | |
| 1181 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
| 1182 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 1183 | |
| 1184 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 1185 | |
| 1186 | /* Collect reference crc with cursor enabled. */ |
| 1187 | igt_pipe_crc_collect_crc(pipe_crc, &crcs[0]); |
| 1188 | |
| 1189 | /* Disable cursor, and immediately queue a flip. Check if resulting crc is correct. */ |
| 1190 | for (int i = 1; i >= 0; i--) { |
| 1191 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 1192 | |
| 1193 | flip_nonblocking(display, pipe, atomic, &fb_info); |
| 1194 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[i]); |
| 1195 | |
| 1196 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 1197 | |
| 1198 | igt_set_timeout(1, "Stuck page flip"); |
| 1199 | igt_ignore_warn(read(display->drm_fd, &vbl, sizeof(vbl))); |
| 1200 | igt_reset_timeout(); |
| 1201 | |
| 1202 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start + 1); |
| 1203 | |
| 1204 | igt_pipe_crc_collect_crc(pipe_crc, &crcs[2]); |
| 1205 | |
| 1206 | igt_assert_crc_equal(&crcs[i], &crcs[2]); |
| 1207 | } |
| 1208 | |
| 1209 | do_cleanup_display(display); |
| 1210 | igt_remove_fb(display->drm_fd, &fb_info); |
| 1211 | igt_remove_fb(display->drm_fd, &cursor_fb); |
| 1212 | igt_pipe_crc_free(pipe_crc); |
| 1213 | } |
| 1214 | |
| 1215 | static void flip_vs_cursor_busy_crc(igt_display_t *display, bool atomic) |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1216 | { |
| 1217 | struct drm_mode_cursor arg[2]; |
| 1218 | struct drm_event_vblank vbl; |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1219 | struct igt_fb fb_info[2], cursor_fb; |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1220 | unsigned vblank_start; |
| 1221 | enum pipe pipe = find_connected_pipe(display, false); |
| 1222 | igt_pipe_crc_t *pipe_crc; |
| 1223 | igt_crc_t crcs[3]; |
| 1224 | |
| 1225 | if (atomic) |
| 1226 | igt_require(display->is_atomic); |
| 1227 | |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1228 | igt_require(set_fb_on_crtc(display, pipe, &fb_info[0])); |
| 1229 | igt_create_color_pattern_fb(display->drm_fd, fb_info[0].width, fb_info[0].height, |
| 1230 | DRM_FORMAT_XRGB8888, LOCAL_I915_FORMAT_MOD_X_TILED, .1, .1, .1, &fb_info[1]); |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1231 | |
| 1232 | igt_create_color_fb(display->drm_fd, 64, 64, DRM_FORMAT_ARGB8888, 0, 1., 1., 1., &cursor_fb); |
| 1233 | populate_cursor_args(display, pipe, arg, &cursor_fb); |
| 1234 | |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1235 | arg[0].flags = arg[1].flags |= DRM_MODE_CURSOR_BO; |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1236 | arg[1].handle = 0; |
| 1237 | arg[1].width = arg[1].height = 0; |
| 1238 | |
| 1239 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
| 1240 | |
| 1241 | pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO); |
| 1242 | |
| 1243 | /* Collect reference crc with cursor disabled. */ |
| 1244 | igt_pipe_crc_collect_crc(pipe_crc, &crcs[1]); |
| 1245 | |
| 1246 | set_cursor_on_pipe(display, pipe, &cursor_fb); |
| 1247 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 1248 | |
| 1249 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[0]); |
| 1250 | |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1251 | /* Collect reference crc with cursor enabled. */ |
| 1252 | igt_pipe_crc_collect_crc(pipe_crc, &crcs[0]); |
| 1253 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1254 | /* |
| 1255 | * Set fb 1 on primary at least once before flipping to force |
| 1256 | * setting the correct cache level, else we get a stall in the |
| 1257 | * page flip handler. |
| 1258 | */ |
| 1259 | igt_plane_set_fb(&display->pipes[pipe].planes[IGT_PLANE_PRIMARY], &fb_info[1]); |
| 1260 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1261 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1262 | igt_plane_set_fb(&display->pipes[pipe].planes[IGT_PLANE_PRIMARY], &fb_info[0]); |
| 1263 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1264 | |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1265 | /* Disable cursor, and immediately queue a flip. Check if resulting crc is correct. */ |
| 1266 | for (int i = 1; i >= 0; i--) { |
Chris Wilson | 18cd796 | 2016-10-05 19:31:27 +0100 | [diff] [blame] | 1267 | uint32_t *busy; |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1268 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1269 | busy = make_fb_busy(display->drm_fd, &fb_info[1]); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1270 | |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1271 | vblank_start = get_vblank(display->drm_fd, pipe, DRM_VBLANK_NEXTONMISS); |
| 1272 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1273 | flip_nonblocking(display, pipe, atomic, &fb_info[1]); |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1274 | do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &arg[i]); |
| 1275 | |
| 1276 | igt_assert_eq(get_vblank(display->drm_fd, pipe, 0), vblank_start); |
| 1277 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1278 | igt_pipe_crc_collect_crc(pipe_crc, &crcs[2]); |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1279 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1280 | finish_fb_busy(busy); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1281 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1282 | igt_set_timeout(1, "Stuck page flip"); |
| 1283 | igt_ignore_warn(read(display->drm_fd, &vbl, sizeof(vbl))); |
| 1284 | igt_reset_timeout(); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1285 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1286 | igt_assert_lte(vblank_start + 1, get_vblank(display->drm_fd, pipe, 0)); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1287 | |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1288 | igt_plane_set_fb(&display->pipes[pipe].planes[IGT_PLANE_PRIMARY], &fb_info[0]); |
| 1289 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1290 | |
| 1291 | igt_assert_crc_equal(&crcs[i], &crcs[2]); |
| 1292 | } |
| 1293 | |
| 1294 | do_cleanup_display(display); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1295 | igt_remove_fb(display->drm_fd, &fb_info[1]); |
| 1296 | igt_remove_fb(display->drm_fd, &fb_info[0]); |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1297 | igt_remove_fb(display->drm_fd, &cursor_fb); |
| 1298 | igt_pipe_crc_free(pipe_crc); |
| 1299 | } |
| 1300 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1301 | igt_main |
| 1302 | { |
Chris Wilson | dab6b6b | 2016-05-24 16:14:32 +0100 | [diff] [blame] | 1303 | const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1304 | igt_display_t display = { .drm_fd = -1 }; |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 1305 | int i; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1306 | |
| 1307 | igt_skip_on_simulation(); |
| 1308 | |
| 1309 | igt_fixture { |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1310 | display.drm_fd = drm_open_driver_master(DRIVER_ANY); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1311 | kmstest_set_vt_graphics_mode(); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 1312 | |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1313 | igt_display_init(&display, display.drm_fd); |
| 1314 | igt_require(display.n_pipes > 0); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 1317 | igt_subtest_group { |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1318 | for (int n = 0; n < I915_MAX_PIPES; n++) { |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 1319 | errno = 0; |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1320 | |
Chris Wilson | 04b8f0e | 2016-05-25 14:53:34 +0100 | [diff] [blame] | 1321 | igt_fixture { |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1322 | igt_skip_on(n >= display.n_pipes); |
Chris Wilson | 04b8f0e | 2016-05-25 14:53:34 +0100 | [diff] [blame] | 1323 | } |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 1324 | |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1325 | igt_subtest_f("pipe-%s-single-bo", kmstest_pipe_name(n)) |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1326 | stress(&display, n, 1, DRM_MODE_CURSOR_BO, 20); |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1327 | igt_subtest_f("pipe-%s-single-move", kmstest_pipe_name(n)) |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1328 | stress(&display, n, 1, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 1329 | |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1330 | igt_subtest_f("pipe-%s-forked-bo", kmstest_pipe_name(n)) |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1331 | stress(&display, n, ncpus, DRM_MODE_CURSOR_BO, 20); |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1332 | igt_subtest_f("pipe-%s-forked-move", kmstest_pipe_name(n)) |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1333 | stress(&display, n, ncpus, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 1334 | |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1335 | igt_subtest_f("pipe-%s-torture-bo", kmstest_pipe_name(n)) |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1336 | stress(&display, n, -ncpus, DRM_MODE_CURSOR_BO, 20); |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1337 | igt_subtest_f("pipe-%s-torture-move", kmstest_pipe_name(n)) |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1338 | stress(&display, n, -ncpus, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1342 | igt_subtest("all-pipes-single-bo") |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1343 | stress(&display, -1, 1, DRM_MODE_CURSOR_BO, 20); |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1344 | igt_subtest("all-pipes-single-move") |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1345 | stress(&display, -1, 1, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 1346 | |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1347 | igt_subtest("all-pipes-forked-bo") |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1348 | stress(&display, -1, ncpus, DRM_MODE_CURSOR_BO, 20); |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1349 | igt_subtest("all-pipes-forked-move") |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1350 | stress(&display, -1, ncpus, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1351 | |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1352 | igt_subtest("all-pipes-torture-bo") |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1353 | stress(&display, -1, -ncpus, DRM_MODE_CURSOR_BO, 20); |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1354 | igt_subtest("all-pipes-torture-move") |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1355 | stress(&display, -1, -ncpus, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 1356 | |
Maarten Lankhorst | 59cdcf1 | 2016-11-02 13:38:48 +0100 | [diff] [blame^] | 1357 | igt_subtest("nonblocking-modeset-vs-cursor-atomic") |
| 1358 | nonblocking_modeset_vs_cursor(&display, 1); |
| 1359 | |
| 1360 | igt_subtest("long-nonblocking-modeset-vs-cursor-atomic") |
| 1361 | nonblocking_modeset_vs_cursor(&display, 16); |
| 1362 | |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1363 | igt_subtest("2x-flip-vs-cursor-legacy") |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1364 | two_screens_flip_vs_cursor(&display, 8, false); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1365 | |
| 1366 | igt_subtest("2x-cursor-vs-flip-legacy") |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1367 | two_screens_cursor_vs_flip(&display, 4, false); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1368 | |
| 1369 | igt_subtest("2x-long-flip-vs-cursor-legacy") |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1370 | two_screens_flip_vs_cursor(&display, 150, false); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1371 | |
| 1372 | igt_subtest("2x-long-cursor-vs-flip-legacy") |
Maarten Lankhorst | dba9667 | 2016-08-01 14:44:17 +0200 | [diff] [blame] | 1373 | two_screens_cursor_vs_flip(&display, 150, false); |
| 1374 | |
| 1375 | igt_subtest("2x-nonblocking-modeset-vs-cursor-atomic") |
| 1376 | two_screens_flip_vs_cursor(&display, 8, true); |
| 1377 | |
| 1378 | igt_subtest("2x-cursor-vs-nonblocking-modeset-atomic") |
| 1379 | two_screens_cursor_vs_flip(&display, 4, true); |
| 1380 | |
| 1381 | igt_subtest("2x-long-nonblocking-modeset-vs-cursor-atomic") |
| 1382 | two_screens_flip_vs_cursor(&display, 150, true); |
| 1383 | |
| 1384 | igt_subtest("2x-long-cursor-vs-nonblocking-modeset-atomic") |
| 1385 | two_screens_cursor_vs_flip(&display, 150, true); |
Maarten Lankhorst | 9654d51 | 2016-07-25 10:53:54 +0200 | [diff] [blame] | 1386 | |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1387 | igt_subtest("flip-vs-cursor-crc-legacy") |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1388 | flip_vs_cursor_crc(&display, false); |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1389 | |
| 1390 | igt_subtest("flip-vs-cursor-crc-atomic") |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1391 | flip_vs_cursor_crc(&display, true); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1392 | |
| 1393 | igt_subtest("flip-vs-cursor-busy-crc-legacy") |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1394 | flip_vs_cursor_busy_crc(&display, false); |
Maarten Lankhorst | 4ef3fe9 | 2016-10-05 15:51:00 +0200 | [diff] [blame] | 1395 | |
| 1396 | igt_subtest("flip-vs-cursor-busy-crc-atomic") |
Maarten Lankhorst | 954923c | 2016-10-06 12:52:53 +0200 | [diff] [blame] | 1397 | flip_vs_cursor_busy_crc(&display, true); |
Maarten Lankhorst | 4fb2178 | 2016-09-07 17:00:39 +0200 | [diff] [blame] | 1398 | |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 1399 | for (i = 0; i <= flip_test_last; i++) { |
| 1400 | const char *modes[flip_test_last+1] = { |
| 1401 | "legacy", |
| 1402 | "varying-size", |
| 1403 | "toggle", |
| 1404 | "atomic", |
| 1405 | "atomic-transitions", |
| 1406 | "atomic-transitions-varying-size" |
| 1407 | }; |
| 1408 | const char *prefix = "short-"; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 1409 | |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 1410 | switch (i) { |
| 1411 | case flip_test_legacy: |
| 1412 | case flip_test_varying_size: |
| 1413 | case flip_test_atomic: |
| 1414 | prefix = "basic-"; |
| 1415 | break; |
| 1416 | default: break; |
| 1417 | } |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1418 | |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 1419 | igt_subtest_f("%sflip-before-cursor-%s", prefix, modes[i]) |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 1420 | basic_flip_cursor(&display, i, FLIP_BEFORE_CURSOR, 0); |
| 1421 | |
| 1422 | igt_subtest_f("%sbusy-flip-before-cursor-%s", prefix, modes[i]) |
| 1423 | basic_flip_cursor(&display, i, FLIP_BEFORE_CURSOR, |
| 1424 | BASIC_BUSY); |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 1425 | |
| 1426 | igt_subtest_f("%sflip-after-cursor-%s", prefix, modes[i]) |
Chris Wilson | d2adbdf | 2016-10-04 13:50:50 +0100 | [diff] [blame] | 1427 | basic_flip_cursor(&display, i, FLIP_AFTER_CURSOR, 0); |
Chris Wilson | 237cb89 | 2016-09-13 11:37:41 +0100 | [diff] [blame] | 1428 | |
| 1429 | igt_subtest_f("flip-vs-cursor-%s", modes[i]) |
| 1430 | flip_vs_cursor(&display, i, 150); |
| 1431 | igt_subtest_f("cursor-vs-flip-%s", modes[i]) |
| 1432 | cursor_vs_flip(&display, i, 150); |
Maarten Lankhorst | 1b8d8bc | 2016-07-12 11:55:26 +0200 | [diff] [blame] | 1433 | |
Maarten Lankhorst | 69aa8a4 | 2016-07-19 13:07:32 +0200 | [diff] [blame] | 1434 | igt_subtest_f("cursorA-vs-flipA-%s", modes[i]) |
| 1435 | flip(&display, 0, 0, 10, i); |
| 1436 | |
| 1437 | igt_subtest_f("cursorA-vs-flipB-%s", modes[i]) |
| 1438 | flip(&display, 0, 1, 10, i); |
| 1439 | |
| 1440 | igt_subtest_f("cursorB-vs-flipA-%s", modes[i]) |
| 1441 | flip(&display, 1, 0, 10, i); |
| 1442 | |
| 1443 | igt_subtest_f("cursorB-vs-flipB-%s", modes[i]) |
| 1444 | flip(&display, 1, 1, 10, i); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1447 | igt_fixture { |
Maarten Lankhorst | 6b98587 | 2016-07-13 14:59:02 +0200 | [diff] [blame] | 1448 | igt_display_fini(&display); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 1449 | } |
| 1450 | } |