igt/gem_userptr_blits: Fix forked access test
[platform/upstream/intel-gpu-tools.git] / tests / gem_exec_lut_handle.c
index fd20ab1..6ee7527 100644 (file)
@@ -36,7 +36,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include "drm.h"
-#include "i915_drm.h"
+#include "ioctl_wrappers.h"
 #include "drmtest.h"
 
 #define BATCH_SIZE             (1024*1024)
@@ -111,7 +111,7 @@ static int exec(int fd, int num_exec, int num_relocs, unsigned flags)
 }
 
 #define ELAPSED(a,b) (1e6*((b)->tv_sec - (a)->tv_sec) + ((b)->tv_usec - (a)->tv_usec))
-int main(int argc, char **argv)
+igt_simple_main
 {
        uint32_t batch[2] = {MI_BATCH_BUFFER_END};
        int fd, n, m, count;
@@ -143,34 +143,62 @@ int main(int argc, char **argv)
        gem_exec[n].handle =  gem_create(fd, 4096);
        gem_write(fd, gem_exec[n].handle, 0, batch, sizeof(batch));
 
-       if (exec(fd, 1, 0, USE_LUT))
-               return 77;
+       igt_skip_on(exec(fd, 1, 0, USE_LUT));
 
        for (p = pass; p->name != NULL; p++) {
                for (n = 1; n <= MAX_NUM_EXEC; n *= 2) {
-                       for (m = 1; m <= MAX_NUM_RELOC; m *= 2) {
+                       double elapsed[16][2];
+                       double s_x, s_y, s_xx, s_xy;
+                       double A, B;
+                       int i, j;
+
+                       for (i = 0, m = 1; m <= MAX_NUM_RELOC; m *= 2, i++) {
                                struct timeval start, end;
-                               double elapsed[2];
 
+                               do_or_die(exec(fd, n, m, 0 | p->flags));
                                gettimeofday(&start, NULL);
                                for (count = 0; count < 1000; count++)
                                        do_or_die(exec(fd, n, m, 0 | p->flags));
                                gettimeofday(&end, NULL);
                                gem_sync(fd, gem_exec[MAX_NUM_EXEC].handle);
-                               elapsed[0] = ELAPSED(&start, &end) / 1000.;
+                               elapsed[i][0] = ELAPSED(&start, &end);
 
+                               do_or_die(exec(fd, n, m, USE_LUT | p->flags));
                                gettimeofday(&start, NULL);
                                for (count = 0; count < 1000; count++)
                                        do_or_die(exec(fd, n, m, USE_LUT | p->flags));
                                gettimeofday(&end, NULL);
                                gem_sync(fd, gem_exec[MAX_NUM_EXEC].handle);
-                               elapsed[1] = ELAPSED(&start, &end) / 1000.;
+                               elapsed[i][1] = ELAPSED(&start, &end);
+                       }
+
+                       igt_info("%s: buffers=%4d:", p->name, n);
 
-                               printf("%s: buffer_count=%d, reloc_count=%d: old=%f us, lut=%f us\n",
-                                      p->name, n, m, elapsed[0], elapsed[1]);
+                       s_x = s_y = s_xx = s_xy = 0;
+                       for (j = 0; j < i; j++) {
+                               int k = 1 << j;
+                               s_x += k;
+                               s_y += elapsed[j][0];
+                               s_xx += k * k;
+                               s_xy += k * elapsed[j][0];
                        }
+                       B = (s_xy - s_x * s_y / j) / (s_xx - s_x * s_x / j);
+                       A = s_y / j - B * s_x / j;
+                       igt_info(" old=%7.0f + %.1f*reloc,", A, B);
+
+                       s_x = s_y = s_xx = s_xy = 0;
+                       for (j = 0; j < i; j++) {
+                               int k = 1 << j;
+                               s_x += k;
+                               s_y += elapsed[j][1];
+                               s_xx += k * k;
+                               s_xy += k * elapsed[j][1];
+                       }
+                       B = (s_xy - s_x * s_y / j) / (s_xx - s_x * s_x / j);
+                       A = s_y / j - B * s_x / j;
+                       igt_info(" lut=%7.0f + %.1f*reloc (ns)", A, B);
+
+                       igt_info("\n");
                }
        }
-
-       return 0;
 }