2 * Copyright © 2007,2009 Intel Corporation
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:
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
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.
24 * Eric Anholt <eric@anholt.net>
25 * Chris Wilson <chris@chris-wilson.co.uk>
34 #include <sys/resource.h>
38 #include "intel_chipset.h"
39 #include "intel_reg.h"
41 #define SAMPLES_PER_SEC 10000
43 static volatile int goddo;
45 static pid_t spawn(char **argv)
53 execvp(argv[0], argv);
57 static void sighandler(int sig)
62 int main(int argc, char **argv)
65 uint64_t ring_idle = 0, ring_time = 0;
66 struct timeval start, end;
67 static struct rusage rusage;
70 intel_mmio_use_pci_bar(intel_get_pci_device());
73 fprintf(stderr, "usage: %s cmd [args...]\n", argv[0]);
77 signal(SIGCHLD, sighandler);
78 signal(SIGINT, SIG_IGN);
79 signal(SIGQUIT, SIG_IGN);
81 gettimeofday(&start, NULL);
82 child = spawn(argv+1);
87 uint32_t ring_head, ring_tail;
89 ring_head = INREG(LP_RING + RING_HEAD) & HEAD_ADDR;
90 ring_tail = INREG(LP_RING + RING_TAIL) & TAIL_ADDR;
92 if (ring_tail == ring_head)
96 usleep(1000000 / SAMPLES_PER_SEC);
98 gettimeofday(&end, NULL);
99 timersub(&end, &start, &end);
101 waitpid(child, &status, 0);
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);
111 return WEXITSTATUS(status);