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