3 * Test time spent in a LTTng instrumentation probe.
7 #include <linux/jiffies.h>
8 #include <linux/compiler.h>
9 #include <linux/init.h>
10 #include <linux/module.h>
13 #define cmpxchg_up(ptr,o,n)\
14 ((__typeof__(*(ptr)))__cmpxchg_up((ptr),(unsigned long)(o),\
15 (unsigned long)(n),sizeof(*(ptr))))
16 static inline unsigned long __cmpxchg_up(volatile void *ptr
, unsigned long old
,
17 unsigned long new, int size
)
22 __asm__
__volatile__("cmpxchgb %b1,%2"
24 : "q"(new), "m"(*__xg(ptr
)), "0"(old
)
28 __asm__
__volatile__("cmpxchgw %w1,%2"
30 : "r"(new), "m"(*__xg(ptr
)), "0"(old
)
34 __asm__
__volatile__("cmpxchgl %1,%2"
36 : "r"(new), "m"(*__xg(ptr
)), "0"(old
)
44 #define NR_LOOPS 20000
46 volatile int test_val
= 100;
49 static inline void do_test(void)
55 ret
= cmpxchg_up(&test_val
, val
, val
+1);
58 static int ltt_test_init(void)
61 cycles_t time1
, time2
, time
;
62 cycles_t max_time
= 0, min_time
= 18446744073709551615ULL; /* (2^64)-1 */
63 cycles_t tot_time
= 0;
65 printk(KERN_ALERT
"test init\n");
67 local_irq_save(flags
);
69 for(i
=0; i
<NR_LOOPS
; i
++) {
70 //for(int j=0; j<10; j++) {
73 //max_time = max(max_time, time);
74 //min_time = min(min_time, time);
75 //printk("val : %d\n", test_val);
78 local_irq_restore(flags
);
82 printk(KERN_ALERT
"test results : time non locked cmpxchg\n");
83 printk(KERN_ALERT
"number of loops : %d\n", NR_LOOPS
);
84 printk(KERN_ALERT
"total time : %llu\n", tot_time
);
85 //printk(KERN_ALERT "min : %llu\n", min_time);
86 //printk(KERN_ALERT "max : %llu\n", max_time);
88 printk(KERN_ALERT
"test end\n");
90 return -EAGAIN
; /* Fail will directly unload the module */
93 static void ltt_test_exit(void)
95 printk(KERN_ALERT
"test exit\n");
98 module_init(ltt_test_init
)
99 module_exit(ltt_test_exit
)
101 MODULE_LICENSE("GPL");
102 MODULE_AUTHOR("Mathieu Desnoyers");
103 MODULE_DESCRIPTION("Linux Trace Toolkit Test");
This page took 0.039431 seconds and 4 git commands to generate.