1 /* test-cmpxchg-nolock.c
3 * Compare local cmpxchg with irq disable / enable.
7 #include <linux/jiffies.h>
8 #include <linux/compiler.h>
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/calc64.h>
12 #include <linux/spinlock.h>
13 #include <linux/seqlock.h>
14 #include <asm/timex.h>
15 #include <asm/system.h>
17 #define NR_LOOPS 20000
21 static void do_testbaseline(void)
25 cycles_t time1
, time2
, time
;
28 local_irq_save(flags
);
31 for (i
= 0; i
< NR_LOOPS
; i
++) {
35 local_irq_restore(flags
);
39 printk(KERN_ALERT
"test results: time for baseline\n");
40 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
41 printk(KERN_ALERT
"total time: %llu\n", time
);
42 time
= div_long_long_rem(time
, NR_LOOPS
, &rem
);
43 printk(KERN_ALERT
"-> baseline takes %llu cycles\n", time
);
44 printk(KERN_ALERT
"test end\n");
47 static void do_test_spinlock(void)
49 static DEFINE_SPINLOCK(mylock
);
52 cycles_t time1
, time2
, time
;
56 spin_lock_irqsave(&mylock
, flags
);
58 for (i
= 0; i
< NR_LOOPS
; i
++) {
63 spin_unlock_irqrestore(&mylock
, flags
);
67 printk(KERN_ALERT
"test results: time for spinlock\n");
68 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
69 printk(KERN_ALERT
"total time: %llu\n", time
);
70 time
= div_long_long_rem(time
, NR_LOOPS
, &rem
);
71 printk(KERN_ALERT
"-> spinlock takes %llu cycles\n", time
);
72 printk(KERN_ALERT
"test end\n");
75 static void do_test_seqlock(void)
77 static seqlock_t test_lock
;
81 cycles_t time1
, time2
, time
;
84 local_irq_save(flags
);
87 for (i
= 0; i
< NR_LOOPS
; i
++) {
89 seq
= read_seqbegin(&test_lock
);
90 } while (read_seqretry(&test_lock
, seq
));
95 local_irq_restore(flags
);
97 printk(KERN_ALERT
"test results: time for seqlock\n");
98 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
99 printk(KERN_ALERT
"total time: %llu\n", time
);
100 time
= div_long_long_rem(time
, NR_LOOPS
, &rem
);
101 printk(KERN_ALERT
"-> seqlock takes %llu cycles\n", time
);
102 printk(KERN_ALERT
"test end\n");
106 * This test will have a higher standard deviation due to incoming interrupts.
108 static void do_test_preempt(void)
112 cycles_t time1
, time2
, time
;
115 local_irq_save(flags
);
117 time1
= get_cycles();
118 for (i
= 0; i
< NR_LOOPS
; i
++) {
122 time2
= get_cycles();
124 time
= time2
- time1
;
125 local_irq_restore(flags
);
127 printk(KERN_ALERT
"test results: time for preempt disable/enable pairs\n");
128 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
129 printk(KERN_ALERT
"total time: %llu\n", time
);
130 time
= div_long_long_rem(time
, NR_LOOPS
, &rem
);
131 printk(KERN_ALERT
"-> preempt disable/enable pair takes %llu cycles\n",
133 printk(KERN_ALERT
"test end\n");
136 static int ltt_test_init(void)
138 printk(KERN_ALERT
"test init\n");
144 return -EAGAIN
; /* Fail will directly unload the module */
147 static void ltt_test_exit(void)
149 printk(KERN_ALERT
"test exit\n");
152 module_init(ltt_test_init
)
153 module_exit(ltt_test_exit
)
155 MODULE_LICENSE("GPL");
156 MODULE_AUTHOR("Mathieu Desnoyers");
157 MODULE_DESCRIPTION("Cmpxchg vs int Test");
This page took 0.046614 seconds and 4 git commands to generate.