xref: /dragonfly/test/sysperf/loop2.c (revision f2c43266)
1 /*
2  * loop2.c
3  *
4  * Used as a helper to test AST delivery.  Loops in user mode for a few
5  * seconds.  This one forks and runs the loop in two processes.
6  *
7  * $DragonFly: src/test/sysperf/loop2.c,v 1.2 2006/04/22 22:32:52 dillon Exp $
8  */
9 
10 #include "blib.h"
11 
12 #define LOOP 1000000
13 #define INNER 100
14 
15 int
16 main(int ac, char **av)
17 {
18     int i;
19     int j;
20     int count = LOOP;
21     pid_t pid;
22 
23     if (ac > 1)
24 	count = strtoul(av[1], NULL, 0);
25 
26     printf("SMP contention, userland-only loop, duel-forks.  Run just one\n");
27 
28     start_timing();
29     if (fork() == 0) {
30 	for (i = count; i > 0; --i) {
31 	    for (j = INNER; j > 0; --j)
32 		nop();
33 	}
34 	_exit(1);
35     } else {
36 	for (i = count; i > 0; --i) {
37 	    for (j = INNER; j > 0; --j)
38 		nop();
39 	}
40 	while (wait(NULL) > 0)
41 	    ;
42 	stop_timing(LOOP, "loop2/2xfork");
43     }
44     return(0);
45 }
46 
47