Skip to content

Commit 8c1f92c

Browse files
Koichiro Denjonmason
authored andcommitted
NTB: ntb_transport: Use seq_file for QP stats debugfs
The ./qp*/stats debugfs file for each NTB transport QP is currently implemented with a hand-crafted kmalloc() buffer and a series of scnprintf() calls. This is a pre-seq_file style pattern and makes future extensions easy to truncate. Convert the stats file to use the seq_file helpers via DEFINE_SHOW_ATTRIBUTE(), which simplifies the code and lets the seq_file core handle buffering and partial reads. Reviewed-by: Frank Li <Frank.Li@nxp.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Koichiro Den <den@valinux.co.jp> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent 6a4b505 commit 8c1f92c

1 file changed

Lines changed: 39 additions & 93 deletions

File tree

drivers/ntb/ntb_transport.c

Lines changed: 39 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <linux/module.h>
5959
#include <linux/pci.h>
6060
#include <linux/slab.h>
61+
#include <linux/seq_file.h>
6162
#include <linux/types.h>
6263
#include <linux/uaccess.h>
6364
#include <linux/mutex.h>
@@ -482,104 +483,49 @@ void ntb_transport_unregister_client(struct ntb_transport_client *drv)
482483
}
483484
EXPORT_SYMBOL_GPL(ntb_transport_unregister_client);
484485

485-
static ssize_t debugfs_read(struct file *filp, char __user *ubuf, size_t count,
486-
loff_t *offp)
486+
static int ntb_qp_debugfs_stats_show(struct seq_file *s, void *v)
487487
{
488-
struct ntb_transport_qp *qp;
489-
char *buf;
490-
ssize_t ret, out_offset, out_count;
491-
492-
qp = filp->private_data;
488+
struct ntb_transport_qp *qp = s->private;
493489

494490
if (!qp || !qp->link_is_up)
495491
return 0;
496492

497-
out_count = 1000;
498-
499-
buf = kmalloc(out_count, GFP_KERNEL);
500-
if (!buf)
501-
return -ENOMEM;
493+
seq_puts(s, "\nNTB QP stats:\n\n");
494+
495+
seq_printf(s, "rx_bytes - \t%llu\n", qp->rx_bytes);
496+
seq_printf(s, "rx_pkts - \t%llu\n", qp->rx_pkts);
497+
seq_printf(s, "rx_memcpy - \t%llu\n", qp->rx_memcpy);
498+
seq_printf(s, "rx_async - \t%llu\n", qp->rx_async);
499+
seq_printf(s, "rx_ring_empty - %llu\n", qp->rx_ring_empty);
500+
seq_printf(s, "rx_err_no_buf - %llu\n", qp->rx_err_no_buf);
501+
seq_printf(s, "rx_err_oflow - \t%llu\n", qp->rx_err_oflow);
502+
seq_printf(s, "rx_err_ver - \t%llu\n", qp->rx_err_ver);
503+
seq_printf(s, "rx_buff - \t0x%p\n", qp->rx_buff);
504+
seq_printf(s, "rx_index - \t%u\n", qp->rx_index);
505+
seq_printf(s, "rx_max_entry - \t%u\n", qp->rx_max_entry);
506+
seq_printf(s, "rx_alloc_entry - \t%u\n\n", qp->rx_alloc_entry);
507+
508+
seq_printf(s, "tx_bytes - \t%llu\n", qp->tx_bytes);
509+
seq_printf(s, "tx_pkts - \t%llu\n", qp->tx_pkts);
510+
seq_printf(s, "tx_memcpy - \t%llu\n", qp->tx_memcpy);
511+
seq_printf(s, "tx_async - \t%llu\n", qp->tx_async);
512+
seq_printf(s, "tx_ring_full - \t%llu\n", qp->tx_ring_full);
513+
seq_printf(s, "tx_err_no_buf - %llu\n", qp->tx_err_no_buf);
514+
seq_printf(s, "tx_mw - \t0x%p\n", qp->tx_mw);
515+
seq_printf(s, "tx_index (H) - \t%u\n", qp->tx_index);
516+
seq_printf(s, "RRI (T) - \t%u\n", qp->remote_rx_info->entry);
517+
seq_printf(s, "tx_max_entry - \t%u\n", qp->tx_max_entry);
518+
seq_printf(s, "free tx - \t%u\n", ntb_transport_tx_free_entry(qp));
519+
seq_putc(s, '\n');
520+
521+
seq_printf(s, "Using TX DMA - \t%s\n", qp->tx_dma_chan ? "Yes" : "No");
522+
seq_printf(s, "Using RX DMA - \t%s\n", qp->rx_dma_chan ? "Yes" : "No");
523+
seq_printf(s, "QP Link - \t%s\n", qp->link_is_up ? "Up" : "Down");
524+
seq_putc(s, '\n');
502525

503-
out_offset = 0;
504-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
505-
"\nNTB QP stats:\n\n");
506-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
507-
"rx_bytes - \t%llu\n", qp->rx_bytes);
508-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
509-
"rx_pkts - \t%llu\n", qp->rx_pkts);
510-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
511-
"rx_memcpy - \t%llu\n", qp->rx_memcpy);
512-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
513-
"rx_async - \t%llu\n", qp->rx_async);
514-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
515-
"rx_ring_empty - %llu\n", qp->rx_ring_empty);
516-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
517-
"rx_err_no_buf - %llu\n", qp->rx_err_no_buf);
518-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
519-
"rx_err_oflow - \t%llu\n", qp->rx_err_oflow);
520-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
521-
"rx_err_ver - \t%llu\n", qp->rx_err_ver);
522-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
523-
"rx_buff - \t0x%p\n", qp->rx_buff);
524-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
525-
"rx_index - \t%u\n", qp->rx_index);
526-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
527-
"rx_max_entry - \t%u\n", qp->rx_max_entry);
528-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
529-
"rx_alloc_entry - \t%u\n\n", qp->rx_alloc_entry);
530-
531-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
532-
"tx_bytes - \t%llu\n", qp->tx_bytes);
533-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
534-
"tx_pkts - \t%llu\n", qp->tx_pkts);
535-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
536-
"tx_memcpy - \t%llu\n", qp->tx_memcpy);
537-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
538-
"tx_async - \t%llu\n", qp->tx_async);
539-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
540-
"tx_ring_full - \t%llu\n", qp->tx_ring_full);
541-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
542-
"tx_err_no_buf - %llu\n", qp->tx_err_no_buf);
543-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
544-
"tx_mw - \t0x%p\n", qp->tx_mw);
545-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
546-
"tx_index (H) - \t%u\n", qp->tx_index);
547-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
548-
"RRI (T) - \t%u\n",
549-
qp->remote_rx_info->entry);
550-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
551-
"tx_max_entry - \t%u\n", qp->tx_max_entry);
552-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
553-
"free tx - \t%u\n",
554-
ntb_transport_tx_free_entry(qp));
555-
556-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
557-
"\n");
558-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
559-
"Using TX DMA - \t%s\n",
560-
qp->tx_dma_chan ? "Yes" : "No");
561-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
562-
"Using RX DMA - \t%s\n",
563-
qp->rx_dma_chan ? "Yes" : "No");
564-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
565-
"QP Link - \t%s\n",
566-
qp->link_is_up ? "Up" : "Down");
567-
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
568-
"\n");
569-
570-
if (out_offset > out_count)
571-
out_offset = out_count;
572-
573-
ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);
574-
kfree(buf);
575-
return ret;
576-
}
577-
578-
static const struct file_operations ntb_qp_debugfs_stats = {
579-
.owner = THIS_MODULE,
580-
.open = simple_open,
581-
.read = debugfs_read,
582-
};
526+
return 0;
527+
}
528+
DEFINE_SHOW_ATTRIBUTE(ntb_qp_debugfs_stats);
583529

584530
static void ntb_list_add(spinlock_t *lock, struct list_head *entry,
585531
struct list_head *list)
@@ -1260,7 +1206,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt,
12601206

12611207
qp->debugfs_stats = debugfs_create_file("stats", S_IRUSR,
12621208
qp->debugfs_dir, qp,
1263-
&ntb_qp_debugfs_stats);
1209+
&ntb_qp_debugfs_stats_fops);
12641210
} else {
12651211
qp->debugfs_dir = NULL;
12661212
qp->debugfs_stats = NULL;

0 commit comments

Comments
 (0)