lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /**************************************************************************
|
| 2 | *
|
| 3 | * Copyright (c) 2012 ZTE Corporation.
|
| 4 | *
|
| 5 | ***************************************************************************
|
| 6 | * Ä£ ¿é Ãû : P98C_OSS
|
| 7 | * ÎÄ ¼þ Ãû : oss_mem.h
|
| 8 | * Ïà¹ØÎļþ :
|
| 9 | * ʵÏÖ¹¦ÄÜ : ÄÚ´æÉêÇë¡¢ÊͷŽӿÚ
|
| 10 | * ×÷ Õß : chenxingfang
|
| 11 | * °æ ±¾ : V1.0
|
| 12 | * Íê³ÉÈÕÆÚ : 2012-08-10
|
| 13 | * ÆäËü˵Ã÷ :
|
| 14 | **************************************************************************/
|
| 15 |
|
| 16 | /**************************************************************************
|
| 17 | * Ð޸ļǼ
|
| 18 | **************************************************************************/
|
| 19 | #ifndef _OSS_MEM_H
|
| 20 | #define _OSS_MEM_H
|
| 21 |
|
| 22 | /**************************************************************************
|
| 23 | * #includeÇø
|
| 24 | **************************************************************************/
|
| 25 | #ifdef _OS_TOS
|
| 26 | #include "tos_pool.h"
|
| 27 | #include "tos_heap.h"
|
| 28 | #elif defined _OS_LINUX
|
| 29 | #include "oss_pool.h"
|
| 30 | #include "linux/mm.h"
|
| 31 | #endif
|
| 32 | #include "oss_pub.h"
|
| 33 |
|
| 34 | #ifdef __cplusplus
|
| 35 | extern "C"
|
| 36 | {
|
| 37 | #endif
|
| 38 |
|
| 39 | /**************************************************************************
|
| 40 | * ³£Á¿¶¨ÒåÇø
|
| 41 | **************************************************************************/
|
| 42 | /* UB */
|
| 43 | #define zOss_GetUB(size) mem_getub(size, ZOSS_FILE, ZOSS_LINE)
|
| 44 | #define zOss_RetUB(msg_ptr) mem_retub(msg_ptr, ZOSS_FILE, ZOSS_LINE)
|
| 45 |
|
| 46 | /* UBÄÚ´æÅäÖòÎÊý */
|
| 47 | #define MEM_MAX_LEAK_UB 200 /* ÄÚ´æÐ¹Â¶²éѯ·µ»ØµÄ×î´óÌõÊý */
|
| 48 | #define ZOSS_UB_MAX_POOLNUM 15 /* ÄÚ´æ³Ø¸öÊý, ×î´ó²»Äܳ¬¹ý255 */
|
| 49 | #define ZOSS_UBHEAD_FILENAME_LEN 31 /* UBÄÚ´æÉêÇëÎļþÃû */
|
| 50 |
|
| 51 | /**************************************************************************
|
| 52 | * Êý¾Ý½á¹¹¶¨ÒåÇø
|
| 53 | **************************************************************************/
|
| 54 | typedef VOID *ZOSS_UB_BLOCK; /* ÄÚ´æ¿éµØÖ·Ö¸Õë */
|
| 55 |
|
| 56 | typedef struct
|
| 57 | {
|
| 58 | UINT32 nMemUsed; /* ÒÑʹÓÃÄÚ´æ´óС£¬ÒÔ×Ö½Ú±íʾ */
|
| 59 | UINT32 nMemTotal; /* ÄÚ´æ×ܵĴóС£¬ÒÔ×Ö½Ú±íʾ */
|
| 60 | UINT32 nMemMaxFree; /* ¿ÉÒÔÉêÇëµÄ×î´óÄÚ´æ */
|
| 61 | }T_Mem_MemInfo; /* ÄÚ´æ»ù±¾ÐÅÏ¢ */
|
| 62 |
|
| 63 | typedef struct
|
| 64 | {
|
| 65 | UINT32 pool_size; /* ÄÚ´æ³Ø´óС,µ¥Î»Îªbyte */
|
| 66 | UINT32 total_block_num; /* Ô¤¶¨ÄÚ´æ¿éÊýÄ¿ */
|
| 67 | }T_ZOss_UBPOOL; /* ÄÚ´æ³ØÅäÖñí */
|
| 68 |
|
| 69 | typedef struct
|
| 70 | {
|
| 71 | UINT32 pool_size; /* ÄÚ´æ³Ø´óС,µ¥Î»Îªbyte */
|
| 72 | UINT16 total_block_num; /* ÄÚ´æ¿é×ÜÊýÄ¿ */
|
| 73 | UINT16 free_block_num; /* ¿ÕÏÐÄÚ´æ¿éÊýÄ¿ */
|
| 74 | UINT32 peak_value; /* ÄÚ´æ¿é×î´óʹÓøöÊý */
|
| 75 | }T_Mem_UBPoolInfo; /* ÄÚ´æ³ØÐÅÏ¢ */
|
| 76 |
|
| 77 | typedef struct
|
| 78 | {
|
| 79 | ZOSS_UB_BLOCK ubBlock; /* ÄÚ´æ¿éÖ¸Õë */
|
| 80 | UINT32 ubBlockSize; /* ÄÚ´æ¿é´óС,µ¥Î»Îªbyte */
|
| 81 | UINT32 usingSize; /* ʵ¼ÊÕ¼ÓôóС */
|
| 82 | CHAR name[ZOSS_UBHEAD_FILENAME_LEN + 1]; /* ÉêÇëλÖÃÎļþÃû */
|
| 83 | UINT32 line; /* ÉêÇëλÖÃÐкŠ*/
|
| 84 | ZOSS_THREAD_ID threadId; /* ÉêÇëÏß³ÌID */
|
| 85 | ZOSS_TASK_ID taskId; /* ÉêÇëÈÎÎñºÅ */
|
| 86 | UINT32 applyTimeTick; /* ÉêÇëʱ¼ä(TICK) */
|
| 87 | }T_Mem_UBBlockInfo; /* й¶ÄÚ´æ¿éÄÚ´æÍ·ÐÅÏ¢ */
|
| 88 |
|
| 89 | typedef struct
|
| 90 | {
|
| 91 | UINT8 pool_num; /* ÄÚ´æ³Ø×ÜÊý */
|
| 92 | T_Mem_UBPoolInfo pool_info[ZOSS_UB_MAX_POOLNUM];
|
| 93 | }T_Mem_UBPoolGrpInfo; /* ÄÚ´æ³Ø×ÜÐÅÏ¢ */
|
| 94 |
|
| 95 | typedef struct
|
| 96 | {
|
| 97 | UINT16 ub_leak_num; /* ÄÚ´æÐ¹Â¶ÊýÄ¿,×î´óΪMEM_MAX_LEAK_UB */
|
| 98 | T_Mem_UBBlockInfo ubHeadInfo[MEM_MAX_LEAK_UB];
|
| 99 | }T_Mem_UBLeakInfo; /* ÄÚ´æÐ¹Â¶ÐÅÏ¢ */
|
| 100 |
|
| 101 | /**************************************************************************
|
| 102 | * º¯ÊýÉùÃ÷Çø
|
| 103 | **************************************************************************/
|
| 104 | #ifdef _OS_LINUX
|
| 105 |
|
| 106 | #if defined(_UB_USE_HEAP_DEBUG)
|
| 107 | extern void *ub_debug_alloc(unsigned long size, const char *file, unsigned long line);
|
| 108 | extern void ub_debug_free(void *ptr);
|
| 109 | static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line)
|
| 110 | {
|
| 111 | return ub_debug_alloc(size, file, line);
|
| 112 | }
|
| 113 | static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line)
|
| 114 | {
|
| 115 | ub_debug_free(msg_ptr);
|
| 116 |
|
| 117 | return ZOSS_SUCCESS;
|
| 118 | }
|
| 119 | #elif defined(_UB_USE_HEAP)
|
| 120 | static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line)
|
| 121 | {
|
| 122 | //zOss_ASSERT(PAGE_SIZE == 4096);
|
| 123 | if(size <= PAGE_SIZE)
|
| 124 | return kmalloc(size, GFP_KERNEL);
|
| 125 | else
|
| 126 | return vmalloc(size);
|
| 127 | }
|
| 128 | static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line)
|
| 129 | {
|
| 130 | if(!is_vmalloc_addr(msg_ptr))
|
| 131 | kfree(msg_ptr);
|
| 132 | else
|
| 133 | vfree(msg_ptr);
|
| 134 |
|
| 135 | return ZOSS_SUCCESS;
|
| 136 | }
|
| 137 | #elif defined(_UB_USE_POOL)
|
| 138 | static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line)
|
| 139 | {
|
| 140 | return pool_alloc(size, file, line);
|
| 141 | }
|
| 142 | static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line)
|
| 143 | {
|
| 144 | pool_free(msg_ptr, file, line);
|
| 145 | return ZOSS_SUCCESS;
|
| 146 | }
|
| 147 | #endif
|
| 148 |
|
| 149 | #else
|
| 150 |
|
| 151 | #if defined(_UB_USE_HEAP)
|
| 152 | static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line)
|
| 153 | {
|
| 154 | return tos_heap_alloc(size, file, line);
|
| 155 | }
|
| 156 | static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line)
|
| 157 | {
|
| 158 | tos_heap_free(msg_ptr, file, line);
|
| 159 | return ZOSS_SUCCESS;
|
| 160 | }
|
| 161 | #elif defined(_UB_USE_POOL)
|
| 162 | static inline VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line)
|
| 163 | {
|
| 164 | return pool_alloc(size, file, line);
|
| 165 | }
|
| 166 | static inline UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line)
|
| 167 | {
|
| 168 | pool_free(msg_ptr, file, line);
|
| 169 | return ZOSS_SUCCESS;
|
| 170 | }
|
| 171 | #else
|
| 172 | VOID *mem_getub(UINT32 size, const CHAR *file, UINT32 line);
|
| 173 | UINT32 mem_retub(VOID *msg_ptr, const CHAR *file, UINT32 line);
|
| 174 | #endif
|
| 175 |
|
| 176 | #endif // #ifdef _OS_LINUX
|
| 177 |
|
| 178 | FLOAT zOss_GetUBFreeRate(UINT32 ubSize);
|
| 179 | VOID zOss_MemLeakStart(UINT32 leak_threadhold);
|
| 180 | VOID zOss_MemLeakEnd(VOID);
|
| 181 | VOID zOss_CheckMem(VOID);
|
| 182 | VOID zOss_SetUbDbgSwitch(UINT32 dbgFlag);
|
| 183 | BOOL zOss_GetMemInitState(VOID);
|
| 184 | UINT32 zOss_GetSysMemInfo(T_Mem_MemInfo *mem_info);
|
| 185 |
|
| 186 | /**************************************************************************
|
| 187 | * È«¾Ö±äÁ¿ÉùÃ÷Çø
|
| 188 | **************************************************************************/
|
| 189 |
|
| 190 | #ifdef __cplusplus
|
| 191 | }
|
| 192 | #endif
|
| 193 |
|
| 194 | #endif /* _OSS_MEM_H */
|
| 195 |
|