4 * $DragonFly: src/test/sysperf/mutex3.c,v 1.1 2006/05/18 02:22:46 dillon Exp $
10 #include <machine/atomic.h>
11 #include <machine/cpufunc.h>
17 spin_lock_contested(void)
23 while (atomic_swap_int(mtx, 1) != 0) {
24 for (i = 0; i < j; ++i)
25 __asm __volatile("pause"::);
37 spin_lock_contested();
38 } else if (atomic_swap_int(mtx, 1) != 0) {
39 spin_lock_contested();
51 main(int ac, char **av)
59 printf("Test simple locked bus cycle mutex latency\n");
60 printf("auto-forks two processes for the test with shared memory\n");
61 printf("This test is only useful on a SMP box\n");
64 mtx = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0);
66 while (stop_timing(0, NULL) == 0) {
67 for (j = 0; j < 100; ++j) {
78 for (count = 0; count < max; count += 100) {
79 for (j = 0; j < 100; ++j) {
81 spin_unlock(); /* release */
85 stop_timing(count, "complex_mtx(uncontested/1cpu)");
88 if ((pid = fork()) == 0) {
90 for (j = 0; j < 100; ++j) {
92 spin_unlock(); /* release */
98 for (count = 0; count < max; count += 100) {
99 for (j = 0; j < 100; ++j) {
101 spin_unlock(); /* release */
105 stop_timing(count, "complex_mtx");
106 printf("proc1=%d proc2=%d\n", counter[64], counter[128]);