2 * Copyright (C) 2015 - Tobias Jakobi
4 * This is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation, either version 2 of the License,
7 * or (at your option) any later version.
9 * It is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with it. If not, see <http://www.gnu.org/licenses/>.
25 #include "exynos_drm.h"
26 #include "exynos_drmif.h"
27 #include "exynos_fimg2d.h"
29 static int output_mathematica = 0;
31 static int fimg2d_perf_simple(struct exynos_bo *bo, struct g2d_context *ctx,
32 unsigned buf_width, unsigned buf_height, unsigned iterations)
34 struct timespec tspec = { 0 };
35 struct g2d_image img = { 0 };
37 unsigned long long g2d_time;
41 img.width = buf_width;
42 img.height = buf_height;
43 img.stride = buf_width * 4;
44 img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;
45 img.buf_type = G2D_IMGBUF_GEM;
46 img.bo[0] = bo->handle;
50 printf("starting simple G2D performance test\n");
51 printf("buffer width = %u, buffer height = %u, iterations = %u\n",
52 buf_width, buf_height, iterations);
54 if (output_mathematica)
57 for (i = 0; i < iterations; ++i) {
60 x = rand() % buf_width;
61 y = rand() % buf_height;
63 if (x == (buf_width - 1))
65 if (y == (buf_height - 1))
68 w = rand() % (buf_width - x);
69 h = rand() % (buf_height - y);
76 ret = g2d_solid_fill(ctx, &img, x, y, w, h);
78 clock_gettime(CLOCK_MONOTONIC, &tspec);
84 fprintf(stderr, "error: iteration %u failed (x = %u, y = %u, w = %u, h = %u)\n",
88 struct timespec end = { 0 };
89 clock_gettime(CLOCK_MONOTONIC, &end);
91 g2d_time = (end.tv_sec - tspec.tv_sec) * 1000000000ULL;
92 g2d_time += (end.tv_nsec - tspec.tv_nsec);
94 if (output_mathematica) {
95 if (i != 0) putchar(',');
96 printf("{%u,%llu}", w * h, g2d_time);
98 printf("num_pixels = %u, usecs = %llu\n", w * h, g2d_time);
103 if (output_mathematica)
109 static int fimg2d_perf_multi(struct exynos_bo *bo, struct g2d_context *ctx,
110 unsigned buf_width, unsigned buf_height, unsigned iterations, unsigned batch)
112 struct timespec tspec = { 0 };
113 struct g2d_image *images;
115 unsigned long long g2d_time;
119 images = calloc(batch, sizeof(struct g2d_image));
120 if (images == NULL) {
121 fprintf(stderr, "error: failed to allocate G2D images.\n");
125 for (i = 0; i < batch; ++i) {
126 images[i].width = buf_width;
127 images[i].height = buf_height;
128 images[i].stride = buf_width * 4;
129 images[i].color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;
130 images[i].buf_type = G2D_IMGBUF_GEM;
131 images[i].bo[0] = bo->handle;
136 printf("starting multi G2D performance test (batch size = %u)\n", batch);
137 printf("buffer width = %u, buffer height = %u, iterations = %u\n",
138 buf_width, buf_height, iterations);
140 if (output_mathematica)
143 for (i = 0; i < iterations; ++i) {
144 unsigned num_pixels = 0;
146 for (j = 0; j < batch; ++j) {
149 x = rand() % buf_width;
150 y = rand() % buf_height;
152 if (x == (buf_width - 1))
154 if (y == (buf_height - 1))
157 w = rand() % (buf_width - x);
158 h = rand() % (buf_height - y);
163 images[j].color = rand();
167 ret = g2d_solid_fill(ctx, &images[j], x, y, w, h);
172 clock_gettime(CLOCK_MONOTONIC, &tspec);
178 fprintf(stderr, "error: iteration %u failed (num_pixels = %u)\n", i, num_pixels);
181 struct timespec end = { 0 };
182 clock_gettime(CLOCK_MONOTONIC, &end);
184 g2d_time = (end.tv_sec - tspec.tv_sec) * 1000000000ULL;
185 g2d_time += (end.tv_nsec - tspec.tv_nsec);
187 if (output_mathematica) {
188 if (i != 0) putchar(',');
189 printf("{%u,%llu}", num_pixels, g2d_time);
191 printf("num_pixels = %u, usecs = %llu\n", num_pixels, g2d_time);
196 if (output_mathematica)
204 static void usage(const char *name)
206 fprintf(stderr, "usage: %s [-ibwh]\n\n", name);
208 fprintf(stderr, "\t-i <number of iterations>\n");
209 fprintf(stderr, "\t-b <size of a batch> (default = 3)\n\n");
211 fprintf(stderr, "\t-w <buffer width> (default = 4096)\n");
212 fprintf(stderr, "\t-h <buffer height> (default = 4096)\n\n");
214 fprintf(stderr, "\t-M <enable Mathematica styled output>\n");
219 int main(int argc, char **argv)
221 int fd, ret, c, parsefail;
223 struct exynos_device *dev;
224 struct g2d_context *ctx;
225 struct exynos_bo *bo;
227 unsigned int iters = 0, batch = 3;
228 unsigned int bufw = 4096, bufh = 4096;
233 while ((c = getopt(argc, argv, "i:b:w:h:M")) != -1) {
236 if (sscanf(optarg, "%u", &iters) != 1)
240 if (sscanf(optarg, "%u", &batch) != 1)
244 if (sscanf(optarg, "%u", &bufw) != 1)
248 if (sscanf(optarg, "%u", &bufh) != 1)
252 output_mathematica = 1;
260 if (parsefail || (argc == 1) || (iters == 0))
263 if (bufw < 2 || bufw > 4096 || bufh < 2 || bufh > 4096) {
264 fprintf(stderr, "error: buffer width/height should be in the range 2 to 4096.\n");
270 if (bufw == 0 || bufh == 0) {
271 fprintf(stderr, "error: buffer width/height should be non-zero.\n");
277 fd = drmOpen("exynos", NULL);
279 fprintf(stderr, "error: failed to open drm\n");
285 dev = exynos_device_create(fd);
287 fprintf(stderr, "error: failed to create device\n");
295 fprintf(stderr, "error: failed to init G2D\n");
301 bo = exynos_bo_create(dev, bufw * bufh * 4, 0);
303 fprintf(stderr, "error: failed to create bo\n");
309 ret = fimg2d_perf_simple(bo, ctx, bufw, bufh, iters);
312 ret = fimg2d_perf_multi(bo, ctx, bufw, bufh, iters, batch);
314 exynos_bo_destroy(bo);
320 exynos_device_destroy(dev);