Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 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 | * Authors: |
| 24 | * Chris Wilson <chris@chris-wilson.co.uk> |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <unistd.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdint.h> |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <inttypes.h> |
| 35 | #include <errno.h> |
| 36 | #include <sys/stat.h> |
| 37 | #include <sys/ioctl.h> |
| 38 | #include <sys/time.h> |
| 39 | #include <time.h> |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 40 | #include <assert.h> |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 41 | |
| 42 | #include "drm.h" |
| 43 | #include "ioctl_wrappers.h" |
| 44 | #include "drmtest.h" |
| 45 | #include "intel_io.h" |
| 46 | #include "igt_stats.h" |
| 47 | |
| 48 | enum { |
| 49 | ADD_BO = 0, |
| 50 | DEL_BO, |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 51 | ADD_CTX, |
| 52 | DEL_CTX, |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 53 | EXEC, |
Chris Wilson | 4bf3ca8 | 2017-03-28 13:12:24 +0100 | [diff] [blame] | 54 | WAIT, |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct trace_add_bo { |
| 58 | uint32_t handle; |
| 59 | uint64_t size; |
| 60 | } __attribute__((packed)); |
| 61 | |
| 62 | struct trace_del_bo { |
| 63 | uint32_t handle; |
| 64 | } __attribute__((packed)); |
| 65 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 66 | struct trace_add_ctx { |
| 67 | uint32_t handle; |
| 68 | } __attribute__((packed)); |
| 69 | |
| 70 | struct trace_del_ctx { |
| 71 | uint32_t handle; |
| 72 | } __attribute__((packed)); |
| 73 | |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 74 | struct trace_exec { |
| 75 | uint32_t object_count; |
| 76 | uint64_t flags; |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 77 | uint32_t context; |
| 78 | }__attribute__((packed)); |
| 79 | |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 80 | struct trace_exec_object { |
| 81 | uint32_t handle; |
| 82 | uint32_t relocation_count; |
| 83 | uint64_t alignment; |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 84 | uint64_t offset; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 85 | uint64_t flags; |
| 86 | uint64_t rsvd1; |
| 87 | uint64_t rsvd2; |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 88 | }__attribute__((packed)); |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 89 | |
Chris Wilson | 4bf3ca8 | 2017-03-28 13:12:24 +0100 | [diff] [blame] | 90 | struct trace_wait { |
| 91 | uint32_t handle; |
| 92 | } __attribute__((packed)); |
| 93 | |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 94 | static uint32_t hars_petruska_f54_1_random(void) |
| 95 | { |
| 96 | static uint32_t state = 0x12345678; |
| 97 | |
| 98 | #define rol(x,k) ((x << k) | (x >> (32-k))) |
| 99 | return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849; |
| 100 | #undef rol |
| 101 | } |
| 102 | |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 103 | static double elapsed(const struct timespec *start, const struct timespec *end) |
| 104 | { |
| 105 | return 1e3*(end->tv_sec - start->tv_sec) + 1e-6*(end->tv_nsec - start->tv_nsec); |
| 106 | } |
| 107 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 108 | static uint32_t __gem_context_create(int fd) |
| 109 | { |
| 110 | struct drm_i915_gem_context_create arg = {}; |
| 111 | drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &arg); |
| 112 | return arg.ctx_id; |
| 113 | } |
| 114 | |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 115 | static double replay(const char *filename, long nop, long range) |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 116 | { |
| 117 | struct timespec t_start, t_end; |
Chris Wilson | 77b8af2 | 2015-08-14 20:35:18 +0100 | [diff] [blame] | 118 | struct drm_i915_gem_execbuffer2 eb = {}; |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 119 | const struct trace_version { |
| 120 | uint32_t magic; |
| 121 | uint32_t version; |
| 122 | } *tv; |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 123 | const uint32_t bbe = 0xa << 23; |
Chris Wilson | 77b8af2 | 2015-08-14 20:35:18 +0100 | [diff] [blame] | 124 | struct drm_i915_gem_exec_object2 *exec_objects = NULL; |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 125 | uint32_t *bo, *ctx; |
| 126 | int num_bo, num_ctx; |
Chris Wilson | 77b8af2 | 2015-08-14 20:35:18 +0100 | [diff] [blame] | 127 | int max_objects = 0; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 128 | struct stat st; |
| 129 | uint8_t *ptr, *end; |
Chris Wilson | 77b8af2 | 2015-08-14 20:35:18 +0100 | [diff] [blame] | 130 | int fd; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 131 | |
| 132 | fd = open(filename, O_RDONLY); |
| 133 | if (fd < 0) |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 134 | return -1; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 135 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 136 | if (fstat(fd, &st) < 0) { |
| 137 | close(fd); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 138 | return -1; |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 139 | } |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 140 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 141 | ptr = mmap(0, st.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 142 | close(fd); |
| 143 | |
Chris Wilson | b483e68 | 2015-08-10 18:45:00 +0100 | [diff] [blame] | 144 | if (ptr == MAP_FAILED) |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 145 | return -1; |
Chris Wilson | b483e68 | 2015-08-10 18:45:00 +0100 | [diff] [blame] | 146 | |
| 147 | madvise(ptr, st.st_size, MADV_SEQUENTIAL); |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 148 | end = ptr + st.st_size; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 149 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 150 | tv = (struct trace_version *)ptr; |
| 151 | if (tv->magic != 0xdeadbeef) { |
| 152 | fprintf(stderr, "%s: invalid magic\n", filename); |
| 153 | return -1; |
| 154 | } |
| 155 | if (tv->version != 1) { |
| 156 | fprintf(stderr, "%s: unhandled version %d\n", |
| 157 | filename, tv->version); |
| 158 | return -1; |
| 159 | } |
| 160 | ptr = (void *)(tv + 1); |
| 161 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 162 | ctx = calloc(1024, sizeof(*ctx)); |
| 163 | num_ctx = 1024; |
| 164 | |
| 165 | bo = calloc(4096, sizeof(*bo)); |
| 166 | num_bo = 4096; |
| 167 | |
| 168 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 169 | if (nop > 0) { |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 170 | bo[0] = gem_create(fd, nop + range); |
| 171 | gem_write(fd, bo[0], nop + range - sizeof(bbe), |
| 172 | &bbe, sizeof(bbe)); |
| 173 | range *= 2; |
| 174 | range -= 64; |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 175 | } else { |
| 176 | bo[0] = gem_create(fd, 4096); |
| 177 | gem_write(fd, bo[0], 0, &bbe, sizeof(bbe)); |
| 178 | } |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 179 | |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 180 | clock_gettime(CLOCK_MONOTONIC, &t_start); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 181 | do switch (*ptr++) { |
| 182 | case ADD_BO: |
| 183 | { |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 184 | struct trace_add_bo *t = (void *)ptr; |
| 185 | ptr = (void *)(t + 1); |
Chris Wilson | 77b8af2 | 2015-08-14 20:35:18 +0100 | [diff] [blame] | 186 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 187 | if (t->handle >= num_bo) { |
| 188 | int new_bo = ALIGN(t->handle, 4096); |
| 189 | bo = realloc(bo, sizeof(*bo)*new_bo); |
| 190 | memset(bo + num_bo, 0, sizeof(*bo)*(new_bo - num_bo)); |
| 191 | num_bo = new_bo; |
| 192 | } |
Chris Wilson | 77b8af2 | 2015-08-14 20:35:18 +0100 | [diff] [blame] | 193 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 194 | bo[t->handle] = gem_create(fd, t->size); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 195 | break; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 196 | } |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 197 | case DEL_BO: |
| 198 | { |
| 199 | struct trace_del_bo *t = (void *)ptr; |
| 200 | ptr = (void *)(t + 1); |
| 201 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 202 | assert(t->handle && t->handle < num_bo && bo[t->handle]); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 203 | gem_close(fd, bo[t->handle]); |
| 204 | bo[t->handle] = 0; |
| 205 | break; |
| 206 | } |
| 207 | case ADD_CTX: |
| 208 | { |
| 209 | struct trace_add_ctx *t = (void *)ptr; |
| 210 | ptr = (void *)(t + 1); |
| 211 | |
| 212 | if (t->handle >= num_ctx) { |
| 213 | int new_ctx = ALIGN(t->handle, 1024); |
| 214 | ctx = realloc(ctx, sizeof(*ctx)*new_ctx); |
| 215 | memset(ctx + num_ctx, 0, sizeof(*ctx)*(new_ctx - num_ctx)); |
| 216 | num_ctx = new_ctx; |
| 217 | } |
| 218 | |
| 219 | ctx[t->handle] = __gem_context_create(fd); |
| 220 | break; |
| 221 | } |
| 222 | case DEL_CTX: |
| 223 | { |
| 224 | struct trace_del_ctx *t = (void *)ptr; |
| 225 | ptr = (void *)(t + 1); |
| 226 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 227 | assert(t->handle < num_ctx && ctx[t->handle]); |
| 228 | gem_context_destroy(fd, ctx[t->handle]); |
| 229 | ctx[t->handle] = 0; |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | case EXEC: |
| 233 | { |
| 234 | struct trace_exec *t = (void *)ptr; |
| 235 | ptr = (void *)(t + 1); |
| 236 | |
| 237 | eb.buffer_count = t->object_count; |
| 238 | eb.flags = t->flags; |
| 239 | eb.rsvd1 = ctx[t->context]; |
| 240 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 241 | if (eb.buffer_count >= max_objects) { |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 242 | free(exec_objects); |
| 243 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 244 | max_objects = ALIGN(eb.buffer_count + 1, 4096); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 245 | |
| 246 | exec_objects = malloc(max_objects*sizeof(*exec_objects)); |
| 247 | eb.buffers_ptr = (uintptr_t)exec_objects; |
| 248 | } |
| 249 | |
| 250 | for (uint32_t i = 0; i < eb.buffer_count; i++) { |
| 251 | struct trace_exec_object *to = (void *)ptr; |
| 252 | ptr = (void *)(to + 1); |
| 253 | |
| 254 | exec_objects[i].handle = bo[to->handle]; |
| 255 | exec_objects[i].alignment = to->alignment; |
| 256 | exec_objects[i].offset = to->offset; |
| 257 | exec_objects[i].flags = to->flags; |
| 258 | exec_objects[i].rsvd1 = to->rsvd1; |
| 259 | exec_objects[i].rsvd2 = to->rsvd2; |
| 260 | |
| 261 | exec_objects[i].relocation_count = to->relocation_count; |
| 262 | exec_objects[i].relocs_ptr = (uintptr_t)ptr; |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 263 | |
| 264 | if (!(eb.flags & I915_EXEC_HANDLE_LUT)) { |
| 265 | struct drm_i915_gem_relocation_entry *relocs = |
| 266 | (struct drm_i915_gem_relocation_entry *)ptr; |
| 267 | for (uint32_t j = 0; j < to->relocation_count; j++) |
| 268 | relocs[j].target_handle = bo[relocs[j].target_handle]; |
| 269 | } |
| 270 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 271 | ptr += sizeof(struct drm_i915_gem_relocation_entry) * to->relocation_count; |
| 272 | } |
| 273 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 274 | ((struct drm_i915_gem_exec_object2 *) |
| 275 | memset(&exec_objects[eb.buffer_count++], 0, |
| 276 | sizeof(*exec_objects)))->handle = bo[0]; |
| 277 | |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 278 | if (nop > 0) { |
| 279 | eb.batch_start_offset = hars_petruska_f54_1_random(); |
| 280 | eb.batch_start_offset = |
| 281 | ((uint64_t)eb.batch_start_offset * range) >> 32; |
| 282 | eb.batch_start_offset = ALIGN(eb.batch_start_offset, 64); |
| 283 | } |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 284 | gem_execbuf(fd, &eb); |
| 285 | break; |
| 286 | } |
| 287 | |
Chris Wilson | 4bf3ca8 | 2017-03-28 13:12:24 +0100 | [diff] [blame] | 288 | case WAIT: |
| 289 | { |
| 290 | struct trace_wait *t = (void *)ptr; |
| 291 | ptr = (void *)(t + 1); |
| 292 | |
Chris Wilson | 005502f | 2017-03-28 16:05:28 +0100 | [diff] [blame] | 293 | assert(t->handle && t->handle < num_bo && bo[t->handle]); |
| 294 | gem_wait(fd, bo[t->handle], NULL); |
Chris Wilson | 4bf3ca8 | 2017-03-28 13:12:24 +0100 | [diff] [blame] | 295 | break; |
| 296 | } |
| 297 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 298 | default: |
| 299 | fprintf(stderr, "Unknown cmd: %x\n", *ptr); |
| 300 | return -1; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 301 | } while (ptr < end); |
| 302 | clock_gettime(CLOCK_MONOTONIC, &t_end); |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 303 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 304 | return elapsed(&t_start, &t_end); |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 305 | } |
| 306 | |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 307 | static long calibrate_nop(int usecs) |
| 308 | { |
| 309 | const uint32_t bbe = 0xa << 23; |
| 310 | int fd = drm_open_driver(DRIVER_INTEL); |
| 311 | struct drm_i915_gem_exec_object2 obj = {}; |
| 312 | struct drm_i915_gem_execbuffer2 eb = { .buffer_count = 1, .buffers_ptr = (uintptr_t)&obj}; |
| 313 | unsigned long size, last_size; |
| 314 | |
| 315 | size = 256*1024; |
| 316 | do { |
| 317 | struct timespec t_start, t_end; |
| 318 | |
| 319 | obj.handle = gem_create(fd, size); |
| 320 | gem_write(fd, obj.handle, size - sizeof(bbe), &bbe, sizeof(bbe)); |
| 321 | gem_execbuf(fd, &eb); |
| 322 | gem_sync(fd, obj.handle); |
| 323 | |
| 324 | clock_gettime(CLOCK_MONOTONIC, &t_start); |
| 325 | for (int loop = 0; loop < 9; loop++) |
| 326 | gem_execbuf(fd, &eb); |
| 327 | gem_sync(fd, obj.handle); |
| 328 | clock_gettime(CLOCK_MONOTONIC, &t_end); |
| 329 | |
| 330 | gem_close(fd, obj.handle); |
| 331 | |
| 332 | last_size = size; |
| 333 | size = 9e-3*usecs / elapsed(&t_start, &t_end) * size; |
| 334 | size = ALIGN(size, 4096); |
| 335 | } while (size != last_size); |
| 336 | |
| 337 | close(fd); |
| 338 | return size; |
| 339 | } |
| 340 | |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 341 | static int measure_nop(long nop) |
| 342 | { |
| 343 | const uint32_t bbe = 0xa << 23; |
| 344 | int fd = drm_open_driver(DRIVER_INTEL); |
| 345 | struct drm_i915_gem_exec_object2 obj = {}; |
| 346 | struct drm_i915_gem_execbuffer2 eb = { .buffer_count = 1, .buffers_ptr = (uintptr_t)&obj}; |
| 347 | struct timespec t_start, t_end; |
| 348 | |
| 349 | obj.handle = gem_create(fd, nop); |
| 350 | gem_write(fd, obj.handle, nop - sizeof(bbe), &bbe, sizeof(bbe)); |
| 351 | gem_execbuf(fd, &eb); |
| 352 | gem_sync(fd, obj.handle); |
| 353 | |
| 354 | clock_gettime(CLOCK_MONOTONIC, &t_start); |
| 355 | for (int loop = 0; loop < 9; loop++) |
| 356 | gem_execbuf(fd, &eb); |
| 357 | gem_sync(fd, obj.handle); |
| 358 | clock_gettime(CLOCK_MONOTONIC, &t_end); |
| 359 | |
| 360 | gem_close(fd, obj.handle); |
| 361 | |
| 362 | close(fd); |
| 363 | return 1e3*elapsed(&t_start, &t_end) / 9; |
| 364 | } |
| 365 | |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 366 | int main(int argc, char **argv) |
| 367 | { |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 368 | int delay = 1000; |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 369 | double *results; |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 370 | long nop = 0; |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 371 | long range = 0; |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 372 | int i, c; |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 373 | |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 374 | results = mmap(NULL, ALIGN(argc*sizeof(double), 4096), |
| 375 | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 376 | |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 377 | while ((c = getopt(argc, argv, "d:n:r:")) != -1) { |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 378 | switch (c) { |
| 379 | case 'd': |
| 380 | delay = atoi(optarg); |
| 381 | break; |
| 382 | case 'n': |
| 383 | nop = strtol(optarg, NULL, 0); |
| 384 | if (nop > 0) |
| 385 | nop = ALIGN(nop, 4096); |
| 386 | break; |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 387 | case 'r': |
| 388 | range = strtol(optarg, NULL, 0); |
| 389 | if (range > 0) |
| 390 | range = ALIGN(range, 4096); |
| 391 | break; |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 392 | default: |
| 393 | break; |
| 394 | } |
| 395 | } |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 396 | |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 397 | if (!nop) |
| 398 | nop = calibrate_nop(delay); |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 399 | if (!range) |
| 400 | range = nop / 2; |
| 401 | if (nop > 0) { |
| 402 | delay = measure_nop(nop); |
| 403 | printf("Using %lu nop batch for ~%dus delay, range %lu [%dus]\n", |
| 404 | nop, delay, |
| 405 | range, (int)(delay * range / nop)); |
| 406 | } |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 407 | |
| 408 | igt_fork(child, argc-optind) |
Chris Wilson | ff9c6d7 | 2017-03-29 18:28:09 +0100 | [diff] [blame] | 409 | results[child] = replay(argv[child + optind], nop, range); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 410 | igt_waitchildren(); |
| 411 | |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 412 | for (i = 0; i < argc - optind; i++) { |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 413 | double t = results[i]; |
| 414 | if (t < 0) |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 415 | printf("%s: failed\n", argv[optind + i]); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 416 | else |
Chris Wilson | dc43fb9 | 2017-03-29 01:31:10 +0100 | [diff] [blame] | 417 | printf("%s: %.3f\n", argv[optind + i], t); |
Chris Wilson | 49e09e7 | 2017-03-28 11:26:39 +0100 | [diff] [blame] | 418 | } |
Chris Wilson | 0393e72 | 2015-08-09 17:39:41 +0100 | [diff] [blame] | 419 | |
| 420 | return 0; |
| 421 | } |