2 * Copyright © 2011 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 * Daniel Vetter <daniel.vetter@ffwll.ch>
40 #include "intel_bufmgr.h"
41 #include "intel_batchbuffer.h"
42 #include "intel_gpu_tools.h"
45 * Testcase: pwrite/pread consistency when touching partial cachelines
47 * Some fancy new pwrite/pread optimizations clflush in-line while
48 * reading/writing. Check whether all required clflushes happen.
52 static drm_intel_bufmgr *bufmgr;
53 struct intel_batchbuffer *batch;
55 drm_intel_bo *scratch_bo;
56 drm_intel_bo *staging_bo;
57 #define BO_SIZE (4*4096)
59 uint64_t mappable_gtt_limit;
63 copy_bo(drm_intel_bo *src, drm_intel_bo *dst)
66 OUT_BATCH(XY_SRC_COPY_BLT_CMD |
67 XY_SRC_COPY_BLT_WRITE_ALPHA |
68 XY_SRC_COPY_BLT_WRITE_RGB);
69 OUT_BATCH((3 << 24) | /* 32 bits */
70 (0xcc << 16) | /* copy ROP */
72 OUT_BATCH(0 << 16 | 0);
73 OUT_BATCH((BO_SIZE/4096) << 16 | 1024);
74 OUT_RELOC_FENCED(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
75 OUT_BATCH(0 << 16 | 0);
77 OUT_RELOC_FENCED(src, I915_GEM_DOMAIN_RENDER, 0, 0);
80 intel_batchbuffer_flush(batch);
84 blt_bo_fill(drm_intel_bo *tmp_bo, drm_intel_bo *bo, int val)
89 drm_intel_gem_bo_map_gtt(tmp_bo);
90 gtt_ptr = tmp_bo->virtual;
92 for (i = 0; i < BO_SIZE; i++)
95 drm_intel_gem_bo_unmap_gtt(tmp_bo);
97 if (bo->offset < mappable_gtt_limit &&
98 (IS_G33(devid) || intel_gen(devid) >= 4))
104 #define MAX_BLT_SIZE 128
106 uint8_t tmp[BO_SIZE];
108 static void test_partial_reads(void)
112 printf("checking partial reads\n");
113 for (i = 0; i < ROUNDS; i++) {
117 blt_bo_fill(staging_bo, scratch_bo, i);
119 start = random() % BO_SIZE;
120 len = random() % (BO_SIZE-start) + 1;
122 drm_intel_bo_get_subdata(scratch_bo, start, len, tmp);
123 for (j = 0; j < len; j++) {
125 printf("mismatch at %i, got: %i, expected: %i\n",
131 igt_progress("partial reads test: ", i, ROUNDS);
136 static void test_partial_writes(void)
141 printf("checking partial writes\n");
142 for (i = 0; i < ROUNDS; i++) {
146 blt_bo_fill(staging_bo, scratch_bo, i);
148 start = random() % BO_SIZE;
149 len = random() % (BO_SIZE-start) + 1;
151 memset(tmp, i + 63, BO_SIZE);
153 drm_intel_bo_subdata(scratch_bo, start, len, tmp);
155 copy_bo(scratch_bo, staging_bo);
156 drm_intel_gem_bo_map_gtt(staging_bo);
157 gtt_ptr = staging_bo->virtual;
159 for (j = 0; j < start; j++) {
160 if (gtt_ptr[j] != val) {
161 printf("mismatch at %i, got: %i, expected: %i\n",
166 for (; j < start + len; j++) {
167 if (gtt_ptr[j] != tmp[0]) {
168 printf("mismatch at %i, got: %i, expected: %i\n",
173 for (; j < BO_SIZE; j++) {
174 if (gtt_ptr[j] != val) {
175 printf("mismatch at %i, got: %i, expected: %i\n",
180 drm_intel_gem_bo_unmap_gtt(staging_bo);
182 igt_progress("partial writes test: ", i, ROUNDS);
187 static void test_partial_read_writes(void)
192 printf("checking partial writes after partial reads\n");
193 for (i = 0; i < ROUNDS; i++) {
197 blt_bo_fill(staging_bo, scratch_bo, i);
200 start = random() % BO_SIZE;
201 len = random() % (BO_SIZE-start) + 1;
203 drm_intel_bo_get_subdata(scratch_bo, start, len, tmp);
204 for (j = 0; j < len; j++) {
206 printf("mismatch in read at %i, got: %i, expected: %i\n",
212 /* Change contents through gtt to make the pread cachelines
214 val = (i + 17) % 256;
215 blt_bo_fill(staging_bo, scratch_bo, val);
218 start = random() % BO_SIZE;
219 len = random() % (BO_SIZE-start) + 1;
221 memset(tmp, i + 63, BO_SIZE);
223 drm_intel_bo_subdata(scratch_bo, start, len, tmp);
225 copy_bo(scratch_bo, staging_bo);
226 drm_intel_gem_bo_map_gtt(staging_bo);
227 gtt_ptr = staging_bo->virtual;
229 for (j = 0; j < start; j++) {
230 if (gtt_ptr[j] != val) {
231 printf("mismatch at %i, got: %i, expected: %i\n",
236 for (; j < start + len; j++) {
237 if (gtt_ptr[j] != tmp[0]) {
238 printf("mismatch at %i, got: %i, expected: %i\n",
243 for (; j < BO_SIZE; j++) {
244 if (gtt_ptr[j] != val) {
245 printf("mismatch at %i, got: %i, expected: %i\n",
250 drm_intel_gem_bo_unmap_gtt(staging_bo);
252 igt_progress("partial read/writes test: ", i, ROUNDS);
256 static void do_tests(int cache_level, const char *suffix)
260 if (cache_level != -1)
261 gem_set_caching(fd, scratch_bo->handle, cache_level);
263 snprintf(name, sizeof(name), "reads%s", suffix);
265 test_partial_reads();
267 snprintf(name, sizeof(name), "writes%s", suffix);
269 test_partial_writes();
271 snprintf(name, sizeof(name), "writes-after-reads%s", suffix);
273 test_partial_read_writes();
276 int main(int argc, char **argv)
280 igt_subtest_init(argc, argv);
281 igt_skip_on_simulation();
285 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
286 //drm_intel_bufmgr_gem_enable_reuse(bufmgr);
287 devid = intel_get_drm_devid(fd);
288 batch = intel_batchbuffer_alloc(bufmgr, devid);
290 /* overallocate the buffers we're actually using because */
291 scratch_bo = drm_intel_bo_alloc(bufmgr, "scratch bo", BO_SIZE, 4096);
292 staging_bo = drm_intel_bo_alloc(bufmgr, "staging bo", BO_SIZE, 4096);
294 igt_init_aperture_trashers(bufmgr);
295 mappable_gtt_limit = gem_mappable_aperture_size();
299 /* Repeat the tests using different levels of snooping */
300 do_tests(0, "-uncached");
301 do_tests(1, "-snoop");
302 do_tests(2, "-display");
304 igt_cleanup_aperture_trashers();
305 drm_intel_bufmgr_destroy(bufmgr);