提交 8d81ef34 编写于 作者: V Vipul Pandya 提交者: Roland Dreier

RDMA/cxgb4: Add debugfs RDMA memory stats

Signed-off-by: NVipul Pandya <vipul@chelsio.com>
Signed-off-by: NSteve Wise <swise@opengridcomputing.com>
Signed-off-by: NRoland Dreier <roland@purestorage.com>
上级 3069ee9b
...@@ -240,6 +240,62 @@ static const struct file_operations stag_debugfs_fops = { ...@@ -240,6 +240,62 @@ static const struct file_operations stag_debugfs_fops = {
.llseek = default_llseek, .llseek = default_llseek,
}; };
static int stats_show(struct seq_file *seq, void *v)
{
struct c4iw_dev *dev = seq->private;
seq_printf(seq, " Object: %10s %10s %10s\n", "Total", "Current", "Max");
seq_printf(seq, " PDID: %10llu %10llu %10llu\n",
dev->rdev.stats.pd.total, dev->rdev.stats.pd.cur,
dev->rdev.stats.pd.max);
seq_printf(seq, " QID: %10llu %10llu %10llu\n",
dev->rdev.stats.qid.total, dev->rdev.stats.qid.cur,
dev->rdev.stats.qid.max);
seq_printf(seq, " TPTMEM: %10llu %10llu %10llu\n",
dev->rdev.stats.stag.total, dev->rdev.stats.stag.cur,
dev->rdev.stats.stag.max);
seq_printf(seq, " PBLMEM: %10llu %10llu %10llu\n",
dev->rdev.stats.pbl.total, dev->rdev.stats.pbl.cur,
dev->rdev.stats.pbl.max);
seq_printf(seq, " RQTMEM: %10llu %10llu %10llu\n",
dev->rdev.stats.rqt.total, dev->rdev.stats.rqt.cur,
dev->rdev.stats.rqt.max);
seq_printf(seq, " OCQPMEM: %10llu %10llu %10llu\n",
dev->rdev.stats.ocqp.total, dev->rdev.stats.ocqp.cur,
dev->rdev.stats.ocqp.max);
return 0;
}
static int stats_open(struct inode *inode, struct file *file)
{
return single_open(file, stats_show, inode->i_private);
}
static ssize_t stats_clear(struct file *file, const char __user *buf,
size_t count, loff_t *pos)
{
struct c4iw_dev *dev = ((struct seq_file *)file->private_data)->private;
mutex_lock(&dev->rdev.stats.lock);
dev->rdev.stats.pd.max = 0;
dev->rdev.stats.qid.max = 0;
dev->rdev.stats.stag.max = 0;
dev->rdev.stats.pbl.max = 0;
dev->rdev.stats.rqt.max = 0;
dev->rdev.stats.ocqp.max = 0;
mutex_unlock(&dev->rdev.stats.lock);
return count;
}
static const struct file_operations stats_debugfs_fops = {
.owner = THIS_MODULE,
.open = stats_open,
.release = single_release,
.read = seq_read,
.llseek = seq_lseek,
.write = stats_clear,
};
static int setup_debugfs(struct c4iw_dev *devp) static int setup_debugfs(struct c4iw_dev *devp)
{ {
struct dentry *de; struct dentry *de;
...@@ -256,6 +312,12 @@ static int setup_debugfs(struct c4iw_dev *devp) ...@@ -256,6 +312,12 @@ static int setup_debugfs(struct c4iw_dev *devp)
(void *)devp, &stag_debugfs_fops); (void *)devp, &stag_debugfs_fops);
if (de && de->d_inode) if (de && de->d_inode)
de->d_inode->i_size = 4096; de->d_inode->i_size = 4096;
de = debugfs_create_file("stats", S_IWUSR, devp->debugfs_root,
(void *)devp, &stats_debugfs_fops);
if (de && de->d_inode)
de->d_inode->i_size = 4096;
return 0; return 0;
} }
...@@ -269,9 +331,13 @@ void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev, ...@@ -269,9 +331,13 @@ void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
list_for_each_safe(pos, nxt, &uctx->qpids) { list_for_each_safe(pos, nxt, &uctx->qpids) {
entry = list_entry(pos, struct c4iw_qid_list, entry); entry = list_entry(pos, struct c4iw_qid_list, entry);
list_del_init(&entry->entry); list_del_init(&entry->entry);
if (!(entry->qid & rdev->qpmask)) if (!(entry->qid & rdev->qpmask)) {
c4iw_put_resource(&rdev->resource.qid_fifo, entry->qid, c4iw_put_resource(&rdev->resource.qid_fifo, entry->qid,
&rdev->resource.qid_fifo_lock); &rdev->resource.qid_fifo_lock);
mutex_lock(&rdev->stats.lock);
rdev->stats.qid.cur -= rdev->qpmask + 1;
mutex_unlock(&rdev->stats.lock);
}
kfree(entry); kfree(entry);
} }
...@@ -332,6 +398,13 @@ static int c4iw_rdev_open(struct c4iw_rdev *rdev) ...@@ -332,6 +398,13 @@ static int c4iw_rdev_open(struct c4iw_rdev *rdev)
goto err1; goto err1;
} }
rdev->stats.pd.total = T4_MAX_NUM_PD;
rdev->stats.stag.total = rdev->lldi.vr->stag.size;
rdev->stats.pbl.total = rdev->lldi.vr->pbl.size;
rdev->stats.rqt.total = rdev->lldi.vr->rq.size;
rdev->stats.ocqp.total = rdev->lldi.vr->ocq.size;
rdev->stats.qid.total = rdev->lldi.vr->qp.size;
err = c4iw_init_resource(rdev, c4iw_num_stags(rdev), T4_MAX_NUM_PD); err = c4iw_init_resource(rdev, c4iw_num_stags(rdev), T4_MAX_NUM_PD);
if (err) { if (err) {
printk(KERN_ERR MOD "error %d initializing resources\n", err); printk(KERN_ERR MOD "error %d initializing resources\n", err);
...@@ -440,6 +513,7 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop) ...@@ -440,6 +513,7 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop)
idr_init(&devp->qpidr); idr_init(&devp->qpidr);
idr_init(&devp->mmidr); idr_init(&devp->mmidr);
spin_lock_init(&devp->lock); spin_lock_init(&devp->lock);
mutex_init(&devp->rdev.stats.lock);
if (c4iw_debugfs_root) { if (c4iw_debugfs_root) {
devp->debugfs_root = debugfs_create_dir( devp->debugfs_root = debugfs_create_dir(
......
...@@ -103,6 +103,22 @@ enum c4iw_rdev_flags { ...@@ -103,6 +103,22 @@ enum c4iw_rdev_flags {
T4_FATAL_ERROR = (1<<0), T4_FATAL_ERROR = (1<<0),
}; };
struct c4iw_stat {
u64 total;
u64 cur;
u64 max;
};
struct c4iw_stats {
struct mutex lock;
struct c4iw_stat qid;
struct c4iw_stat pd;
struct c4iw_stat stag;
struct c4iw_stat pbl;
struct c4iw_stat rqt;
struct c4iw_stat ocqp;
};
struct c4iw_rdev { struct c4iw_rdev {
struct c4iw_resource resource; struct c4iw_resource resource;
unsigned long qpshift; unsigned long qpshift;
...@@ -117,6 +133,7 @@ struct c4iw_rdev { ...@@ -117,6 +133,7 @@ struct c4iw_rdev {
struct cxgb4_lld_info lldi; struct cxgb4_lld_info lldi;
unsigned long oc_mw_pa; unsigned long oc_mw_pa;
void __iomem *oc_mw_kva; void __iomem *oc_mw_kva;
struct c4iw_stats stats;
}; };
static inline int c4iw_fatal_error(struct c4iw_rdev *rdev) static inline int c4iw_fatal_error(struct c4iw_rdev *rdev)
......
...@@ -135,6 +135,11 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, ...@@ -135,6 +135,11 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
&rdev->resource.tpt_fifo_lock); &rdev->resource.tpt_fifo_lock);
if (!stag_idx) if (!stag_idx)
return -ENOMEM; return -ENOMEM;
mutex_lock(&rdev->stats.lock);
rdev->stats.stag.cur += 32;
if (rdev->stats.stag.cur > rdev->stats.stag.max)
rdev->stats.stag.max = rdev->stats.stag.cur;
mutex_unlock(&rdev->stats.lock);
*stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff); *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
} }
PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n", PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
...@@ -165,9 +170,13 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, ...@@ -165,9 +170,13 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
(rdev->lldi.vr->stag.start >> 5), (rdev->lldi.vr->stag.start >> 5),
sizeof(tpt), &tpt); sizeof(tpt), &tpt);
if (reset_tpt_entry) if (reset_tpt_entry) {
c4iw_put_resource(&rdev->resource.tpt_fifo, stag_idx, c4iw_put_resource(&rdev->resource.tpt_fifo, stag_idx,
&rdev->resource.tpt_fifo_lock); &rdev->resource.tpt_fifo_lock);
mutex_lock(&rdev->stats.lock);
rdev->stats.stag.cur -= 32;
mutex_unlock(&rdev->stats.lock);
}
return err; return err;
} }
......
...@@ -190,6 +190,9 @@ static int c4iw_deallocate_pd(struct ib_pd *pd) ...@@ -190,6 +190,9 @@ static int c4iw_deallocate_pd(struct ib_pd *pd)
PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid); PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid);
c4iw_put_resource(&rhp->rdev.resource.pdid_fifo, php->pdid, c4iw_put_resource(&rhp->rdev.resource.pdid_fifo, php->pdid,
&rhp->rdev.resource.pdid_fifo_lock); &rhp->rdev.resource.pdid_fifo_lock);
mutex_lock(&rhp->rdev.stats.lock);
rhp->rdev.stats.pd.cur--;
mutex_unlock(&rhp->rdev.stats.lock);
kfree(php); kfree(php);
return 0; return 0;
} }
...@@ -222,6 +225,11 @@ static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev, ...@@ -222,6 +225,11 @@ static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev,
return ERR_PTR(-EFAULT); return ERR_PTR(-EFAULT);
} }
} }
mutex_lock(&rhp->rdev.stats.lock);
rhp->rdev.stats.pd.cur++;
if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
mutex_unlock(&rhp->rdev.stats.lock);
PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php); PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php);
return &php->ibpd; return &php->ibpd;
} }
......
...@@ -185,6 +185,9 @@ u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx) ...@@ -185,6 +185,9 @@ u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
&rdev->resource.qid_fifo_lock); &rdev->resource.qid_fifo_lock);
if (!qid) if (!qid)
goto out; goto out;
mutex_lock(&rdev->stats.lock);
rdev->stats.qid.cur += rdev->qpmask + 1;
mutex_unlock(&rdev->stats.lock);
for (i = qid+1; i & rdev->qpmask; i++) { for (i = qid+1; i & rdev->qpmask; i++) {
entry = kmalloc(sizeof *entry, GFP_KERNEL); entry = kmalloc(sizeof *entry, GFP_KERNEL);
if (!entry) if (!entry)
...@@ -213,6 +216,10 @@ u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx) ...@@ -213,6 +216,10 @@ u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
out: out:
mutex_unlock(&uctx->lock); mutex_unlock(&uctx->lock);
PDBG("%s qid 0x%x\n", __func__, qid); PDBG("%s qid 0x%x\n", __func__, qid);
mutex_lock(&rdev->stats.lock);
if (rdev->stats.qid.cur > rdev->stats.qid.max)
rdev->stats.qid.max = rdev->stats.qid.cur;
mutex_unlock(&rdev->stats.lock);
return qid; return qid;
} }
...@@ -249,6 +256,9 @@ u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx) ...@@ -249,6 +256,9 @@ u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
&rdev->resource.qid_fifo_lock); &rdev->resource.qid_fifo_lock);
if (!qid) if (!qid)
goto out; goto out;
mutex_lock(&rdev->stats.lock);
rdev->stats.qid.cur += rdev->qpmask + 1;
mutex_unlock(&rdev->stats.lock);
for (i = qid+1; i & rdev->qpmask; i++) { for (i = qid+1; i & rdev->qpmask; i++) {
entry = kmalloc(sizeof *entry, GFP_KERNEL); entry = kmalloc(sizeof *entry, GFP_KERNEL);
if (!entry) if (!entry)
...@@ -277,6 +287,10 @@ u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx) ...@@ -277,6 +287,10 @@ u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
out: out:
mutex_unlock(&uctx->lock); mutex_unlock(&uctx->lock);
PDBG("%s qid 0x%x\n", __func__, qid); PDBG("%s qid 0x%x\n", __func__, qid);
mutex_lock(&rdev->stats.lock);
if (rdev->stats.qid.cur > rdev->stats.qid.max)
rdev->stats.qid.max = rdev->stats.qid.cur;
mutex_unlock(&rdev->stats.lock);
return qid; return qid;
} }
...@@ -315,12 +329,22 @@ u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size) ...@@ -315,12 +329,22 @@ u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size)
if (!addr) if (!addr)
printk_ratelimited(KERN_WARNING MOD "%s: Out of PBL memory\n", printk_ratelimited(KERN_WARNING MOD "%s: Out of PBL memory\n",
pci_name(rdev->lldi.pdev)); pci_name(rdev->lldi.pdev));
if (addr) {
mutex_lock(&rdev->stats.lock);
rdev->stats.pbl.cur += roundup(size, 1 << MIN_PBL_SHIFT);
if (rdev->stats.pbl.cur > rdev->stats.pbl.max)
rdev->stats.pbl.max = rdev->stats.pbl.cur;
mutex_unlock(&rdev->stats.lock);
}
return (u32)addr; return (u32)addr;
} }
void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size) void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size)
{ {
PDBG("%s addr 0x%x size %d\n", __func__, addr, size); PDBG("%s addr 0x%x size %d\n", __func__, addr, size);
mutex_lock(&rdev->stats.lock);
rdev->stats.pbl.cur -= roundup(size, 1 << MIN_PBL_SHIFT);
mutex_unlock(&rdev->stats.lock);
gen_pool_free(rdev->pbl_pool, (unsigned long)addr, size); gen_pool_free(rdev->pbl_pool, (unsigned long)addr, size);
} }
...@@ -377,12 +401,22 @@ u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size) ...@@ -377,12 +401,22 @@ u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size)
if (!addr) if (!addr)
printk_ratelimited(KERN_WARNING MOD "%s: Out of RQT memory\n", printk_ratelimited(KERN_WARNING MOD "%s: Out of RQT memory\n",
pci_name(rdev->lldi.pdev)); pci_name(rdev->lldi.pdev));
if (addr) {
mutex_lock(&rdev->stats.lock);
rdev->stats.rqt.cur += roundup(size << 6, 1 << MIN_RQT_SHIFT);
if (rdev->stats.rqt.cur > rdev->stats.rqt.max)
rdev->stats.rqt.max = rdev->stats.rqt.cur;
mutex_unlock(&rdev->stats.lock);
}
return (u32)addr; return (u32)addr;
} }
void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size) void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size)
{ {
PDBG("%s addr 0x%x size %d\n", __func__, addr, size << 6); PDBG("%s addr 0x%x size %d\n", __func__, addr, size << 6);
mutex_lock(&rdev->stats.lock);
rdev->stats.rqt.cur -= roundup(size << 6, 1 << MIN_RQT_SHIFT);
mutex_unlock(&rdev->stats.lock);
gen_pool_free(rdev->rqt_pool, (unsigned long)addr, size << 6); gen_pool_free(rdev->rqt_pool, (unsigned long)addr, size << 6);
} }
...@@ -433,12 +467,22 @@ u32 c4iw_ocqp_pool_alloc(struct c4iw_rdev *rdev, int size) ...@@ -433,12 +467,22 @@ u32 c4iw_ocqp_pool_alloc(struct c4iw_rdev *rdev, int size)
{ {
unsigned long addr = gen_pool_alloc(rdev->ocqp_pool, size); unsigned long addr = gen_pool_alloc(rdev->ocqp_pool, size);
PDBG("%s addr 0x%x size %d\n", __func__, (u32)addr, size); PDBG("%s addr 0x%x size %d\n", __func__, (u32)addr, size);
if (addr) {
mutex_lock(&rdev->stats.lock);
rdev->stats.ocqp.cur += roundup(size, 1 << MIN_OCQP_SHIFT);
if (rdev->stats.ocqp.cur > rdev->stats.ocqp.max)
rdev->stats.ocqp.max = rdev->stats.ocqp.cur;
mutex_unlock(&rdev->stats.lock);
}
return (u32)addr; return (u32)addr;
} }
void c4iw_ocqp_pool_free(struct c4iw_rdev *rdev, u32 addr, int size) void c4iw_ocqp_pool_free(struct c4iw_rdev *rdev, u32 addr, int size)
{ {
PDBG("%s addr 0x%x size %d\n", __func__, addr, size); PDBG("%s addr 0x%x size %d\n", __func__, addr, size);
mutex_lock(&rdev->stats.lock);
rdev->stats.ocqp.cur -= roundup(size, 1 << MIN_OCQP_SHIFT);
mutex_unlock(&rdev->stats.lock);
gen_pool_free(rdev->ocqp_pool, (unsigned long)addr, size); gen_pool_free(rdev->ocqp_pool, (unsigned long)addr, size);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册