From patchwork Tue Dec 19 19:29:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kim, Dongwon" X-Patchwork-Id: 10124079 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 1761B6019C for ; Tue, 19 Dec 2017 19:37:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 089642924D for ; Tue, 19 Dec 2017 19:37:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1AEC29551; Tue, 19 Dec 2017 19:37:43 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5AEEC2924D for ; Tue, 19 Dec 2017 19:37:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 305BA6E32C; Tue, 19 Dec 2017 19:36:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 319316E32C for ; Tue, 19 Dec 2017 19:36:41 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2017 11:36:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,428,1508828400"; d="scan'208";a="4018547" Received: from downor-z87x-ud5h.fm.intel.com ([10.1.122.11]) by orsmga007.jf.intel.com with ESMTP; 19 Dec 2017 11:36:40 -0800 From: Dongwon Kim To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 21/60] hyper_dmabuf: exposing drv information using sysfs Date: Tue, 19 Dec 2017 11:29:37 -0800 Message-Id: <1513711816-2618-21-git-send-email-dongwon.kim@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> References: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> MIME-Version: 1.0 Cc: =?UTF-8?q?Micha=C5=82=20Janiszewski?= , xen-devel@lists.xenproject.org, mateuszx.potrola@intel.com, dri-devel@lists.freedesktop.org, dongwon.kim@intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: MichaƂ Janiszewski This adds two entries in SYSFS with information about imported and exported entries. The information exposed contains details about number of pages, whether a buffer is valid or not, and importer/exporter count. Sysfs for hyper_dmabuf can be enabled by setting a new config option, "CONFIG_HYPER_DMABUF_SYSFS" to 'yes'. Signed-off-by: Dongwon Kim --- drivers/xen/hyper_dmabuf/Kconfig | 7 +++ drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c | 12 ++++- drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c | 2 +- drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c | 74 ++++++++++++++++++++++++++++ drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h | 3 ++ 5 files changed, 96 insertions(+), 2 deletions(-) diff --git a/drivers/xen/hyper_dmabuf/Kconfig b/drivers/xen/hyper_dmabuf/Kconfig index 75e1f96..56633a2 100644 --- a/drivers/xen/hyper_dmabuf/Kconfig +++ b/drivers/xen/hyper_dmabuf/Kconfig @@ -11,4 +11,11 @@ config HYPER_DMABUF_XEN help Configuring hyper_dmabuf driver for XEN hypervisor +config HYPER_DMABUF_SYSFS + bool "Enable sysfs information about hyper DMA buffers" + default y + help + Expose information about imported and exported buffers using + hyper_dmabuf driver + endmenu diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c index 9d99769..3fc30e6 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c @@ -22,7 +22,7 @@ int unregister_device(void); struct hyper_dmabuf_private hyper_dmabuf_private; /*===============================================================================================*/ -static int hyper_dmabuf_drv_init(void) +static int __init hyper_dmabuf_drv_init(void) { int ret = 0; @@ -51,10 +51,16 @@ static int hyper_dmabuf_drv_init(void) } ret = hyper_dmabuf_private.backend_ops->init_comm_env(); + if (ret < 0) { + return -EINVAL; + } +#ifdef CONFIG_HYPER_DMABUF_SYSFS + ret = hyper_dmabuf_register_sysfs(hyper_dmabuf_private.device); if (ret < 0) { return -EINVAL; } +#endif /* interrupt for comm should be registered here: */ return ret; @@ -63,6 +69,10 @@ static int hyper_dmabuf_drv_init(void) /*-----------------------------------------------------------------------------------------------*/ static void hyper_dmabuf_drv_exit(void) { +#ifdef CONFIG_HYPER_DMABUF_SYSFS + hyper_dmabuf_unregister_sysfs(hyper_dmabuf_private.device); +#endif + /* hash tables for export/import entries and ring_infos */ hyper_dmabuf_table_destroy(); diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c index 9b05063..924710f 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c @@ -24,7 +24,7 @@ int dmabuf_refcount(struct dma_buf *dma_buf) return -1; } -/* return total number of pages referecned by a sgt +/* return total number of pages referenced by a sgt * for pre-calculation of # of pages behind a given sgt */ static int hyper_dmabuf_get_num_pgs(struct sg_table *sgt) diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c index 18731de..1d224c4 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c @@ -11,6 +11,80 @@ DECLARE_HASHTABLE(hyper_dmabuf_hash_imported, MAX_ENTRY_IMPORTED); DECLARE_HASHTABLE(hyper_dmabuf_hash_exported, MAX_ENTRY_EXPORTED); +#ifdef CONFIG_HYPER_DMABUF_SYSFS +static ssize_t hyper_dmabuf_imported_show(struct device *drv, struct device_attribute *attr, char *buf) +{ + struct hyper_dmabuf_info_entry_imported *info_entry; + int bkt; + ssize_t count = 0; + size_t total = 0; + + hash_for_each(hyper_dmabuf_hash_imported, bkt, info_entry, node) { + int id = info_entry->info->hyper_dmabuf_id; + int nents = info_entry->info->nents; + bool valid = info_entry->info->valid; + int num_importers = info_entry->info->num_importers; + total += nents; + count += scnprintf(buf + count, PAGE_SIZE - count, "id:%d, nents:%d, v:%c, numi:%d\n", + id, nents, (valid ? 't' : 'f'), num_importers); + } + count += scnprintf(buf + count, PAGE_SIZE - count, "total nents: %lu\n", + total); + + return count; +} + +static ssize_t hyper_dmabuf_exported_show(struct device *drv, struct device_attribute *attr, char *buf) +{ + struct hyper_dmabuf_info_entry_exported *info_entry; + int bkt; + ssize_t count = 0; + size_t total = 0; + + hash_for_each(hyper_dmabuf_hash_exported, bkt, info_entry, node) { + int id = info_entry->info->hyper_dmabuf_id; + int nents = info_entry->info->nents; + bool valid = info_entry->info->valid; + int importer_exported = info_entry->info->importer_exported; + total += nents; + count += scnprintf(buf + count, PAGE_SIZE - count, "id:%d, nents:%d, v:%c, ie:%d\n", + id, nents, (valid ? 't' : 'f'), importer_exported); + } + count += scnprintf(buf + count, PAGE_SIZE - count, "total nents: %lu\n", + total); + + return count; +} + +static DEVICE_ATTR(imported, S_IRUSR, hyper_dmabuf_imported_show, NULL); +static DEVICE_ATTR(exported, S_IRUSR, hyper_dmabuf_exported_show, NULL); + +int hyper_dmabuf_register_sysfs(struct device *dev) +{ + int err; + + err = device_create_file(dev, &dev_attr_imported); + if (err < 0) + goto err1; + err = device_create_file(dev, &dev_attr_exported); + if (err < 0) + goto err2; + + return 0; +err2: + device_remove_file(dev, &dev_attr_imported); +err1: + return -1; +} + +int hyper_dmabuf_unregister_sysfs(struct device *dev) +{ + device_remove_file(dev, &dev_attr_imported); + device_remove_file(dev, &dev_attr_exported); + return 0; +} +#endif + int hyper_dmabuf_table_init() { hash_init(hyper_dmabuf_hash_imported); diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h index f55d06e..a46f884 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h @@ -37,4 +37,7 @@ int hyper_dmabuf_remove_exported(int id); int hyper_dmabuf_remove_imported(int id); +int hyper_dmabuf_register_sysfs(struct device *dev); +int hyper_dmabuf_unregister_sysfs(struct device *dev); + #endif // __HYPER_DMABUF_LIST_H__