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 * Chris Wilson <chris@chris-wilson.co.uk>
38 #include <sys/ioctl.h>
45 #define OBJECT_SIZE 16384
47 #define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
48 #define BLT_WRITE_ALPHA (1<<21)
49 #define BLT_WRITE_RGB (1<<20)
50 #define BLT_SRC_TILED (1<<15)
51 #define BLT_DST_TILED (1<<11)
53 static void do_gem_write(int fd, uint32_t handle, void *buf, int len, int loops)
56 gem_write(fd, handle, 0, buf, len);
59 static double elapsed(const struct timeval *start,
60 const struct timeval *end,
63 return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop;
66 static const char *bytes_per_sec(char *buf, double v)
68 const char *order[] = {
77 while (v > 1000 && o[1]) {
81 sprintf(buf, "%.1f%s/s", v, *o);
86 int main(int argc, char **argv)
102 igt_skip_on_simulation();
104 igt_subtest_init(argc, argv);
105 igt_skip_on_simulation();
107 if (argc > 1 && atoi(argv[1]))
108 object_size = atoi(argv[1]);
109 if (object_size == 0)
110 object_size = OBJECT_SIZE;
111 object_size = (object_size + 3) & -4;
115 dst = gem_create(fd, object_size);
116 src = malloc(object_size);
118 igt_subtest("normal") {
119 for (count = 1; count <= 1<<17; count <<= 1) {
120 struct timeval start, end;
122 gettimeofday(&start, NULL);
123 do_gem_write(fd, dst, src, object_size, count);
124 gettimeofday(&end, NULL);
125 printf("Time to pwrite %d bytes x %6d: %7.3fµs, %s\n",
127 elapsed(&start, &end, count),
128 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
133 for (c = cache; c->level != -1; c++) {
134 igt_subtest(c->name) {
135 gem_set_caching(fd, dst, c->level);
137 for (count = 1; count <= 1<<17; count <<= 1) {
138 struct timeval start, end;
140 gettimeofday(&start, NULL);
141 do_gem_write(fd, dst, src, object_size, count);
142 gettimeofday(&end, NULL);
143 printf("Time to %s pwrite %d bytes x %6d: %7.3fµs, %s\n",
144 c->name, object_size, count,
145 elapsed(&start, &end, count),
146 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));