blob: 8608592a132433af3d7ae45d7e942ee8077aff41 [file] [log] [blame]
Chris Wilson07d59b32011-01-20 22:10:10 +00001/*
2 * Copyright © 2011 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Chris Wilson <chris@chris-wilson.co.uk>
25 *
26 */
27
28#include <unistd.h>
29#include <stdlib.h>
30#include <stdint.h>
31#include <stdio.h>
32#include <string.h>
33#include <assert.h>
34#include <fcntl.h>
35#include <inttypes.h>
36#include <errno.h>
37#include <sys/stat.h>
38#include <sys/ioctl.h>
39#include <sys/mman.h>
40#include <sys/time.h>
41#include "drm.h"
42#include "i915_drm.h"
43#include "drmtest.h"
Daniel Vetterd9d95782012-12-04 17:13:05 +010044#include "intel_gpu_tools.h"
Chris Wilson07d59b32011-01-20 22:10:10 +000045
Daniel Vetter51f08302012-12-05 19:29:11 +010046bool skipped_all = true;
47
Chris Wilson07d59b32011-01-20 22:10:10 +000048static double elapsed(const struct timeval *start,
49 const struct timeval *end,
50 int loop)
51{
52 return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop;
53}
54
Daniel Vetterd9d95782012-12-04 17:13:05 +010055static int exec(int fd, uint32_t handle, int loops, unsigned ring_id)
Chris Wilson07d59b32011-01-20 22:10:10 +000056{
57 struct drm_i915_gem_execbuffer2 execbuf;
Daniel Vettera7a80c22012-01-10 15:50:20 +010058 struct drm_i915_gem_exec_object2 gem_exec[1];
Chris Wilson2a292182011-12-14 17:41:34 +000059 int ret = 0;
Chris Wilson07d59b32011-01-20 22:10:10 +000060
Daniel Vettera7a80c22012-01-10 15:50:20 +010061 gem_exec[0].handle = handle;
62 gem_exec[0].relocation_count = 0;
63 gem_exec[0].relocs_ptr = 0;
64 gem_exec[0].alignment = 0;
65 gem_exec[0].offset = 0;
66 gem_exec[0].flags = 0;
67 gem_exec[0].rsvd1 = 0;
68 gem_exec[0].rsvd2 = 0;
Chris Wilson07d59b32011-01-20 22:10:10 +000069
Daniel Vettera7a80c22012-01-10 15:50:20 +010070 execbuf.buffers_ptr = (uintptr_t)gem_exec;
Chris Wilson07d59b32011-01-20 22:10:10 +000071 execbuf.buffer_count = 1;
72 execbuf.batch_start_offset = 0;
73 execbuf.batch_len = 8;
74 execbuf.cliprects_ptr = 0;
75 execbuf.num_cliprects = 0;
76 execbuf.DR1 = 0;
77 execbuf.DR4 = 0;
Daniel Vetterad591962012-12-05 04:16:38 +010078 execbuf.flags = ring_id;
Ben Widawsky5a28ef82012-03-18 18:42:44 -070079 i915_execbuffer2_set_context_id(execbuf, 0);
Chris Wilson07d59b32011-01-20 22:10:10 +000080 execbuf.rsvd2 = 0;
81
Chris Wilson2a292182011-12-14 17:41:34 +000082 while (loops-- && ret == 0) {
Chris Wilson07d59b32011-01-20 22:10:10 +000083 ret = drmIoctl(fd,
84 DRM_IOCTL_I915_GEM_EXECBUFFER2,
85 &execbuf);
86 }
87 gem_sync(fd, handle);
Chris Wilson2a292182011-12-14 17:41:34 +000088
89 return ret;
Chris Wilson07d59b32011-01-20 22:10:10 +000090}
91
Daniel Vetterd9d95782012-12-04 17:13:05 +010092static void loop(int fd, uint32_t handle, unsigned ring_id, const char *ring_name)
Chris Wilson07d59b32011-01-20 22:10:10 +000093{
Chris Wilson07d59b32011-01-20 22:10:10 +000094 int count;
Chris Wilson07d59b32011-01-20 22:10:10 +000095
Daniel Vetter51f08302012-12-05 19:29:11 +010096 skipped_all = false;
97
Chris Wilson07d59b32011-01-20 22:10:10 +000098 for (count = 1; count <= 1<<17; count <<= 1) {
99 struct timeval start, end;
100
101 gettimeofday(&start, NULL);
Daniel Vetterd9d95782012-12-04 17:13:05 +0100102 if (exec(fd, handle, count, ring_id))
Chris Wilson2a292182011-12-14 17:41:34 +0000103 exit(1);
Chris Wilson07d59b32011-01-20 22:10:10 +0000104 gettimeofday(&end, NULL);
Daniel Vetterd9d95782012-12-04 17:13:05 +0100105 printf("Time to exec x %d: %7.3fµs (ring=%s)\n",
106 count, elapsed(&start, &end, count), ring_name);
Chris Wilson07d59b32011-01-20 22:10:10 +0000107 fflush(stdout);
108 }
Daniel Vetterd9d95782012-12-04 17:13:05 +0100109
110}
111int main(int argc, char **argv)
112{
113 uint32_t batch[2] = {MI_BATCH_BUFFER_END};
114 uint32_t handle;
115 uint32_t devid;
116 int fd;
117
Daniel Vetterad591962012-12-05 04:16:38 +0100118 drmtest_subtest_init(argc, argv);
119
Daniel Vetterd9d95782012-12-04 17:13:05 +0100120 fd = drm_open_any();
121 devid = intel_get_drm_devid(fd);
122
123 handle = gem_create(fd, 4096);
124 gem_write(fd, handle, 0, batch, sizeof(batch));
125
126 if (drmtest_run_subtest("render"))
127 loop(fd, handle, I915_EXEC_RENDER, "render");
128
129 if (drmtest_run_subtest("bsd"))
130 if (HAS_BSD_RING(devid))
131 loop(fd, handle, I915_EXEC_BSD, "bsd");
132
133 if (drmtest_run_subtest("blt"))
134 if (HAS_BLT_RING(devid))
135 loop(fd, handle, I915_EXEC_BLT, "blt");
136
137
Chris Wilson07d59b32011-01-20 22:10:10 +0000138 gem_close(fd, handle);
139
140 close(fd);
141
Daniel Vetter51f08302012-12-05 19:29:11 +0100142 return skipped_all ? 77 : 0;
Chris Wilson07d59b32011-01-20 22:10:10 +0000143}