Upgrade libressl. 1/2
[dragonfly.git] / test / sysperf / loop900k.c
1 /*
2  * Infinite loop test with 900,000 processes
3  *
4  * Requires system w/ 128GB+ of ram, kern.maxproc=4000000 set in
5  * /boot/loader.conf.  80 second stabilization time after last
6  * process is forked.
7  *
8  * Also test tear-down by ^C'ing the test.
9  */
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <sys/mman.h>
13 #include <sys/resource.h>
14 #include <errno.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <string.h>
19 #include <signal.h>
20
21 #define COUNT   900000
22
23 int
24 main(int ac, char **av)
25 {
26         int status;
27         int i;
28         int j;
29         int idno;
30         char *path;
31         char *id;
32         char c;
33
34         if (ac == 1) {
35                 for (i = 0; i < COUNT; i += 100) {
36 #if 0
37                         asprintf(&path, "cp %s /tmp/x%06d", av[0], i);
38                         system(path);
39                         free(path);
40                         asprintf(&path, "/tmp/x%06d", i);
41 #else
42                         asprintf(&path, "%s", av[0]);
43 #endif
44                         asprintf(&id, "%d", i);
45                         if (vfork() == 0) {
46                                 execl(path, path, id, NULL);
47                                 _exit(0);
48                         }
49                         if (i % 1000 == 0) {
50                                 printf("running %d\r", i);
51                                 fflush(stdout);
52                         }
53                         free(path);
54                         free(id);
55                 }
56         } else {
57                 idno = strtol(av[1], NULL, 0);
58                 setpriority(PRIO_PROCESS, 0, 5);
59                 for (j = 0; j < 100; ++j) {
60                         if (j == 99 || fork() == 0) {
61                                 int dummy = 0;
62
63                                 setpriority(PRIO_PROCESS, 0, 15);
64                                 sleep(80);
65
66                                 while (1) {
67                                         ;
68                                 }
69                                 _exit(0);
70                         }
71                 }
72                 while (wait3(NULL, 0, NULL) >= 0 || errno == EINTR)
73                         ;
74                 _exit(0);
75         }
76         printf("running %d\n", i);
77         for (;;) {
78                 sleep(1);
79         }
80         return 0;
81 }