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> |
| 27 | |
| 28 | #include "igt.h" |
Chris Wilson | 376b813 | 2016-07-03 09:42:38 +0100 | [diff] [blame^] | 29 | #include "igt_rand.h" |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 30 | #include "igt_stats.h" |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 31 | |
Tomeu Vizoso | 047c999 | 2016-06-07 10:18:34 +0200 | [diff] [blame] | 32 | #if defined(__x86_64__) || defined(__i386__) |
| 33 | #define cpu_relax() __builtin_ia32_pause() |
| 34 | #else |
| 35 | #define cpu_relax() asm volatile("": : :"memory") |
| 36 | #endif |
| 37 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 38 | IGT_TEST_DESCRIPTION("Stress legacy cursor ioctl"); |
| 39 | |
| 40 | struct data { |
| 41 | int fd; |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 42 | drmModeRes *resources; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
Chris Wilson | dab6b6b | 2016-05-24 16:14:32 +0100 | [diff] [blame] | 45 | static void stress(struct data *data, |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 46 | uint32_t *crtc_id, unsigned num_crtcs, |
| 47 | int num_children, unsigned mode, |
| 48 | int timeout) |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 49 | { |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 50 | struct drm_mode_cursor arg; |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 51 | uint64_t *results; |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 52 | bool torture; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 53 | int n; |
| 54 | |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 55 | torture = false; |
| 56 | if (num_children < 0) { |
| 57 | torture = true; |
| 58 | num_children = -num_children; |
| 59 | } |
| 60 | |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 61 | results = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 62 | igt_assert(results != MAP_FAILED); |
| 63 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 64 | memset(&arg, 0, sizeof(arg)); |
| 65 | arg.flags = DRM_MODE_CURSOR_BO; |
| 66 | arg.crtc_id = 0; |
| 67 | arg.width = 64; |
| 68 | arg.height = 64; |
| 69 | arg.handle = gem_create(data->fd, 4*64*64); |
| 70 | |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 71 | for (n = 0; n < num_crtcs; n++) { |
| 72 | arg.crtc_id = crtc_id[n]; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 73 | drmIoctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 74 | } |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 75 | |
| 76 | arg.flags = mode; |
Chris Wilson | dab6b6b | 2016-05-24 16:14:32 +0100 | [diff] [blame] | 77 | igt_fork(child, num_children) { |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 78 | struct sched_param rt = {.sched_priority = 99 }; |
| 79 | cpu_set_t allowed; |
| 80 | unsigned long count = 0; |
| 81 | |
| 82 | sched_setscheduler(getpid(), SCHED_RR, &rt); |
| 83 | |
| 84 | CPU_ZERO(&allowed); |
| 85 | CPU_SET(child, &allowed); |
| 86 | sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed); |
| 87 | |
Chris Wilson | 376b813 | 2016-07-03 09:42:38 +0100 | [diff] [blame^] | 88 | hars_petruska_f54_1_random_perturb(child); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 89 | igt_until_timeout(timeout) { |
Chris Wilson | 376b813 | 2016-07-03 09:42:38 +0100 | [diff] [blame^] | 90 | arg.crtc_id = crtc_id[hars_petruska_f54_1_random_unsafe() % num_crtcs]; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 91 | do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 92 | count++; |
| 93 | } |
| 94 | |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 95 | igt_debug("[%d] count=%lu\n", child, count); |
| 96 | results[child] = count; |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 97 | } |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 98 | if (torture) { |
| 99 | igt_fork(child, num_children) { |
| 100 | struct sched_param rt = {.sched_priority = 1 }; |
| 101 | cpu_set_t allowed; |
| 102 | unsigned long long count = 0; |
| 103 | |
| 104 | sched_setscheduler(getpid(), SCHED_RR, &rt); |
| 105 | |
| 106 | CPU_ZERO(&allowed); |
| 107 | CPU_SET(child, &allowed); |
| 108 | sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed); |
| 109 | igt_until_timeout(timeout) { |
| 110 | count++; |
Tomeu Vizoso | 047c999 | 2016-06-07 10:18:34 +0200 | [diff] [blame] | 111 | cpu_relax(); |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 112 | } |
| 113 | igt_debug("[hog:%d] count=%llu\n", child, count); |
| 114 | } |
| 115 | } |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 116 | igt_waitchildren(); |
| 117 | |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 118 | if (num_children > 1) { |
| 119 | igt_stats_t stats; |
| 120 | |
| 121 | igt_stats_init_with_size(&stats, num_children); |
| 122 | results[num_children] = 0; |
| 123 | for (int child = 0; child < num_children; child++) { |
| 124 | igt_stats_push(&stats, results[child]); |
| 125 | results[num_children] += results[child]; |
| 126 | } |
| 127 | igt_info("Total updates %llu (median of %d processes is %.2f)\n", |
| 128 | (long long)results[num_children], |
| 129 | num_children, |
| 130 | igt_stats_get_median(&stats)); |
| 131 | igt_stats_fini(&stats); |
| 132 | } else { |
| 133 | igt_info("Total updates %llu\n", (long long)results[0]); |
| 134 | } |
| 135 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 136 | gem_close(data->fd, arg.handle); |
Chris Wilson | c74e071 | 2016-05-24 16:24:15 +0100 | [diff] [blame] | 137 | munmap(results, 4096); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 140 | static bool set_fb_on_crtc(struct data *data, int pipe, struct igt_fb *fb_info) |
| 141 | { |
| 142 | struct drm_mode_modeinfo *modes = malloc(4096*sizeof(*modes)); |
| 143 | uint32_t encoders[32]; |
| 144 | |
| 145 | for (int o = 0; o < data->resources->count_connectors; o++) { |
| 146 | struct drm_mode_get_connector conn; |
| 147 | struct drm_mode_crtc set; |
| 148 | int e, m; |
| 149 | |
| 150 | memset(&conn, 0, sizeof(conn)); |
| 151 | conn.connector_id = data->resources->connectors[o]; |
| 152 | conn.count_modes = 4096; |
| 153 | conn.modes_ptr = (uintptr_t)modes; |
| 154 | conn.count_encoders = 32; |
| 155 | conn.encoders_ptr = (uintptr_t)encoders; |
| 156 | |
| 157 | drmIoctl(data->fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn); |
| 158 | |
| 159 | for (e = 0; e < conn.count_encoders; e++) { |
| 160 | struct drm_mode_get_encoder enc; |
| 161 | |
| 162 | memset(&enc, 0, sizeof(enc)); |
| 163 | enc.encoder_id = encoders[e]; |
| 164 | drmIoctl(data->fd, DRM_IOCTL_MODE_GETENCODER, &enc); |
| 165 | if (enc.possible_crtcs & (1 << pipe)) |
| 166 | break; |
| 167 | } |
| 168 | if (e == conn.count_encoders) |
| 169 | continue; |
| 170 | |
| 171 | for (m = 0; m < conn.count_modes; m++) { |
| 172 | if (modes[m].hdisplay == fb_info->width && |
| 173 | modes[m].vdisplay == fb_info->height) |
| 174 | break; |
| 175 | } |
| 176 | if (m == conn.count_modes) |
| 177 | continue; |
| 178 | |
| 179 | memset(&set, 0, sizeof(set)); |
| 180 | set.crtc_id = data->resources->crtcs[pipe]; |
| 181 | set.fb_id = fb_info->fb_id; |
| 182 | set.set_connectors_ptr = (uintptr_t)&conn.connector_id; |
| 183 | set.count_connectors = 1; |
| 184 | set.mode = modes[m]; |
| 185 | set.mode_valid = 1; |
| 186 | if (drmIoctl(data->fd, DRM_IOCTL_MODE_SETCRTC, &set) == 0) |
| 187 | return true; |
| 188 | } |
| 189 | |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | static void flip(struct data *data, |
| 194 | int cursor_pipe, int flip_pipe, |
| 195 | int timeout) |
| 196 | { |
| 197 | struct drm_mode_cursor arg; |
| 198 | uint64_t *results; |
| 199 | struct igt_fb fb_info; |
| 200 | uint32_t fb_id; |
| 201 | |
| 202 | results = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 203 | igt_assert(results != MAP_FAILED); |
| 204 | |
| 205 | memset(&arg, 0, sizeof(arg)); |
| 206 | arg.flags = DRM_MODE_CURSOR_BO; |
| 207 | arg.crtc_id = data->resources->crtcs[cursor_pipe]; |
| 208 | arg.width = 64; |
| 209 | arg.height = 64; |
| 210 | arg.handle = gem_create(data->fd, 4*64*64); |
| 211 | |
| 212 | drmIoctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 213 | |
| 214 | fb_id = igt_create_fb(data->fd, 1024, 768, DRM_FORMAT_XRGB8888, |
| 215 | I915_TILING_NONE, &fb_info); |
| 216 | igt_require(set_fb_on_crtc(data, flip_pipe, &fb_info)); |
| 217 | |
| 218 | arg.flags = DRM_MODE_CURSOR_MOVE; |
| 219 | igt_fork(child, 1) { |
| 220 | unsigned long count = 0; |
| 221 | |
| 222 | igt_until_timeout(timeout) { |
| 223 | do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 224 | count++; |
| 225 | } |
| 226 | |
| 227 | igt_debug("cursor count=%lu\n", count); |
| 228 | results[0] = count; |
| 229 | } |
| 230 | igt_fork(child, 1) { |
| 231 | unsigned long count = 0; |
| 232 | unsigned crtc = data->resources->crtcs[flip_pipe]; |
| 233 | |
| 234 | igt_until_timeout(timeout) { |
| 235 | char buf[128]; |
| 236 | drmModePageFlip(data->fd, crtc, fb_id, |
| 237 | DRM_MODE_PAGE_FLIP_EVENT, |
| 238 | NULL); |
Chris Wilson | d86d6eb | 2016-06-23 21:07:36 +0100 | [diff] [blame] | 239 | while (read(data->fd, buf, sizeof(buf)) < 0 && |
| 240 | (errno == EINTR || errno == EAGAIN)) |
| 241 | ; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 242 | count++; |
| 243 | } |
| 244 | |
| 245 | igt_debug("flip count=%lu\n", count); |
| 246 | results[1] = count; |
| 247 | } |
| 248 | igt_waitchildren(); |
| 249 | |
| 250 | gem_close(data->fd, arg.handle); |
| 251 | munmap(results, 4096); |
| 252 | } |
| 253 | |
| 254 | static inline uint32_t pipe_select(int pipe) |
| 255 | { |
| 256 | if (pipe > 1) |
| 257 | return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT; |
| 258 | else if (pipe > 0) |
| 259 | return DRM_VBLANK_SECONDARY; |
| 260 | else |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | static unsigned get_vblank(int fd, int pipe, unsigned flags) |
| 265 | { |
| 266 | union drm_wait_vblank vbl; |
| 267 | |
| 268 | memset(&vbl, 0, sizeof(vbl)); |
| 269 | vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe) | flags; |
| 270 | if (drmIoctl(fd, DRM_IOCTL_WAIT_VBLANK, &vbl)) |
| 271 | return 0; |
| 272 | |
| 273 | return vbl.reply.sequence; |
| 274 | } |
| 275 | |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 276 | static void basic_flip_vs_cursor(struct data *data, int nloops) |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 277 | { |
| 278 | struct drm_mode_cursor arg; |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 279 | struct drm_event_vblank vbl; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 280 | struct igt_fb fb_info; |
| 281 | unsigned vblank_start; |
| 282 | int target; |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 283 | uint32_t fb_id; |
| 284 | |
| 285 | memset(&arg, 0, sizeof(arg)); |
| 286 | arg.flags = DRM_MODE_CURSOR_BO; |
| 287 | arg.crtc_id = data->resources->crtcs[0]; |
| 288 | arg.width = 64; |
| 289 | arg.height = 64; |
| 290 | arg.handle = gem_create(data->fd, 4*64*64); |
| 291 | |
| 292 | drmIoctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 293 | arg.flags = DRM_MODE_CURSOR_MOVE; |
| 294 | |
| 295 | fb_id = igt_create_fb(data->fd, 1024, 768, DRM_FORMAT_XRGB8888, |
| 296 | I915_TILING_NONE, &fb_info); |
| 297 | igt_require(set_fb_on_crtc(data, 0, &fb_info)); |
| 298 | |
| 299 | target = 4096; |
| 300 | do { |
| 301 | vblank_start = get_vblank(data->fd, 0, DRM_VBLANK_NEXTONMISS); |
| 302 | igt_assert_eq(get_vblank(data->fd, 0, 0), vblank_start); |
| 303 | for (int n = 0; n < target; n++) |
| 304 | do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 305 | target /= 2; |
| 306 | if (get_vblank(data->fd, 0, 0) == vblank_start) |
| 307 | break; |
| 308 | } while (target); |
| 309 | igt_require(target > 1); |
| 310 | |
| 311 | igt_debug("Using a target of %d cursor updates per half-vblank\n", |
| 312 | target); |
| 313 | |
| 314 | vblank_start = get_vblank(data->fd, 0, DRM_VBLANK_NEXTONMISS); |
| 315 | igt_assert_eq(get_vblank(data->fd, 0, 0), vblank_start); |
| 316 | for (int n = 0; n < target; n++) |
| 317 | do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 318 | igt_assert_eq(get_vblank(data->fd, 0, 0), vblank_start); |
| 319 | |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 320 | while (nloops--) { |
| 321 | /* Start with a synchronous query to align with the vblank */ |
| 322 | vblank_start = get_vblank(data->fd, 0, DRM_VBLANK_NEXTONMISS); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 323 | do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 324 | |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 325 | /* Schedule a nonblocking flip for the next vblank */ |
| 326 | do_or_die(drmModePageFlip(data->fd, arg.crtc_id, fb_id, |
| 327 | DRM_MODE_PAGE_FLIP_EVENT, &fb_id)); |
| 328 | |
| 329 | igt_assert_eq(get_vblank(data->fd, 0, 0), vblank_start); |
| 330 | for (int n = 0; n < target; n++) |
| 331 | do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 332 | igt_assert_eq(get_vblank(data->fd, 0, 0), vblank_start); |
| 333 | |
| 334 | igt_set_timeout(1, "Stuck page flip"); |
| 335 | igt_ignore_warn(read(data->fd, &vbl, sizeof(vbl))); |
| 336 | igt_assert_eq(get_vblank(data->fd, 0, 0), vblank_start + 1); |
| 337 | igt_reset_timeout(); |
| 338 | } |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 339 | |
| 340 | igt_remove_fb(data->fd, &fb_info); |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 341 | gem_close(data->fd, arg.handle); |
| 342 | } |
| 343 | |
| 344 | static void basic_cursor_vs_flip(struct data *data, int nloops) |
| 345 | { |
| 346 | struct drm_mode_cursor arg; |
| 347 | struct drm_event_vblank vbl; |
| 348 | struct igt_fb fb_info; |
| 349 | unsigned vblank_start, vblank_last; |
| 350 | volatile unsigned long *shared; |
| 351 | int target; |
| 352 | uint32_t fb_id; |
| 353 | |
| 354 | shared = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 355 | igt_assert(shared != MAP_FAILED); |
| 356 | |
| 357 | memset(&arg, 0, sizeof(arg)); |
| 358 | arg.flags = DRM_MODE_CURSOR_BO; |
| 359 | arg.crtc_id = data->resources->crtcs[0]; |
| 360 | arg.width = 64; |
| 361 | arg.height = 64; |
| 362 | arg.handle = gem_create(data->fd, 4*64*64); |
| 363 | |
| 364 | drmIoctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 365 | arg.flags = DRM_MODE_CURSOR_MOVE; |
| 366 | |
| 367 | fb_id = igt_create_fb(data->fd, 1024, 768, DRM_FORMAT_XRGB8888, |
| 368 | I915_TILING_NONE, &fb_info); |
| 369 | igt_require(set_fb_on_crtc(data, 0, &fb_info)); |
| 370 | |
| 371 | target = 4096; |
| 372 | do { |
| 373 | vblank_start = get_vblank(data->fd, 0, DRM_VBLANK_NEXTONMISS); |
| 374 | igt_assert_eq(get_vblank(data->fd, 0, 0), vblank_start); |
| 375 | for (int n = 0; n < target; n++) |
| 376 | do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 377 | target /= 2; |
| 378 | if (get_vblank(data->fd, 0, 0) == vblank_start) |
| 379 | break; |
| 380 | } while (target); |
| 381 | igt_require(target > 1); |
| 382 | |
| 383 | igt_debug("Using a target of %d cursor updates per half-vblank\n", |
| 384 | target); |
| 385 | |
| 386 | for (int i = 0; i < nloops; i++) { |
| 387 | shared[0] = 0; |
| 388 | igt_fork(child, 1) { |
| 389 | unsigned long count = 0; |
| 390 | while (!shared[0]) { |
| 391 | drmIoctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg); |
| 392 | count++; |
| 393 | } |
| 394 | igt_debug("child: %lu cursor updates\n", count); |
| 395 | shared[0] = count; |
| 396 | } |
| 397 | do_or_die(drmModePageFlip(data->fd, arg.crtc_id, fb_id, |
| 398 | DRM_MODE_PAGE_FLIP_EVENT, &fb_id)); |
| 399 | igt_assert_eq(read(data->fd, &vbl, sizeof(vbl)), sizeof(vbl)); |
| 400 | vblank_start = vblank_last = vbl.sequence; |
| 401 | for (int n = 0; n < 60; n++) { |
| 402 | do_or_die(drmModePageFlip(data->fd, arg.crtc_id, fb_id, |
| 403 | DRM_MODE_PAGE_FLIP_EVENT, &fb_id)); |
| 404 | igt_assert_eq(read(data->fd, &vbl, sizeof(vbl)), sizeof(vbl)); |
| 405 | if (vbl.sequence != vblank_last + 1) { |
| 406 | igt_warn("page flip %d was delayed, missed %d frames\n", |
| 407 | n, vbl.sequence - vblank_last - 1); |
| 408 | } |
| 409 | vblank_last = vbl.sequence; |
| 410 | } |
| 411 | igt_assert_eq(vbl.sequence, vblank_start + 60); |
| 412 | |
| 413 | shared[0] = 1; |
| 414 | igt_waitchildren(); |
| 415 | igt_assert_f(shared[0] > 60*target, |
| 416 | "completed %lu cursor updated in a period of 60 flips, " |
| 417 | "we expect to complete approximately %lu updateds, " |
| 418 | "with the threshold set at %lu\n", |
| 419 | shared[0], 2*60ul*target, 60ul*target); |
| 420 | } |
| 421 | |
| 422 | igt_remove_fb(data->fd, &fb_info); |
| 423 | gem_close(data->fd, arg.handle); |
| 424 | munmap((void *)shared, 4096); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 425 | } |
| 426 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 427 | igt_main |
| 428 | { |
Chris Wilson | dab6b6b | 2016-05-24 16:14:32 +0100 | [diff] [blame] | 429 | const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 430 | struct data data = { .fd = -1 }; |
| 431 | |
| 432 | igt_skip_on_simulation(); |
| 433 | |
| 434 | igt_fixture { |
| 435 | data.fd = drm_open_driver_master(DRIVER_INTEL); |
| 436 | kmstest_set_vt_graphics_mode(); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 437 | |
| 438 | data.resources = drmModeGetResources(data.fd); |
| 439 | igt_assert(data.resources); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 442 | igt_subtest_group { |
| 443 | for (int n = 0; n < 26; n++) { |
Chris Wilson | 04b8f0e | 2016-05-25 14:53:34 +0100 | [diff] [blame] | 444 | uint32_t *crtcs = NULL; |
Chris Wilson | dab6b6b | 2016-05-24 16:14:32 +0100 | [diff] [blame] | 445 | |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 446 | errno = 0; |
Chris Wilson | 04b8f0e | 2016-05-25 14:53:34 +0100 | [diff] [blame] | 447 | igt_fixture { |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 448 | igt_skip_on(n >= data.resources->count_crtcs); |
Chris Wilson | 04b8f0e | 2016-05-25 14:53:34 +0100 | [diff] [blame] | 449 | crtcs = &data.resources->crtcs[n]; |
| 450 | } |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 451 | |
| 452 | igt_subtest_f("single-%c-bo", 'A' + n) |
| 453 | stress(&data, crtcs, 1, 1, DRM_MODE_CURSOR_BO, 20); |
| 454 | igt_subtest_f("single-%c-move", 'A' + n) |
| 455 | stress(&data, crtcs, 1, 1, DRM_MODE_CURSOR_MOVE, 20); |
| 456 | |
| 457 | igt_subtest_f("forked-%c-bo", 'A' + n) |
| 458 | stress(&data, crtcs, 1, ncpus, DRM_MODE_CURSOR_BO, 20); |
| 459 | igt_subtest_f("forked-%c-move", 'A' + n) |
| 460 | stress(&data, crtcs, 1, ncpus, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 461 | |
| 462 | igt_subtest_f("torture-%c-bo", 'A' + n) |
| 463 | stress(&data, crtcs, 1, -ncpus, DRM_MODE_CURSOR_BO, 20); |
| 464 | igt_subtest_f("torture-%c-move", 'A' + n) |
| 465 | stress(&data, crtcs, 1, -ncpus, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
| 469 | igt_subtest("single-all-bo") |
| 470 | stress(&data, |
| 471 | data.resources->crtcs, data.resources->count_crtcs, |
| 472 | 1, DRM_MODE_CURSOR_BO, 20); |
| 473 | igt_subtest("single-all-move") |
| 474 | stress(&data, |
| 475 | data.resources->crtcs, data.resources->count_crtcs, |
| 476 | 1, DRM_MODE_CURSOR_MOVE, 20); |
| 477 | |
| 478 | igt_subtest("forked-all-bo") |
| 479 | stress(&data, |
| 480 | data.resources->crtcs, data.resources->count_crtcs, |
| 481 | ncpus, DRM_MODE_CURSOR_BO, 20); |
| 482 | igt_subtest("forked-all-move") |
| 483 | stress(&data, |
| 484 | data.resources->crtcs, data.resources->count_crtcs, |
| 485 | ncpus, DRM_MODE_CURSOR_MOVE, 20); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 486 | |
Chris Wilson | f5d370c | 2016-06-04 21:25:17 +0100 | [diff] [blame] | 487 | igt_subtest("torture-all-bo") |
| 488 | stress(&data, |
| 489 | data.resources->crtcs, data.resources->count_crtcs, |
| 490 | -ncpus, DRM_MODE_CURSOR_BO, 20); |
| 491 | igt_subtest("torture-all-move") |
| 492 | stress(&data, |
| 493 | data.resources->crtcs, data.resources->count_crtcs, |
| 494 | -ncpus, DRM_MODE_CURSOR_MOVE, 20); |
| 495 | |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 496 | igt_subtest_group { |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 497 | igt_subtest("basic-flip-vs-cursor") |
| 498 | basic_flip_vs_cursor(&data, 1); |
| 499 | igt_subtest("long-flip-vs-cursor") |
| 500 | basic_flip_vs_cursor(&data, 150); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 501 | igt_subtest("basic-cursor-vs-flip") |
Chris Wilson | 88c1f7c | 2016-06-23 22:53:23 +0100 | [diff] [blame] | 502 | basic_cursor_vs_flip(&data, 1); |
| 503 | igt_subtest("long-cursor-vs-flip") |
| 504 | basic_cursor_vs_flip(&data, 150); |
Chris Wilson | 162d456 | 2016-06-22 15:41:23 +0100 | [diff] [blame] | 505 | |
| 506 | igt_subtest("cursorA-vs-flipA") |
| 507 | flip(&data, 0, 0, 10); |
| 508 | igt_subtest("cursorA-vs-flipB") |
| 509 | flip(&data, 0, 1, 10); |
| 510 | igt_subtest("cursorB-vs-flipA") |
| 511 | flip(&data, 1, 0, 10); |
| 512 | igt_subtest("cursorB-vs-flipB") |
| 513 | flip(&data, 1, 1, 10); |
| 514 | } |
| 515 | |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 516 | igt_fixture { |
Chris Wilson | cce2ff0 | 2016-05-25 08:34:25 +0100 | [diff] [blame] | 517 | drmModeFreeResources(data.resources); |
Chris Wilson | 9579e54 | 2016-05-23 21:56:01 +0100 | [diff] [blame] | 518 | } |
| 519 | } |