update rcu
[lttv.git] / tests / kernel / test-rcu-speed.c
CommitLineData
3343768e 1/* test-cmpxchg-nolock.c
2 *
3 * Compare local cmpxchg with irq disable / enable.
4 */
5
6
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>
14
15#define NR_LOOPS 20000
16
17int test_val;
18
19static void do_testbaseline(void)
20{
21 int ret;
22 long flags;
23 unsigned int i;
24 cycles_t time1, time2, time;
25 long rem;
26
27 local_irq_save(flags);
28 preempt_disable();
29 time1 = get_cycles();
30 for (i = 0; i < NR_LOOPS; i++) {
31 asm volatile ("");
32 }
33 time2 = get_cycles();
34 local_irq_restore(flags);
35 preempt_enable();
36 time = time2 - time1;
37
38 printk(KERN_ALERT "test results: time for baseline\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 "-> baseline takes %llu cycles\n", time);
43 printk(KERN_ALERT "test end\n");
44}
45
46static void do_test_spinlock(void)
47{
48 static DEFINE_SPINLOCK mylock;
49 int ret;
50 long flags;
51 unsigned int i;
52 cycles_t time1, time2, time;
53 long rem;
54
55 preempt_disable();
56 spin_lock_irqsave(flags);
57 time1 = get_cycles();
58 for (i = 0; i < NR_LOOPS; i++) {
59 spin_unlock_irqrestore(flags);
60 spin_lock_irqsave(flags);
61 }
62 time2 = get_cycles();
63 spin_unlock_irqrestore(flags);
64 preempt_enable();
65 time = time2 - time1;
66
67 printk(KERN_ALERT "test results: time for spinlock\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 "-> spinlock takes %llu cycles\n", time);
72 printk(KERN_ALERT "test end\n");
73}
74
75static void do_test_seqlock(void)
76{
77 static seqlock_t test_lock;
78 int ret;
79 long flags;
80 unsigned int i;
81 cycles_t time1, time2, time;
82 long rem;
83
84 local_irq_save(flags);
85 preempt_disable();
86 time1 = get_cycles();
87 for (i = 0; i < NR_LOOPS; i++) {
88 do {
89 seq = read_seqbegin(&test_lock);
90 } while (read_seqretry(&test_lock, seq));
91 }
92 time2 = get_cycles();
93 preempt_enable();
94 time = time2 - time1;
95 local_irq_restore(flags);
96
97 printk(KERN_ALERT "test results: time for seqlock\n");
98 printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
99 printk(KERN_ALERT "total time: %llu\n", time);
100 time = div_long_long_rem(time, NR_LOOPS, &rem);
101 printk(KERN_ALERT "-> seqlock takes %llu cycles\n", time);
102 printk(KERN_ALERT "test end\n");
103}
104
105/*
106 * This test will have a higher standard deviation due to incoming interrupts.
107 */
108static void do_test_preempt(void)
109{
110 long flags;
111 unsigned int i;
112 cycles_t time1, time2, time;
113 long rem;
114
115 local_irq_save(flags);
116 preempt_disable();
117 time1 = get_cycles();
118 for (i = 0; i < NR_LOOPS; i++) {
119 preempt_enable();
120 preempt_disable();
121 }
122 time2 = get_cycles();
123 preempt_enable();
124 time = time2 - time1;
125 local_irq_restore(flags);
126
127 printk(KERN_ALERT "test results: time for preempt disable/enable pairs\n");
128 printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
129 printk(KERN_ALERT "total time: %llu\n", time);
130 time = div_long_long_rem(time, NR_LOOPS, &rem);
131 printk(KERN_ALERT "-> preempt disable/enable pair takes %llu cycles\n",
132 time);
133 printk(KERN_ALERT "test end\n");
134}
135
136static int ltt_test_init(void)
137{
138 printk(KERN_ALERT "test init\n");
139
140 do_testbaseline();
141 do_test_spinlock();
142 do_test_seqlock();
143 do_test_preempt();
144 return -EAGAIN; /* Fail will directly unload the module */
145}
146
147static void ltt_test_exit(void)
148{
149 printk(KERN_ALERT "test exit\n");
150}
151
152module_init(ltt_test_init)
153module_exit(ltt_test_exit)
154
155MODULE_LICENSE("GPL");
156MODULE_AUTHOR("Mathieu Desnoyers");
157MODULE_DESCRIPTION("Cmpxchg vs int Test");
158
This page took 0.027649 seconds and 4 git commands to generate.