From 72906266a4076a9bb9982ac661a6f4d47df22ee9 Mon Sep 17 00:00:00 2001 From: Sooyong Suk Date: Thu, 4 Jul 2024 18:09:48 +0900 Subject: [PATCH] ANDROID: dma-buf: add dma_heap_try_get_pool_size_kb for vendor hook We'd like to get total dma-heap pool size via vendor hooks such as meminfo_proc_show or show_mem. Bug: 351175506 Change-Id: I3f7b14a07768f941c91b3e05d8776d4238565e37 Signed-off-by: Sooyong Suk --- drivers/dma-buf/dma-heap.c | 18 ++++++++++++++++++ include/linux/dma-heap.h | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 0499be80d23d..bf18aa205fdf 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -393,6 +393,24 @@ static char *dma_heap_devnode(const struct device *dev, umode_t *mode) return kasprintf(GFP_KERNEL, "dma_heap/%s", dev_name(dev)); } +long dma_heap_try_get_pool_size_kb(void) +{ + struct dma_heap *heap; + u64 total_pool_size = 0; + + if (!mutex_trylock(&heap_list_lock)) + return -1; + + list_for_each_entry(heap, &heap_list, list) { + if (heap->ops->get_pool_size) + total_pool_size += heap->ops->get_pool_size(heap); + } + mutex_unlock(&heap_list_lock); + + return (long)(total_pool_size / 1024); +} +EXPORT_SYMBOL_GPL(dma_heap_try_get_pool_size_kb); + static ssize_t total_pools_kb_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index c31af802ea86..15bd3a7cd24d 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -109,4 +109,11 @@ void dma_heap_buffer_free(struct dma_buf *); int dma_heap_bufferfd_alloc(struct dma_heap *heap, size_t len, unsigned int fd_flags, unsigned int heap_flags); + +/** + * dma_heap_try_get_pool_size_kb - Returns total dma-heap pool size in kb + * if there is no lock contention. The pool size will always be 0 if no heaps + * use pools, or do not implement get_pool_size. + **/ +long dma_heap_try_get_pool_size_kb(void); #endif /* _DMA_HEAPS_H */