/************************************************************************** | |
* | |
* Copyright (c) 2012 ZTE Corporation. | |
* | |
*************************************************************************** | |
* Ä£ ¿é Ãû : P98C_OSS | |
* ÎÄ ¼þ Ãû : oss_mem.h | |
* Ïà¹ØÎļþ : | |
* ʵÏÖ¹¦ÄÜ : ÄÚ´æÉêÇë¡¢ÊÍ·Å½Ó¿Ú | |
* ×÷ Õß : chenxingfang | |
* °æ ±¾ : V1.0 | |
* Íê³ÉÈÕÆÚ : 2012-08-10 | |
* ÆäËü˵Ã÷ : | |
**************************************************************************/ | |
/************************************************************************** | |
* Ð޸ļǼ | |
**************************************************************************/ | |
#ifndef _OSS_MEM_H | |
#define _OSS_MEM_H | |
/************************************************************************** | |
* #includeÇø | |
**************************************************************************/ | |
#ifdef _OS_TOS | |
#include "tos_pool.h" | |
#include "tos_heap.h" | |
#elif defined _OS_LINUX | |
#include "oss_pool.h" | |
#include "linux/mm.h" | |
#endif | |
#include "oss_pub.h" | |
#ifdef __cplusplus | |
extern "C" | |
{ | |
#endif | |
/************************************************************************** | |
* ³£Á¿¶¨ÒåÇø | |
**************************************************************************/ | |
/* UB */ | |
#define zOss_GetUB(size) mem_getub(size, ZOSS_FILE, ZOSS_LINE) | |
#define zOss_RetUB(msg_ptr) mem_retub(msg_ptr, ZOSS_FILE, ZOSS_LINE) | |
/* UBÄÚ´æÅäÖòÎÊý */ | |
#define MEM_MAX_LEAK_UB 200 /* ÄÚ´æÐ¹Â¶²éѯ·µ»ØµÄ×î´óÌõÊý */ | |
#define ZOSS_UB_MAX_POOLNUM 15 /* ÄÚ´æ³Ø¸öÊý, ×î´ó²»Äܳ¬¹ý255 */ | |
#define ZOSS_UBHEAD_FILENAME_LEN 31 /* UBÄÚ´æÉêÇëÎļþÃû */ | |
/************************************************************************** | |
* Êý¾Ý½á¹¹¶¨ÒåÇø | |
**************************************************************************/ | |
typedef VOID *ZOSS_UB_BLOCK; /* ÄÚ´æ¿éµØÖ·Ö¸Õë */ | |
typedef struct | |
{ | |
UINT32 nMemUsed; /* ÒÑʹÓÃÄÚ´æ´óС£¬ÒÔ×Ö½Ú±íʾ */ | |
UINT32 nMemTotal; /* ÄÚ´æ×ܵĴóС£¬ÒÔ×Ö½Ú±íʾ */ | |
UINT32 nMemMaxFree; /* ¿ÉÒÔÉêÇëµÄ×î´óÄÚ´æ */ | |
}T_Mem_MemInfo; /* ÄÚ´æ»ù±¾ÐÅÏ¢ */ | |
typedef struct | |
{ | |
UINT32 pool_size; /* ÄÚ´æ³Ø´óС,µ¥Î»Îªbyte */ | |
UINT32 total_block_num; /* Ô¤¶¨ÄÚ´æ¿éÊýÄ¿ */ | |
}T_ZOss_UBPOOL; /* ÄÚ´æ³ØÅäÖñí */ | |
typedef struct | |
{ | |
UINT32 pool_size; /* ÄÚ´æ³Ø´óС,µ¥Î»Îªbyte */ | |
UINT16 total_block_num; /* ÄÚ´æ¿é×ÜÊýÄ¿ */ | |
UINT16 free_block_num; /* ¿ÕÏÐÄÚ´æ¿éÊýÄ¿ */ | |
UINT32 peak_value; /* ÄÚ´æ¿é×î´óʹÓøöÊý */ | |
}T_Mem_UBPoolInfo; /* ÄÚ´æ³ØÐÅÏ¢ */ | |
typedef struct | |
{ | |
ZOSS_UB_BLOCK ubBlock; /* ÄÚ´æ¿éÖ¸Õë */ | |
UINT32 ubBlockSize; /* ÄÚ´æ¿é´óС,µ¥Î»Îªbyte */ | |
UINT32 usingSize; /* ʵ¼ÊÕ¼ÓôóС */ | |
CHAR name[ZOSS_UBHEAD_FILENAME_LEN + 1]; /* ÉêÇëλÖÃÎļþÃû */ | |
UINT32 line; /* ÉêÇëλÖÃÐкŠ*/ | |
ZOSS_THREAD_ID threadId; /* ÉêÇëÏß³ÌID */ | |
ZOSS_TASK_ID taskId; /* ÉêÇëÈÎÎñºÅ */ | |
UINT32 applyTimeTick; /* ÉêÇëʱ¼ä(TICK) */ | |
}T_Mem_UBBlockInfo; /* й¶ÄÚ´æ¿éÄÚ´æÍ·ÐÅÏ¢ */ | |
typedef struct | |
{ | |
UINT8 pool_num; /* ÄÚ´æ³Ø×ÜÊý */ | |
T_Mem_UBPoolInfo pool_info[ZOSS_UB_MAX_POOLNUM]; | |
}T_Mem_UBPoolGrpInfo; /* ÄÚ´æ³Ø×ÜÐÅÏ¢ */ | |
typedef struct | |
{ | |
UINT16 ub_leak_num; /* ÄÚ´æÐ¹Â¶ÊýÄ¿,×î´óΪMEM_MAX_LEAK_UB */ | |
T_Mem_UBBlockInfo ubHeadInfo[MEM_MAX_LEAK_UB]; | |
}T_Mem_UBLeakInfo; /* ÄÚ´æÐ¹Â¶ÐÅÏ¢ */ | |
/************************************************************************** | |
* º¯ÊýÉùÃ÷Çø | |
**************************************************************************/ | |
#ifdef _OS_LINUX | |
#if defined(_UB_USE_HEAP_DEBUG) | |
extern void *ub_debug_alloc(unsigned long size, const char *file, unsigned long line); | |
extern void ub_debug_free(void *ptr); | |
static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line) | |
{ | |
return ub_debug_alloc(size, file, line); | |
} | |
static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line) | |
{ | |
ub_debug_free(msg_ptr); | |
return ZOSS_SUCCESS; | |
} | |
#elif defined(_UB_USE_HEAP) | |
static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line) | |
{ | |
//zOss_ASSERT(PAGE_SIZE == 4096); | |
if(size <= PAGE_SIZE) | |
return kmalloc(size, GFP_KERNEL); | |
else | |
return vmalloc(size); | |
} | |
static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line) | |
{ | |
if(!is_vmalloc_addr(msg_ptr)) | |
kfree(msg_ptr); | |
else | |
vfree(msg_ptr); | |
return ZOSS_SUCCESS; | |
} | |
#elif defined(_UB_USE_POOL) | |
static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line) | |
{ | |
return pool_alloc(size, file, line); | |
} | |
static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line) | |
{ | |
pool_free(msg_ptr, file, line); | |
return ZOSS_SUCCESS; | |
} | |
#endif | |
#else | |
#if defined(_UB_USE_HEAP) | |
static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line) | |
{ | |
return tos_heap_alloc(size, file, line); | |
} | |
static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line) | |
{ | |
tos_heap_free(msg_ptr, file, line); | |
return ZOSS_SUCCESS; | |
} | |
#elif defined(_UB_USE_POOL) | |
static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line) | |
{ | |
return pool_alloc(size, file, line); | |
} | |
static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line) | |
{ | |
pool_free(msg_ptr, file, line); | |
return ZOSS_SUCCESS; | |
} | |
#else | |
VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line); | |
UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line); | |
#endif | |
#endif // #ifdef _OS_LINUX | |
FLOAT zOss_GetUBFreeRate(UINT32 ubSize); | |
VOID zOss_MemLeakStart(UINT32 leak_threadhold); | |
VOID zOss_MemLeakEnd(VOID); | |
VOID zOss_CheckMem(VOID); | |
VOID zOss_SetUbDbgSwitch(UINT32 dbgFlag); | |
BOOL zOss_GetMemInitState(VOID); | |
UINT32 zOss_GetSysMemInfo(T_Mem_MemInfo *mem_info); | |
/************************************************************************** | |
* È«¾Ö±äÁ¿ÉùÃ÷Çø | |
**************************************************************************/ | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif /* _OSS_MEM_H */ | |