aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips
diff options
context:
space:
mode:
authorDavid Daney <ddaney@caviumnetworks.com>2010-02-16 18:26:35 -0500
committerRalf Baechle <ralf@linux-mips.org>2010-02-27 06:53:42 -0500
commitbba90760582d2563b28a4738fb785185a59e9e71 (patch)
treeb1efda424d8ab0ef24220ce4da484819d749e2b2 /arch/mips
parent500c2e1fdbcc2b273bd4c695a9b8ac8196f61614 (diff)
MIPS: Crazy spinlock speed test.
This is just a test program for raw_spinlocks. The main reason I wrote it is to validate my spinlock changes that I sent in a previous patch. To use it enable CONFIG_DEBUG_FS and CONFIG_SPINLOCK_TEST then at run time do: # mount -t debugfs none /sys/kernel/debug/ # cat /sys/kernel/debug/mips/spin_single # cat /sys/kernel/debug/mips/spin_multi On my 600MHz octeon cn5860 (16 CPUs) I get spin_single spin_multi base 106885 247941 spinlock_patch 75194 219465 This shows that for uncontended locks the spinlock patch gives 41% improvement and for contended locks 12% improvement (1/time). Signed-off-by: David Daney <ddaney@caviumnetworks.com> To: linux-mips@linux-mips.org Patchwork: http://patchwork.linux-mips.org/patch/969/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r--arch/mips/Kconfig.debug7
-rw-r--r--arch/mips/kernel/Makefile1
-rw-r--r--arch/mips/kernel/spinlock_test.c141
3 files changed, 149 insertions, 0 deletions
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 32a010d5edb9..43dc27997730 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -121,4 +121,11 @@ config DEBUG_ZBOOT
121 to reduce the kernel image size and speed up the booting procedure a 121 to reduce the kernel image size and speed up the booting procedure a
122 little. 122 little.
123 123
124config SPINLOCK_TEST
125 bool "Enable spinlock timing tests in debugfs"
126 depends on DEBUG_FS
127 default n
128 help
129 Add several files to the debugfs to test spinlock speed.
130
124endmenu 131endmenu
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index 9326af5186fe..ef20957ca14b 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -93,6 +93,7 @@ obj-$(CONFIG_GPIO_TXX9) += gpio_txx9.o
93 93
94obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o 94obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
95obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 95obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
96obj-$(CONFIG_SPINLOCK_TEST) += spinlock_test.o
96 97
97CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi) 98CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi)
98 99
diff --git a/arch/mips/kernel/spinlock_test.c b/arch/mips/kernel/spinlock_test.c
new file mode 100644
index 000000000000..da61134dfc53
--- /dev/null
+++ b/arch/mips/kernel/spinlock_test.c
@@ -0,0 +1,141 @@
1#include <linux/init.h>
2#include <linux/kthread.h>
3#include <linux/hrtimer.h>
4#include <linux/fs.h>
5#include <linux/debugfs.h>
6#include <linux/module.h>
7#include <linux/spinlock.h>
8
9
10static int ss_get(void *data, u64 *val)
11{
12 ktime_t start, finish;
13 int loops;
14 int cont;
15 DEFINE_RAW_SPINLOCK(ss_spin);
16
17 loops = 1000000;
18 cont = 1;
19
20 start = ktime_get();
21
22 while (cont) {
23 raw_spin_lock(&ss_spin);
24 loops--;
25 if (loops == 0)
26 cont = 0;
27 raw_spin_unlock(&ss_spin);
28 }
29
30 finish = ktime_get();
31
32 *val = ktime_us_delta(finish, start);
33
34 return 0;
35}
36
37DEFINE_SIMPLE_ATTRIBUTE(fops_ss, ss_get, NULL, "%llu\n");
38
39
40
41struct spin_multi_state {
42 raw_spinlock_t lock;
43 atomic_t start_wait;
44 atomic_t enter_wait;
45 atomic_t exit_wait;
46 int loops;
47};
48
49struct spin_multi_per_thread {
50 struct spin_multi_state *state;
51 ktime_t start;
52};
53
54static int multi_other(void *data)
55{
56 int loops;
57 int cont;
58 struct spin_multi_per_thread *pt = data;
59 struct spin_multi_state *s = pt->state;
60
61 loops = s->loops;
62 cont = 1;
63
64 atomic_dec(&s->enter_wait);
65
66 while (atomic_read(&s->enter_wait))
67 ; /* spin */
68
69 pt->start = ktime_get();
70
71 atomic_dec(&s->start_wait);
72
73 while (atomic_read(&s->start_wait))
74 ; /* spin */
75
76 while (cont) {
77 raw_spin_lock(&s->lock);
78 loops--;
79 if (loops == 0)
80 cont = 0;
81 raw_spin_unlock(&s->lock);
82 }
83
84 atomic_dec(&s->exit_wait);
85 while (atomic_read(&s->exit_wait))
86 ; /* spin */
87 return 0;
88}
89
90static int multi_get(void *data, u64 *val)
91{
92 ktime_t finish;
93 struct spin_multi_state ms;
94 struct spin_multi_per_thread t1, t2;
95
96 ms.lock = __RAW_SPIN_LOCK_UNLOCKED("multi_get");
97 ms.loops = 1000000;
98
99 atomic_set(&ms.start_wait, 2);
100 atomic_set(&ms.enter_wait, 2);
101 atomic_set(&ms.exit_wait, 2);
102 t1.state = &ms;
103 t2.state = &ms;
104
105 kthread_run(multi_other, &t2, "multi_get");
106
107 multi_other(&t1);
108
109 finish = ktime_get();
110
111 *val = ktime_us_delta(finish, t1.start);
112
113 return 0;
114}
115
116DEFINE_SIMPLE_ATTRIBUTE(fops_multi, multi_get, NULL, "%llu\n");
117
118
119extern struct dentry *mips_debugfs_dir;
120static int __init spinlock_test(void)
121{
122 struct dentry *d;
123
124 if (!mips_debugfs_dir)
125 return -ENODEV;
126
127 d = debugfs_create_file("spin_single", S_IRUGO,
128 mips_debugfs_dir, NULL,
129 &fops_ss);
130 if (!d)
131 return -ENOMEM;
132
133 d = debugfs_create_file("spin_multi", S_IRUGO,
134 mips_debugfs_dir, NULL,
135 &fops_multi);
136 if (!d)
137 return -ENOMEM;
138
139 return 0;
140}
141device_initcall(spinlock_test);