Merge branch 'vendor/OPENRESOLV' with the following changes:
[dragonfly.git] / test / sysperf / loop4.c
1 /*
2  * loop4.c
3  *
4  * Used to test syscall mpsafeness, with editing
5  *
6  * $DragonFly: src/test/sysperf/loop4.c,v 1.1 2008/05/09 15:49:42 dillon Exp $
7  */
8
9 #include "blib.h"
10 #include <fcntl.h>
11
12 #define INNER 100
13
14 void doloop(int count);
15 void func_nop1(void);
16 void func_nop2(void);
17
18 int
19 main(int ac, char **av)
20 {
21     int i;
22     int fd;
23     int count;
24     int nfork;
25     pid_t pid;
26
27     if (ac > 1)
28         nfork = strtoul(av[1], NULL, 0);
29
30     printf("SMP contention, dup() + close(), Run just one\n");
31
32     start_timing();
33     count = 0;
34     while (stop_timing(0, NULL) == 0) {
35         doloop(1000);
36         count += 1000;
37     }
38     printf("loop %d times\n", count);
39
40     start_timing();
41     for (i = 1; i < nfork; ++i) {
42             if (fork() == 0) {
43                 doloop(count);
44                 _exit(1);
45             }
46     }
47     doloop(count);
48     while (wait(NULL) > 0)
49         ;
50     stop_timing(count * INNER, "loop2/2xfork");
51     return(0);
52 }
53
54 void
55 doloop(int count)
56 {
57     int i;
58     int j;
59     int fd = open("/usr/share/dict/words", O_RDONLY);
60     register void (*func)(void) = func_nop1;
61
62     if (fd < 0)
63         perror("open");
64     for (i = count; i > 0; --i) {
65         for (j = INNER; j > 0; --j) {
66                 getuid();
67         }
68     }
69     close(fd);
70 }
71
72 void
73 func_nop1(void)
74 {
75 }
76
77 void
78 func_nop2(void)
79 {
80 }
81