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