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> |
| 38 | #include <sys/mman.h> |
| 39 | #include <sys/time.h> |
| 40 | #include "drm.h" |
| 41 | #include "i915_drm.h" |
| 42 | #include "drmtest.h" |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 43 | #include "intel_gpu_tools.h" |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 44 | |
Zhong Li | bafbbf1 | 2013-04-23 15:06:45 +0800 | [diff] [blame] | 45 | #define LOCAL_I915_EXEC_VEBOX (4<<0) |
Daniel Vetter | 51f0830 | 2012-12-05 19:29:11 +0100 | [diff] [blame] | 46 | |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 47 | static double elapsed(const struct timeval *start, |
| 48 | const struct timeval *end, |
| 49 | int loop) |
| 50 | { |
| 51 | return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop; |
| 52 | } |
| 53 | |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 54 | static int exec(int fd, uint32_t handle, int loops, unsigned ring_id) |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 55 | { |
| 56 | struct drm_i915_gem_execbuffer2 execbuf; |
Daniel Vetter | a7a80c2 | 2012-01-10 15:50:20 +0100 | [diff] [blame] | 57 | struct drm_i915_gem_exec_object2 gem_exec[1]; |
Chris Wilson | 2a29218 | 2011-12-14 17:41:34 +0000 | [diff] [blame] | 58 | int ret = 0; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 59 | |
Daniel Vetter | a7a80c2 | 2012-01-10 15:50:20 +0100 | [diff] [blame] | 60 | gem_exec[0].handle = handle; |
| 61 | gem_exec[0].relocation_count = 0; |
| 62 | gem_exec[0].relocs_ptr = 0; |
| 63 | gem_exec[0].alignment = 0; |
| 64 | gem_exec[0].offset = 0; |
| 65 | gem_exec[0].flags = 0; |
| 66 | gem_exec[0].rsvd1 = 0; |
| 67 | gem_exec[0].rsvd2 = 0; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 68 | |
Daniel Vetter | a7a80c2 | 2012-01-10 15:50:20 +0100 | [diff] [blame] | 69 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 70 | execbuf.buffer_count = 1; |
| 71 | execbuf.batch_start_offset = 0; |
| 72 | execbuf.batch_len = 8; |
| 73 | execbuf.cliprects_ptr = 0; |
| 74 | execbuf.num_cliprects = 0; |
| 75 | execbuf.DR1 = 0; |
| 76 | execbuf.DR4 = 0; |
Daniel Vetter | ad59196 | 2012-12-05 04:16:38 +0100 | [diff] [blame] | 77 | execbuf.flags = ring_id; |
Ben Widawsky | 5a28ef8 | 2012-03-18 18:42:44 -0700 | [diff] [blame] | 78 | i915_execbuffer2_set_context_id(execbuf, 0); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 79 | execbuf.rsvd2 = 0; |
| 80 | |
Chris Wilson | 2a29218 | 2011-12-14 17:41:34 +0000 | [diff] [blame] | 81 | while (loops-- && ret == 0) { |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 82 | ret = drmIoctl(fd, |
| 83 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 84 | &execbuf); |
| 85 | } |
| 86 | gem_sync(fd, handle); |
Chris Wilson | 2a29218 | 2011-12-14 17:41:34 +0000 | [diff] [blame] | 87 | |
| 88 | return ret; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 91 | 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] | 92 | { |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 93 | int count; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 94 | |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame^] | 95 | gem_require_ring(fd, ring_id); |
| 96 | |
Damien Lespiau | d1e8623 | 2013-03-25 20:06:20 +0000 | [diff] [blame] | 97 | for (count = 1; count <= SLOW_QUICK(1<<17, 1<<4); count <<= 1) { |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 98 | struct timeval start, end; |
| 99 | |
| 100 | gettimeofday(&start, NULL); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 101 | if (exec(fd, handle, count, ring_id)) |
Daniel Vetter | 5e25fcc | 2013-08-13 12:56:06 +0200 | [diff] [blame] | 102 | igt_fail(1); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 103 | gettimeofday(&end, NULL); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 104 | printf("Time to exec x %d: %7.3fµs (ring=%s)\n", |
| 105 | count, elapsed(&start, &end, count), ring_name); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 106 | fflush(stdout); |
| 107 | } |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 108 | } |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame^] | 109 | |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 110 | int main(int argc, char **argv) |
| 111 | { |
| 112 | uint32_t batch[2] = {MI_BATCH_BUFFER_END}; |
| 113 | uint32_t handle; |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 114 | int fd; |
| 115 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 116 | igt_subtest_init(argc, argv); |
Daniel Vetter | ad59196 | 2012-12-05 04:16:38 +0100 | [diff] [blame] | 117 | |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 118 | fd = drm_open_any(); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 119 | |
| 120 | handle = gem_create(fd, 4096); |
| 121 | gem_write(fd, handle, 0, batch, sizeof(batch)); |
| 122 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 123 | igt_subtest("render") |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 124 | loop(fd, handle, I915_EXEC_RENDER, "render"); |
| 125 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 126 | igt_subtest("bsd") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame^] | 127 | loop(fd, handle, I915_EXEC_BSD, "bsd"); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 128 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 129 | igt_subtest("blt") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame^] | 130 | loop(fd, handle, I915_EXEC_BLT, "blt"); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 131 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 132 | igt_subtest("vebox") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame^] | 133 | loop(fd, handle, LOCAL_I915_EXEC_VEBOX, "vebox"); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 134 | |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 135 | gem_close(fd, handle); |
| 136 | |
| 137 | close(fd); |
| 138 | |
Daniel Vetter | 6877877 | 2013-08-12 12:26:35 +0200 | [diff] [blame] | 139 | igt_exit(); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 140 | } |