2 * Copyright © 2014 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>
37 #include <sys/ioctl.h>
42 #include "ioctl_wrappers.h"
44 #include "intel_chipset.h"
46 static const uint32_t canary = 0xdeadbeef;
54 static double elapsed(const struct timeval *start,
55 const struct timeval *end)
57 return 1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec);
60 static void busy(data_t *data, uint32_t handle, int size, int loops)
62 struct drm_i915_gem_relocation_entry reloc[20];
63 struct drm_i915_gem_exec_object2 gem_exec[2];
64 struct drm_i915_gem_execbuffer2 execbuf;
65 struct drm_i915_gem_pwrite gem_pwrite;
66 struct drm_i915_gem_create create;
67 uint32_t buf[170], *b;
70 memset(reloc, 0, sizeof(reloc));
71 memset(gem_exec, 0, sizeof(gem_exec));
72 memset(&execbuf, 0, sizeof(execbuf));
75 for (i = 0; i < 20; i++) {
76 *b++ = XY_COLOR_BLT_CMD_NOLEN |
77 ((data->intel_gen >= 8) ? 5 : 4) |
78 COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB;
79 *b++ = 0xf0 << 16 | 1 << 25 | 1 << 24 | 4096;
81 *b++ = size >> 12 << 16 | 1024;
82 reloc[i].offset = (b - buf) * sizeof(uint32_t);
83 reloc[i].target_handle = handle;
84 reloc[i].read_domains = I915_GEM_DOMAIN_RENDER;
85 reloc[i].write_domain = I915_GEM_DOMAIN_RENDER;
87 if (data->intel_gen >= 8)
91 *b++ = MI_BATCH_BUFFER_END;
95 gem_exec[0].handle = handle;
96 gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE;
100 drmIoctl(data->fd, DRM_IOCTL_I915_GEM_CREATE, &create);
101 gem_exec[1].handle = create.handle;
102 gem_exec[1].relocation_count = 20;
103 gem_exec[1].relocs_ptr = (uintptr_t)reloc;
105 execbuf.buffers_ptr = (uintptr_t)gem_exec;
106 execbuf.buffer_count = 2;
107 execbuf.batch_len = (b - buf) * sizeof(buf[0]);
108 execbuf.flags = 1 << 11;
109 if (HAS_BLT_RING(data->devid))
110 execbuf.flags |= I915_EXEC_BLT;
112 gem_pwrite.handle = gem_exec[1].handle;
113 gem_pwrite.offset = 0;
114 gem_pwrite.size = execbuf.batch_len;
115 gem_pwrite.data_ptr = (uintptr_t)buf;
116 if (drmIoctl(data->fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite) == 0) {
118 drmIoctl(data->fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
121 drmIoctl(data->fd, DRM_IOCTL_GEM_CLOSE, &create.handle);
124 static void run(data_t *data, int child)
126 const int size = 4096 * (256 + child * child);
127 const int tiling = child % 2;
128 const int write = child % 2;
129 uint32_t handle = gem_create(data->fd, size);
135 if (tiling != I915_TILING_NONE)
136 gem_set_tiling(data->fd, handle, tiling, 4096);
138 /* load up the unfaulted bo */
139 busy(data, handle, size, 100);
141 /* Note that we ignore the API and rely on the implict
142 * set-to-gtt-domain within the fault handler.
145 ptr = gem_mmap(data->fd, handle, size, PROT_READ | PROT_WRITE);
146 ptr[rand() % (size / 4)] = canary;
148 ptr = gem_mmap(data->fd, handle, size, PROT_READ);
149 x = ptr[rand() % (size / 4)];
152 igt_assert(x == canary);
157 struct timeval start, end;
161 /* check for an intel gpu before goint nuts. */
162 int fd = drm_open_any();
165 igt_skip_on_simulation();
167 data.fd = drm_open_any();
168 data.devid = intel_get_drm_devid(data.fd);
169 data.intel_gen = intel_gen(data.devid);
171 gettimeofday(&start, NULL);
172 igt_fork(child, ARRAY_SIZE(children))
175 gettimeofday(&end, NULL);
177 igt_info("Time to execute %lu children: %7.3fms\n",
178 ARRAY_SIZE(children), elapsed(&start, &end) / 1000);