Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011,2012 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 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | /* |
| 30 | * Testcase: Check whether we correctly invalidate the cs tlb |
| 31 | * |
| 32 | * Motivated by a strange bug on launchpad where *acth != ipehr, on snb notably |
| 33 | * where everything should be coherent by default. |
| 34 | * |
| 35 | * https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/1063252 |
| 36 | */ |
| 37 | |
| 38 | #include <unistd.h> |
| 39 | #include <stdlib.h> |
| 40 | #include <stdint.h> |
| 41 | #include <stdio.h> |
| 42 | #include <string.h> |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 43 | #include <fcntl.h> |
| 44 | #include <inttypes.h> |
| 45 | #include <errno.h> |
| 46 | #include <sys/stat.h> |
| 47 | #include <sys/ioctl.h> |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 48 | #include <sys/time.h> |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 49 | |
| 50 | #include <drm.h> |
| 51 | |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 52 | #include "ioctl_wrappers.h" |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 53 | #include "drmtest.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 54 | #include "intel_io.h" |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 55 | #include "igt_aux.h" |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 56 | |
Zhong Li | 21e7e34 | 2013-04-23 15:06:44 +0800 | [diff] [blame] | 57 | #define LOCAL_I915_EXEC_VEBOX (4<<0) |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 58 | #define BATCH_SIZE (1024*1024) |
| 59 | |
| 60 | static int exec(int fd, uint32_t handle, int split, |
| 61 | uint64_t *gtt_ofs, unsigned ring_id) |
| 62 | { |
| 63 | struct drm_i915_gem_execbuffer2 execbuf; |
| 64 | struct drm_i915_gem_exec_object2 gem_exec[1]; |
| 65 | int ret = 0; |
| 66 | |
| 67 | gem_exec[0].handle = handle; |
| 68 | gem_exec[0].relocation_count = 0; |
| 69 | gem_exec[0].relocs_ptr = 0; |
| 70 | gem_exec[0].alignment = 0; |
| 71 | gem_exec[0].offset = 0x00100000; |
| 72 | gem_exec[0].flags = 0; |
| 73 | gem_exec[0].rsvd1 = 0; |
| 74 | gem_exec[0].rsvd2 = 0; |
| 75 | |
| 76 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 77 | execbuf.buffer_count = 1; |
| 78 | execbuf.batch_start_offset = 0; |
| 79 | execbuf.batch_len = 8*(split+1); |
| 80 | execbuf.cliprects_ptr = 0; |
| 81 | execbuf.num_cliprects = 0; |
| 82 | execbuf.DR1 = 0; |
| 83 | execbuf.DR4 = 0; |
| 84 | execbuf.flags = ring_id; |
| 85 | i915_execbuffer2_set_context_id(execbuf, 0); |
| 86 | execbuf.rsvd2 = 0; |
| 87 | |
| 88 | ret = drmIoctl(fd, |
| 89 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 90 | &execbuf); |
| 91 | |
| 92 | *gtt_ofs = gem_exec[0].offset; |
| 93 | |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | static void run_on_ring(int fd, unsigned ring_id, const char *ring_name) |
| 98 | { |
| 99 | uint32_t handle, handle_new; |
| 100 | uint64_t gtt_offset, gtt_offset_new; |
| 101 | uint32_t *batch_ptr, *batch_ptr_old; |
| 102 | unsigned split; |
| 103 | char buf[100]; |
| 104 | int i; |
| 105 | |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 106 | gem_require_ring(fd, ring_id); |
| 107 | |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 108 | sprintf(buf, "testing %s cs tlb coherency: ", ring_name); |
| 109 | |
| 110 | /* Shut up gcc, too stupid. */ |
| 111 | batch_ptr_old = NULL; |
| 112 | handle = 0; |
| 113 | gtt_offset = 0; |
| 114 | |
| 115 | for (split = 0; split < BATCH_SIZE/8 - 1; split += 2) { |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 116 | igt_progress(buf, split, BATCH_SIZE/8 - 1); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 117 | |
| 118 | handle_new = gem_create(fd, BATCH_SIZE); |
| 119 | batch_ptr = gem_mmap__cpu(fd, handle_new, BATCH_SIZE, |
| 120 | PROT_READ | PROT_WRITE); |
| 121 | batch_ptr[split*2] = MI_BATCH_BUFFER_END; |
| 122 | |
| 123 | for (i = split*2 + 2; i < BATCH_SIZE/8; i++) |
| 124 | batch_ptr[i] = 0xffffffff; |
| 125 | |
| 126 | if (split > 0) { |
| 127 | gem_sync(fd, handle); |
| 128 | gem_close(fd, handle); |
| 129 | } |
| 130 | |
Daniel Vetter | f3c54d0 | 2013-09-25 14:36:59 +0200 | [diff] [blame] | 131 | igt_assert(exec(fd, handle_new, split, >t_offset_new, 0) == 0); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 132 | |
| 133 | if (split > 0) { |
| 134 | /* Check that we've managed to collide in the tlb. */ |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 135 | igt_assert(gtt_offset == gtt_offset_new); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 136 | |
| 137 | /* We hang onto the storage of the old batch by keeping |
| 138 | * the cpu mmap around. */ |
| 139 | munmap(batch_ptr_old, BATCH_SIZE); |
| 140 | } |
| 141 | |
| 142 | handle = handle_new; |
| 143 | gtt_offset = gtt_offset_new; |
| 144 | batch_ptr_old = batch_ptr; |
| 145 | } |
| 146 | |
| 147 | } |
| 148 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 149 | int fd; |
| 150 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 151 | igt_main |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 152 | { |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 153 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 154 | igt_skip_on_simulation(); |
Daniel Vetter | 9d65d48 | 2012-11-28 12:09:58 +0100 | [diff] [blame] | 155 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 156 | igt_fixture { |
| 157 | fd = drm_open_any(); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 158 | |
Daniel Vetter | 9d65d48 | 2012-11-28 12:09:58 +0100 | [diff] [blame] | 159 | /* This test is very sensitive to residual gtt_mm noise from previous |
| 160 | * tests. Try to quiet thing down first. */ |
| 161 | gem_quiescent_gpu(fd); |
| 162 | sleep(5); /* needs more serious ducttape */ |
| 163 | } |
Daniel Vetter | 554237f | 2012-10-18 22:37:20 +0200 | [diff] [blame] | 164 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 165 | igt_subtest("render") |
Daniel Vetter | 9d65d48 | 2012-11-28 12:09:58 +0100 | [diff] [blame] | 166 | run_on_ring(fd, I915_EXEC_RENDER, "render"); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 167 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 168 | igt_subtest("bsd") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 169 | run_on_ring(fd, I915_EXEC_BSD, "bsd"); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 170 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 171 | igt_subtest("blt") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 172 | run_on_ring(fd, I915_EXEC_BLT, "blt"); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 173 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 174 | igt_subtest("vebox") |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 175 | run_on_ring(fd, LOCAL_I915_EXEC_VEBOX, "vebox"); |
Zhong Li | 21e7e34 | 2013-04-23 15:06:44 +0800 | [diff] [blame] | 176 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 177 | igt_fixture |
| 178 | close(fd); |
Daniel Vetter | c9795c6 | 2012-10-09 17:30:59 +0200 | [diff] [blame] | 179 | } |