diff --git a/mpp/base/mpp_buffer_impl.cpp b/mpp/base/mpp_buffer_impl.cpp index d7708532..b5c301de 100644 --- a/mpp/base/mpp_buffer_impl.cpp +++ b/mpp/base/mpp_buffer_impl.cpp @@ -59,7 +59,7 @@ private: RK_U32 total_max; // misc group for internal / externl buffer with different type - RK_U32 misc[MPP_BUFFER_MODE_BUTT][MPP_BUFFER_TYPE_BUTT]; + RK_U32 misc[MPP_BUFFER_MODE_BUTT][MPP_BUFFER_TYPE_BUTT][MPP_ALLOCATOR_WITH_FLAG_NUM]; RK_U32 misc_count; /* preset allocator apis */ MppAllocator mAllocator[MPP_BUFFER_TYPE_BUTT][MPP_ALLOCATOR_WITH_FLAG_NUM]; @@ -895,7 +895,7 @@ MppBufferService::MppBufferService() total_max(0), misc_count(0) { - RK_S32 i, j; + RK_S32 i, j, k; INIT_LIST_HEAD(&mListGroup); INIT_LIST_HEAD(&mListOrphan); @@ -905,7 +905,8 @@ MppBufferService::MppBufferService() // NOTE: Do not create misc group at beginning. Only create on when needed. for (i = 0; i < MPP_BUFFER_MODE_BUTT; i++) for (j = 0; j < MPP_BUFFER_TYPE_BUTT; j++) - misc[i][j] = 0; + for (k = 0; k < MPP_ALLOCATOR_WITH_FLAG_NUM; k++) + misc[i][j][k] = 0; for (i = 0; i < (RK_S32)HASH_SIZE(mHashGroup); i++) INIT_HLIST_HEAD(&mHashGroup[i]); @@ -915,7 +916,7 @@ MppBufferService::MppBufferService() MppBufferService::~MppBufferService() { - RK_S32 i, j; + RK_S32 i, j, k; finalizing = 1; @@ -923,14 +924,13 @@ MppBufferService::~MppBufferService() if (misc_count) { mpp_log_f("cleaning misc group\n"); for (i = 0; i < MPP_BUFFER_MODE_BUTT; i++) - for (j = 0; j < MPP_BUFFER_TYPE_BUTT; j++) { - RK_U32 id = misc[i][j]; + for (j = 0; j < MPP_BUFFER_TYPE_BUTT; j++) + for (k = 0; k < MPP_ALLOCATOR_WITH_FLAG_NUM; k++) { + RK_U32 id = MPP_FETCH_AND(&misc[i][j][k], 0); - if (id) { - put_group(__FUNCTION__, get_group_by_id(id)); - misc[i][j] = 0; + if (id) + put_group(__FUNCTION__, get_group_by_id(id)); } - } } // then remove the remaining group which is the leak one @@ -996,6 +996,22 @@ RK_U32 MppBufferService::get_group_id() return id; } +static RK_U32 type_to_flag(MppBufferType type) +{ + RK_U32 flag = MPP_ALLOC_FLAG_NONE; + + if (type & MPP_BUFFER_FLAGS_DMA32) + flag += MPP_ALLOC_FLAG_DMA32; + + if (type & MPP_BUFFER_FLAGS_CACHABLE) + flag += MPP_ALLOC_FLAG_CACHABLE; + + if (type & MPP_BUFFER_FLAGS_CONTIG) + flag += MPP_ALLOC_FLAG_CMA; + + return flag; +} + MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *caller, MppBufferMode mode, MppBufferType type, RK_U32 is_misc) @@ -1018,14 +1034,7 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal return NULL; } - if (type & MPP_BUFFER_FLAGS_DMA32) - flag += MPP_ALLOC_FLAG_DMA32; - - if (type & MPP_BUFFER_FLAGS_CACHABLE) - flag += MPP_ALLOC_FLAG_CACHABLE; - - if (type & MPP_BUFFER_FLAGS_CONTIG) - flag += MPP_ALLOC_FLAG_CMA; + flag = type_to_flag(type); p->flags = (MppAllocFlagType)flag; @@ -1095,7 +1104,7 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal buf_grp_add_log(p, GRP_CREATE, caller); if (is_misc) { - misc[mode][buffer_type] = id; + misc[mode][buffer_type][flag] = id; p->is_misc = 1; misc_count++; } @@ -1105,14 +1114,17 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal RK_U32 MppBufferService::get_misc(MppBufferMode mode, MppBufferType type) { + RK_U32 flag = type_to_flag(type); + type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); if (type == MPP_BUFFER_TYPE_NORMAL) return 0; mpp_assert(mode < MPP_BUFFER_MODE_BUTT); mpp_assert(type < MPP_BUFFER_TYPE_BUTT); + mpp_assert(flag < MPP_ALLOC_FLAG_TYPE_NB); - return misc[mode][type]; + return misc[mode][type][flag]; } void MppBufferService::put_group(const char *caller, MppBufferGroupImpl *p) @@ -1179,6 +1191,7 @@ void MppBufferService::destroy_group(MppBufferGroupImpl *group) { MppBufferMode mode = group->mode; MppBufferType type = group->type; + RK_U32 flag = type_to_flag(type); RK_U32 id = group->group_id; mpp_assert(group->count_used == 0); @@ -1202,8 +1215,8 @@ void MppBufferService::destroy_group(MppBufferGroupImpl *group) mpp_mem_pool_put(mpp_buf_grp_pool, group); group_count--; - if (id == misc[mode][type]) { - misc[mode][type] = 0; + if (id == misc[mode][type][flag]) { + misc[mode][type][flag] = 0; misc_count--; } } diff --git a/osal/allocator/allocator_dma_heap.c b/osal/allocator/allocator_dma_heap.c index f2465af3..ea7b83dd 100644 --- a/osal/allocator/allocator_dma_heap.c +++ b/osal/allocator/allocator_dma_heap.c @@ -366,6 +366,7 @@ static MppAllocFlagType os_allocator_dma_heap_flags(void *ctx) os_allocator allocator_dma_heap = { .type = MPP_BUFFER_TYPE_DMA_HEAP, + .name = "dma_heap", .open = os_allocator_dma_heap_open, .close = os_allocator_dma_heap_close, .alloc = os_allocator_dma_heap_alloc, diff --git a/osal/allocator/allocator_drm.c b/osal/allocator/allocator_drm.c index 9a773c03..6b1a0790 100644 --- a/osal/allocator/allocator_drm.c +++ b/osal/allocator/allocator_drm.c @@ -34,8 +34,6 @@ #include "mpp_common.h" #include "mpp_runtime.h" -static RK_U32 drm_debug = 0; - #define DRM_FUNCTION (0x00000001) #define DRM_DEVICE (0x00000002) #define DRM_IOCTL (0x00000004) @@ -45,6 +43,8 @@ static RK_U32 drm_debug = 0; #define drm_dbg_dev(fmt, ...) drm_dbg(DRM_DEVICE, fmt, ## __VA_ARGS__) #define drm_dbg_ioctl(fmt, ...) drm_dbg(DRM_IOCTL, fmt, ## __VA_ARGS__) +static RK_U32 drm_debug = 0; + /* memory type definitions. */ enum drm_rockchip_gem_mem_type { /* Physically Continuous memory. */ @@ -152,8 +152,8 @@ static int drm_alloc(int fd, size_t len, size_t align, RK_U32 *handle, RK_U32 fl return ret; *handle = dmcb.handle; - drm_dbg_func("dev %d alloc aligned %d flags %x handle %d size %lld\n", fd, - align, dmcb.flags, dmcb.handle, dmcb.size); + drm_dbg_func("dev %d alloc aligned %d flags %x|%x handle %d size %lld\n", fd, + align, flags, dmcb.flags, dmcb.handle, dmcb.size); return ret; } @@ -265,7 +265,7 @@ static MPP_RET os_allocator_drm_import(void *ctx, MppBufferInfo *data) RK_S32 fd_ext = data->fd; MPP_RET ret = MPP_OK; - drm_dbg_func("enter dev %d\n", p->drm_device); + drm_dbg_func("enter dev %d fd %d\n", p->drm_device, fd_ext); mpp_assert(fd_ext > 0); @@ -277,7 +277,7 @@ static MPP_RET os_allocator_drm_import(void *ctx, MppBufferInfo *data) ret = MPP_NOK; } - drm_dbg_func("leave dev %d\n", p->drm_device); + drm_dbg_func("leave dev %d fd %d -> %d\n", p->drm_device, fd_ext, data->fd); return ret; } @@ -375,6 +375,7 @@ static MppAllocFlagType os_allocator_drm_flags(void *ctx) os_allocator allocator_drm = { .type = MPP_BUFFER_TYPE_DRM, + .name = "drm", .open = os_allocator_drm_open, .close = os_allocator_drm_close, .alloc = os_allocator_drm_alloc, diff --git a/osal/allocator/allocator_ext_dma.c b/osal/allocator/allocator_ext_dma.c index 482470ae..93d39dca 100644 --- a/osal/allocator/allocator_ext_dma.c +++ b/osal/allocator/allocator_ext_dma.c @@ -150,6 +150,7 @@ static MppAllocFlagType os_allocator_ext_dma_flags(void *ctx) os_allocator allocator_ext_dma = { .type = MPP_BUFFER_TYPE_EXT_DMA, + .name = "ext_dma", .open = allocator_ext_dma_open, .close = allocator_ext_dma_close, .alloc = allocator_ext_dma_alloc, diff --git a/osal/allocator/allocator_ion.c b/osal/allocator/allocator_ion.c index 3739e46f..bbc57c51 100644 --- a/osal/allocator/allocator_ion.c +++ b/osal/allocator/allocator_ion.c @@ -491,6 +491,7 @@ static MppAllocFlagType os_allocator_ion_flags(void *ctx) os_allocator allocator_ion = { .type = MPP_BUFFER_TYPE_ION, + .name = "ion", .open = allocator_ion_open, .close = allocator_ion_close, .alloc = allocator_ion_alloc, diff --git a/osal/allocator/allocator_std.c b/osal/allocator/allocator_std.c index 1e324f4d..a8843698 100644 --- a/osal/allocator/allocator_std.c +++ b/osal/allocator/allocator_std.c @@ -116,6 +116,7 @@ static MppAllocFlagType os_allocator_std_flags(void *ctx) os_allocator allocator_std = { .type = MPP_BUFFER_TYPE_NORMAL, + .name = "std", .open = allocator_std_open, .close = allocator_std_close, .alloc = allocator_std_alloc, diff --git a/osal/mpp_allocator_api.h b/osal/mpp_allocator_api.h index 1f5722f0..d8bb49d9 100644 --- a/osal/mpp_allocator_api.h +++ b/osal/mpp_allocator_api.h @@ -12,6 +12,7 @@ typedef MPP_RET (*OsAllocatorFunc)(void *ctx, MppBufferInfo *info); typedef struct os_allocator_t { MppBufferType type; + const char *name; MPP_RET (*open)(void **ctx, size_t alignment, MppAllocFlagType flags); MPP_RET (*close)(void *ctx);