xref: /dragonfly/test/sysperf/lockmgr2.c (revision c69bf40f)
1 /*
2  * varsym..c
3  *
4  * varsym [threads]
5  *
6  * tests shared lock using varsym_get()
7  */
8 
9 #include "blib.h"
10 #include <sys/file.h>
11 #include <assert.h>
12 
13 int
14 main(int ac, char **av)
15 {
16 	long long count = 0;
17 	long long max;
18 	char c;
19 	int n;
20 	int i;
21 	int j;
22 	int fd;
23 	int status;
24 	char *path;
25 	char buf[256];
26 	struct stat st;
27 
28 	printf("timing standard fstat() syscall\n");
29 
30 	close(open("/tmp/lockmgr2.test", O_RDWR|O_CREAT, 0666));
31 	start_timing();
32 	while (stop_timing(0, NULL) == 0) {
33 		fd = open("/tmp/lockmgr2.test", O_RDONLY, 0666);
34 		assert(fd >= 0);
35 		fstat(fd, &st);
36 		close(fd);
37 		++count;
38 	}
39 	max = count;
40 	close(fd);
41 
42 	if (ac > 1)
43 		n = strtol(av[1], NULL, 0);
44 	else
45 		n = 1;
46 
47 	start_timing();
48 	for (i = 0; i < n; ++i) {
49 		asprintf(&path, "/tmp/lockmgr.test");
50 		close(open(path, O_RDWR|O_CREAT, 0666));
51 		if (fork() == 0) {
52 			for (count = 0; count < max; ++count) {
53 				fd = open(path, O_RDONLY, 0666);
54 				assert(fd >= 0);
55 				fstat(fd, &st);
56 				close(fd);
57 			}
58 			_exit(0);
59 		}
60 	}
61 	while (wait3(&status, 0, NULL) >= 0 || errno == EINTR)
62 		;
63 	stop_timing(max * n, "lockmgr2");
64 
65 	return(0);
66 }
67