x86: cpa: move clflush_cache_range()
[wrt350n-kernel.git] / kernel / rcupreempt_trace.c
blob49ac4947af2417975e8fc55b30621c79e7ed8fa3
1 /*
2 * Read-Copy Update tracing for realtime implementation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright IBM Corporation, 2006
20 * Papers: http://www.rdrop.com/users/paulmck/RCU
22 * For detailed explanation of Read-Copy Update mechanism see -
23 * Documentation/RCU/ *.txt
26 #include <linux/types.h>
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/spinlock.h>
30 #include <linux/smp.h>
31 #include <linux/rcupdate.h>
32 #include <linux/interrupt.h>
33 #include <linux/sched.h>
34 #include <asm/atomic.h>
35 #include <linux/bitops.h>
36 #include <linux/module.h>
37 #include <linux/completion.h>
38 #include <linux/moduleparam.h>
39 #include <linux/percpu.h>
40 #include <linux/notifier.h>
41 #include <linux/rcupdate.h>
42 #include <linux/cpu.h>
43 #include <linux/mutex.h>
44 #include <linux/rcupreempt_trace.h>
45 #include <linux/debugfs.h>
47 static struct mutex rcupreempt_trace_mutex;
48 static char *rcupreempt_trace_buf;
49 #define RCUPREEMPT_TRACE_BUF_SIZE 4096
51 void rcupreempt_trace_move2done(struct rcupreempt_trace *trace)
53 trace->done_length += trace->wait_length;
54 trace->done_add += trace->wait_length;
55 trace->wait_length = 0;
57 void rcupreempt_trace_move2wait(struct rcupreempt_trace *trace)
59 trace->wait_length += trace->next_length;
60 trace->wait_add += trace->next_length;
61 trace->next_length = 0;
63 void rcupreempt_trace_try_flip_1(struct rcupreempt_trace *trace)
65 atomic_inc(&trace->rcu_try_flip_1);
67 void rcupreempt_trace_try_flip_e1(struct rcupreempt_trace *trace)
69 atomic_inc(&trace->rcu_try_flip_e1);
71 void rcupreempt_trace_try_flip_i1(struct rcupreempt_trace *trace)
73 trace->rcu_try_flip_i1++;
75 void rcupreempt_trace_try_flip_ie1(struct rcupreempt_trace *trace)
77 trace->rcu_try_flip_ie1++;
79 void rcupreempt_trace_try_flip_g1(struct rcupreempt_trace *trace)
81 trace->rcu_try_flip_g1++;
83 void rcupreempt_trace_try_flip_a1(struct rcupreempt_trace *trace)
85 trace->rcu_try_flip_a1++;
87 void rcupreempt_trace_try_flip_ae1(struct rcupreempt_trace *trace)
89 trace->rcu_try_flip_ae1++;
91 void rcupreempt_trace_try_flip_a2(struct rcupreempt_trace *trace)
93 trace->rcu_try_flip_a2++;
95 void rcupreempt_trace_try_flip_z1(struct rcupreempt_trace *trace)
97 trace->rcu_try_flip_z1++;
99 void rcupreempt_trace_try_flip_ze1(struct rcupreempt_trace *trace)
101 trace->rcu_try_flip_ze1++;
103 void rcupreempt_trace_try_flip_z2(struct rcupreempt_trace *trace)
105 trace->rcu_try_flip_z2++;
107 void rcupreempt_trace_try_flip_m1(struct rcupreempt_trace *trace)
109 trace->rcu_try_flip_m1++;
111 void rcupreempt_trace_try_flip_me1(struct rcupreempt_trace *trace)
113 trace->rcu_try_flip_me1++;
115 void rcupreempt_trace_try_flip_m2(struct rcupreempt_trace *trace)
117 trace->rcu_try_flip_m2++;
119 void rcupreempt_trace_check_callbacks(struct rcupreempt_trace *trace)
121 trace->rcu_check_callbacks++;
123 void rcupreempt_trace_done_remove(struct rcupreempt_trace *trace)
125 trace->done_remove += trace->done_length;
126 trace->done_length = 0;
128 void rcupreempt_trace_invoke(struct rcupreempt_trace *trace)
130 atomic_inc(&trace->done_invoked);
132 void rcupreempt_trace_next_add(struct rcupreempt_trace *trace)
134 trace->next_add++;
135 trace->next_length++;
138 static void rcupreempt_trace_sum(struct rcupreempt_trace *sp)
140 struct rcupreempt_trace *cp;
141 int cpu;
143 memset(sp, 0, sizeof(*sp));
144 for_each_possible_cpu(cpu) {
145 cp = rcupreempt_trace_cpu(cpu);
146 sp->next_length += cp->next_length;
147 sp->next_add += cp->next_add;
148 sp->wait_length += cp->wait_length;
149 sp->wait_add += cp->wait_add;
150 sp->done_length += cp->done_length;
151 sp->done_add += cp->done_add;
152 sp->done_remove += cp->done_remove;
153 atomic_set(&sp->done_invoked, atomic_read(&cp->done_invoked));
154 sp->rcu_check_callbacks += cp->rcu_check_callbacks;
155 atomic_set(&sp->rcu_try_flip_1,
156 atomic_read(&cp->rcu_try_flip_1));
157 atomic_set(&sp->rcu_try_flip_e1,
158 atomic_read(&cp->rcu_try_flip_e1));
159 sp->rcu_try_flip_i1 += cp->rcu_try_flip_i1;
160 sp->rcu_try_flip_ie1 += cp->rcu_try_flip_ie1;
161 sp->rcu_try_flip_g1 += cp->rcu_try_flip_g1;
162 sp->rcu_try_flip_a1 += cp->rcu_try_flip_a1;
163 sp->rcu_try_flip_ae1 += cp->rcu_try_flip_ae1;
164 sp->rcu_try_flip_a2 += cp->rcu_try_flip_a2;
165 sp->rcu_try_flip_z1 += cp->rcu_try_flip_z1;
166 sp->rcu_try_flip_ze1 += cp->rcu_try_flip_ze1;
167 sp->rcu_try_flip_z2 += cp->rcu_try_flip_z2;
168 sp->rcu_try_flip_m1 += cp->rcu_try_flip_m1;
169 sp->rcu_try_flip_me1 += cp->rcu_try_flip_me1;
170 sp->rcu_try_flip_m2 += cp->rcu_try_flip_m2;
174 static ssize_t rcustats_read(struct file *filp, char __user *buffer,
175 size_t count, loff_t *ppos)
177 struct rcupreempt_trace trace;
178 ssize_t bcount;
179 int cnt = 0;
181 rcupreempt_trace_sum(&trace);
182 mutex_lock(&rcupreempt_trace_mutex);
183 snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE - cnt,
184 "ggp=%ld rcc=%ld\n",
185 rcu_batches_completed(),
186 trace.rcu_check_callbacks);
187 snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE - cnt,
188 "na=%ld nl=%ld wa=%ld wl=%ld da=%ld dl=%ld dr=%ld di=%d\n"
189 "1=%d e1=%d i1=%ld ie1=%ld g1=%ld a1=%ld ae1=%ld a2=%ld\n"
190 "z1=%ld ze1=%ld z2=%ld m1=%ld me1=%ld m2=%ld\n",
192 trace.next_add, trace.next_length,
193 trace.wait_add, trace.wait_length,
194 trace.done_add, trace.done_length,
195 trace.done_remove, atomic_read(&trace.done_invoked),
196 atomic_read(&trace.rcu_try_flip_1),
197 atomic_read(&trace.rcu_try_flip_e1),
198 trace.rcu_try_flip_i1, trace.rcu_try_flip_ie1,
199 trace.rcu_try_flip_g1,
200 trace.rcu_try_flip_a1, trace.rcu_try_flip_ae1,
201 trace.rcu_try_flip_a2,
202 trace.rcu_try_flip_z1, trace.rcu_try_flip_ze1,
203 trace.rcu_try_flip_z2,
204 trace.rcu_try_flip_m1, trace.rcu_try_flip_me1,
205 trace.rcu_try_flip_m2);
206 bcount = simple_read_from_buffer(buffer, count, ppos,
207 rcupreempt_trace_buf, strlen(rcupreempt_trace_buf));
208 mutex_unlock(&rcupreempt_trace_mutex);
209 return bcount;
212 static ssize_t rcugp_read(struct file *filp, char __user *buffer,
213 size_t count, loff_t *ppos)
215 long oldgp = rcu_batches_completed();
216 ssize_t bcount;
218 mutex_lock(&rcupreempt_trace_mutex);
219 synchronize_rcu();
220 snprintf(rcupreempt_trace_buf, RCUPREEMPT_TRACE_BUF_SIZE,
221 "oldggp=%ld newggp=%ld\n", oldgp, rcu_batches_completed());
222 bcount = simple_read_from_buffer(buffer, count, ppos,
223 rcupreempt_trace_buf, strlen(rcupreempt_trace_buf));
224 mutex_unlock(&rcupreempt_trace_mutex);
225 return bcount;
228 static ssize_t rcuctrs_read(struct file *filp, char __user *buffer,
229 size_t count, loff_t *ppos)
231 int cnt = 0;
232 int cpu;
233 int f = rcu_batches_completed() & 0x1;
234 ssize_t bcount;
236 mutex_lock(&rcupreempt_trace_mutex);
238 cnt += snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE,
239 "CPU last cur F M\n");
240 for_each_online_cpu(cpu) {
241 long *flipctr = rcupreempt_flipctr(cpu);
242 cnt += snprintf(&rcupreempt_trace_buf[cnt],
243 RCUPREEMPT_TRACE_BUF_SIZE - cnt,
244 "%3d %4ld %3ld %d %d\n",
245 cpu,
246 flipctr[!f],
247 flipctr[f],
248 rcupreempt_flip_flag(cpu),
249 rcupreempt_mb_flag(cpu));
251 cnt += snprintf(&rcupreempt_trace_buf[cnt],
252 RCUPREEMPT_TRACE_BUF_SIZE - cnt,
253 "ggp = %ld, state = %s\n",
254 rcu_batches_completed(),
255 rcupreempt_try_flip_state_name());
256 cnt += snprintf(&rcupreempt_trace_buf[cnt],
257 RCUPREEMPT_TRACE_BUF_SIZE - cnt,
258 "\n");
259 bcount = simple_read_from_buffer(buffer, count, ppos,
260 rcupreempt_trace_buf, strlen(rcupreempt_trace_buf));
261 mutex_unlock(&rcupreempt_trace_mutex);
262 return bcount;
265 static struct file_operations rcustats_fops = {
266 .owner = THIS_MODULE,
267 .read = rcustats_read,
270 static struct file_operations rcugp_fops = {
271 .owner = THIS_MODULE,
272 .read = rcugp_read,
275 static struct file_operations rcuctrs_fops = {
276 .owner = THIS_MODULE,
277 .read = rcuctrs_read,
280 static struct dentry *rcudir, *statdir, *ctrsdir, *gpdir;
281 static int rcupreempt_debugfs_init(void)
283 rcudir = debugfs_create_dir("rcu", NULL);
284 if (!rcudir)
285 goto out;
286 statdir = debugfs_create_file("rcustats", 0444, rcudir,
287 NULL, &rcustats_fops);
288 if (!statdir)
289 goto free_out;
291 gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
292 if (!gpdir)
293 goto free_out;
295 ctrsdir = debugfs_create_file("rcuctrs", 0444, rcudir,
296 NULL, &rcuctrs_fops);
297 if (!ctrsdir)
298 goto free_out;
299 return 0;
300 free_out:
301 if (statdir)
302 debugfs_remove(statdir);
303 if (gpdir)
304 debugfs_remove(gpdir);
305 debugfs_remove(rcudir);
306 out:
307 return 1;
310 static int __init rcupreempt_trace_init(void)
312 mutex_init(&rcupreempt_trace_mutex);
313 rcupreempt_trace_buf = kmalloc(RCUPREEMPT_TRACE_BUF_SIZE, GFP_KERNEL);
314 if (!rcupreempt_trace_buf)
315 return 1;
316 return rcupreempt_debugfs_init();
319 static void __exit rcupreempt_trace_cleanup(void)
321 debugfs_remove(statdir);
322 debugfs_remove(gpdir);
323 debugfs_remove(ctrsdir);
324 debugfs_remove(rcudir);
325 kfree(rcupreempt_trace_buf);
329 module_init(rcupreempt_trace_init);
330 module_exit(rcupreempt_trace_cleanup);