Skip to contentSkip to conversation

dmabuf: Add the capability to expose DMA-BUF stats in sysfs

PATCH Superseded Hridya Valsaraju 7 participants 14 messages Jan 27, 2021 – Feb 4, 2021

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 dmabuf: Add the capability to expose DMA-BUF stats in sysfs

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

 .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
 drivers/dma-buf/Kconfig                       |  11 +
 drivers/dma-buf/Makefile                      |   1 +
 drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
 drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
 drivers/dma-buf/dma-buf.c                     |  37 +++
 include/linux/dma-buf.h                       |  20 ++
 7 files changed, 468 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers
 create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c
 create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h
Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers new file +52 -0
new file mode 100644
index 000000000000..6f7c65209f07
@@ -0,0 +1,52 @@
+What:		/sys/kernel/dmabuf/buffers
+Date:		January 2021
+KernelVersion:	v5.12
+Contact:	Hridya Valsaraju <[email protected]>
+Description:	The /sys/kernel/dmabuf/buffers directory contains a
+		snapshot of the internal state of every DMA-BUF.
+		/sys/kernel/dmabuf/buffers/<inode_number> will contain the
+		statistics for the DMA-BUF with the unique inode number
+		<inode_number>
+Users:		kernel memory tuning/debugging tools
+
+What:		/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name
+Date:		January 2021
+KernelVersion:	v5.12
+Contact:	Hridya Valsaraju <[email protected]>
+Description:	This file is read-only and contains the name of the exporter of
+		the DMA-BUF.
+
+What:		/sys/kernel/dmabuf/buffers/<inode_number>/size
+Date:		January 2021
+KernelVersion:	v5.12
+Contact:	Hridya Valsaraju <[email protected]>
+Description:	This file is read-only and specifies the size of the DMA-BUF in
+		bytes.
+
+What:		/sys/kernel/dmabuf/buffers/<inode_number>/attachments
+Date:		January 2021
+KernelVersion:	v5.12
+Contact:	Hridya Valsaraju <[email protected]>
+Description:	This directory will contain subdirectories representing every
+		attachment of the DMA-BUF.
+
+What:		/sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attachment_uid>
+Date:		January 2021
+KernelVersion:	v5.12
+Contact:	Hridya Valsaraju <[email protected]>
+Description:	This directory will contain information on the attaching device
+		and the number of current distinct device mappings.
+
+What:		/sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attachment_uid>/device
+Date:		January 2021
+KernelVersion:	v5.12
+Contact:	Hridya Valsaraju <[email protected]>
+Description:	This file is read-only and is a symlink to the attaching devices's
+		sysfs entry.
+
+What:		/sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attachment_uid>/map_counter
+Date:		January 2021
+KernelVersion:	v5.12
+Contact:	Hridya Valsaraju <[email protected]>
+Description:	This file is read-only and contains a map_counter indicating the
+		number of distinct device mappings of the attachment.
drivers/dma-buf/Kconfig +11 -0
index 4f8224a6ac95..27e6a2dafeaa 100644
@@ -64,6 +64,17 @@ menuconfig DMABUF_HEAPS
 	  allows userspace to allocate dma-bufs that can be shared
 	  between drivers.
 
+menuconfig DMABUF_SYSFS_STATS
+	bool "DMA-BUF sysfs statistics"
+	select DMA_SHARED_BUFFER
+	help
+	   Choose this option to enable DMA-BUF sysfs statistics
+	   in location /sys/kernel/dmabuf/buffers.
+
+	   /sys/kernel/dmabuf/buffers/<inode_number> will contain
+	   statistics for the DMA-BUF with the unique inode number
+	   <inode_number>.
+
 source "drivers/dma-buf/heaps/Kconfig"
 
 endmenu
drivers/dma-buf/Makefile +1 -0
index 995e05f609ff..40d81f23cacf 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_DMABUF_HEAPS)	+= heaps/
 obj-$(CONFIG_SYNC_FILE)		+= sync_file.o
 obj-$(CONFIG_SW_SYNC)		+= sw_sync.o sync_debug.o
 obj-$(CONFIG_UDMABUF)		+= udmabuf.o
+obj-$(CONFIG_DMABUF_SYSFS_STATS) += dma-buf-sysfs-stats.o
 
 dmabuf_selftests-y := \
 	selftest.o \
drivers/dma-buf/dma-buf-sysfs-stats.c new file +285 -0

285 lines not on this page · raw message

drivers/dma-buf/dma-buf-sysfs-stats.h new file +62 -0

62 lines not on this page · raw message

drivers/dma-buf/dma-buf.c +37 -0
index 9ad6397aaa97..29f9ea18eb47 100644
@@ -29,6 +29,8 @@
 #include <uapi/linux/dma-buf.h>
 #include <uapi/linux/magic.h>
 
+#include "dma-buf-sysfs-stats.h"
+
 static inline int is_dma_buf_file(struct file *);
 
 struct dma_buf_list {
@@ -79,6 +81,7 @@ static void dma_buf_release(struct dentry *dentry)
 	if (dmabuf->resv == (struct dma_resv *)&dmabuf[1])
 		dma_resv_fini(dmabuf->resv);
 
+	dma_buf_stats_teardown(dmabuf);
 	module_put(dmabuf->owner);
 	kfree(dmabuf->name);
 	kfree(dmabuf);
@@ -579,6 +582,10 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 	file->f_mode |= FMODE_LSEEK;
 	dmabuf->file = file;
 
+	ret = dma_buf_stats_setup(dmabuf);
+	if (ret)
+		goto err_sysfs;
+
 	mutex_init(&dmabuf->lock);
 	INIT_LIST_HEAD(&dmabuf->attachments);
 
@@ -588,6 +595,14 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 
 	return dmabuf;
 
+err_sysfs:
+	/*
+	 * Set file->f_path.dentry->d_fsdata to NULL so that when
+	 * dma_buf_release() gets invoked by dentry_ops, it exits
+	 * early before calling the release() dma_buf op.
+	 */
+	file->f_path.dentry->d_fsdata = NULL;
+	fput(file);
 err_dmabuf:
 	kfree(dmabuf);
 err_module:
@@ -692,6 +707,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 {
 	struct dma_buf_attachment *attach;
 	int ret;
+	unsigned int attach_uid;
 
 	if (WARN_ON(!dmabuf || !dev))
 		return ERR_PTR(-EINVAL);
@@ -717,8 +733,13 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 	}
 	dma_resv_lock(dmabuf->resv, NULL);
 	list_add(&attach->node, &dmabuf->attachments);
+	attach_uid = dma_buf_update_attach_uid(dmabuf);
 	dma_resv_unlock(dmabuf->resv);
 
+	ret = dma_buf_attach_stats_setup(attach, attach_uid);
+	if (ret)
+		goto err_sysfs;
+
 	/* When either the importer or the exporter can't handle dynamic
 	 * mappings we cache the mapping here to avoid issues with the
 	 * reservation object lock.
@@ -745,6 +766,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 			dma_resv_unlock(attach->dmabuf->resv);
 		attach->sgt = sgt;
 		attach->dir = DMA_BIDIRECTIONAL;
+		dma_buf_update_attachment_map_count(attach, 1 /* delta */);
 	}
 
 	return attach;
@@ -761,6 +783,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 	if (dma_buf_is_dynamic(attach->dmabuf))
 		dma_resv_unlock(attach->dmabuf->resv);
 
+err_sysfs:
 	dma_buf_detach(dmabuf, attach);
 	return ERR_PTR(ret);
 }
@@ -799,6 +822,7 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
 			dma_resv_lock(attach->dmabuf->resv, NULL);
 
 		dmabuf->ops->unmap_dma_buf(attach, attach->sgt, attach->dir);
+		dma_buf_update_attachment_map_count(attach, -1 /* delta */);
 
 		if (dma_buf_is_dynamic(attach->dmabuf)) {
 			dma_buf_unpin(attach);
@@ -812,6 +836,7 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
 	if (dmabuf->ops->detach)
 		dmabuf->ops->detach(dmabuf, attach);
 
+	dma_buf_attach_stats_teardown(attach);
 	kfree(attach);
 }
 EXPORT_SYMBOL_GPL(dma_buf_detach);
@@ -938,6 +963,9 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 	}
 #endif /* CONFIG_DMA_API_DEBUG */
 
+	if (!IS_ERR(sg_table))
+		dma_buf_update_attachment_map_count(attach, 1 /* delta */);
+
 	return sg_table;
 }
 EXPORT_SYMBOL_GPL(dma_buf_map_attachment);
@@ -975,6 +1003,8 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
 	if (dma_buf_is_dynamic(attach->dmabuf) &&
 	    !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY))
 		dma_buf_unpin(attach);
+
+	dma_buf_update_attachment_map_count(attach, -1 /* delta */);
 }
 EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment);
 
@@ -1412,6 +1442,12 @@ static inline void dma_buf_uninit_debugfs(void)
 
 static int __init dma_buf_init(void)
 {
+	int ret;
+
+	ret = dma_buf_init_sysfs_statistics();
+	if (ret)
+		return ret;
+
 	dma_buf_mnt = kern_mount(&dma_buf_fs_type);
 	if (IS_ERR(dma_buf_mnt))
 		return PTR_ERR(dma_buf_mnt);
@@ -1427,5 +1463,6 @@ static void __exit dma_buf_deinit(void)
 {
 	dma_buf_uninit_debugfs();
 	kern_unmount(dma_buf_mnt);
+	dma_buf_uninit_sysfs_statistics();
 }
 __exitcall(dma_buf_deinit);
include/linux/dma-buf.h +20 -0
index cf72699cb2bc..4ae5cc38a4a7 100644
@@ -294,6 +294,9 @@ struct dma_buf_ops {
  * @poll: for userspace poll support
  * @cb_excl: for userspace poll support
  * @cb_shared: for userspace poll support
+ * @sysfs_entry: for exposing information about this buffer in sysfs.
+ * The attachment_uid member of @sysfs_entry is protected by dma_resv lock
+ * and is incremented on each attach.
  *
  * This represents a shared buffer, created by calling dma_buf_export(). The
  * userspace representation is a normal file descriptor, which can be created by
@@ -329,6 +332,15 @@ struct dma_buf {
 
 		__poll_t active;
 	} cb_excl, cb_shared;
+#ifdef CONFIG_DMABUF_SYSFS_STATS
+	/* for sysfs stats */
+	struct dma_buf_sysfs_entry {
+		struct kobject kobj;
+		struct dma_buf *dmabuf;
+		unsigned int attachment_uid;
+		struct kset *attach_stats_kset;
+	} *sysfs_entry;
+#endif
 };
 
 /**
@@ -378,6 +390,7 @@ struct dma_buf_attach_ops {
  * @importer_ops: importer operations for this attachment, if provided
  * dma_buf_map/unmap_attachment() must be called with the dma_resv lock held.
  * @importer_priv: importer specific attachment data.
+ * @sysfs_entry: For exposing information about this attachment in sysfs.
  *
  * This structure holds the attachment information between the dma_buf buffer
  * and its user device(s). The list contains one attachment struct per device
@@ -398,6 +411,13 @@ struct dma_buf_attachment {
 	const struct dma_buf_attach_ops *importer_ops;
 	void *importer_priv;
 	void *priv;
+#ifdef CONFIG_DMABUF_SYSFS_STATS
+	/* for sysfs stats */
+	struct dma_buf_attach_sysfs_entry {
+		struct kobject kobj;
+		unsigned int map_counter;
+	} *sysfs_entry;
+#endif
 };
 
 /**
Signature · 1 line
2.30.0.280.ga3ce27912f-goog
Reviewed-by on v3 1/1
#1 lore raw
Quoted 66 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

Quoted 11 lines
 .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
 drivers/dma-buf/Kconfig                       |  11 +
 drivers/dma-buf/Makefile                      |   1 +
 drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
 drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
 drivers/dma-buf/dma-buf.c                     |  37 +++
 include/linux/dma-buf.h                       |  20 ++
 7 files changed, 468 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers
 create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c
 create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#2 lore raw

Hi Hridya,

Quoted 47 lines · Greg KH
Quoted 45 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

Quoted 6 lines
Quoted 6 lines

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

Quoted 30 lines
Quoted 15 lines

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

Quoted 11 lines
 .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
 drivers/dma-buf/Kconfig                       |  11 +
 drivers/dma-buf/Makefile                      |   1 +
 drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
 drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
 drivers/dma-buf/dma-buf.c                     |  37 +++
 include/linux/dma-buf.h                       |  20 ++
 7 files changed, 468 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers
 create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c
 create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

Quoted 1 line

Best,
Sumit.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

From the technical side it looks clean to me, feel free to add my acked-by while pushing.

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Regards,
Christian.

Quoted 30 lines
Quoted 30 lines
Quoted 24 lines

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

  .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
  drivers/dma-buf/Kconfig                       |  11 +
  drivers/dma-buf/Makefile                      |   1 +
  drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
  drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
  drivers/dma-buf/dma-buf.c                     |  37 +++
  include/linux/dma-buf.h                       |  20 ++
  7 files changed, 468 insertions(+)
Quoted 3 lines

create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

Quoted 7 lines
Quoted 1 line

Best,
Sumit.
_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/linaro-mm-sig

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#4 lore raw
Quoted 64 lines · Christian König

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

Quoted 6 lines

From the technical side it looks clean to me, feel free to add my
acked-by while pushing.

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Naturally.

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

Daniel, do you still have objections around adding this patch in?

Quoted 3 lines

Regards,
Christian.

Best,
Sumit.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 25 lines

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

  .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
  drivers/dma-buf/Kconfig                       |  11 +
  drivers/dma-buf/Makefile                      |   1 +
  drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
  drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
  drivers/dma-buf/dma-buf.c                     |  37 +++
  include/linux/dma-buf.h                       |  20 ++
  7 files changed, 468 insertions(+)
Quoted 3 lines

create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Best,
Sumit.
_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/linaro-mm-sig

--
Thanks and regards,

Sumit Semwal
Linaro Consumer Group - Tech Lead
Linaro.org │ Open source software for ARM SoCs
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 3 lines · Sumit Semwal

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

IIRC he's away this week. (I don't remember when he comes back.)

Quoted 1 line

Daniel, do you still have objections around adding this patch in?

(Adding him explicitly in CC)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#6 lore raw

Hi Simon,

Quoted 7 lines · Simon Ser
Quoted 3 lines · Sumit Semwal

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

Quoted 5 lines

IIRC he's away this week. (I don't remember when he comes back.)

Quoted 1 line

Daniel, do you still have objections around adding this patch in?

(Adding him explicitly in CC)

Thanks for doing this!

Best,
Sumit.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
Quoted 13 lines · Sumit Semwal

Hi Simon,

Quoted 9 lines · Simon Ser
Quoted 3 lines · Sumit Semwal

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

IIRC he's away this week. (I don't remember when he comes back.)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Daniel, do you still have objections around adding this patch in?

(Adding him explicitly in CC)

Thanks for doing this!

Best,
Sumit.

Thank you all for the help :)

Regards,
Hridya

#8 lore raw
In reply to Sumit Semwal
Quoted 74 lines · Sumit Semwal
Quoted 64 lines · Christian König

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

Quoted 6 lines

From the technical side it looks clean to me, feel free to add my
acked-by while pushing.

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Quoted 5 lines

Naturally.

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

The tracepoint being orthogonal didn't really look convincing to me, since I do expect we'll need that at a much more generic level, at allocators. Whether that's dma-buf heaps or in drm or wherever. And we probably also need that to somehow align with cgroups accounting.

But I guess for this it should be easy to extend however we see fit, so retrofitting allocator sources and anything else we want/need for the overall gpu memory account shouldn't be a problem. Also, it's first, so the proof for showing it all works together is more on the tracepoints :-)

Quoted 1 line

Daniel, do you still have objections around adding this patch in?

Needs docs (especially the uapi I think would be useful to document), igt tests, that kind of stuff still I think? It's meant to be generic uapi across drivers, generally we're a pile stricter for that (and yes dma-buf heaps I think didn't do all that, so maybe there's an argument for doing this a bit more sloppy or at least "the testsuite is somewhere else").

But I think it would be good to have this all done. -Daniel

Quoted 58 lines
Quoted 4 lines

Regards,
Christian.

Best,
Sumit.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 25 lines

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

  .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
  drivers/dma-buf/Kconfig                       |  11 +
  drivers/dma-buf/Makefile                      |   1 +
  drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
  drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
  drivers/dma-buf/dma-buf.c                     |  37 +++
  include/linux/dma-buf.h                       |  20 ++
  7 files changed, 468 insertions(+)
Quoted 3 lines

create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Best,
Sumit.
_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/linaro-mm-sig

--
Thanks and regards,

Sumit Semwal
Linaro Consumer Group - Tech Lead
Linaro.org │ Open source software for ARM SoCs
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw
Quoted 93 lines · Daniel Vetter
Quoted 74 lines · Sumit Semwal
Quoted 64 lines · Christian König

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

Quoted 6 lines

From the technical side it looks clean to me, feel free to add my
acked-by while pushing.

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Quoted 5 lines

Naturally.

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

The tracepoint being orthogonal didn't really look convincing to me, since I do expect we'll need that at a much more generic level, at allocators. Whether that's dma-buf heaps or in drm or wherever. And we probably also need that to somehow align with cgroups accounting.

But I guess for this it should be easy to extend however we see fit, so retrofitting allocator sources and anything else we want/need for the overall gpu memory account shouldn't be a problem. Also, it's first, so the proof for showing it all works together is more on the tracepoints :-)

Quoted 8 lines
Quoted 1 line

Daniel, do you still have objections around adding this patch in?

Needs docs (especially the uapi I think would be useful to document), igt tests, that kind of stuff still I think? It's meant to be generic uapi across drivers, generally we're a pile stricter for that (and yes dma-buf heaps I think didn't do all that, so maybe there's an argument for doing this a bit more sloppy or at least "the testsuite is somewhere else").

Thank you for taking another look Daniel!

I will try adding an IGT test for the sysfs files. Other than the documentation in Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers(included in the patch), is there another place you would like to see the documentation copied to?

Regards,
Hridya

Quoted 69 lines

But I think it would be good to have this all done. -Daniel

Quoted 51 lines
Quoted 4 lines

Regards,
Christian.

Best,
Sumit.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 25 lines

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

  .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
  drivers/dma-buf/Kconfig                       |  11 +
  drivers/dma-buf/Makefile                      |   1 +
  drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
  drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
  drivers/dma-buf/dma-buf.c                     |  37 +++
  include/linux/dma-buf.h                       |  20 ++
  7 files changed, 468 insertions(+)
Quoted 3 lines

create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Best,
Sumit.
_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/linaro-mm-sig

--
Thanks and regards,

Quoted 7 lines

Sumit Semwal
Linaro Consumer Group - Tech Lead
Linaro.org │ Open source software for ARM SoCs
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

#10 lore raw
Quoted 103 lines · Hridya Valsaraju
Quoted 93 lines · Daniel Vetter
Quoted 74 lines · Sumit Semwal
Quoted 64 lines · Christian König

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

Quoted 6 lines

From the technical side it looks clean to me, feel free to add my
acked-by while pushing.

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Quoted 5 lines

Naturally.

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

The tracepoint being orthogonal didn't really look convincing to me, since I do expect we'll need that at a much more generic level, at allocators. Whether that's dma-buf heaps or in drm or wherever. And we probably also need that to somehow align with cgroups accounting.

But I guess for this it should be easy to extend however we see fit, so retrofitting allocator sources and anything else we want/need for the overall gpu memory account shouldn't be a problem. Also, it's first, so the proof for showing it all works together is more on the tracepoints :-)

Quoted 8 lines
Quoted 1 line

Daniel, do you still have objections around adding this patch in?

Needs docs (especially the uapi I think would be useful to document), igt tests, that kind of stuff still I think? It's meant to be generic uapi across drivers, generally we're a pile stricter for that (and yes dma-buf heaps I think didn't do all that, so maybe there's an argument for doing this a bit more sloppy or at least "the testsuite is somewhere else").

Quoted 7 lines

Thank you for taking another look Daniel!

I will try adding an IGT test for the sysfs files. Other than the documentation in Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers(included in the patch), is there another place you would like to see the documentation copied to?

So just read the other thread, and sounds like Christian König brought up a solid concern with dma-buf fds generally not staying around for much.

So I'm leaning more towards "this sounds like it's going to be useful for Android only, nothing else" concern.
-Daniel

Quoted 73 lines

Regards,
Hridya

Quoted 69 lines

But I think it would be good to have this all done. -Daniel

Quoted 51 lines
Quoted 4 lines

Regards,
Christian.

Best,
Sumit.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 25 lines

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

  .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
  drivers/dma-buf/Kconfig                       |  11 +
  drivers/dma-buf/Makefile                      |   1 +
  drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
  drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
  drivers/dma-buf/dma-buf.c                     |  37 +++
  include/linux/dma-buf.h                       |  20 ++
  7 files changed, 468 insertions(+)
Quoted 3 lines

create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Best,
Sumit.
_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/linaro-mm-sig

--
Thanks and regards,

Quoted 7 lines

Sumit Semwal
Linaro Consumer Group - Tech Lead
Linaro.org │ Open source software for ARM SoCs
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw
Quoted 107 lines · Daniel Vetter
Quoted 105 lines · Hridya Valsaraju
Quoted 93 lines · Daniel Vetter
Quoted 74 lines · Sumit Semwal
Quoted 64 lines · Christian König

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://lore.kernel.org/patchwork/patch/1088791/
[2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
[3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

Quoted 6 lines

From the technical side it looks clean to me, feel free to add my
acked-by while pushing.

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Quoted 5 lines

Naturally.

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

The tracepoint being orthogonal didn't really look convincing to me, since I do expect we'll need that at a much more generic level, at allocators. Whether that's dma-buf heaps or in drm or wherever. And we probably also need that to somehow align with cgroups accounting.

But I guess for this it should be easy to extend however we see fit, so retrofitting allocator sources and anything else we want/need for the overall gpu memory account shouldn't be a problem. Also, it's first, so the proof for showing it all works together is more on the tracepoints :-)

Quoted 8 lines
Quoted 1 line

Daniel, do you still have objections around adding this patch in?

Needs docs (especially the uapi I think would be useful to document), igt tests, that kind of stuff still I think? It's meant to be generic uapi across drivers, generally we're a pile stricter for that (and yes dma-buf heaps I think didn't do all that, so maybe there's an argument for doing this a bit more sloppy or at least "the testsuite is somewhere else").

Thank you for taking another look Daniel!

Quoted 8 lines
Quoted 5 lines

I will try adding an IGT test for the sysfs files. Other than the documentation in Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers(included in the patch), is there another place you would like to see the documentation copied to?

So just read the other thread, and sounds like Christian König brought up a solid concern with dma-buf fds generally not staying around for much.

Thank you for the reply Daniel! Could you please elaborate on the connection with the other thread you mentioned? I am a little confused since this patch does not deal with tracking DMA-BUF fds.

Regards,
Hridya

Quoted 83 lines

So I'm leaning more towards "this sounds like it's going to be useful for Android only, nothing else" concern.
-Daniel

Quoted 73 lines

Regards,
Hridya

Quoted 69 lines

But I think it would be good to have this all done. -Daniel

Quoted 51 lines
Quoted 4 lines

Regards,
Christian.

Best,
Sumit.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 25 lines

---
Changes in v3:
Fix a warning reported by the kernel test robot.

Changes in v2:
-Move statistics to /sys/kernel/dmabuf/buffers in oder to allow addition of other DMA-BUF-related sysfs stats in future. Based on feedback from Daniel Vetter.
-Each attachment has its own directory to represent attaching devices as symlinks and to introduce map_count as a separate file. Based on feedback from Daniel Vetter and Christian König. Thank you both! -Commit messages updated to point to userspace code in AOSP that will read the DMA-BUF sysfs stats.

  .../ABI/testing/sysfs-kernel-dmabuf-buffers   |  52 ++++
  drivers/dma-buf/Kconfig                       |  11 +
  drivers/dma-buf/Makefile                      |   1 +
  drivers/dma-buf/dma-buf-sysfs-stats.c         | 285 ++++++++++++++++++
  drivers/dma-buf/dma-buf-sysfs-stats.h         |  62 ++++
  drivers/dma-buf/dma-buf.c                     |  37 +++
  include/linux/dma-buf.h                       |  20 ++
  7 files changed, 468 insertions(+)
Quoted 3 lines

create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h

I don't know the dma-buf code at all, but from a sysfs/kobject point of view, this patch looks good to me:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Best,
Sumit.
_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/linaro-mm-sig

--
Thanks and regards,

Quoted 7 lines

Sumit Semwal
Linaro Consumer Group - Tech Lead
Linaro.org │ Open source software for ARM SoCs
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

maintainer
#12 lore raw

Am 03.02.21 um 21:14 schrieb Hridya Valsaraju:

Quoted 104 lines · Daniel Vetter
Quoted 103 lines · Hridya Valsaraju
Quoted 102 lines · Daniel Vetter
Quoted 87 lines · Sumit Semwal
Quoted 67 lines
Quoted 65 lines · Christian König

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fpatchwork%2Fpatch%2F1088791%2F&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f08d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886768855%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=imVoJbadV221%2F6u32diSyEICLk7WUNakz8G742RPSaA%3D&amp;reserved=0
[2]: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fandroid-review.googlesource.com%2Fq%2Ftopic%3A%2522dmabuf-sysfs%2522&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f08d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886778838%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=X78MH6IvdcE1mGMngrVdBYooi93vpjvfLU9kQHjZyKo%3D&amp;reserved=0+(status:open%20OR%20status:merged)
[3]: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fandroid-review.googlesource.com%2Fc%2Fplatform%2Fsystem%2Fmemory%2Flibmeminfo%2F%2B%2F1549734&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f08d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886778838%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=JH7m5yspXKDqVX5DB380cnU4kWNSyh6ctDaphJvOyw8%3D&amp;reserved=0

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

From the technical side it looks clean to me, feel free to add my
acked-by while pushing.

Quoted 8 lines
Quoted 3 lines

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Naturally.

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

The tracepoint being orthogonal didn't really look convincing to me, since I do expect we'll need that at a much more generic level, at allocators. Whether that's dma-buf heaps or in drm or wherever. And we probably also need that to somehow align with cgroups accounting.

But I guess for this it should be easy to extend however we see fit, so retrofitting allocator sources and anything else we want/need for the overall gpu memory account shouldn't be a problem. Also, it's first, so the proof for showing it all works together is more on the tracepoints :-)

Quoted 7 lines
Quoted 1 line

Daniel, do you still have objections around adding this patch in?

Needs docs (especially the uapi I think would be useful to document), igt tests, that kind of stuff still I think? It's meant to be generic uapi across drivers, generally we're a pile stricter for that (and yes dma-buf heaps I think didn't do all that, so maybe there's an argument for doing this a bit more sloppy or at least "the testsuite is somewhere else").

Thank you for taking another look Daniel!

I will try adding an IGT test for the sysfs files. Other than the documentation in Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers(included in the patch), is there another place you would like to see the documentation copied to?

Quoted 5 lines
Quoted 2 lines

So just read the other thread, and sounds like Christian König brought up a solid concern with dma-buf fds generally not staying around for much.

Thank you for the reply Daniel! Could you please elaborate on the connection with the other thread you mentioned? I am a little confused since this patch does not deal with tracking DMA-BUF fds.

In general DMA-buf fd are meant to be a temporary transport vehicle to interchange the data between processes.

This here sounds like Android is using them as a long term reference. That is not necessary a good idea and causes multiple issues.

On of those issues you try to address here, but Daniel is question now why do you have this problem in the first place?

Regards,
Christian.

Quoted 8 lines

Regards,
Hridya

Quoted 4 lines

So I'm leaning more towards "this sounds like it's going to be useful for Android only, nothing else" concern.
-Daniel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw
Quoted 112 lines · Christian König

Am 03.02.21 um 21:14 schrieb Hridya Valsaraju:

Quoted 104 lines · Daniel Vetter
Quoted 103 lines · Hridya Valsaraju
Quoted 102 lines · Daniel Vetter
Quoted 87 lines · Sumit Semwal
Quoted 67 lines
Quoted 65 lines · Christian König

Am 28.01.21 um 12:00 schrieb Sumit Semwal:

Quoted 53 lines

Hi Hridya,

Quoted 50 lines · Greg KH
Quoted 49 lines · Hridya Valsaraju

This patch allows statistics to be enabled for each DMA-BUF in sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS.

The following stats will be exposed by the interface:

/sys/kernel/dmabuf/buffers/<inode_number>/exporter_name /sys/kernel/dmabuf/buffers/<inode_number>/size /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter

The inode_number is unique for each DMA-BUF and was added earlier [1] in order to allow userspace to track DMA-BUF usage across different processes.

Currently, this information is exposed in /sys/kernel/debug/dma_buf/bufinfo.
However, since debugfs is considered unsafe to be mounted in production, it is being duplicated in sysfs.

This information will be used to derive DMA-BUF per-exporter stats and per-device usage stats for Android Bug reports. The corresponding userspace changes can be found at [2]. Telemetry tools will also capture this information(along with other memory metrics) periodically as well as on important events like a foreground app kill (which might have been triggered by Low Memory Killer). It will also contribute to provide a snapshot of the system memory usage on other events such as OOM kills and Application Not Responding events.

A shell script that can be run on a classic Linux environment to read out the DMA-BUF statistics can be found at [3](suggested by John Stultz).

The patch contains the following improvements over the previous version:
1) Each attachment is represented by its own directory to allow creating a symlink to the importing device and to also provide room for future expansion.
2) The number of distinct mappings of each attachment is exposed in a separate file.
3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers inorder to make the interface expandable in future.

All of the improvements above are based on suggestions/feedback from Daniel Vetter and Christian König.

[1]: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fpatchwork%2Fpatch%2F1088791%2F&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f08d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886768855%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=imVoJbadV221%2F6u32diSyEICLk7WUNakz8G742RPSaA%3D&amp;reserved=0
[2]: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fandroid-review.googlesource.com%2Fq%2Ftopic%3A%2522dmabuf-sysfs%2522&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f08d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886778838%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=X78MH6IvdcE1mGMngrVdBYooi93vpjvfLU9kQHjZyKo%3D&amp;reserved=0+(status:open%20OR%20status:merged)
[3]: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fandroid-review.googlesource.com%2Fc%2Fplatform%2Fsystem%2Fmemory%2Flibmeminfo%2F%2B%2F1549734&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C32ff828b838e44b1de6f08d8c8805913%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637479800886778838%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=JH7m5yspXKDqVX5DB380cnU4kWNSyh6ctDaphJvOyw8%3D&amp;reserved=0

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks for the patch!

Christian: If you're satisfied with the explanation around not directly embedding kobjects into the dma_buf and dma_buf_attachment structs, then with Greg's r-b from sysfs PoV, I think we can merge it. Please let me know if you feel otherwise!

From the technical side it looks clean to me, feel free to add my
acked-by while pushing.

Quoted 8 lines
Quoted 3 lines

But I would at least try to convince Daniel on the design. At least some of his concerns seems to be valid and keep in mind that we need to support this interface forever.

Naturally.

Since he didn't comment over Hridya's last clarification about the tracepoints to track total GPU memory allocations being orthogonal to this series, I assumed he agreed with it.

The tracepoint being orthogonal didn't really look convincing to me, since I do expect we'll need that at a much more generic level, at allocators. Whether that's dma-buf heaps or in drm or wherever. And we probably also need that to somehow align with cgroups accounting.

But I guess for this it should be easy to extend however we see fit, so retrofitting allocator sources and anything else we want/need for the overall gpu memory account shouldn't be a problem. Also, it's first, so the proof for showing it all works together is more on the tracepoints :-)

Quoted 7 lines
Quoted 1 line

Daniel, do you still have objections around adding this patch in?

Needs docs (especially the uapi I think would be useful to document), igt tests, that kind of stuff still I think? It's meant to be generic uapi across drivers, generally we're a pile stricter for that (and yes dma-buf heaps I think didn't do all that, so maybe there's an argument for doing this a bit more sloppy or at least "the testsuite is somewhere else").

Thank you for taking another look Daniel!

I will try adding an IGT test for the sysfs files. Other than the documentation in Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers(included in the patch), is there another place you would like to see the documentation copied to?

Quoted 5 lines
Quoted 2 lines

So just read the other thread, and sounds like Christian König brought up a solid concern with dma-buf fds generally not staying around for much.

Thank you for the reply Daniel! Could you please elaborate on the connection with the other thread you mentioned? I am a little confused since this patch does not deal with tracking DMA-BUF fds.

Quoted 8 lines

In general DMA-buf fd are meant to be a temporary transport vehicle to interchange the data between processes.

This here sounds like Android is using them as a long term reference. That is not necessary a good idea and causes multiple issues.

On of those issues you try to address here, but Daniel is question now why do you have this problem in the first place?

Afaik it's how Android works, lots more fd passing than we do (that's also why Android has sync_file, i.e. pass a sync fd around every frame, whereas we have drm_syncobj, i.e. pass the sync container object fd once around at startup and be done).

I more meant that now I'm leaning more towards "we really need a unified *pu buffer reporting scheme" before signing up to something that only works for very limited use cases.

The other thing that popped up is that between this patch, the virtio tracepoint there's now a 3rd patch from google Android to account xpu buffer memory in some cases (but only some, only partially). So really this gap-fillers here don't work, and we need something that really looks at the entire problem and figures out how to account that memory. Which is probably cgroups, but we'll see.

I asked John to set up some meeting at least with the Android side so we can start to figure this out for real.
-Daniel

Quoted 13 lines

Regards,
Christian.

Quoted 8 lines

Regards,
Hridya

Quoted 4 lines

So I'm leaning more towards "this sounds like it's going to be useful for Android only, nothing else" concern.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel