49930b9a84a71dfeb39efff78859deb8eb193005
4 * - spin lock irqsave/ spin unlock irqrestore
5 * - using a sequence read lock (uncontended)
6 * - preempt disable/enable
10 #include <linux/jiffies.h>
11 #include <linux/compiler.h>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/math64.h>
15 #include <linux/spinlock.h>
16 #include <linux/seqlock.h>
17 #include <linux/cpumask.h>
18 #include <asm/timex.h>
19 #include <asm/system.h>
21 #define NR_LOOPS 20000
23 #ifndef CONFIG_PREEMPT
24 #error "Your kernel should be build with preemption enabled"
27 #ifdef CONFIG_DEBUG_PREEMPT
28 #error "Please disable CONFIG_DEBUG_PREEMPT"
31 #ifdef CONFIG_DEBUG_SPINLOCK
32 #error "Please disable CONFIG_DEBUG_SPINLOCK"
36 #error "Please disable CONFIG_LOCKDEP"
41 static void do_testbaseline(void)
45 cycles_t time1
, time2
, time
;
48 local_irq_save(flags
);
51 for (i
= 0; i
< NR_LOOPS
; i
++) {
55 local_irq_restore(flags
);
59 printk(KERN_ALERT
"test results: time for baseline\n");
60 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
61 printk(KERN_ALERT
"total time: %llu\n", time
);
62 time
= div_u64_rem(time
, NR_LOOPS
, &rem
);
63 printk(KERN_ALERT
"-> baseline takes %llu cycles\n", time
);
64 printk(KERN_ALERT
"test end\n");
67 static void do_test_spinlock(void)
69 static DEFINE_SPINLOCK(mylock
);
72 cycles_t time1
, time2
, time
;
76 spin_lock_irqsave(&mylock
, flags
);
78 for (i
= 0; i
< NR_LOOPS
; i
++) {
83 spin_unlock_irqrestore(&mylock
, flags
);
87 printk(KERN_ALERT
"test results: time for spinlock\n");
88 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
89 printk(KERN_ALERT
"total time: %llu\n", time
);
90 time
= div_u64_rem(time
, NR_LOOPS
, &rem
);
91 printk(KERN_ALERT
"-> spinlock takes %llu cycles\n", time
);
92 printk(KERN_ALERT
"test end\n");
95 static void do_test_seqlock(void)
97 static seqlock_t test_lock
;
101 cycles_t time1
, time2
, time
;
104 local_irq_save(flags
);
105 time1
= get_cycles();
106 for (i
= 0; i
< NR_LOOPS
; i
++) {
108 seq
= read_seqbegin(&test_lock
);
109 } while (read_seqretry(&test_lock
, seq
));
111 time2
= get_cycles();
112 time
= time2
- time1
;
113 local_irq_restore(flags
);
115 printk(KERN_ALERT
"test results: time for seqlock\n");
116 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
117 printk(KERN_ALERT
"total time: %llu\n", time
);
118 time
= div_u64_rem(time
, NR_LOOPS
, &rem
);
119 printk(KERN_ALERT
"-> seqlock takes %llu cycles\n", time
);
120 printk(KERN_ALERT
"test end\n");
124 * Note : This test _should_ trigger lockdep errors due to preemption
125 * disabling/enabling within irq off section. Given we are only interested in
126 * having the most precise measurement for preemption disable/enable, we don't
129 static void do_test_preempt(void)
133 cycles_t time1
, time2
, time
;
136 local_irq_save(flags
);
138 time1
= get_cycles();
139 for (i
= 0; i
< NR_LOOPS
; i
++) {
143 time2
= get_cycles();
145 time
= time2
- time1
;
146 local_irq_restore(flags
);
148 printk(KERN_ALERT
"test results: time for preempt disable/enable pairs\n");
149 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
150 printk(KERN_ALERT
"total time: %llu\n", time
);
151 time
= div_u64_rem(time
, NR_LOOPS
, &rem
);
152 printk(KERN_ALERT
"-> preempt disable/enable pair takes %llu cycles\n",
154 printk(KERN_ALERT
"test end\n");
157 static int ltt_test_init(void)
159 printk(KERN_ALERT
"test init\n");
161 printk(KERN_ALERT
"Number of active CPUs : %d\n", num_online_cpus());
166 return -EAGAIN
; /* Fail will directly unload the module */
169 static void ltt_test_exit(void)
171 printk(KERN_ALERT
"test exit\n");
174 module_init(ltt_test_init
)
175 module_exit(ltt_test_exit
)
177 MODULE_LICENSE("GPL");
178 MODULE_AUTHOR("Mathieu Desnoyers");
179 MODULE_DESCRIPTION("Cmpxchg vs int Test");
This page took 0.035291 seconds and 3 git commands to generate.