From patchwork Mon Feb 5 22:03:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 10201917 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 C8E7C605F3 for ; Mon, 5 Feb 2018 22:04:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B592D21BED for ; Mon, 5 Feb 2018 22:04:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B435D2888A; Mon, 5 Feb 2018 22:04:14 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 AF4AF289A8 for ; Mon, 5 Feb 2018 22:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751864AbeBEWDu (ORCPT ); Mon, 5 Feb 2018 17:03:50 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:40535 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750846AbeBEWDt (ORCPT ); Mon, 5 Feb 2018 17:03:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RDPlaiZRHL+A4KrlPLgms06jCI8xg2eaxYDkDTw/ZaY=; b=e5av3ffqMR+jV0lt+b+XvfUZ3 gPfsksnB92hvNuJ5/1UHpy7+noN7rPEuQGnetoreL6XN3wLtB4ahLyjXDNjefO5bShdDe3W1MMUiz 1qUIw/qA1BwhNQQJ3Ke1Rian7aI5SeUimGHUw5B2dlLNEXG8YUMDN70n6D/b0yamAalSvDQqdB3OW n3RuBgfNvo/6syoTRolSj+Nlyb9GzkcJq43WiO3z7+yclsSSPkpOeUbNPvQSP1hUT9ha5s4rG9RwJ bE5HRXnrfbGeHMUWvh8A13F7h6oL6wsNm1Xc4MCFhMmxNj+gDCOrh/kqyUghsqqXj+PrCQvqIo/bk MRY/yLJ3A==; Received: from [46.120.250.42] (helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1eiora-000145-5H; Mon, 05 Feb 2018 22:03:46 +0000 From: Sagi Grimberg To: linux-block@vger.kernel.org, linux-rdma@vger.kernel.org Cc: Jason Gunthorpe , Christoph Hellwig , Jens Axboe , Idan Burstein , Bart Van Assche Subject: [PATCH rfc 2/5] irq-am: add some debugfs exposure on tuning state Date: Tue, 6 Feb 2018 00:03:13 +0200 Message-Id: <20180205220316.30236-3-sagi@grimberg.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180205220316.30236-1-sagi@grimberg.me> References: <20180205220316.30236-1-sagi@grimberg.me> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Useful for local debugging Signed-off-by: Sagi Grimberg --- include/linux/irq-am.h | 2 + lib/irq-am.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/include/linux/irq-am.h b/include/linux/irq-am.h index 5ddd5ca268aa..18df315633a4 100644 --- a/include/linux/irq-am.h +++ b/include/linux/irq-am.h @@ -101,6 +101,8 @@ struct irq_am { struct work_struct work; irq_am_fn *program; + struct dentry *debugfs_dir; + int id; }; void irq_am_add_event(struct irq_am *am); diff --git a/lib/irq-am.c b/lib/irq-am.c index ed7befd7a560..6cd2f131f5e8 100644 --- a/lib/irq-am.c +++ b/lib/irq-am.c @@ -12,6 +12,61 @@ * more details. */ #include +#include + +static DEFINE_IDA(am_ida); + +#ifdef CONFIG_DEBUG_FS +struct dentry *irq_am_debugfs_root; + +struct irq_am_debugfs_attr { + const char *name; + umode_t mode; + int (*show)(void *, struct seq_file *); + ssize_t (*write)(void *, const char __user *, size_t, loff_t *); +}; + +static int irq_am_tune_state_show(void *data, struct seq_file *m) +{ + struct irq_am *am = data; + + seq_printf(m, "%d\n", am->tune_state); + return 0; +} + +static int irq_am_curr_level_show(void *data, struct seq_file *m) +{ + struct irq_am *am = data; + + seq_printf(m, "%d\n", am->curr_level); + return 0; +} + +static int irq_am_debugfs_show(struct seq_file *m, void *v) +{ + const struct irq_am_debugfs_attr *attr = m->private; + void *data = d_inode(m->file->f_path.dentry->d_parent)->i_private; + + return attr->show(data, m); +} + +static int irq_am_debugfs_open(struct inode *inode, struct file *file) +{ + return single_open(file, irq_am_debugfs_show, inode->i_private); +} + +static const struct file_operations irq_am_debugfs_fops = { + .open = irq_am_debugfs_open, + .read = seq_read, + .release = seq_release, +}; + +static const struct irq_am_debugfs_attr irq_am_attrs[] = { + {"tune_state", 0400, irq_am_tune_state_show}, + {"curr_level", 0400, irq_am_curr_level_show}, + {}, +}; +#endif static void irq_am_try_step(struct irq_am *am) { @@ -160,10 +215,51 @@ static void irq_am_program_moderation_work(struct work_struct *w) am->state = IRQ_AM_START_MEASURING; } +#ifdef CONFIG_DEBUG_FS +static bool debugfs_create_files(struct dentry *parent, void *data, + const struct irq_am_debugfs_attr *attr) +{ + d_inode(parent)->i_private = data; + + for (; attr->name; attr++) { + if (!debugfs_create_file(attr->name, attr->mode, parent, + (void *)attr, &irq_am_debugfs_fops)) + return false; + } + return true; +} + +static int irq_am_register_debugfs(struct irq_am *am) +{ + char name[20]; + + snprintf(name, sizeof(name), "am%u", am->id); + am->debugfs_dir = debugfs_create_dir(name, + irq_am_debugfs_root); + if (!am->debugfs_dir) + return -ENOMEM; + + if (!debugfs_create_files(am->debugfs_dir, am, + irq_am_attrs)) + return -ENOMEM; + return 0; +} + +static void irq_am_deregister_debugfs(struct irq_am *am) +{ + debugfs_remove_recursive(am->debugfs_dir); +} + +#else +static int irq_am_register_debugfs(struct irq_am *am) {} +static void irq_am_deregister_debugfs(struct irq_am *am) {} +#endif void irq_am_cleanup(struct irq_am *am) { flush_work(&am->work); + irq_am_deregister_debugfs(am); + ida_simple_remove(&am_ida, am->id); } EXPORT_SYMBOL_GPL(irq_am_cleanup); @@ -177,6 +273,19 @@ void irq_am_init(struct irq_am *am, unsigned int nr_events, am->nr_events = nr_events; am->curr_level = start_level; am->program = fn; + am->id = ida_simple_get(&am_ida, 0, 0, GFP_KERNEL); + WARN_ON(am->id < 0); INIT_WORK(&am->work, irq_am_program_moderation_work); + if (irq_am_register_debugfs(am)) + pr_warn("irq-am %d failed to register debugfs\n", am->id); } EXPORT_SYMBOL_GPL(irq_am_init); + +static __init int irq_am_setup(void) +{ +#ifdef CONFIG_DEBUG_FS + irq_am_debugfs_root = debugfs_create_dir("irq_am", NULL); +#endif + return 0; +} +subsys_initcall(irq_am_setup);