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 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 28 | #include "igt.h" |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <stdint.h> |
| 32 | #include <stdio.h> |
| 33 | #include <string.h> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 34 | #include <fcntl.h> |
| 35 | #include <inttypes.h> |
| 36 | #include <errno.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <sys/ioctl.h> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 39 | #include <sys/time.h> |
Chris Wilson | b430709 | 2015-07-01 13:53:07 +0100 | [diff] [blame] | 40 | #include <time.h> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 41 | #include "drm.h" |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 42 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 43 | #define LOCAL_I915_EXEC_NO_RELOC (1<<11) |
| 44 | #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) |
| 45 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 46 | #define LOCAL_I915_EXEC_BSD_SHIFT (13) |
| 47 | #define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT) |
Daniel Vetter | 51f0830 | 2012-12-05 19:29:11 +0100 | [diff] [blame] | 48 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 49 | #define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 50 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 51 | static double elapsed(const struct timespec *start, const struct timespec *end) |
| 52 | { |
| 53 | return ((end->tv_sec - start->tv_sec) + |
| 54 | (end->tv_nsec - start->tv_nsec)*1e-9); |
| 55 | } |
| 56 | |
| 57 | static void single(int fd, uint32_t handle, unsigned ring_id, const char *ring_name) |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 58 | { |
| 59 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 60 | struct drm_i915_gem_exec_object2 obj; |
| 61 | struct timespec start, now; |
| 62 | unsigned int count = 0; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 63 | |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 64 | gem_require_ring(fd, ring_id); |
| 65 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 66 | memset(&obj, 0, sizeof(obj)); |
| 67 | obj.handle = handle; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 68 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 69 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 70 | execbuf.buffers_ptr = (uintptr_t)&obj; |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 71 | execbuf.buffer_count = 1; |
| 72 | execbuf.flags = ring_id; |
| 73 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 74 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
Chris Wilson | 3e2443f | 2016-03-10 11:50:53 +0000 | [diff] [blame^] | 75 | if (__gem_execbuf(fd, &execbuf)) { |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 76 | execbuf.flags = ring_id; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 77 | gem_execbuf(fd, &execbuf); |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 78 | } |
| 79 | gem_sync(fd, handle); |
| 80 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 81 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 82 | do { |
| 83 | for (int loop = 0; loop < 1024; loop++) { |
| 84 | gem_execbuf(fd, &execbuf); |
| 85 | count++; |
| 86 | } |
| 87 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 88 | } while (elapsed(&start, &now) < 20.); |
| 89 | gem_sync(fd, handle); |
| 90 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 91 | |
| 92 | igt_info("%s: %'u cycles: %.3fus\n", |
| 93 | ring_name, count, elapsed(&start, &now)*1e6 / count); |
| 94 | } |
| 95 | |
Chris Wilson | 0aacdac | 2016-03-09 21:06:16 +0000 | [diff] [blame] | 96 | static bool ignore_engine(int fd, unsigned engine) |
| 97 | { |
| 98 | if (engine == 0) |
| 99 | return true; |
| 100 | |
| 101 | if (gem_has_bsd2(fd) && engine == I915_EXEC_BSD) |
| 102 | return true; |
| 103 | |
| 104 | return false; |
| 105 | } |
| 106 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 107 | static void all(int fd, uint32_t handle) |
| 108 | { |
| 109 | struct drm_i915_gem_execbuffer2 execbuf; |
| 110 | struct drm_i915_gem_exec_object2 obj; |
| 111 | struct timespec start, now; |
| 112 | unsigned engines[16]; |
| 113 | unsigned nengine; |
| 114 | unsigned engine; |
| 115 | unsigned int count = 0; |
| 116 | |
| 117 | nengine = 0; |
| 118 | for_each_engine(fd, engine) |
Chris Wilson | 0aacdac | 2016-03-09 21:06:16 +0000 | [diff] [blame] | 119 | if (!ignore_engine(fd, engine)) engines[nengine++] = engine; |
| 120 | igt_require(nengine); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 121 | |
| 122 | memset(&obj, 0, sizeof(obj)); |
| 123 | obj.handle = handle; |
| 124 | |
| 125 | memset(&execbuf, 0, sizeof(execbuf)); |
| 126 | execbuf.buffers_ptr = (uintptr_t)&obj; |
| 127 | execbuf.buffer_count = 1; |
| 128 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 129 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
Chris Wilson | 3e2443f | 2016-03-10 11:50:53 +0000 | [diff] [blame^] | 130 | if (__gem_execbuf(fd, &execbuf)) { |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 131 | execbuf.flags = 0; |
| 132 | gem_execbuf(fd, &execbuf); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 133 | } |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 134 | gem_sync(fd, handle); |
| 135 | |
| 136 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 137 | do { |
| 138 | for (int loop = 0; loop < 1024; loop++) { |
| 139 | for (int n = 0; n < nengine; n++) { |
| 140 | execbuf.flags &= ~ENGINE_FLAGS; |
| 141 | execbuf.flags |= engines[n]; |
| 142 | gem_execbuf(fd, &execbuf); |
| 143 | } |
| 144 | } |
| 145 | count += nengine * 1024; |
| 146 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 147 | } while (elapsed(&start, &now) < 150.); /* Hang detection ~120s */ |
| 148 | gem_sync(fd, handle); |
| 149 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 150 | |
| 151 | igt_info("All (%d engines): %'u cycles: %.3fus\n", |
| 152 | nengine, count, elapsed(&start, &now)*1e6 / count); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 153 | } |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 154 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 155 | igt_main |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 156 | { |
Chris Wilson | 7e0853c | 2016-01-27 14:17:53 +0000 | [diff] [blame] | 157 | const struct intel_execution_engine *e; |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 158 | uint32_t handle = 0; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 159 | int device = -1; |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 160 | |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 161 | igt_fixture { |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 162 | const uint32_t bbe = MI_BATCH_BUFFER_END; |
| 163 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 164 | device = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 165 | handle = gem_create(device, 4096); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 166 | gem_write(device, handle, 0, &bbe, sizeof(bbe)); |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 167 | } |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 168 | |
Chris Wilson | 7e0853c | 2016-01-27 14:17:53 +0000 | [diff] [blame] | 169 | for (e = intel_execution_engines; e->name; e++) |
| 170 | igt_subtest_f("%s", e->name) |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 171 | single(device, handle, e->exec_id | e->flags, e->name); |
| 172 | |
| 173 | igt_subtest("basic") |
| 174 | all(device, handle); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 175 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 176 | igt_fixture { |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 177 | gem_close(device, handle); |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 178 | close(device); |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 179 | } |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 180 | } |