02e6c126 |
1 | /* test-cmpxchg.c |
2 | * |
3 | * Test time spent in a LTTng instrumentation probe. |
4 | */ |
5 | |
6 | |
cad735b5 |
7 | #include <linux/jiffies.h> |
8 | #include <linux/compiler.h> |
02e6c126 |
9 | #include <linux/init.h> |
10 | #include <linux/module.h> |
02e6c126 |
11 | |
d254c2d4 |
12 | #define NR_LOOPS 20000 |
13 | |
cad735b5 |
14 | volatile int test_val = 100; |
15 | |
02e6c126 |
16 | |
38b8d96b |
17 | static inline void do_test(void) |
02e6c126 |
18 | { |
cad735b5 |
19 | int val, ret; |
02e6c126 |
20 | |
21 | val = test_val; |
22 | |
cad735b5 |
23 | ret = cmpxchg(&test_val, val, val+1); |
02e6c126 |
24 | } |
25 | |
38b8d96b |
26 | //void (*fct)(void) = do_test; |
cad735b5 |
27 | |
02e6c126 |
28 | static int ltt_test_init(void) |
29 | { |
30 | unsigned int i; |
31 | cycles_t time1, time2, time; |
32 | cycles_t max_time = 0, min_time = 18446744073709551615ULL; /* (2^64)-1 */ |
33 | cycles_t tot_time = 0; |
34 | unsigned long flags; |
35 | printk(KERN_ALERT "test init\n"); |
36 | |
37 | local_irq_save(flags); |
cad735b5 |
38 | time1 = get_cycles(); |
02e6c126 |
39 | for(i=0; i<NR_LOOPS; i++) { |
cad735b5 |
40 | //for(int j=0; j<10; j++) { |
02e6c126 |
41 | do_test(); |
cad735b5 |
42 | //} |
43 | //max_time = max(max_time, time); |
44 | //min_time = min(min_time, time); |
45 | //printk("val : %d\n", test_val); |
02e6c126 |
46 | } |
cad735b5 |
47 | time2 = get_cycles(); |
02e6c126 |
48 | local_irq_restore(flags); |
cad735b5 |
49 | time = time2 - time1; |
50 | tot_time += time; |
02e6c126 |
51 | |
b64661e6 |
52 | printk(KERN_ALERT "test results : time for cmpxchg\n"); |
02e6c126 |
53 | printk(KERN_ALERT "number of loops : %d\n", NR_LOOPS); |
54 | printk(KERN_ALERT "total time : %llu\n", tot_time); |
cad735b5 |
55 | //printk(KERN_ALERT "min : %llu\n", min_time); |
56 | //printk(KERN_ALERT "max : %llu\n", max_time); |
02e6c126 |
57 | |
58 | printk(KERN_ALERT "test end\n"); |
59 | |
60 | return -EAGAIN; /* Fail will directly unload the module */ |
61 | } |
62 | |
63 | static void ltt_test_exit(void) |
64 | { |
65 | printk(KERN_ALERT "test exit\n"); |
66 | } |
67 | |
68 | module_init(ltt_test_init) |
69 | module_exit(ltt_test_exit) |
70 | |
71 | MODULE_LICENSE("GPL"); |
72 | MODULE_AUTHOR("Mathieu Desnoyers"); |
73 | MODULE_DESCRIPTION("Linux Trace Toolkit Test"); |
74 | |