2 * Copyright © 2011,2012 Intel Corporation
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:
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
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
24 * Chris Wilson <chris@chris-wilson.co.uk>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
30 * Testcase: run a couple of big batches to force the unbind on misalignment code.
42 #include <sys/ioctl.h>
47 #include "ioctl_wrappers.h"
49 #include "intel_chipset.h"
56 copy(int fd, uint32_t dst, uint32_t src, uint32_t *all_bo, int n_bo, int alignment, int error)
59 struct drm_i915_gem_relocation_entry reloc[2];
60 struct drm_i915_gem_exec_object2 *obj;
61 struct drm_i915_gem_execbuffer2 exec;
65 batch[i++] = (XY_SRC_COPY_BLT_CMD |
66 XY_SRC_COPY_BLT_WRITE_ALPHA |
67 XY_SRC_COPY_BLT_WRITE_RGB | 6);
68 if (intel_gen(intel_get_drm_devid(fd)) >= 8)
70 batch[i++] = (3 << 24) | /* 32 bits */
71 (0xcc << 16) | /* copy ROP */
73 batch[i++] = 0; /* dst x1,y1 */
74 batch[i++] = (HEIGHT << 16) | WIDTH; /* dst x2,y2 */
75 batch[i++] = 0; /* dst reloc */
76 if (intel_gen(intel_get_drm_devid(fd)) >= 8)
77 batch[i++] = 0; /* FIXME */
78 batch[i++] = 0; /* src x1,y1 */
80 batch[i++] = 0; /* src reloc */
81 if (intel_gen(intel_get_drm_devid(fd)) >= 8)
82 batch[i++] = 0; /* FIXME */
83 batch[i++] = MI_BATCH_BUFFER_END;
86 handle = gem_create(fd, 4096);
87 gem_write(fd, handle, 0, batch, sizeof(batch));
89 reloc[0].target_handle = dst;
91 reloc[0].offset = 4 * sizeof(batch[0]);
92 reloc[0].presumed_offset = 0;
93 reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
94 reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
96 reloc[1].target_handle = src;
98 reloc[1].offset = 7 * sizeof(batch[0]);
99 reloc[1].presumed_offset = 0;
100 reloc[1].read_domains = I915_GEM_DOMAIN_RENDER;
101 reloc[1].write_domain = 0;
103 obj = calloc(n_bo + 1, sizeof(*obj));
104 for (n = 0; n < n_bo; n++) {
105 obj[n].handle = all_bo[n];
106 obj[n].alignment = alignment;
108 obj[n].handle = handle;
109 obj[n].relocation_count = 2;
110 obj[n].relocs_ptr = (uintptr_t)reloc;
112 exec.buffers_ptr = (uintptr_t)obj;
113 exec.buffer_count = n_bo + 1;
114 exec.batch_start_offset = 0;
115 exec.batch_len = i * 4;
116 exec.DR1 = exec.DR4 = 0;
117 exec.num_cliprects = 0;
118 exec.cliprects_ptr = 0;
119 exec.flags = HAS_BLT_RING(intel_get_drm_devid(fd)) ? I915_EXEC_BLT : 0;
120 i915_execbuffer2_set_context_id(exec, 0);
123 ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
126 igt_assert(ret == error);
128 gem_close(fd, handle);
132 static void minor_evictions(int fd, int size, int count)
135 int n, m, alignment, pass, fail;
137 igt_require(intel_check_memory(2*count, size, CHECK_RAM));
139 bo = malloc(3*count*sizeof(*bo));
142 for (n = 0; n < 2*count; n++)
143 bo[n] = gem_create(fd, size);
146 for (alignment = m = 4096; alignment <= size; alignment <<= 1) {
147 for (fail = 0; fail < 10; fail++) {
148 for (pass = 0; pass < 100; pass++) {
149 for (n = 0; n < count; n++, m += 7)
150 sel[n] = bo[m%(2*count)];
151 copy(fd, sel[0], sel[1], sel, count, alignment, 0);
153 copy(fd, bo[0], bo[0], bo, 2*count, alignment, ENOSPC);
157 for (n = 0; n < 2*count; n++)
158 gem_close(fd, bo[n]);
162 static void major_evictions(int fd, int size, int count)
164 int n, m, loop, alignment, max;
167 igt_require(intel_check_memory(count, size, CHECK_RAM));
169 bo = malloc(count*sizeof(*bo));
172 for (n = 0; n < count; n++)
173 bo[n] = gem_create(fd, size);
175 max = gem_aperture_size(fd) - size;
176 for (alignment = m = 4096; alignment < max; alignment <<= 1) {
177 for (loop = 0; loop < 100; loop++, m += 17) {
179 copy(fd, bo[n], bo[n], &bo[n], 1, alignment, 0);
183 for (n = 0; n < count; n++)
184 gem_close(fd, bo[n]);
194 igt_skip_on_simulation();
200 igt_subtest("minor-normal") {
202 count = 3*gem_aperture_size(fd) / size / 4;
203 minor_evictions(fd, size, count);
206 igt_subtest("major-normal") {
207 size = 3*gem_aperture_size(fd) / 4;
209 major_evictions(fd, size, count);
212 igt_fork_signal_helper();
213 igt_subtest("minor-interruptible") {
215 count = 3*gem_aperture_size(fd) / size / 4;
216 minor_evictions(fd, size, count);
219 igt_subtest("major-interruptible") {
220 size = 3*gem_aperture_size(fd) / 4;
222 major_evictions(fd, size, count);
224 igt_stop_signal_helper();