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 <asm/timex.h>
13 #include <asm/system.h>
15 #define NR_LOOPS 20000
19 static void do_test_cmpxchg(void)
24 cycles_t time1
, time2
, time
;
27 local_irq_save(flags
);
30 for (i
= 0; i
< NR_LOOPS
; i
++) {
31 ret
= cmpxchg_local(&test_val
, 0, 0);
34 local_irq_restore(flags
);
38 printk(KERN_ALERT
"test results: time for non locked cmpxchg\n");
39 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
40 printk(KERN_ALERT
"total time: %llu\n", time
);
41 time
= div_long_long_rem(time
, NR_LOOPS
, &rem
);
42 printk(KERN_ALERT
"-> non locked cmpxchg takes %llu cycles\n", time
);
43 printk(KERN_ALERT
"test end\n");
47 * This test will have a higher standard deviation due to incoming interrupts.
49 static void do_test_enable_int(void)
53 cycles_t time1
, time2
, time
;
56 local_irq_save(flags
);
59 for (i
= 0; i
< NR_LOOPS
; i
++) {
60 local_irq_restore(flags
);
63 local_irq_restore(flags
);
67 printk(KERN_ALERT
"test results: time for enabling interrupts (STI)\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
"-> enabling interrupts (STI) takes %llu cycles\n",
73 printk(KERN_ALERT
"test end\n");
76 static void do_test_disable_int(void)
78 unsigned long flags
, flags2
;
80 cycles_t time1
, time2
, time
;
83 local_irq_save(flags
);
86 for ( i
= 0; i
< NR_LOOPS
; i
++) {
87 local_irq_save(flags2
);
90 local_irq_restore(flags
);
94 printk(KERN_ALERT
"test results: time for disabling interrupts (CLI)\n");
95 printk(KERN_ALERT
"number of loops: %d\n", NR_LOOPS
);
96 printk(KERN_ALERT
"total time: %llu\n", time
);
97 time
= div_long_long_rem(time
, NR_LOOPS
, &rem
);
98 printk(KERN_ALERT
"-> disabling interrupts (CLI) takes %llu cycles\n",
100 printk(KERN_ALERT
"test end\n");
105 static int ltt_test_init(void)
107 printk(KERN_ALERT
"test init\n");
110 do_test_enable_int();
111 do_test_disable_int();
112 return -EAGAIN
; /* Fail will directly unload the module */
115 static void ltt_test_exit(void)
117 printk(KERN_ALERT
"test exit\n");
120 module_init(ltt_test_init
)
121 module_exit(ltt_test_exit
)
123 MODULE_LICENSE("GPL");
124 MODULE_AUTHOR("Mathieu Desnoyers");
125 MODULE_DESCRIPTION("Cmpxchg vs int Test");
This page took 0.031588 seconds and 4 git commands to generate.