2 * Copyright © 2012 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>
28 /* Exercises the basic execbuffer using theh andle LUT interface */
43 #define MI_BATCH_BUFFER_END (0xA<<23)
44 #define BATCH_SIZE (1024*1024)
46 #define LOCAL_I915_EXEC_NO_RELOC (1<<11)
47 #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
49 #define MAX_NUM_EXEC 2048
50 #define MAX_NUM_RELOC 4096
53 #define SKIP_RELOC 0x2
56 struct drm_i915_gem_exec_object2 gem_exec[MAX_NUM_EXEC+1];
57 struct drm_i915_gem_relocation_entry gem_reloc[MAX_NUM_RELOC];
59 static uint32_t state = 0x12345678;
62 hars_petruska_f54_1_random (void)
64 #define rol(x,k) ((x << k) | (x >> (32-k)))
65 return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
70 static int exec(int fd, int num_exec, int num_relocs, unsigned flags)
72 struct drm_i915_gem_execbuffer2 execbuf;
73 struct drm_i915_gem_exec_object2 *objects;
76 gem_exec[MAX_NUM_EXEC].relocation_count = num_relocs;
77 gem_exec[MAX_NUM_EXEC].relocs_ptr = (uintptr_t) gem_reloc;
79 objects = gem_exec + MAX_NUM_EXEC - num_exec;
81 for (i = 0; i < num_relocs; i++) {
82 int target = hars_petruska_f54_1_random() % num_exec;
83 gem_reloc[i].offset = 1024;
84 gem_reloc[i].delta = 0;
85 gem_reloc[i].target_handle =
86 flags & USE_LUT ? target : objects[target].handle;
87 gem_reloc[i].read_domains = I915_GEM_DOMAIN_RENDER;
88 gem_reloc[i].write_domain = 0;
89 gem_reloc[i].presumed_offset = 0;
90 if (flags & SKIP_RELOC)
91 gem_reloc[i].presumed_offset = objects[target].offset;
94 execbuf.buffers_ptr = (uintptr_t)objects;
95 execbuf.buffer_count = num_exec + 1;
96 execbuf.batch_start_offset = 0;
97 execbuf.batch_len = 8;
98 execbuf.cliprects_ptr = 0;
99 execbuf.num_cliprects = 0;
104 execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT;
105 if (flags & NO_RELOC)
106 execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC;
107 i915_execbuffer2_set_context_id(execbuf, 0);
111 DRM_IOCTL_I915_GEM_EXECBUFFER2,
115 #define ELAPSED(a,b) (1e6*((b)->tv_sec - (a)->tv_sec) + ((b)->tv_usec - (a)->tv_usec))
116 int main(int argc, char **argv)
118 uint32_t batch[2] = {MI_BATCH_BUFFER_END};
124 { .name = "relocation", .flags = 0 },
125 { .name = "skip-relocs", .flags = SKIP_RELOC },
126 { .name = "no-relocs", .flags = NO_RELOC },
130 drmtest_skip_on_simulation();
134 for (n = 0; n < MAX_NUM_EXEC; n++) {
135 gem_exec[n].handle = gem_create(fd, 4096);
136 gem_exec[n].relocation_count = 0;
137 gem_exec[n].relocs_ptr = 0;
138 gem_exec[n].alignment = 0;
139 gem_exec[n].offset = 0;
140 gem_exec[n].flags = 0;
141 gem_exec[n].rsvd1 = 0;
142 gem_exec[n].rsvd2 = 0;
145 gem_exec[n].handle = gem_create(fd, 4096);
146 gem_write(fd, gem_exec[n].handle, 0, batch, sizeof(batch));
148 if (exec(fd, 1, 0, USE_LUT))
151 for (p = pass; p->name != NULL; p++) {
152 for (n = 1; n <= MAX_NUM_EXEC; n *= 2) {
153 for (m = 1; m <= MAX_NUM_RELOC; m *= 2) {
154 struct timeval start, end;
157 gettimeofday(&start, NULL);
158 for (count = 0; count < 1000; count++)
159 do_or_die(exec(fd, n, m, 0 | p->flags));
160 gettimeofday(&end, NULL);
161 gem_sync(fd, gem_exec[MAX_NUM_EXEC].handle);
162 elapsed[0] = ELAPSED(&start, &end) / 1000.;
164 gettimeofday(&start, NULL);
165 for (count = 0; count < 1000; count++)
166 do_or_die(exec(fd, n, m, USE_LUT | p->flags));
167 gettimeofday(&end, NULL);
168 gem_sync(fd, gem_exec[MAX_NUM_EXEC].handle);
169 elapsed[1] = ELAPSED(&start, &end) / 1000.;
171 printf("%s: buffer_count=%d, reloc_count=%d: old=%f us, lut=%f us\n",
172 p->name, n, m, elapsed[0], elapsed[1]);