kms_fbc_crc: Use I915_TILING_X to create fbs
[platform/upstream/intel-gpu-tools.git] / tools / intel_gpu_time.c
1 /*
2  * Copyright © 2007,2009 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
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *    Chris Wilson <chris@chris-wilson.co.uk>
26  *
27  */
28
29 #include <unistd.h>
30 #include <signal.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <sys/time.h>
34 #include <sys/resource.h>
35 #include <sys/wait.h>
36
37 #include "intel_io.h"
38 #include "intel_chipset.h"
39 #include "intel_reg.h"
40
41 #define SAMPLES_PER_SEC             10000
42
43 static volatile int goddo;
44
45 static pid_t spawn(char **argv)
46 {
47         pid_t pid;
48
49         pid = fork();
50         if (pid != 0)
51                 return pid;
52
53         execvp(argv[0], argv);
54         exit(1);
55 }
56
57 static void sighandler(int sig)
58 {
59         goddo = sig;
60 }
61
62 int main(int argc, char **argv)
63 {
64         pid_t child;
65         uint64_t ring_idle = 0, ring_time = 0;
66         struct timeval start, end;
67         static struct rusage rusage;
68         int status;
69
70         intel_mmio_use_pci_bar(intel_get_pci_device());
71
72         if (argc == 1) {
73                 fprintf(stderr, "usage: %s cmd [args...]\n", argv[0]);
74                 return 1;
75         }
76
77         signal(SIGCHLD, sighandler);
78         signal(SIGINT, SIG_IGN);
79         signal(SIGQUIT, SIG_IGN);
80
81         gettimeofday(&start, NULL);
82         child = spawn(argv+1);
83         if (child < 0)
84                 return 127;
85
86         while (!goddo) {
87                 uint32_t ring_head, ring_tail;
88
89                 ring_head = INREG(LP_RING + RING_HEAD) & HEAD_ADDR;
90                 ring_tail = INREG(LP_RING + RING_TAIL) & TAIL_ADDR;
91
92                 if (ring_tail == ring_head)
93                         ring_idle++;
94                 ring_time++;
95
96                 usleep(1000000 / SAMPLES_PER_SEC);
97         }
98         gettimeofday(&end, NULL);
99         timersub(&end, &start, &end);
100
101         waitpid(child, &status, 0);
102
103         getrusage(RUSAGE_CHILDREN, &rusage);
104         printf("user: %ld.%06lds, sys: %ld.%06lds, elapsed: %ld.%06lds, CPU: %.1f%%, GPU: %.1f%%\n",
105                rusage.ru_utime.tv_sec, rusage.ru_utime.tv_usec,
106                rusage.ru_stime.tv_sec, rusage.ru_stime.tv_usec,
107                end.tv_sec, end.tv_usec,
108                100*(rusage.ru_utime.tv_sec + 1e-6*rusage.ru_utime.tv_usec + rusage.ru_stime.tv_sec + 1e-6*rusage.ru_stime.tv_usec) / (end.tv_sec + 1e-6*end.tv_usec),
109                100 - ring_idle * 100. / ring_time);
110
111         return WEXITSTATUS(status);
112 }