dma-buf: support to stat peak size for all dmabuf

The system memory presure always take care of the peak memory size, for
dmabuf, the peak size is useful when media module to design drivers.

Get peak can show the peak size currently, and reset peak can clear it.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
Change-Id: I56b0323167361e11dd657a22449aad65751fc81a
This commit is contained in:
Jianqun Xu
2022-05-05 09:57:40 +08:00
committed by Tao Huang
parent f89952729b
commit d870c5bea7
2 changed files with 55 additions and 0 deletions

View File

@@ -63,6 +63,43 @@ int get_each_dmabuf(int (*callback)(const struct dma_buf *dmabuf,
}
EXPORT_SYMBOL_GPL(get_each_dmabuf);
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
static size_t db_total_size;
static size_t db_peak_size;
void dma_buf_reset_peak_size(void)
{
mutex_lock(&db_list.lock);
db_peak_size = 0;
mutex_unlock(&db_list.lock);
}
EXPORT_SYMBOL_GPL(dma_buf_reset_peak_size);
size_t dma_buf_get_peak_size(void)
{
size_t sz;
mutex_lock(&db_list.lock);
sz = db_peak_size;
mutex_unlock(&db_list.lock);
return sz;
}
EXPORT_SYMBOL_GPL(dma_buf_get_peak_size);
size_t dma_buf_get_total_size(void)
{
size_t sz;
mutex_lock(&db_list.lock);
sz = db_total_size;
mutex_unlock(&db_list.lock);
return sz;
}
EXPORT_SYMBOL_GPL(dma_buf_get_total_size);
#endif
static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen)
{
struct dma_buf *dmabuf;
@@ -129,6 +166,9 @@ static int dma_buf_file_release(struct inode *inode, struct file *file)
dmabuf = file->private_data;
mutex_lock(&db_list.lock);
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
db_total_size -= dmabuf->size;
#endif
list_del(&dmabuf->list_node);
mutex_unlock(&db_list.lock);
@@ -700,6 +740,10 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
mutex_lock(&db_list.lock);
list_add(&dmabuf->list_node, &db_list.head);
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
db_total_size += dmabuf->size;
db_peak_size = max(db_total_size, db_peak_size);
#endif
mutex_unlock(&db_list.lock);
if (IS_ENABLED(CONFIG_DMABUF_DEBUG))

View File

@@ -660,4 +660,15 @@ static inline void dma_buf_set_destructor(struct dma_buf *dmabuf,
dmabuf->dtor_data = dtor_data;
}
#endif
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
void dma_buf_reset_peak_size(void);
size_t dma_buf_get_peak_size(void);
size_t dma_buf_get_total_size(void);
#else
static inline void dma_buf_reset_peak_size(void) {}
static inline size_t dma_buf_get_peak_size(void) { return 0; }
static inline size_t dma_buf_get_total_size(void) { return 0; }
#endif
#endif /* __DMA_BUF_H__ */