Skip to content

Commit d870c5b

Browse files
jayxurockchiprkhuangtao
authored andcommitted
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 <[email protected]> Change-Id: I56b0323167361e11dd657a22449aad65751fc81a
1 parent f899527 commit d870c5b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

drivers/dma-buf/dma-buf.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,43 @@ int get_each_dmabuf(int (*callback)(const struct dma_buf *dmabuf,
6363
}
6464
EXPORT_SYMBOL_GPL(get_each_dmabuf);
6565

66+
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
67+
static size_t db_total_size;
68+
static size_t db_peak_size;
69+
70+
void dma_buf_reset_peak_size(void)
71+
{
72+
mutex_lock(&db_list.lock);
73+
db_peak_size = 0;
74+
mutex_unlock(&db_list.lock);
75+
}
76+
EXPORT_SYMBOL_GPL(dma_buf_reset_peak_size);
77+
78+
size_t dma_buf_get_peak_size(void)
79+
{
80+
size_t sz;
81+
82+
mutex_lock(&db_list.lock);
83+
sz = db_peak_size;
84+
mutex_unlock(&db_list.lock);
85+
86+
return sz;
87+
}
88+
EXPORT_SYMBOL_GPL(dma_buf_get_peak_size);
89+
90+
size_t dma_buf_get_total_size(void)
91+
{
92+
size_t sz;
93+
94+
mutex_lock(&db_list.lock);
95+
sz = db_total_size;
96+
mutex_unlock(&db_list.lock);
97+
98+
return sz;
99+
}
100+
EXPORT_SYMBOL_GPL(dma_buf_get_total_size);
101+
#endif
102+
66103
static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen)
67104
{
68105
struct dma_buf *dmabuf;
@@ -129,6 +166,9 @@ static int dma_buf_file_release(struct inode *inode, struct file *file)
129166
dmabuf = file->private_data;
130167

131168
mutex_lock(&db_list.lock);
169+
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
170+
db_total_size -= dmabuf->size;
171+
#endif
132172
list_del(&dmabuf->list_node);
133173
mutex_unlock(&db_list.lock);
134174

@@ -700,6 +740,10 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
700740

701741
mutex_lock(&db_list.lock);
702742
list_add(&dmabuf->list_node, &db_list.head);
743+
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
744+
db_total_size += dmabuf->size;
745+
db_peak_size = max(db_total_size, db_peak_size);
746+
#endif
703747
mutex_unlock(&db_list.lock);
704748

705749
if (IS_ENABLED(CONFIG_DMABUF_DEBUG))

include/linux/dma-buf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,15 @@ static inline void dma_buf_set_destructor(struct dma_buf *dmabuf,
660660
dmabuf->dtor_data = dtor_data;
661661
}
662662
#endif
663+
664+
#if IS_ENABLED(CONFIG_DMABUF_DEBUG)
665+
void dma_buf_reset_peak_size(void);
666+
size_t dma_buf_get_peak_size(void);
667+
size_t dma_buf_get_total_size(void);
668+
#else
669+
static inline void dma_buf_reset_peak_size(void) {}
670+
static inline size_t dma_buf_get_peak_size(void) { return 0; }
671+
static inline size_t dma_buf_get_total_size(void) { return 0; }
672+
#endif
673+
663674
#endif /* __DMA_BUF_H__ */

0 commit comments

Comments
 (0)