1 #include <linux/init.h>
2 #include <linux/kthread.h>
3 #include <linux/hrtimer.h>
5 #include <linux/debugfs.h>
6 #include <linux/export.h>
7 #include <linux/spinlock.h>
10 static int ss_get(void *data
, u64
*val
)
12 ktime_t start
, finish
;
15 DEFINE_RAW_SPINLOCK(ss_spin
);
23 raw_spin_lock(&ss_spin
);
27 raw_spin_unlock(&ss_spin
);
32 *val
= ktime_us_delta(finish
, start
);
37 DEFINE_SIMPLE_ATTRIBUTE(fops_ss
, ss_get
, NULL
, "%llu\n");
41 struct spin_multi_state
{
49 struct spin_multi_per_thread
{
50 struct spin_multi_state
*state
;
54 static int multi_other(void *data
)
58 struct spin_multi_per_thread
*pt
= data
;
59 struct spin_multi_state
*s
= pt
->state
;
64 atomic_dec(&s
->enter_wait
);
66 while (atomic_read(&s
->enter_wait
))
69 pt
->start
= ktime_get();
71 atomic_dec(&s
->start_wait
);
73 while (atomic_read(&s
->start_wait
))
77 raw_spin_lock(&s
->lock
);
81 raw_spin_unlock(&s
->lock
);
84 atomic_dec(&s
->exit_wait
);
85 while (atomic_read(&s
->exit_wait
))
90 static int multi_get(void *data
, u64
*val
)
93 struct spin_multi_state ms
;
94 struct spin_multi_per_thread t1
, t2
;
96 ms
.lock
= __RAW_SPIN_LOCK_UNLOCKED("multi_get");
99 atomic_set(&ms
.start_wait
, 2);
100 atomic_set(&ms
.enter_wait
, 2);
101 atomic_set(&ms
.exit_wait
, 2);
105 kthread_run(multi_other
, &t2
, "multi_get");
109 finish
= ktime_get();
111 *val
= ktime_us_delta(finish
, t1
.start
);
116 DEFINE_SIMPLE_ATTRIBUTE(fops_multi
, multi_get
, NULL
, "%llu\n");
118 static int __init
spinlock_test(void)
122 if (!mips_debugfs_dir
)
125 d
= debugfs_create_file("spin_single", S_IRUGO
,
126 mips_debugfs_dir
, NULL
,
131 d
= debugfs_create_file("spin_multi", S_IRUGO
,
132 mips_debugfs_dir
, NULL
,
139 device_initcall(spinlock_test
);