Skip to content

Commit db02754

Browse files
Sunil MushranJoel Becker
authored andcommitted
ocfs2/cluster: Show o2net timing statistics
Adds debugfs dentry o2net/stats to show the o2net timing statistics. Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com> Signed-off-by: Joel Becker <joel.becker@oracle.com>
1 parent e453039 commit db02754

1 file changed

Lines changed: 157 additions & 54 deletions

File tree

‎fs/ocfs2/cluster/netdebug.c‎

Lines changed: 157 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@
4646
#define O2NET_DEBUG_DIR "o2net"
4747
#define SC_DEBUG_NAME "sock_containers"
4848
#define NST_DEBUG_NAME "send_tracking"
49+
#define STATS_DEBUG_NAME "stats"
50+
51+
#define SHOW_SOCK_CONTAINERS 0
52+
#define SHOW_SOCK_STATS 1
4953

5054
static struct dentry *o2net_dentry;
5155
static struct dentry *sc_dentry;
5256
static struct dentry *nst_dentry;
57+
static struct dentry *stats_dentry;
5358

5459
static DEFINE_SPINLOCK(o2net_debug_lock);
5560

@@ -232,6 +237,11 @@ void o2net_debug_del_sc(struct o2net_sock_container *sc)
232237
spin_unlock(&o2net_debug_lock);
233238
}
234239

240+
struct o2net_sock_debug {
241+
int dbg_ctxt;
242+
struct o2net_sock_container *dbg_sock;
243+
};
244+
235245
static struct o2net_sock_container
236246
*next_sc(struct o2net_sock_container *sc_start)
237247
{
@@ -257,7 +267,8 @@ static struct o2net_sock_container
257267

258268
static void *sc_seq_start(struct seq_file *seq, loff_t *pos)
259269
{
260-
struct o2net_sock_container *sc, *dummy_sc = seq->private;
270+
struct o2net_sock_debug *sd = seq->private;
271+
struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
261272

262273
spin_lock(&o2net_debug_lock);
263274
sc = next_sc(dummy_sc);
@@ -268,7 +279,8 @@ static void *sc_seq_start(struct seq_file *seq, loff_t *pos)
268279

269280
static void *sc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
270281
{
271-
struct o2net_sock_container *sc, *dummy_sc = seq->private;
282+
struct o2net_sock_debug *sd = seq->private;
283+
struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
272284

273285
spin_lock(&o2net_debug_lock);
274286
sc = next_sc(dummy_sc);
@@ -280,63 +292,107 @@ static void *sc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
280292
return sc; /* unused, just needs to be null when done */
281293
}
282294

283-
static int sc_seq_show(struct seq_file *seq, void *v)
295+
#ifdef CONFIG_OCFS2_FS_STATS
296+
# define sc_send_count(_s) ((_s)->sc_send_count)
297+
# define sc_recv_count(_s) ((_s)->sc_recv_count)
298+
# define sc_tv_acquiry_total_ns(_s) (ktime_to_ns((_s)->sc_tv_acquiry_total))
299+
# define sc_tv_send_total_ns(_s) (ktime_to_ns((_s)->sc_tv_send_total))
300+
# define sc_tv_status_total_ns(_s) (ktime_to_ns((_s)->sc_tv_status_total))
301+
# define sc_tv_process_total_ns(_s) (ktime_to_ns((_s)->sc_tv_process_total))
302+
#else
303+
# define sc_send_count(_s) (0U)
304+
# define sc_recv_count(_s) (0U)
305+
# define sc_tv_acquiry_total_ns(_s) (0LL)
306+
# define sc_tv_send_total_ns(_s) (0LL)
307+
# define sc_tv_status_total_ns(_s) (0LL)
308+
# define sc_tv_process_total_ns(_s) (0LL)
309+
#endif
310+
311+
/* So that debugfs.ocfs2 can determine which format is being used */
312+
#define O2NET_STATS_STR_VERSION 1
313+
static void sc_show_sock_stats(struct seq_file *seq,
314+
struct o2net_sock_container *sc)
284315
{
285-
struct o2net_sock_container *sc, *dummy_sc = seq->private;
316+
if (!sc)
317+
return;
318+
319+
seq_printf(seq, "%d,%u,%lu,%lld,%lld,%lld,%lu,%lld\n", O2NET_STATS_STR_VERSION,
320+
sc->sc_node->nd_num, (unsigned long)sc_send_count(sc),
321+
(long long)sc_tv_acquiry_total_ns(sc),
322+
(long long)sc_tv_send_total_ns(sc),
323+
(long long)sc_tv_status_total_ns(sc),
324+
(unsigned long)sc_recv_count(sc),
325+
(long long)sc_tv_process_total_ns(sc));
326+
}
286327

287-
spin_lock(&o2net_debug_lock);
288-
sc = next_sc(dummy_sc);
328+
static void sc_show_sock_container(struct seq_file *seq,
329+
struct o2net_sock_container *sc)
330+
{
331+
struct inet_sock *inet = NULL;
332+
__be32 saddr = 0, daddr = 0;
333+
__be16 sport = 0, dport = 0;
334+
335+
if (!sc)
336+
return;
337+
338+
if (sc->sc_sock) {
339+
inet = inet_sk(sc->sc_sock->sk);
340+
/* the stack's structs aren't sparse endian clean */
341+
saddr = (__force __be32)inet->inet_saddr;
342+
daddr = (__force __be32)inet->inet_daddr;
343+
sport = (__force __be16)inet->inet_sport;
344+
dport = (__force __be16)inet->inet_dport;
345+
}
289346

290-
if (sc != NULL) {
291-
struct inet_sock *inet = NULL;
347+
/* XXX sigh, inet-> doesn't have sparse annotation so any
348+
* use of it here generates a warning with -Wbitwise */
349+
seq_printf(seq, "%p:\n"
350+
" krefs: %d\n"
351+
" sock: %pI4:%u -> "
352+
"%pI4:%u\n"
353+
" remote node: %s\n"
354+
" page off: %zu\n"
355+
" handshake ok: %u\n"
356+
" timer: %lld usecs\n"
357+
" data ready: %lld usecs\n"
358+
" advance start: %lld usecs\n"
359+
" advance stop: %lld usecs\n"
360+
" func start: %lld usecs\n"
361+
" func stop: %lld usecs\n"
362+
" func key: 0x%08x\n"
363+
" func type: %u\n",
364+
sc,
365+
atomic_read(&sc->sc_kref.refcount),
366+
&saddr, inet ? ntohs(sport) : 0,
367+
&daddr, inet ? ntohs(dport) : 0,
368+
sc->sc_node->nd_name,
369+
sc->sc_page_off,
370+
sc->sc_handshake_ok,
371+
(long long)ktime_to_us(sc->sc_tv_timer),
372+
(long long)ktime_to_us(sc->sc_tv_data_ready),
373+
(long long)ktime_to_us(sc->sc_tv_advance_start),
374+
(long long)ktime_to_us(sc->sc_tv_advance_stop),
375+
(long long)ktime_to_us(sc->sc_tv_func_start),
376+
(long long)ktime_to_us(sc->sc_tv_func_stop),
377+
sc->sc_msg_key,
378+
sc->sc_msg_type);
379+
}
292380

293-
__be32 saddr = 0, daddr = 0;
294-
__be16 sport = 0, dport = 0;
381+
static int sc_seq_show(struct seq_file *seq, void *v)
382+
{
383+
struct o2net_sock_debug *sd = seq->private;
384+
struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
295385

296-
if (sc->sc_sock) {
297-
inet = inet_sk(sc->sc_sock->sk);
298-
/* the stack's structs aren't sparse endian clean */
299-
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;
303-
}
386+
spin_lock(&o2net_debug_lock);
387+
sc = next_sc(dummy_sc);
304388

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"
309-
" sock: %pI4:%u -> "
310-
"%pI4:%u\n"
311-
" remote node: %s\n"
312-
" page off: %zu\n"
313-
" handshake ok: %u\n"
314-
" 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"
321-
" func type: %u\n",
322-
sc,
323-
atomic_read(&sc->sc_kref.refcount),
324-
&saddr, inet ? ntohs(sport) : 0,
325-
&daddr, inet ? ntohs(dport) : 0,
326-
sc->sc_node->nd_name,
327-
sc->sc_page_off,
328-
sc->sc_handshake_ok,
329-
(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),
335-
sc->sc_msg_key,
336-
sc->sc_msg_type);
389+
if (sc) {
390+
if (sd->dbg_ctxt == SHOW_SOCK_CONTAINERS)
391+
sc_show_sock_container(seq, sc);
392+
else
393+
sc_show_sock_stats(seq, sc);
337394
}
338395

339-
340396
spin_unlock(&o2net_debug_lock);
341397

342398
return 0;
@@ -353,7 +409,7 @@ static const struct seq_operations sc_seq_ops = {
353409
.show = sc_seq_show,
354410
};
355411

356-
static int sc_fop_open(struct inode *inode, struct file *file)
412+
static int sc_common_open(struct file *file, struct o2net_sock_debug *sd)
357413
{
358414
struct o2net_sock_container *dummy_sc;
359415
struct seq_file *seq;
@@ -371,7 +427,8 @@ static int sc_fop_open(struct inode *inode, struct file *file)
371427
goto out;
372428

373429
seq = file->private_data;
374-
seq->private = dummy_sc;
430+
seq->private = sd;
431+
sd->dbg_sock = dummy_sc;
375432
o2net_debug_add_sc(dummy_sc);
376433

377434
dummy_sc = NULL;
@@ -384,12 +441,48 @@ static int sc_fop_open(struct inode *inode, struct file *file)
384441
static int sc_fop_release(struct inode *inode, struct file *file)
385442
{
386443
struct seq_file *seq = file->private_data;
387-
struct o2net_sock_container *dummy_sc = seq->private;
444+
struct o2net_sock_debug *sd = seq->private;
445+
struct o2net_sock_container *dummy_sc = sd->dbg_sock;
388446

389447
o2net_debug_del_sc(dummy_sc);
390448
return seq_release_private(inode, file);
391449
}
392450

451+
static int stats_fop_open(struct inode *inode, struct file *file)
452+
{
453+
struct o2net_sock_debug *sd;
454+
455+
sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL);
456+
if (sd == NULL)
457+
return -ENOMEM;
458+
459+
sd->dbg_ctxt = SHOW_SOCK_STATS;
460+
sd->dbg_sock = NULL;
461+
462+
return sc_common_open(file, sd);
463+
}
464+
465+
static const struct file_operations stats_seq_fops = {
466+
.open = stats_fop_open,
467+
.read = seq_read,
468+
.llseek = seq_lseek,
469+
.release = sc_fop_release,
470+
};
471+
472+
static int sc_fop_open(struct inode *inode, struct file *file)
473+
{
474+
struct o2net_sock_debug *sd;
475+
476+
sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL);
477+
if (sd == NULL)
478+
return -ENOMEM;
479+
480+
sd->dbg_ctxt = SHOW_SOCK_CONTAINERS;
481+
sd->dbg_sock = NULL;
482+
483+
return sc_common_open(file, sd);
484+
}
485+
393486
static const struct file_operations sc_seq_fops = {
394487
.open = sc_fop_open,
395488
.read = seq_read,
@@ -421,8 +514,17 @@ int o2net_debugfs_init(void)
421514
goto bail;
422515
}
423516

517+
stats_dentry = debugfs_create_file(STATS_DEBUG_NAME, S_IFREG|S_IRUSR,
518+
o2net_dentry, NULL,
519+
&stats_seq_fops);
520+
if (!stats_dentry) {
521+
mlog_errno(-ENOMEM);
522+
goto bail;
523+
}
524+
424525
return 0;
425526
bail:
527+
debugfs_remove(stats_dentry);
426528
debugfs_remove(sc_dentry);
427529
debugfs_remove(nst_dentry);
428530
debugfs_remove(o2net_dentry);
@@ -431,6 +533,7 @@ int o2net_debugfs_init(void)
431533

432534
void o2net_debugfs_exit(void)
433535
{
536+
debugfs_remove(stats_dentry);
434537
debugfs_remove(sc_dentry);
435538
debugfs_remove(nst_dentry);
436539
debugfs_remove(o2net_dentry);

0 commit comments

Comments
 (0)