From patchwork Thu Mar 30 22:12:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 9655229 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D9D2F6034C for ; Thu, 30 Mar 2017 22:14:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA53F28614 for ; Thu, 30 Mar 2017 22:14:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF03228616; Thu, 30 Mar 2017 22:14:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6987028614 for ; Thu, 30 Mar 2017 22:14:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934968AbdC3WNk (ORCPT ); Thu, 30 Mar 2017 18:13:40 -0400 Received: from ale.deltatee.com ([207.54.116.67]:44317 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934944AbdC3WNi (ORCPT ); Thu, 30 Mar 2017 18:13:38 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1ctiJI-0004kn-6k; Thu, 30 Mar 2017 16:12:56 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.84_2) (envelope-from ) id 1ctiJD-0001M4-MQ; Thu, 30 Mar 2017 16:12:47 -0600 From: Logan Gunthorpe To: Christoph Hellwig , Sagi Grimberg , "James E.J. Bottomley" , "Martin K. Petersen" , Jens Axboe , Steve Wise , Stephen Bates , Max Gurtovoy , Dan Williams , Keith Busch , Jason Gunthorpe Cc: linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, Logan Gunthorpe Date: Thu, 30 Mar 2017 16:12:35 -0600 Message-Id: <1490911959-5146-5-git-send-email-logang@deltatee.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1490911959-5146-1-git-send-email-logang@deltatee.com> References: <1490911959-5146-1-git-send-email-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: hch@lst.de, sagi@grimberg.me, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, axboe@kernel.dk, swise@opengridcomputing.com, sbates@raithlin.com, maxg@mellanox.com, dan.j.williams@intel.com, keith.busch@intel.com, jgunthorpe@obsidianresearch.com, linux-nvme@lists.infradead.org, linux-nvdimm@lists.01.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [RFC 4/8] p2pmem: Add debugfs "stats" file X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Steve Wise For each p2pmem instance, add a "stats" file to show the gen_pool statistics. Signed-off-by: Steve Wise Signed-off-by: Logan Gunthorpe Signed-off-by: Stephen Bates --- drivers/memory/p2pmem.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/p2pmem.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/drivers/memory/p2pmem.c b/drivers/memory/p2pmem.c index c4ea311..71741c2 100644 --- a/drivers/memory/p2pmem.c +++ b/drivers/memory/p2pmem.c @@ -18,6 +18,7 @@ #include #include #include +#include MODULE_DESCRIPTION("Peer 2 Peer Memory Device"); MODULE_VERSION("0.1"); @@ -27,6 +28,40 @@ MODULE_AUTHOR("Microsemi Corporation"); static struct class *p2pmem_class; static DEFINE_IDA(p2pmem_ida); +static struct dentry *p2pmem_debugfs_root; + +static int stats_show(struct seq_file *seq, void *v) +{ + struct p2pmem_dev *p = seq->private; + + if (p->pool) { + seq_printf(seq, "total size: %lu\n", gen_pool_size(p->pool)); + seq_printf(seq, "available: %lu\n", gen_pool_avail(p->pool)); + } + return 0; +} + +static int stats_open(struct inode *inode, struct file *file) +{ + return single_open(file, stats_show, inode->i_private); +} + +static const struct file_operations stats_debugfs_fops = { + .owner = THIS_MODULE, + .open = stats_open, + .release = single_release, + .read = seq_read, + .llseek = seq_lseek, +}; + +static void setup_debugfs(struct p2pmem_dev *p) +{ + struct dentry *de; + + de = debugfs_create_file("stats", 0400, p->debugfs_root, + (void *)p, &stats_debugfs_fops); +} + static struct p2pmem_dev *to_p2pmem(struct device *dev) { return container_of(dev, struct p2pmem_dev, dev); @@ -62,6 +97,8 @@ static void p2pmem_release(struct device *dev) { struct p2pmem_dev *p = to_p2pmem(dev); + debugfs_remove_recursive(p->debugfs_root); + if (p->pool) gen_pool_destroy(p->pool); @@ -114,6 +151,13 @@ struct p2pmem_dev *p2pmem_create(struct device *parent) if (rc) goto err_id; + if (p2pmem_debugfs_root) { + p->debugfs_root = debugfs_create_dir(dev_name(&p->dev), + p2pmem_debugfs_root); + if (p->debugfs_root) + setup_debugfs(p); + } + rc = device_add(&p->dev); if (rc) goto err_id; @@ -390,12 +434,17 @@ static int __init p2pmem_init(void) if (IS_ERR(p2pmem_class)) return PTR_ERR(p2pmem_class); + p2pmem_debugfs_root = debugfs_create_dir("p2pmem", NULL); + if (!p2pmem_debugfs_root) + pr_info("could not create debugfs entry, continuing\n"); + return 0; } module_init(p2pmem_init); static void __exit p2pmem_exit(void) { + debugfs_remove_recursive(p2pmem_debugfs_root); class_destroy(p2pmem_class); pr_info(KBUILD_MODNAME ": unloaded.\n"); diff --git a/include/linux/p2pmem.h b/include/linux/p2pmem.h index 71dc1e1..4cd6f35 100644 --- a/include/linux/p2pmem.h +++ b/include/linux/p2pmem.h @@ -26,6 +26,8 @@ struct p2pmem_dev { struct percpu_ref ref; struct completion cmp; struct gen_pool *pool; + + struct dentry *debugfs_root; }; #ifdef CONFIG_P2PMEM