From: MichaĆ Janiszewski michal1x.janiszewski@intel.com
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 dongwon.kim@intel.com --- 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__