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