lib/igt_kms: Unify pipe name helpers
[platform/upstream/intel-gpu-tools.git] / tests / gem_exec_nop.c
1 /*
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 <fcntl.h>
34 #include <inttypes.h>
35 #include <errno.h>
36 #include <sys/stat.h>
37 #include <sys/ioctl.h>
38 #include <sys/time.h>
39 #include "drm.h"
40 #include "ioctl_wrappers.h"
41 #include "drmtest.h"
42 #include "intel_io.h"
43
44 #define LOCAL_I915_EXEC_VEBOX (4<<0)
45
46 static double elapsed(const struct timeval *start,
47                       const struct timeval *end,
48                       int loop)
49 {
50         return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop;
51 }
52
53 static int exec(int fd, uint32_t handle, int loops, unsigned ring_id)
54 {
55         struct drm_i915_gem_execbuffer2 execbuf;
56         struct drm_i915_gem_exec_object2 gem_exec[1];
57         int ret = 0;
58
59         gem_exec[0].handle = handle;
60         gem_exec[0].relocation_count = 0;
61         gem_exec[0].relocs_ptr = 0;
62         gem_exec[0].alignment = 0;
63         gem_exec[0].offset = 0;
64         gem_exec[0].flags = 0;
65         gem_exec[0].rsvd1 = 0;
66         gem_exec[0].rsvd2 = 0;
67
68         execbuf.buffers_ptr = (uintptr_t)gem_exec;
69         execbuf.buffer_count = 1;
70         execbuf.batch_start_offset = 0;
71         execbuf.batch_len = 8;
72         execbuf.cliprects_ptr = 0;
73         execbuf.num_cliprects = 0;
74         execbuf.DR1 = 0;
75         execbuf.DR4 = 0;
76         execbuf.flags = ring_id;
77         i915_execbuffer2_set_context_id(execbuf, 0);
78         execbuf.rsvd2 = 0;
79
80         while (loops-- && ret == 0) {
81                 ret = drmIoctl(fd,
82                                DRM_IOCTL_I915_GEM_EXECBUFFER2,
83                                &execbuf);
84         }
85         gem_sync(fd, handle);
86
87         return ret;
88 }
89
90 static void loop(int fd, uint32_t handle, unsigned ring_id, const char *ring_name)
91 {
92         int count;
93
94         gem_require_ring(fd, ring_id);
95
96         for (count = 1; count <= SLOW_QUICK(1<<17, 1<<4); count <<= 1) {
97                 struct timeval start, end;
98
99                 gettimeofday(&start, NULL);
100                 igt_assert(exec(fd, handle, count, ring_id) == 0);
101                 gettimeofday(&end, NULL);
102                 igt_info("Time to exec x %d:            %7.3fµs (ring=%s)\n",
103                          count, elapsed(&start, &end, count), ring_name);
104                 fflush(stdout);
105         }
106 }
107
108 uint32_t batch[2] = {MI_BATCH_BUFFER_END};
109 uint32_t handle;
110 int fd;
111
112 igt_main
113 {
114         igt_fixture {
115                 fd = drm_open_any();
116
117                 handle = gem_create(fd, 4096);
118                 gem_write(fd, handle, 0, batch, sizeof(batch));
119         }
120
121         igt_subtest("render")
122                 loop(fd, handle, I915_EXEC_RENDER, "render");
123
124         igt_subtest("bsd")
125                 loop(fd, handle, I915_EXEC_BSD, "bsd");
126
127         igt_subtest("blt")
128                 loop(fd, handle, I915_EXEC_BLT, "blt");
129
130         igt_subtest("vebox")
131                 loop(fd, handle, LOCAL_I915_EXEC_VEBOX, "vebox");
132
133         igt_fixture {
134                 gem_close(fd, handle);
135
136                 close(fd);
137         }
138 }