From 68aa16a5170d8d39cddedb1d5bc00e0064e1c5b9 Mon Sep 17 00:00:00 2001 From: wenlong_12 Date: Thu, 4 Jan 2024 11:30:02 +0000 Subject: [PATCH] =?UTF-8?q?dma=20=E4=B8=AD=E5=A2=9E=E5=8A=A0memtrace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenlong_12 --- libdmabufheap/include/dmabuf_alloc.h | 14 ++------------ libdmabufheap/src/dmabuf_alloc.c | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/libdmabufheap/include/dmabuf_alloc.h b/libdmabufheap/include/dmabuf_alloc.h index abec18f..a8eefba 100644 --- a/libdmabufheap/include/dmabuf_alloc.h +++ b/libdmabufheap/include/dmabuf_alloc.h @@ -21,7 +21,6 @@ #include #undef LOG_TAG -#define LOG_TAG "dmabufheap" #ifdef __cplusplus #if __cplusplus @@ -38,18 +37,9 @@ typedef enum { typedef struct { unsigned int fd; size_t size; - __u64 heapFlags; + unsigned int heapFlags; } DmabufHeapBuffer; -enum DmaHeapFlagOwnerId { - DMA_OWNER_DEFAULT, - DMA_OWNER_GPU, - DMA_OWNER_MEDIA_CODEC, - COUNT_DMA_OWNER, -}; - -void SetOwnerIdForHeapFlags(DmabufHeapBuffer *buffer, enum DmaHeapFlagOwnerId ownerId); - int DmabufHeapOpen(const char *heapName); int DmabufHeapClose(unsigned int fd); @@ -68,4 +58,4 @@ int DmabufHeapBufferSyncEnd(unsigned int bufferFd, DmabufHeapBufferSyncType sync #endif /* End of #if __cplusplus */ #endif /* End of #ifdef __cplusplus */ -#endif /* LIB_DMA_BUF_HEAP_H */ \ No newline at end of file +#endif /* LIB_DMA_BUF_HEAP_H */ diff --git a/libdmabufheap/src/dmabuf_alloc.c b/libdmabufheap/src/dmabuf_alloc.c index 79e7d53..05ace67 100644 --- a/libdmabufheap/src/dmabuf_alloc.c +++ b/libdmabufheap/src/dmabuf_alloc.c @@ -21,14 +21,18 @@ #include #include #include "securec.h" -#include "hilog/log.h" #include "dmabuf_alloc.h" +#include "memory_trace.h" #define DMA_BUF_HEAP_ROOT "/dev/dma_heap/" #define HEAP_ROOT_LEN strlen(DMA_BUF_HEAP_ROOT) #define HEAP_NAME_MAX_LEN 128 #define HEAP_PATH_LEN (HEAP_ROOT_LEN + HEAP_NAME_MAX_LEN + 1) +#define LOG_DOMAIN 0xD002D0A +#define LOG_TAG "BacktraceTest" + +#include "hilog/log.h" static bool IsHeapNameValid(const char *heapName) { if ((heapName == NULL) || (strlen(heapName) == 0) || @@ -51,32 +55,28 @@ static bool IsSyncTypeValid(DmabufHeapBufferSyncType syncType) } } -void SetOwnerIdForHeapFlags(DmabufHeapBuffer *buffer, enum DmaHeapFlagOwnerId ownerId) -{ - if (buffer) { - set_owner_id_for_heap_flags(&buffer->heapFlags, ownerId); - } -} - int DmabufHeapOpen(const char *heapName) { if (!IsHeapNameValid(heapName)) { HILOG_ERROR(LOG_CORE, "heapName is wrong, name = %s.", (heapName == NULL) ? "NULL" : heapName); return -EINVAL; } - char heapPath[HEAP_PATH_LEN] = DMA_BUF_HEAP_ROOT; errno_t ret = strcat_s(heapPath, HEAP_PATH_LEN, heapName); if (ret != EOK) { HILOG_ERROR(LOG_CORE, "strcat_s is wrong, heapName = %s, ret = %d.", heapName, ret); return -EINVAL; } - - return open(heapPath, O_RDONLY | O_CLOEXEC); + int fd = open(heapPath, O_RDONLY | O_CLOEXEC); + long newFd = fd; + memtrace((void *)newFd, 128, "DmabufHeap", true); + return fd; } int DmabufHeapClose(unsigned int fd) { + long newFd = fd; + memtrace((void *)newFd, 128, "DmabufHeap", false); return close(fd); } @@ -97,13 +97,14 @@ int DmabufHeapBufferAlloc(unsigned int heapFd, DmabufHeapBuffer *buffer) HILOG_ERROR(LOG_CORE, "alloc buffer failed, size = %zu, ret = %d.", buffer->size, ret); return ret; } - + memtrace((void *)buffer, buffer->size, "DmabufHeap", true); buffer->fd = data.fd; return ret; } int DmabufHeapBufferFree(DmabufHeapBuffer *buffer) { + memtrace((void *)buffer, buffer->size, "DmabufHeap", false); return close(buffer->fd); } -- Gitee