man: Add cross references
[dragonfly.git] / test / sysperf / exec1.c
blob5c44fb5ebcebf54c8e0f2adca444d5218b8aa70a
1 /*
2 * exec1.c
4 * $DragonFly: src/test/sysperf/exec1.c,v 1.2 2004/04/14 17:59:45 dillon Exp $
5 */
7 #include "blib.h"
8 #include <sys/resource.h>
9 #include <sys/wait.h>
10 #include <sys/time.h>
11 #include <machine/atomic.h>
13 char *Av0;
15 static
16 void
17 execltest(void)
19 pid_t pid;
20 char *elm;
22 if ((elm = strrchr(Av0, '/')) == NULL)
23 elm = Av0;
24 else
25 ++elm;
27 if ((pid = vfork()) == 0) {
28 execl(Av0, elm, "dummy", NULL);
29 _exit(1);
30 } else if (pid < 0) {
31 perror("vfork");
32 exit(1);
33 } else {
34 int status;
36 while (waitpid(pid, &status, 0) != pid)
38 if (WEXITSTATUS(status)) {
39 fprintf(stderr, "execl in child failed\n");
40 exit(1);
45 int
46 main(int ac, char **av)
48 int i;
49 int count;
50 int status;
51 int ncpus;
52 int n;
53 long *countr;
55 countr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
57 Av0 = av[0];
58 if (ac == 2 && strcmp(av[1], "dummy") == 0)
59 exit(0);
60 ncpus = 1;
61 if (ac > 1)
62 ncpus = strtol(av[1], NULL, 0);
64 count = 0;
65 start_timing();
66 while (stop_timing(0, NULL) == 0) {
67 for (i = 0; i < 100; ++i)
68 execltest();
69 count += 100;
71 count *= 5; /* 5 second run */
72 start_timing();
73 for (n = 0; n < ncpus; ++n) {
74 if (fork() == 0) {
75 count = 0;
76 while (get_timing() < 5000000) {
77 execltest();
78 ++count;
79 stop_timing(0, NULL);
81 atomic_add_long(countr, count);
82 _exit(0);
85 while (wait3(&status, 0, NULL) >= 0 || errno == EINTR)
87 #ifdef ISSTATIC
88 stop_timing(*countr, "execl static program:");
89 #else
90 stop_timing(*countr, "execl dynamic program:");
91 #endif
92 return(0);