1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
/*
* Copyright © 2009 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
/** @file gem_pread_after_blit.c
*
* This is a test of pread's behavior when getting values out of just-drawn-to
* buffers.
*
* The goal is to catch failure in the whole-buffer-flush or
* ranged-buffer-flush paths in the kernel.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <drm.h>
#include "i915/gem.h"
#include "igt.h"
/**
* TEST: gem pread after blit
* Description: Test pread behavior when getting values out of just-drawn-to buffers.
* Category: Core
* Mega feature: General Core features
* Sub-category: CMD submission
* Functionality: pread
*
* SUBTEST: default-hang
*
* SUBTEST: default-interruptible
*
* SUBTEST: default-normal
*
* SUBTEST: display-hang
*
* SUBTEST: display-interruptible
*
* SUBTEST: display-normal
*
* SUBTEST: snooped-hang
*
* SUBTEST: snooped-interruptible
*
* SUBTEST: snooped-normal
*
* SUBTEST: uncached-hang
*
* SUBTEST: uncached-interruptible
*
* SUBTEST: uncached-normal
*/
IGT_TEST_DESCRIPTION("Test pread behavior when getting values out of"
" just-drawn-to buffers.");
static const int width = 512, height = 512;
static const int size = 1024 * 1024;
#define PAGE_SIZE 4096
static struct intel_buf *
create_bo(struct buf_ops *bops, uint32_t val)
{
struct intel_buf *buf;
uint32_t *vaddr;
int i;
buf = intel_buf_create(bops, width, height, 32, 0, I915_TILING_NONE,
I915_COMPRESSION_NONE);
/* Fill the BO with dwords starting at start_val */
intel_buf_cpu_map(buf, 1);
vaddr = buf->ptr;
for (i = 0; i < 1024 * 1024 / 4; i++)
vaddr[i] = val++;
intel_buf_unmap(buf);
return buf;
}
static void
verify_large_read(int fd, struct intel_buf *buf, uint32_t val)
{
uint32_t tmp[size / 4];
int i;
gem_read(fd, buf->handle, 0, tmp, size);
for (i = 0; i < size / 4; i++) {
igt_assert_f(tmp[i] == val,
"Unexpected value 0x%08x instead of "
"0x%08x at offset 0x%08x (%p)\n",
tmp[i], val, i * 4, tmp);
val++;
}
}
/** This reads at the size that Mesa usees for software fallbacks. */
static void
verify_small_read(int fd, struct intel_buf *buf, uint32_t val)
{
uint32_t tmp[4096 / 4];
int offset, i;
for (i = 0; i < 4096 / 4; i++)
tmp[i] = 0x00c0ffee;
for (offset = 0; offset < size; offset += PAGE_SIZE) {
gem_read(fd, buf->handle, offset, tmp, PAGE_SIZE);
for (i = 0; i < PAGE_SIZE; i += 4) {
igt_assert_f(tmp[i / 4] == val,
"Unexpected value 0x%08x instead of "
"0x%08x at offset 0x%08x\n",
tmp[i / 4], val, i * 4);
val++;
}
}
}
typedef igt_hang_t (*do_hang)(int fd, struct intel_bb *ibb);
static igt_hang_t no_hang(int fd, struct intel_bb *ibb)
{
return (igt_hang_t){0};
}
static igt_hang_t bcs_hang(int fd, struct intel_bb *ibb)
{
return igt_hang_ring(fd, ibb->gen >= 6 ? I915_EXEC_BLT : I915_EXEC_DEFAULT);
}
static void do_test(struct buf_ops *bops, int cache_level,
struct intel_buf *src[2],
const uint32_t start[2],
struct intel_buf *tmp[2],
int loop, do_hang do_hang_func)
{
struct intel_bb *ibb;
igt_hang_t hang;
int fd = buf_ops_get_fd(bops);
ibb = intel_bb_create(fd, 4096);
if (cache_level != -1) {
gem_set_caching(fd, tmp[0]->handle, cache_level);
gem_set_caching(fd, tmp[1]->handle, cache_level);
}
do {
/* First, do a full-buffer read after blitting */
intel_bb_copy_intel_buf(ibb, src[0], tmp[0], size);
hang = do_hang_func(fd, ibb);
verify_large_read(fd, tmp[0], start[0]);
igt_post_hang_ring(fd, hang);
intel_bb_copy_intel_buf(ibb, src[1], tmp[0], size);
hang = do_hang_func(fd, ibb);
verify_large_read(fd, tmp[0], start[1]);
igt_post_hang_ring(fd, hang);
intel_bb_copy_intel_buf(ibb, src[0], tmp[0], size);
hang = do_hang_func(fd, ibb);
verify_small_read(fd, tmp[0], start[0]);
igt_post_hang_ring(fd, hang);
intel_bb_copy_intel_buf(ibb, src[1], tmp[0], size);
hang = do_hang_func(fd, ibb);
verify_small_read(fd, tmp[0], start[1]);
igt_post_hang_ring(fd, hang);
intel_bb_copy_intel_buf(ibb, src[0], tmp[0], size);
hang = do_hang_func(fd, ibb);
verify_large_read(fd, tmp[0], start[0]);
igt_post_hang_ring(fd, hang);
intel_bb_copy_intel_buf(ibb, src[0], tmp[0], size);
intel_bb_copy_intel_buf(ibb, src[1], tmp[1], size);
hang = do_hang_func(fd, ibb);
verify_large_read(fd, tmp[0], start[0]);
verify_large_read(fd, tmp[1], start[1]);
igt_post_hang_ring(fd, hang);
intel_bb_copy_intel_buf(ibb, src[0], tmp[0], size);
intel_bb_copy_intel_buf(ibb, src[1], tmp[1], size);
hang = do_hang_func(fd, ibb);
verify_large_read(fd, tmp[1], start[1]);
verify_large_read(fd, tmp[0], start[0]);
igt_post_hang_ring(fd, hang);
intel_bb_copy_intel_buf(ibb, src[0], tmp[1], size);
intel_bb_copy_intel_buf(ibb, src[1], tmp[0], size);
hang = do_hang_func(fd, ibb);
verify_large_read(fd, tmp[0], start[1]);
verify_large_read(fd, tmp[1], start[0]);
igt_post_hang_ring(fd, hang);
} while (--loop);
intel_bb_destroy(ibb);
}
igt_main
{
const uint32_t start[2] = {0, 1024 * 1024 / 4};
const struct {
const char *name;
int cache;
} tests[] = {
{ "default", -1 },
{ "uncached", 0 },
{ "snooped", 1 },
{ "display", 2 },
{ NULL, -1 },
}, *t;
struct intel_buf *src[2], *dst[2];
struct buf_ops *bops;
int fd;
igt_fixture {
fd = drm_open_driver(DRIVER_INTEL);
igt_require_gem(fd);
gem_require_pread_pwrite(fd);
bops = buf_ops_create(fd);
src[0] = create_bo(bops, start[0]);
src[1] = create_bo(bops, start[1]);
dst[0] = intel_buf_create(bops, width, height, 32, 4096,
I915_TILING_NONE, I915_COMPRESSION_NONE);
dst[1] = intel_buf_create(bops, width, height, 32, 4096,
I915_TILING_NONE, I915_COMPRESSION_NONE);
}
for (t = tests; t->name; t++) {
igt_subtest_f("%s-normal", t->name)
do_test(bops, t->cache, src, start, dst, 1, no_hang);
igt_fork_signal_helper();
igt_subtest_f("%s-interruptible", t->name)
do_test(bops, t->cache, src, start, dst, 100, no_hang);
igt_stop_signal_helper();
igt_subtest_f("%s-hang", t->name)
do_test(bops, t->cache, src, start, dst, 1, bcs_hang);
}
igt_fixture {
intel_buf_destroy(src[0]);
intel_buf_destroy(src[1]);
intel_buf_destroy(dst[0]);
intel_buf_destroy(dst[1]);
buf_ops_destroy(bops);
}
igt_fixture
drm_close_driver(fd);
}
|