2 * Copyright © 2010 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 * Eric Anholt <eric@anholt.net>
25 * Chris Wilson <chris@chris-wilson.co.uk>
38 #include <sys/ioctl.h>
41 #include "ioctl_wrappers.h"
44 #define OBJECT_SIZE 16384
46 static double elapsed(const struct timeval *start,
47 const struct timeval *end,
50 return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop;
53 int main(int argc, char **argv)
55 struct timeval start, end;
58 int size = OBJECT_SIZE;
64 igt_skip_on_simulation();
69 igt_warn("Invalid object size specified\n");
77 handle = gem_create(fd, size);
80 for (tiling = I915_TILING_NONE; tiling <= I915_TILING_Y; tiling++) {
81 if (tiling != I915_TILING_NONE) {
82 igt_info("\nSetting tiling mode to %s\n",
83 tiling == I915_TILING_X ? "X" : "Y");
84 gem_set_tiling(fd, handle, tiling, 512);
87 if (tiling == I915_TILING_NONE) {
88 gem_set_domain(fd, handle,
93 uint32_t *base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
94 volatile uint32_t *ptr = base;
97 for (i = 0; i < size/sizeof(*ptr); i++)
100 /* force overtly clever gcc to actually compute x */
106 gettimeofday(&start, NULL);
107 for (loop = 0; loop < 1000; loop++) {
108 base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
112 for (i = 0; i < size/sizeof(*ptr); i++)
115 /* force overtly clever gcc to actually compute x */
120 gettimeofday(&end, NULL);
121 igt_info("Time to read %dk through a CPU map: %7.3fµs\n",
122 size/1024, elapsed(&start, &end, loop));
125 gettimeofday(&start, NULL);
126 for (loop = 0; loop < 1000; loop++) {
127 base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
130 for (i = 0; i < size/sizeof(*ptr); i++)
135 gettimeofday(&end, NULL);
136 igt_info("Time to write %dk through a CPU map: %7.3fµs\n",
137 size/1024, elapsed(&start, &end, loop));
139 gettimeofday(&start, NULL);
140 for (loop = 0; loop < 1000; loop++) {
141 base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
142 memset(base, 0, size);
145 gettimeofday(&end, NULL);
146 igt_info("Time to clear %dk through a CPU map: %7.3fµs\n",
147 size/1024, elapsed(&start, &end, loop));
149 gettimeofday(&start, NULL);
150 base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
151 for (loop = 0; loop < 1000; loop++)
152 memset(base, 0, size);
154 gettimeofday(&end, NULL);
155 igt_info("Time to clear %dk through a cached CPU map: %7.3fµs\n",
156 size/1024, elapsed(&start, &end, loop));
160 gettimeofday(&start, NULL);
161 for (loop = 0; loop < 1000; loop++)
162 gem_write(fd, handle, 0, buf, size);
163 gettimeofday(&end, NULL);
164 igt_info("Time to pwrite %dk through the CPU: %7.3fµs\n",
165 size/1024, elapsed(&start, &end, loop));
168 gettimeofday(&start, NULL);
169 for (loop = 0; loop < 1000; loop++)
170 gem_read(fd, handle, 0, buf, size);
171 gettimeofday(&end, NULL);
172 igt_info("Time to pread %dk through the CPU: %7.3fµs\n",
173 size/1024, elapsed(&start, &end, loop));
176 /* prefault into gtt */
178 uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
179 volatile uint32_t *ptr = base;
182 for (i = 0; i < size/sizeof(*ptr); i++)
185 /* force overtly clever gcc to actually compute x */
191 gettimeofday(&start, NULL);
192 for (loop = 0; loop < 1000; loop++) {
193 uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
194 volatile uint32_t *ptr = base;
197 for (i = 0; i < size/sizeof(*ptr); i++)
200 /* force overtly clever gcc to actually compute x */
205 gettimeofday(&end, NULL);
206 igt_info("Time to read %dk through a GTT map: %7.3fµs\n",
207 size/1024, elapsed(&start, &end, loop));
210 gettimeofday(&start, NULL);
211 for (loop = 0; loop < 1000; loop++) {
212 uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
213 volatile uint32_t *ptr = base;
215 for (i = 0; i < size/sizeof(*ptr); i++)
220 gettimeofday(&end, NULL);
221 igt_info("Time to write %dk through a GTT map: %7.3fµs\n",
222 size/1024, elapsed(&start, &end, loop));
225 gettimeofday(&start, NULL);
226 for (loop = 0; loop < 1000; loop++) {
227 uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
228 memset(base, 0, size);
231 gettimeofday(&end, NULL);
232 igt_info("Time to clear %dk through a GTT map: %7.3fµs\n",
233 size/1024, elapsed(&start, &end, loop));
235 gettimeofday(&start, NULL);{
236 uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
237 for (loop = 0; loop < 1000; loop++)
238 memset(base, 0, size);
240 } gettimeofday(&end, NULL);
241 igt_info("Time to clear %dk through a cached GTT map: %7.3fµs\n",
242 size/1024, elapsed(&start, &end, loop));
245 gettimeofday(&start, NULL);
246 for (loop = 0; loop < 1000; loop++) {
247 uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
248 volatile uint32_t *ptr = base;
251 for (i = 0; i < size/sizeof(*ptr); i++)
254 /* force overtly clever gcc to actually compute x */
259 gettimeofday(&end, NULL);
260 igt_info("Time to read %dk (again) through a GTT map: %7.3fµs\n",
261 size/1024, elapsed(&start, &end, loop));
263 if (tiling == I915_TILING_NONE) {
265 gettimeofday(&start, NULL);
266 for (loop = 0; loop < 1000; loop++)
267 gem_write(fd, handle, 0, buf, size);
268 gettimeofday(&end, NULL);
269 igt_info("Time to pwrite %dk through the GTT: %7.3fµs\n",
270 size/1024, elapsed(&start, &end, loop));
273 gettimeofday(&start, NULL);
274 for (loop = 0; loop < 1000; loop++)
275 gem_read(fd, handle, 0, buf, size);
276 gettimeofday(&end, NULL);
277 igt_info("Time to pread %dk through the GTT: %7.3fµs\n",
278 size/1024, elapsed(&start, &end, loop));
280 /* GTT pwrite, including clflush */
281 gettimeofday(&start, NULL);
282 for (loop = 0; loop < 1000; loop++) {
283 gem_write(fd, handle, 0, buf, size);
284 gem_sync(fd, handle);
286 gettimeofday(&end, NULL);
287 igt_info("Time to pwrite %dk through the GTT (clflush): %7.3fµs\n",
288 size/1024, elapsed(&start, &end, loop));
290 /* GTT pread, including clflush */
291 gettimeofday(&start, NULL);
292 for (loop = 0; loop < 1000; loop++) {
293 gem_sync(fd, handle);
294 gem_read(fd, handle, 0, buf, size);
296 gettimeofday(&end, NULL);
297 igt_info("Time to pread %dk through the GTT (clflush): %7.3fµs\n",
298 size/1024, elapsed(&start, &end, loop));
301 igt_info("Now partial writes.\n");
304 /* partial GTT pwrite, including clflush */
305 gettimeofday(&start, NULL);
306 for (loop = 0; loop < 1000; loop++) {
307 gem_write(fd, handle, 0, buf, size);
308 gem_sync(fd, handle);
310 gettimeofday(&end, NULL);
311 igt_info("Time to pwrite %dk through the GTT (clflush): %7.3fµs\n",
312 size/1024, elapsed(&start, &end, loop));
314 /* partial GTT pread, including clflush */
315 gettimeofday(&start, NULL);
316 for (loop = 0; loop < 1000; loop++) {
317 gem_sync(fd, handle);
318 gem_read(fd, handle, 0, buf, size);
320 gettimeofday(&end, NULL);
321 igt_info("Time to pread %dk through the GTT (clflush): %7.3fµs\n",
322 size/1024, elapsed(&start, &end, loop));
329 gem_close(fd, handle);