pkg_radd/pkg_search: add support for BINPKG_BASE
[dragonfly.git] / test / sysperf / mutex4.c
blobec3ea0dc1fc0d567900e91fe28058b152af88ea5
1 /*
2 * mutex4.c
4 * $DragonFly: src/test/sysperf/mutex4.c,v 1.1 2008/05/09 15:49:42 dillon Exp $
5 */
7 #include "blib.h"
9 #include <sys/types.h>
10 #include <machine/atomic.h>
11 #include <machine/cpufunc.h>
13 struct globaldata {
14 int gd_cpumask;
15 int gd_spinlocks;
18 int *mtx;
19 struct globaldata gd;
21 typedef struct globaldata *globaldata_t;
23 void
24 rd_lock_contested(void)
28 static __inline void
29 rd_lock(void)
31 atomic_set_int(mtx, 1);
32 *mtx = 2;
33 *mtx = 3;
36 static __inline void
37 rd_unlock(void)
41 int
42 main(int ac, char **av)
44 long long count = 0;
45 long long max;
46 int j;
47 int *counter;
48 pid_t pid;
50 printf("Test simple locked bus cycle mutex latency\n");
51 printf("auto-forks two processes for the test with shared memory\n");
52 printf("This test is only useful on a SMP box\n");
54 start_timing();
55 mtx = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0);
56 counter = mtx + 64;
57 gd.gd_cpumask = 0x00000001;
58 gd.gd_spinlocks = 0;
59 while (stop_timing(0, NULL) == 0) {
60 for (j = 0; j < 100; ++j) {
61 rd_lock();
62 rd_unlock();
64 count += 100;
66 max = count;
67 *mtx = 0;
69 start_timing();
70 for (count = 0; count < max; count += 100) {
71 for (j = 0; j < 100; ++j) {
72 rd_lock();
73 rd_unlock(); /* release */
76 stop_timing(count, "complex_mtx(uncontested/1cpu)");
78 if ((pid = fork()) == 0) {
79 for (;;) {
80 for (j = 0; j < 100; ++j) {
81 rd_lock();
82 rd_unlock(); /* release */
83 ++counter[128];
86 } else {
87 gd.gd_cpumask = 0x00000002;
88 gd.gd_spinlocks = 0;
89 start_timing();
90 for (count = 0; count < max; count += 100) {
91 for (j = 0; j < 100; ++j) {
92 rd_lock();
93 rd_unlock(); /* release */
94 ++counter[64];
97 stop_timing(count, "complex_mtx");
98 printf("proc1=%d proc2=%d\n", counter[64], counter[128]);
99 kill(pid, 9);
101 return(0);