gem_close_race: Bump the workload
[platform/upstream/intel-gpu-tools.git] / tests / gem_close_race.c
1 /*
2  * Copyright © 2013 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 "i915_drm.h"
41 #include "drmtest.h"
42
43 #define OBJECT_SIZE 1024*1024*4
44
45 #define COPY_BLT_CMD            (2<<29|0x53<<22|0x6)
46 #define BLT_WRITE_ALPHA         (1<<21)
47 #define BLT_WRITE_RGB           (1<<20)
48
49 static char device[80];
50
51 static void selfcopy(int fd, uint32_t handle)
52 {
53         struct drm_i915_gem_relocation_entry reloc[2];
54         struct drm_i915_gem_exec_object2 gem_exec[2];
55         struct drm_i915_gem_execbuffer2 execbuf;
56         uint32_t buf[10];
57         int loop;
58
59         memset(reloc, 0, sizeof(reloc));
60         memset(gem_exec, 0, sizeof(gem_exec));
61         memset(&execbuf, 0, sizeof(execbuf));
62
63         buf[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
64         buf[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
65         buf[2] = 0;
66         buf[3] = 512 << 16 | 1024;
67         buf[4] = 0;
68         reloc[0].offset = 4 * sizeof(uint32_t);
69         reloc[0].target_handle = handle;
70         reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
71         reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
72
73         buf[5] = 512 << 16;
74         buf[6] = 4*1024;
75         buf[7] = 0;
76         reloc[1].offset = 7 * sizeof(uint32_t);
77         reloc[1].target_handle = handle;
78         reloc[1].read_domains = I915_GEM_DOMAIN_RENDER;
79         reloc[1].write_domain = 0;
80
81         buf[8] = MI_BATCH_BUFFER_END;
82         buf[9] = 0;
83
84         gem_exec[0].handle = handle;
85
86         gem_exec[1].handle = gem_create(fd, 4096);
87         gem_exec[1].relocation_count = 2;
88         gem_exec[1].relocs_ptr = (uintptr_t)reloc;
89
90         gem_write(fd, gem_exec[1].handle, 0, buf, sizeof(buf));
91
92         execbuf.buffers_ptr = (uintptr_t)gem_exec;
93         execbuf.buffer_count = 2;
94         execbuf.batch_len = sizeof(buf);
95         if (HAS_BLT_RING(intel_get_drm_devid(fd)))
96                 execbuf.flags |= I915_EXEC_BLT;
97
98         for (loop = 30; loop--; )
99                 gem_execbuf(fd, &execbuf);
100 }
101
102 static uint32_t load(int fd)
103 {
104         uint32_t handle;
105
106         handle = gem_create(fd, OBJECT_SIZE);
107         if (handle == 0)
108                 return 0;
109
110         selfcopy(fd, handle);
111         return handle;
112 }
113
114 static void run(int child)
115 {
116         uint32_t handle;
117         int fd;
118
119         fd = open(device, O_RDWR);
120         igt_assert(fd != -1);
121
122         handle = load(fd);
123         if ((child & 63) == 63)
124                 gem_read(fd, handle, 0, &handle, sizeof(handle));
125 }
126
127 int main(int argc, char *argv[])
128 {
129         igt_skip_on_simulation();
130         igt_subtest_init(argc, argv);
131
132         sprintf(device, "/dev/dri/card%d", drm_get_card());
133
134         igt_subtest("gem-close-race") {
135                 igt_fork(child, 2000)
136                         run(child);
137                 igt_waitchildren();
138         }
139
140         igt_exit();
141 }