blob: 536a93d13a06d3b5dd64c94f88986612631221f6 [file] [log] [blame]
Sunil Mushran2309e9e2008-04-14 10:46:19 -07001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * netdebug.c
5 *
6 * debug functionality for o2net
7 *
8 * Copyright (C) 2005, 2008 Oracle. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
24 *
25 */
26
27#ifdef CONFIG_DEBUG_FS
28
29#include <linux/module.h>
30#include <linux/types.h>
31#include <linux/slab.h>
32#include <linux/idr.h>
33#include <linux/kref.h>
34#include <linux/seq_file.h>
35#include <linux/debugfs.h>
36
37#include <linux/uaccess.h>
38
39#include "tcp.h"
40#include "nodemanager.h"
41#define MLOG_MASK_PREFIX ML_TCP
42#include "masklog.h"
43
44#include "tcp_internal.h"
45
46#define O2NET_DEBUG_DIR "o2net"
47#define SC_DEBUG_NAME "sock_containers"
48#define NST_DEBUG_NAME "send_tracking"
49
50static struct dentry *o2net_dentry;
51static struct dentry *sc_dentry;
52static struct dentry *nst_dentry;
53
54static DEFINE_SPINLOCK(o2net_debug_lock);
55
56static LIST_HEAD(sock_containers);
57static LIST_HEAD(send_tracking);
58
59void o2net_debug_add_nst(struct o2net_send_tracking *nst)
60{
61 spin_lock(&o2net_debug_lock);
62 list_add(&nst->st_net_debug_item, &send_tracking);
63 spin_unlock(&o2net_debug_lock);
64}
65
66void o2net_debug_del_nst(struct o2net_send_tracking *nst)
67{
68 spin_lock(&o2net_debug_lock);
69 if (!list_empty(&nst->st_net_debug_item))
70 list_del_init(&nst->st_net_debug_item);
71 spin_unlock(&o2net_debug_lock);
72}
73
74static struct o2net_send_tracking
75 *next_nst(struct o2net_send_tracking *nst_start)
76{
77 struct o2net_send_tracking *nst, *ret = NULL;
78
79 assert_spin_locked(&o2net_debug_lock);
80
81 list_for_each_entry(nst, &nst_start->st_net_debug_item,
82 st_net_debug_item) {
83 /* discover the head of the list */
84 if (&nst->st_net_debug_item == &send_tracking)
85 break;
86
87 /* use st_task to detect real nsts in the list */
88 if (nst->st_task != NULL) {
89 ret = nst;
90 break;
91 }
92 }
93
94 return ret;
95}
96
97static void *nst_seq_start(struct seq_file *seq, loff_t *pos)
98{
99 struct o2net_send_tracking *nst, *dummy_nst = seq->private;
100
101 spin_lock(&o2net_debug_lock);
102 nst = next_nst(dummy_nst);
103 spin_unlock(&o2net_debug_lock);
104
105 return nst;
106}
107
108static void *nst_seq_next(struct seq_file *seq, void *v, loff_t *pos)
109{
110 struct o2net_send_tracking *nst, *dummy_nst = seq->private;
111
112 spin_lock(&o2net_debug_lock);
113 nst = next_nst(dummy_nst);
114 list_del_init(&dummy_nst->st_net_debug_item);
115 if (nst)
116 list_add(&dummy_nst->st_net_debug_item,
117 &nst->st_net_debug_item);
118 spin_unlock(&o2net_debug_lock);
119
120 return nst; /* unused, just needs to be null when done */
121}
122
123static int nst_seq_show(struct seq_file *seq, void *v)
124{
125 struct o2net_send_tracking *nst, *dummy_nst = seq->private;
Sunil Mushran3f9c14f2010-12-22 12:39:38 -0800126 ktime_t now;
127 s64 sock, send, status;
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700128
129 spin_lock(&o2net_debug_lock);
130 nst = next_nst(dummy_nst);
131
Sunil Mushran3f9c14f2010-12-22 12:39:38 -0800132 now = ktime_get();
133 sock = ktime_to_us(ktime_sub(now, nst->st_sock_time));
134 send = ktime_to_us(ktime_sub(now, nst->st_send_time));
135 status = ktime_to_us(ktime_sub(now, nst->st_status_time));
136
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700137 if (nst != NULL) {
138 /* get_task_comm isn't exported. oh well. */
139 seq_printf(seq, "%p:\n"
140 " pid: %lu\n"
141 " tgid: %lu\n"
142 " process name: %s\n"
143 " node: %u\n"
144 " sc: %p\n"
145 " message id: %d\n"
146 " message type: %u\n"
147 " message key: 0x%08x\n"
Sunil Mushran3f9c14f2010-12-22 12:39:38 -0800148 " sock acquiry: %lld usecs ago\n"
149 " send start: %lld usecs ago\n"
150 " wait start: %lld usecs ago\n",
Sunil Mushran37096a72010-12-20 16:35:00 -0800151 nst, (unsigned long)task_pid_nr(nst->st_task),
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700152 (unsigned long)nst->st_task->tgid,
153 nst->st_task->comm, nst->st_node,
154 nst->st_sc, nst->st_id, nst->st_msg_type,
155 nst->st_msg_key,
Sunil Mushran3f9c14f2010-12-22 12:39:38 -0800156 (long long)sock,
157 (long long)send,
158 (long long)status);
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700159 }
160
161 spin_unlock(&o2net_debug_lock);
162
163 return 0;
164}
165
166static void nst_seq_stop(struct seq_file *seq, void *v)
167{
168}
169
James Morris88e9d342009-09-22 16:43:43 -0700170static const struct seq_operations nst_seq_ops = {
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700171 .start = nst_seq_start,
172 .next = nst_seq_next,
173 .stop = nst_seq_stop,
174 .show = nst_seq_show,
175};
176
177static int nst_fop_open(struct inode *inode, struct file *file)
178{
179 struct o2net_send_tracking *dummy_nst;
180 struct seq_file *seq;
181 int ret;
182
183 dummy_nst = kmalloc(sizeof(struct o2net_send_tracking), GFP_KERNEL);
184 if (dummy_nst == NULL) {
185 ret = -ENOMEM;
186 goto out;
187 }
188 dummy_nst->st_task = NULL;
189
190 ret = seq_open(file, &nst_seq_ops);
191 if (ret)
192 goto out;
193
194 seq = file->private_data;
195 seq->private = dummy_nst;
196 o2net_debug_add_nst(dummy_nst);
197
198 dummy_nst = NULL;
199
200out:
201 kfree(dummy_nst);
202 return ret;
203}
204
205static int nst_fop_release(struct inode *inode, struct file *file)
206{
207 struct seq_file *seq = file->private_data;
208 struct o2net_send_tracking *dummy_nst = seq->private;
209
210 o2net_debug_del_nst(dummy_nst);
211 return seq_release_private(inode, file);
212}
213
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700214static const struct file_operations nst_seq_fops = {
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700215 .open = nst_fop_open,
216 .read = seq_read,
217 .llseek = seq_lseek,
218 .release = nst_fop_release,
219};
220
221void o2net_debug_add_sc(struct o2net_sock_container *sc)
222{
223 spin_lock(&o2net_debug_lock);
224 list_add(&sc->sc_net_debug_item, &sock_containers);
225 spin_unlock(&o2net_debug_lock);
226}
227
228void o2net_debug_del_sc(struct o2net_sock_container *sc)
229{
230 spin_lock(&o2net_debug_lock);
231 list_del_init(&sc->sc_net_debug_item);
232 spin_unlock(&o2net_debug_lock);
233}
234
235static struct o2net_sock_container
236 *next_sc(struct o2net_sock_container *sc_start)
237{
238 struct o2net_sock_container *sc, *ret = NULL;
239
240 assert_spin_locked(&o2net_debug_lock);
241
242 list_for_each_entry(sc, &sc_start->sc_net_debug_item,
243 sc_net_debug_item) {
244 /* discover the head of the list miscast as a sc */
245 if (&sc->sc_net_debug_item == &sock_containers)
246 break;
247
248 /* use sc_page to detect real scs in the list */
249 if (sc->sc_page != NULL) {
250 ret = sc;
251 break;
252 }
253 }
254
255 return ret;
256}
257
258static void *sc_seq_start(struct seq_file *seq, loff_t *pos)
259{
260 struct o2net_sock_container *sc, *dummy_sc = seq->private;
261
262 spin_lock(&o2net_debug_lock);
263 sc = next_sc(dummy_sc);
264 spin_unlock(&o2net_debug_lock);
265
266 return sc;
267}
268
269static void *sc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
270{
271 struct o2net_sock_container *sc, *dummy_sc = seq->private;
272
273 spin_lock(&o2net_debug_lock);
274 sc = next_sc(dummy_sc);
275 list_del_init(&dummy_sc->sc_net_debug_item);
276 if (sc)
277 list_add(&dummy_sc->sc_net_debug_item, &sc->sc_net_debug_item);
278 spin_unlock(&o2net_debug_lock);
279
280 return sc; /* unused, just needs to be null when done */
281}
282
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700283static int sc_seq_show(struct seq_file *seq, void *v)
284{
285 struct o2net_sock_container *sc, *dummy_sc = seq->private;
286
287 spin_lock(&o2net_debug_lock);
288 sc = next_sc(dummy_sc);
289
290 if (sc != NULL) {
291 struct inet_sock *inet = NULL;
292
293 __be32 saddr = 0, daddr = 0;
294 __be16 sport = 0, dport = 0;
295
296 if (sc->sc_sock) {
297 inet = inet_sk(sc->sc_sock->sk);
298 /* the stack's structs aren't sparse endian clean */
Eric Dumazetc720c7e2009-10-15 06:30:45 +0000299 saddr = (__force __be32)inet->inet_saddr;
300 daddr = (__force __be32)inet->inet_daddr;
301 sport = (__force __be16)inet->inet_sport;
302 dport = (__force __be16)inet->inet_dport;
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700303 }
304
305 /* XXX sigh, inet-> doesn't have sparse annotation so any
306 * use of it here generates a warning with -Wbitwise */
307 seq_printf(seq, "%p:\n"
308 " krefs: %d\n"
Harvey Harrisonbe859402008-10-31 00:56:28 -0700309 " sock: %pI4:%u -> "
310 "%pI4:%u\n"
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700311 " remote node: %s\n"
312 " page off: %zu\n"
313 " handshake ok: %u\n"
Sunil Mushranff1becb2010-12-22 12:39:39 -0800314 " timer: %lld usecs\n"
315 " data ready: %lld usecs\n"
316 " advance start: %lld usecs\n"
317 " advance stop: %lld usecs\n"
318 " func start: %lld usecs\n"
319 " func stop: %lld usecs\n"
320 " func key: 0x%08x\n"
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700321 " func type: %u\n",
322 sc,
323 atomic_read(&sc->sc_kref.refcount),
Harvey Harrisonbe859402008-10-31 00:56:28 -0700324 &saddr, inet ? ntohs(sport) : 0,
325 &daddr, inet ? ntohs(dport) : 0,
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700326 sc->sc_node->nd_name,
327 sc->sc_page_off,
328 sc->sc_handshake_ok,
Sunil Mushranff1becb2010-12-22 12:39:39 -0800329 (long long)ktime_to_us(sc->sc_tv_timer),
330 (long long)ktime_to_us(sc->sc_tv_data_ready),
331 (long long)ktime_to_us(sc->sc_tv_advance_start),
332 (long long)ktime_to_us(sc->sc_tv_advance_stop),
333 (long long)ktime_to_us(sc->sc_tv_func_start),
334 (long long)ktime_to_us(sc->sc_tv_func_stop),
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700335 sc->sc_msg_key,
336 sc->sc_msg_type);
337 }
338
339
340 spin_unlock(&o2net_debug_lock);
341
342 return 0;
343}
344
345static void sc_seq_stop(struct seq_file *seq, void *v)
346{
347}
348
James Morris88e9d342009-09-22 16:43:43 -0700349static const struct seq_operations sc_seq_ops = {
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700350 .start = sc_seq_start,
351 .next = sc_seq_next,
352 .stop = sc_seq_stop,
353 .show = sc_seq_show,
354};
355
356static int sc_fop_open(struct inode *inode, struct file *file)
357{
358 struct o2net_sock_container *dummy_sc;
359 struct seq_file *seq;
360 int ret;
361
362 dummy_sc = kmalloc(sizeof(struct o2net_sock_container), GFP_KERNEL);
363 if (dummy_sc == NULL) {
364 ret = -ENOMEM;
365 goto out;
366 }
367 dummy_sc->sc_page = NULL;
368
369 ret = seq_open(file, &sc_seq_ops);
370 if (ret)
371 goto out;
372
373 seq = file->private_data;
374 seq->private = dummy_sc;
375 o2net_debug_add_sc(dummy_sc);
376
377 dummy_sc = NULL;
378
379out:
380 kfree(dummy_sc);
381 return ret;
382}
383
384static int sc_fop_release(struct inode *inode, struct file *file)
385{
386 struct seq_file *seq = file->private_data;
387 struct o2net_sock_container *dummy_sc = seq->private;
388
389 o2net_debug_del_sc(dummy_sc);
390 return seq_release_private(inode, file);
391}
392
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700393static const struct file_operations sc_seq_fops = {
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700394 .open = sc_fop_open,
395 .read = seq_read,
396 .llseek = seq_lseek,
397 .release = sc_fop_release,
398};
399
400int o2net_debugfs_init(void)
401{
402 o2net_dentry = debugfs_create_dir(O2NET_DEBUG_DIR, NULL);
403 if (!o2net_dentry) {
404 mlog_errno(-ENOMEM);
405 goto bail;
406 }
407
408 nst_dentry = debugfs_create_file(NST_DEBUG_NAME, S_IFREG|S_IRUSR,
409 o2net_dentry, NULL,
410 &nst_seq_fops);
411 if (!nst_dentry) {
412 mlog_errno(-ENOMEM);
413 goto bail;
414 }
415
416 sc_dentry = debugfs_create_file(SC_DEBUG_NAME, S_IFREG|S_IRUSR,
417 o2net_dentry, NULL,
418 &sc_seq_fops);
419 if (!sc_dentry) {
420 mlog_errno(-ENOMEM);
421 goto bail;
422 }
423
424 return 0;
425bail:
Sunil Mushran37096a72010-12-20 16:35:00 -0800426 debugfs_remove(sc_dentry);
427 debugfs_remove(nst_dentry);
428 debugfs_remove(o2net_dentry);
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700429 return -ENOMEM;
430}
431
432void o2net_debugfs_exit(void)
433{
Sunil Mushran37096a72010-12-20 16:35:00 -0800434 debugfs_remove(sc_dentry);
435 debugfs_remove(nst_dentry);
436 debugfs_remove(o2net_dentry);
Sunil Mushran2309e9e2008-04-14 10:46:19 -0700437}
438
439#endif /* CONFIG_DEBUG_FS */