Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [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> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 33 | #include <fcntl.h> |
| 34 | #include <inttypes.h> |
| 35 | #include <errno.h> |
| 36 | #include <sys/stat.h> |
| 37 | #include <sys/ioctl.h> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 38 | #include <sys/time.h> |
| 39 | #include "drm.h" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 40 | #include "ioctl_wrappers.h" |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 41 | #include "drmtest.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 42 | #include "intel_io.h" |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 43 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame^] | 44 | #define LOCAL_I915_EXEC_NO_RELOC (1<<11) |
| 45 | #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) |
| 46 | |
Zhong Li | bafbbf1 | 2013-04-23 15:06:45 +0800 | [diff] [blame] | 47 | #define LOCAL_I915_EXEC_VEBOX (4<<0) |
Daniel Vetter | 51f0830 | 2012-12-05 19:29:11 +0100 | [diff] [blame] | 48 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame^] | 49 | static int dcmp(const void *A, const void *B) |
| 50 | { |
| 51 | double a = *(double *)A, b = *(double *)B; |
| 52 | if (a < b) |
| 53 | return -1; |
| 54 | else if (a > b) |
| 55 | return 1; |
| 56 | else |
| 57 | return 0; |
| 58 | } |
| 59 | |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 60 | static double elapsed(const struct timeval *start, |
| 61 | const struct timeval *end, |
| 62 | int loop) |
| 63 | { |
| 64 | return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop; |
| 65 | } |
| 66 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame^] | 67 | static void loop(int fd, uint32_t handle, unsigned ring_id, const char *ring_name) |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 68 | { |
| 69 | struct drm_i915_gem_execbuffer2 execbuf; |
Daniel Vetter | a7a80c2 | 2012-01-10 15:50:20 +0100 | [diff] [blame] | 70 | struct drm_i915_gem_exec_object2 gem_exec[1]; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 71 | int count; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 72 | |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 73 | gem_require_ring(fd, ring_id); |
| 74 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame^] | 75 | memset(&gem_exec, 0, sizeof(gem_exec)); |
| 76 | gem_exec[0].handle = handle; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 77 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame^] | 78 | memset(&execbuf, 0, sizeof(execbuf)); |
| 79 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 80 | execbuf.buffer_count = 1; |
| 81 | execbuf.flags = ring_id; |
| 82 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 83 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
| 84 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf)) { |
| 85 | execbuf.flags = ring_id; |
| 86 | do_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf); |
| 87 | } |
| 88 | gem_sync(fd, handle); |
| 89 | |
| 90 | for (count = 1; count <= SLOW_QUICK(1<<17, 1<<4); count <<= 1) { |
| 91 | const int reps = 9; |
| 92 | double t[reps], sum; |
| 93 | int n; |
| 94 | |
| 95 | for (n = 0; n < reps; n++) { |
| 96 | struct timeval start, end; |
| 97 | int loops = count; |
| 98 | gettimeofday(&start, NULL); |
| 99 | while (loops--) |
| 100 | do_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf); |
| 101 | gem_sync(fd, handle); |
| 102 | gettimeofday(&end, NULL); |
| 103 | t[n] = elapsed(&start, &end, count); |
| 104 | } |
| 105 | |
| 106 | qsort(t, reps, sizeof(double), dcmp); |
| 107 | sum = 0; |
| 108 | for (n = 2; n < reps-2; n++) |
| 109 | sum += t[n]; |
| 110 | sum /= reps - 4; |
| 111 | |
Daniel Vetter | e624fa8 | 2014-05-14 00:36:04 +0200 | [diff] [blame] | 112 | igt_info("Time to exec x %d: %7.3fµs (ring=%s)\n", |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame^] | 113 | count, sum, ring_name); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 114 | fflush(stdout); |
| 115 | } |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 116 | } |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 117 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 118 | uint32_t batch[2] = {MI_BATCH_BUFFER_END}; |
| 119 | uint32_t handle; |
| 120 | int fd; |
| 121 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 122 | igt_main |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 123 | { |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 124 | igt_fixture { |
| 125 | fd = drm_open_any(); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 126 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 127 | handle = gem_create(fd, 4096); |
| 128 | gem_write(fd, handle, 0, batch, sizeof(batch)); |
| 129 | } |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 130 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 131 | igt_subtest("render") |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 132 | loop(fd, handle, I915_EXEC_RENDER, "render"); |
| 133 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 134 | igt_subtest("bsd") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 135 | loop(fd, handle, I915_EXEC_BSD, "bsd"); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 136 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 137 | igt_subtest("blt") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 138 | loop(fd, handle, I915_EXEC_BLT, "blt"); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 139 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 140 | igt_subtest("vebox") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 141 | loop(fd, handle, LOCAL_I915_EXEC_VEBOX, "vebox"); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 142 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 143 | igt_fixture { |
| 144 | gem_close(fd, handle); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 145 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 146 | close(fd); |
| 147 | } |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 148 | } |