27 #ifdef CONFIG_DEBUG_FS
29 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/slab.h>
40 #include "nodemanager.h"
41 #define MLOG_MASK_PREFIX ML_TCP
44 #include "tcp_internal.h"
46 #define O2NET_DEBUG_DIR "o2net"
47 #define SC_DEBUG_NAME "sock_containers"
48 #define NST_DEBUG_NAME "send_tracking"
49 #define STATS_DEBUG_NAME "stats"
50 #define NODES_DEBUG_NAME "connected_nodes"
52 #define SHOW_SOCK_CONTAINERS 0
53 #define SHOW_SOCK_STATS 1
55 static struct dentry *o2net_dentry;
56 static struct dentry *sc_dentry;
57 static struct dentry *nst_dentry;
58 static struct dentry *stats_dentry;
59 static struct dentry *nodes_dentry;
68 spin_lock(&o2net_debug_lock);
69 list_add(&nst->st_net_debug_item, &send_tracking);
70 spin_unlock(&o2net_debug_lock);
75 spin_lock(&o2net_debug_lock);
76 if (!list_empty(&nst->st_net_debug_item))
77 list_del_init(&nst->st_net_debug_item);
78 spin_unlock(&o2net_debug_lock);
91 if (&nst->st_net_debug_item == &send_tracking)
95 if (nst->st_task !=
NULL) {
104 static void *nst_seq_start(
struct seq_file *seq, loff_t *
pos)
108 spin_lock(&o2net_debug_lock);
109 nst = next_nst(dummy_nst);
110 spin_unlock(&o2net_debug_lock);
115 static void *nst_seq_next(
struct seq_file *seq,
void *
v, loff_t *
pos)
119 spin_lock(&o2net_debug_lock);
120 nst = next_nst(dummy_nst);
121 list_del_init(&dummy_nst->st_net_debug_item);
123 list_add(&dummy_nst->st_net_debug_item,
124 &nst->st_net_debug_item);
125 spin_unlock(&o2net_debug_lock);
130 static int nst_seq_show(
struct seq_file *seq,
void *v)
136 spin_lock(&o2net_debug_lock);
137 nst = next_nst(dummy_nst);
142 sock = ktime_to_us(ktime_sub(now, nst->st_sock_time));
143 send = ktime_to_us(ktime_sub(now, nst->st_send_time));
144 status = ktime_to_us(ktime_sub(now, nst->st_status_time));
150 " process name: %s\n"
154 " message type: %u\n"
155 " message key: 0x%08x\n"
156 " sock acquiry: %lld usecs ago\n"
157 " send start: %lld usecs ago\n"
158 " wait start: %lld usecs ago\n",
159 nst, (
unsigned long)task_pid_nr(nst->st_task),
160 (
unsigned long)nst->st_task->tgid,
161 nst->st_task->comm, nst->st_node,
162 nst->st_sc, nst->st_id, nst->st_msg_type,
169 spin_unlock(&o2net_debug_lock);
174 static void nst_seq_stop(
struct seq_file *seq,
void *v)
179 .
start = nst_seq_start,
180 .next = nst_seq_next,
181 .stop = nst_seq_stop,
182 .show = nst_seq_show,
192 if (dummy_nst ==
NULL) {
196 dummy_nst->st_task =
NULL;
204 o2net_debug_add_nst(dummy_nst);
213 static int nst_fop_release(
struct inode *inode,
struct file *file)
218 o2net_debug_del_nst(dummy_nst);
223 .
open = nst_fop_open,
226 .release = nst_fop_release,
231 spin_lock(&o2net_debug_lock);
232 list_add(&sc->sc_net_debug_item, &sock_containers);
233 spin_unlock(&o2net_debug_lock);
238 spin_lock(&o2net_debug_lock);
239 list_del_init(&sc->sc_net_debug_item);
240 spin_unlock(&o2net_debug_lock);
243 struct o2net_sock_debug {
258 if (&sc->sc_net_debug_item == &sock_containers)
271 static void *sc_seq_start(
struct seq_file *seq, loff_t *pos)
273 struct o2net_sock_debug *
sd = seq->
private;
276 spin_lock(&o2net_debug_lock);
277 sc = next_sc(dummy_sc);
278 spin_unlock(&o2net_debug_lock);
283 static void *sc_seq_next(
struct seq_file *seq,
void *v, loff_t *pos)
285 struct o2net_sock_debug *
sd = seq->
private;
288 spin_lock(&o2net_debug_lock);
289 sc = next_sc(dummy_sc);
290 list_del_init(&dummy_sc->sc_net_debug_item);
292 list_add(&dummy_sc->sc_net_debug_item, &sc->sc_net_debug_item);
293 spin_unlock(&o2net_debug_lock);
298 #ifdef CONFIG_OCFS2_FS_STATS
299 # define sc_send_count(_s) ((_s)->sc_send_count)
300 # define sc_recv_count(_s) ((_s)->sc_recv_count)
301 # define sc_tv_acquiry_total_ns(_s) (ktime_to_ns((_s)->sc_tv_acquiry_total))
302 # define sc_tv_send_total_ns(_s) (ktime_to_ns((_s)->sc_tv_send_total))
303 # define sc_tv_status_total_ns(_s) (ktime_to_ns((_s)->sc_tv_status_total))
304 # define sc_tv_process_total_ns(_s) (ktime_to_ns((_s)->sc_tv_process_total))
306 # define sc_send_count(_s) (0U)
307 # define sc_recv_count(_s) (0U)
308 # define sc_tv_acquiry_total_ns(_s) (0LL)
309 # define sc_tv_send_total_ns(_s) (0LL)
310 # define sc_tv_status_total_ns(_s) (0LL)
311 # define sc_tv_process_total_ns(_s) (0LL)
315 #define O2NET_STATS_STR_VERSION 1
316 static void sc_show_sock_stats(
struct seq_file *seq,
322 seq_printf(seq,
"%d,%u,%lu,%lld,%lld,%lld,%lu,%lld\n", O2NET_STATS_STR_VERSION,
323 sc->
sc_node->nd_num, (
unsigned long)sc_send_count(sc),
324 (
long long)sc_tv_acquiry_total_ns(sc),
325 (
long long)sc_tv_send_total_ns(sc),
326 (
long long)sc_tv_status_total_ns(sc),
327 (
unsigned long)sc_recv_count(sc),
328 (
long long)sc_tv_process_total_ns(sc));
331 static void sc_show_sock_container(
struct seq_file *seq,
336 __be16 sport = 0, dport = 0;
342 inet = inet_sk(sc->
sc_sock->sk);
358 " handshake ok: %u\n"
359 " timer: %lld usecs\n"
360 " data ready: %lld usecs\n"
361 " advance start: %lld usecs\n"
362 " advance stop: %lld usecs\n"
363 " func start: %lld usecs\n"
364 " func stop: %lld usecs\n"
365 " func key: 0x%08x\n"
369 &saddr, inet ?
ntohs(sport) : 0,
374 (
long long)ktime_to_us(sc->sc_tv_timer),
375 (
long long)ktime_to_us(sc->sc_tv_data_ready),
376 (
long long)ktime_to_us(sc->sc_tv_advance_start),
377 (
long long)ktime_to_us(sc->sc_tv_advance_stop),
378 (
long long)ktime_to_us(sc->sc_tv_func_start),
379 (
long long)ktime_to_us(sc->sc_tv_func_stop),
384 static int sc_seq_show(
struct seq_file *seq,
void *v)
386 struct o2net_sock_debug *sd = seq->
private;
389 spin_lock(&o2net_debug_lock);
390 sc = next_sc(dummy_sc);
393 if (sd->dbg_ctxt == SHOW_SOCK_CONTAINERS)
394 sc_show_sock_container(seq, sc);
396 sc_show_sock_stats(seq, sc);
399 spin_unlock(&o2net_debug_lock);
404 static void sc_seq_stop(
struct seq_file *seq,
void *v)
409 .
start = sc_seq_start,
415 static int sc_common_open(
struct file *file,
struct o2net_sock_debug *sd)
422 if (dummy_sc ==
NULL) {
434 sd->dbg_sock = dummy_sc;
435 o2net_debug_add_sc(dummy_sc);
444 static int sc_fop_release(
struct inode *inode,
struct file *file)
447 struct o2net_sock_debug *sd = seq->
private;
450 o2net_debug_del_sc(dummy_sc);
454 static int stats_fop_open(
struct inode *inode,
struct file *file)
456 struct o2net_sock_debug *sd;
462 sd->dbg_ctxt = SHOW_SOCK_STATS;
465 return sc_common_open(file, sd);
469 .
open = stats_fop_open,
472 .release = sc_fop_release,
475 static int sc_fop_open(
struct inode *inode,
struct file *file)
477 struct o2net_sock_debug *sd;
483 sd->dbg_ctxt = SHOW_SOCK_CONTAINERS;
486 return sc_common_open(file, sd);
493 .release = sc_fop_release,
496 static int o2net_fill_bitmap(
char *
buf,
int len)
510 static int nodes_fop_open(
struct inode *inode,
struct file *file)
518 i_size_write(inode, o2net_fill_bitmap(buf,
PAGE_SIZE));
525 static int o2net_debug_release(
struct inode *inode,
struct file *file)
531 static ssize_t o2net_debug_read(
struct file *file,
char __user *buf,
532 size_t nbytes, loff_t *ppos)
539 .
open = nodes_fop_open,
540 .release = o2net_debug_release,
541 .read = o2net_debug_read,
545 void o2net_debugfs_exit(
void)
554 int o2net_debugfs_init(
void)
561 o2net_dentry,
NULL, &nst_seq_fops);
564 o2net_dentry,
NULL, &sc_seq_fops);
567 o2net_dentry,
NULL, &stats_seq_fops);
570 o2net_dentry,
NULL, &nodes_fops);
574 o2net_debugfs_exit();