blob: 235c8f6944768101b778cc0e8bb46669788cfbec [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>
Chris Wilson07d59b32011-01-20 22:10:10 +000033#include <fcntl.h>
34#include <inttypes.h>
35#include <errno.h>
36#include <sys/stat.h>
37#include <sys/ioctl.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000038#include <sys/time.h>
39#include "drm.h"
Daniel Vettere49ceb82014-03-22 21:07:37 +010040#include "ioctl_wrappers.h"
Chris Wilson07d59b32011-01-20 22:10:10 +000041#include "drmtest.h"
Daniel Vetterc03c6ce2014-03-22 21:34:29 +010042#include "intel_io.h"
Chris Wilson07d59b32011-01-20 22:10:10 +000043
Chris Wilsoncd8d3802015-03-24 09:15:12 +000044#define LOCAL_I915_EXEC_NO_RELOC (1<<11)
45#define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
46
Zhong Libafbbf12013-04-23 15:06:45 +080047#define LOCAL_I915_EXEC_VEBOX (4<<0)
Daniel Vetter51f08302012-12-05 19:29:11 +010048
Chris Wilsoncd8d3802015-03-24 09:15:12 +000049static int dcmp(const void *A, const void *B)
50{
51 double a = *(double *)A, b = *(double *)B;
52 if (a < b)
53 return -1;
54 else if (a > b)
55 return 1;
56 else
57 return 0;
58}
59
Chris Wilson07d59b32011-01-20 22:10:10 +000060static double elapsed(const struct timeval *start,
61 const struct timeval *end,
62 int loop)
63{
64 return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop;
65}
66
Chris Wilsoncd8d3802015-03-24 09:15:12 +000067static void loop(int fd, uint32_t handle, unsigned ring_id, const char *ring_name)
Chris Wilson07d59b32011-01-20 22:10:10 +000068{
69 struct drm_i915_gem_execbuffer2 execbuf;
Daniel Vettera7a80c22012-01-10 15:50:20 +010070 struct drm_i915_gem_exec_object2 gem_exec[1];
Chris Wilson07d59b32011-01-20 22:10:10 +000071 int count;
Chris Wilson07d59b32011-01-20 22:10:10 +000072
Daniel Vetter8f5387e2013-08-13 13:20:58 +020073 gem_require_ring(fd, ring_id);
74
Chris Wilsoncd8d3802015-03-24 09:15:12 +000075 memset(&gem_exec, 0, sizeof(gem_exec));
76 gem_exec[0].handle = handle;
Chris Wilson07d59b32011-01-20 22:10:10 +000077
Chris Wilsoncd8d3802015-03-24 09:15:12 +000078 memset(&execbuf, 0, sizeof(execbuf));
79 execbuf.buffers_ptr = (uintptr_t)gem_exec;
80 execbuf.buffer_count = 1;
81 execbuf.flags = ring_id;
82 execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT;
83 execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC;
84 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf)) {
85 execbuf.flags = ring_id;
86 do_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
87 }
88 gem_sync(fd, handle);
89
90 for (count = 1; count <= SLOW_QUICK(1<<17, 1<<4); count <<= 1) {
91 const int reps = 9;
92 double t[reps], sum;
93 int n;
94
95 for (n = 0; n < reps; n++) {
96 struct timeval start, end;
97 int loops = count;
98 gettimeofday(&start, NULL);
99 while (loops--)
100 do_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
101 gem_sync(fd, handle);
102 gettimeofday(&end, NULL);
103 t[n] = elapsed(&start, &end, count);
104 }
105
106 qsort(t, reps, sizeof(double), dcmp);
107 sum = 0;
108 for (n = 2; n < reps-2; n++)
109 sum += t[n];
110 sum /= reps - 4;
111
Daniel Vettere624fa82014-05-14 00:36:04 +0200112 igt_info("Time to exec x %d: %7.3fµs (ring=%s)\n",
Chris Wilsoncd8d3802015-03-24 09:15:12 +0000113 count, sum, ring_name);
Chris Wilson07d59b32011-01-20 22:10:10 +0000114 fflush(stdout);
115 }
Daniel Vetterd9d95782012-12-04 17:13:05 +0100116}
Daniel Vetter8f5387e2013-08-13 13:20:58 +0200117
Daniel Vetterb3880d32013-08-14 18:02:46 +0200118uint32_t batch[2] = {MI_BATCH_BUFFER_END};
119uint32_t handle;
120int fd;
121
Daniel Vetter071e9ca2013-10-31 16:23:26 +0100122igt_main
Daniel Vetterd9d95782012-12-04 17:13:05 +0100123{
Daniel Vetterb3880d32013-08-14 18:02:46 +0200124 igt_fixture {
125 fd = drm_open_any();
Daniel Vetterd9d95782012-12-04 17:13:05 +0100126
Daniel Vetterb3880d32013-08-14 18:02:46 +0200127 handle = gem_create(fd, 4096);
128 gem_write(fd, handle, 0, batch, sizeof(batch));
129 }
Daniel Vetterd9d95782012-12-04 17:13:05 +0100130
Daniel Vetter1caaf0a2013-08-12 12:17:35 +0200131 igt_subtest("render")
Daniel Vetterd9d95782012-12-04 17:13:05 +0100132 loop(fd, handle, I915_EXEC_RENDER, "render");
133
Daniel Vetter1caaf0a2013-08-12 12:17:35 +0200134 igt_subtest("bsd")
Daniel Vetter8f5387e2013-08-13 13:20:58 +0200135 loop(fd, handle, I915_EXEC_BSD, "bsd");
Daniel Vetterd9d95782012-12-04 17:13:05 +0100136
Daniel Vetter1caaf0a2013-08-12 12:17:35 +0200137 igt_subtest("blt")
Daniel Vetter8f5387e2013-08-13 13:20:58 +0200138 loop(fd, handle, I915_EXEC_BLT, "blt");
Daniel Vetterd9d95782012-12-04 17:13:05 +0100139
Daniel Vetter1caaf0a2013-08-12 12:17:35 +0200140 igt_subtest("vebox")
Daniel Vetter8f5387e2013-08-13 13:20:58 +0200141 loop(fd, handle, LOCAL_I915_EXEC_VEBOX, "vebox");
Daniel Vetterd9d95782012-12-04 17:13:05 +0100142
Daniel Vetterb3880d32013-08-14 18:02:46 +0200143 igt_fixture {
144 gem_close(fd, handle);
Chris Wilson07d59b32011-01-20 22:10:10 +0000145
Daniel Vetterb3880d32013-08-14 18:02:46 +0200146 close(fd);
147 }
Chris Wilson07d59b32011-01-20 22:10:10 +0000148}