1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
20 /********************************************************************20**
22 Name: Lockless Memory Manager
26 Desc: Data structure definitions that are used by
27 the Lockless Memory Manager.
31 *********************************************************************21*/
41 #ifdef SS_LOCKLESS_MEMORY
43 typedef struct cmMmDynRegCb CmMmDynRegCb;
44 typedef struct cmMmDynBktCb CmMmDynBktCb;
45 typedef struct cmMmMapBkt CmMmMapBkt;
46 typedef struct cmMmGlobRegCb CmMmGlobRegCb;
47 typedef struct cmMmGlobalBktCb CmMmGlobalBktCb;
48 typedef struct cmMmBlkSetElement CmMmBlkSetElement;
49 typedef Data CmMmEntry;
51 /* Size-To-Bucket map table structure */
54 U16 bktIdx; /* The index to the memory bucket */
56 #if (ERRCLASS & ERRCLS_DEBUG)
57 U16 numReq; /* Number of the allocation request */
58 U16 numFailure; /* Number of allocation failure form the bucket */
63 /* The following structre is used as node to place the first address of the
64 * bucket list in the linkedlist. During initialization, all the buckets are
65 * divided into limited number sets. The first pointer of the bucket is placed
66 * in the following structure and node is placed in the linked list. Once the one set
67 * get over, the next address in the BktCb is changed to new address */
68 struct cmMmBlkSetElement
70 CmLList memSetNode; /* Linked list of the first pointer of the
72 U32 numFreeBlks; /* Number of Free Blocks avilable in the current
74 CmMmEntry *nextBktPtr; /* Address of the first bucket which will be
75 used for the allocation */
78 /* The following structure is used for the storing the buckets/pools
79 * this will be present for each bucket which is configured and
80 * will contains the all the information about the bucket. This
81 * will be used in global region */
82 struct cmMmGlobalBktCb
84 U8 poolId; /* Pool Id */
85 Size size; /* Size of the pool */
86 CmLListCp listValidBktSet; /* LList Cp used to store the nodes of memory element
87 node which holds valid pointers */
88 CmLListCp listFreeBktSet; /* LList Cp used to store the nodes of memory element
89 node which holds invalid information */
90 CmMmEntry *startAddr; /* Starting address */
91 CmMmEntry *next; /* Next address which will be allocated */
92 U32 numBlks; /* Total number of buckets configured */
94 U32 bktFailCnt; /* bucket alloc failure count */
95 U32 bktNoFitCnt; /* number of blocks not fit */
96 SLockId bucketLock; /* Lock used for the allocation/freeing of
100 /* The following structure is used for the storing the buckets/pools
101 * this will be present for each bucket which is configured and
102 * will contains the all the information about the bucket. This
103 * is used in the system taks local region */
106 U8 poolId; /* Pool Id */
107 Size size; /* Size of the pool */
108 CmLListCp memBlkSetElem; /* Memory set element likend list */
109 CmMmBlkSetElement *crntMemBlkSetElem; /* Pointer to the current memort block set */
110 CmMmEntry *startAddr; /* Starting address */
111 CmMmEntry *next; /* Next address which will be allocated */
112 U32 numBktAlloc; /* Total number of buckets allocted */
113 U32 numBkt; /* Total number of buckets configured */
114 U16 bucketSetSize; /* Size of bucket sets */
115 U16 blkSetRelThreshold; /* Upper threshold of bucket count upon
116 reaching will free the set to global region */
117 U16 blkSetAcquireThreshold; /* Lower threshold of bucket count upon
118 reaching will request the set from
120 U32 bktFailCnt; /* bucket alloc failure count */
121 U32 bktNoFitCnt; /* number of blocks not fit */
124 /* The individual Task regionCb which will be associate with every system
125 * task which will be created. This contains the mapping of the size to
126 * to bucket index and the different bucket informations.*/
127 #ifdef SS_USE_ICC_MEMORY
130 Region region; /* Region Id of the memory */
131 U16 bktSize[CMM_MAX_BKT_ENT]; /* Bucket Size */
132 void *iccHdl; /* Handler used for ICC memory */
133 SsAlloc alloc; /* allocation function pointer */
134 SsFree free; /* deallocation function pointer */
135 SsCtl ctl; /* control request function pointer */
140 Region region; /* Region Id of the memory */
141 U8 regType; /* Region Type, static or dynamic or global */
142 U8 numBktBlk; /* Keeps the count of number of bucket set blocks */
143 U16 numBkts; /* Number of buckets in the Bucket Pool */
144 Size bktSize; /* Size of the memory used for the bucket pool */
145 U16 bktQnPwr; /* Quantum size of the bucket pool */
146 Size bktMaxBlkSize; /* Maximum size of block in the bucket pool */
147 CmMmDynBktCb bktTbl[CMM_MAX_BKT_ENT]; /* Pointer to the memory bkt tbl */
148 SsAlloc alloc; /* allocation function pointer */
149 SsFree free; /* deallocation function pointer */
150 SsCtl ctl; /* control request function pointer */
151 CmMmMapBkt mapTbl[CMM_MAX_MAP_ENT]; /* size-to-bucket map table */
153 #endif /* SS_USE_ICC_MEMORY */
155 /* The global region Cb which holds the entire buckets configured */
158 Region region; /* Region Id of the memory */
159 U16 numBkts; /* Number of buckets in the Bucket Pool */
160 CmMmGlobalBktCb bktTbl[CMM_MAX_BKT_ENT]; /* Pointer to the memory bkt tbl */
166 typedef struct cmMmRegCfg CmMmRegCfg;
167 typedef struct cmMmBktCfg CmMmBktCfg;
170 typedef struct cmMmRegCb CmMmRegCb;
171 typedef struct cmMmHeapCb CmMmHeapCb;
172 typedef struct cmMmBkt CmMmBkt;
173 typedef struct cmHEntry CmHEntry;
174 /* cm_mem_x_001.main_9 - addition of new data types for providing
175 * header for memory blocks in buckets and a hash list to maintain
176 * size vs. numAttempts statistics
178 /* cm_mem_x_001.main_11: Additions */
179 #ifdef SS_HISTOGRAM_SUPPORT
180 typedef struct cmHstGrmHashListCp CmHstGrmHashListCp;
181 typedef struct cmHstGrmHashListEnt CmHstGrmHashListEnt;
182 typedef struct cmMemEntries CmMemEntries;
183 #endif /* SS_HISTOGRAM_SUPPORT */
185 /* forward definitions */
188 /************************************************************************
189 Common Memory Manager Configuration Data Structures
190 ************************************************************************/
192 /* Bucket configuration structure. */
195 Size size; /* Size of the memory block */
196 U32 numBlks; /* Number of the block in the bucket */
199 /* Memory Region configuration structure. */
202 Size size; /* Size of the memory */
203 Data *vAddr; /* Start address of the memory */
204 U8 lType; /* Lock Type to be used */
206 U8 chFlag; /* Flag defines the memory region characteristics */
207 Data *pAddr; /* Physical address of the memory block: Valid
208 if CMM_REG_PHY_VALID bit of chFlag is set */
209 Size bktQnSize; /* Quatum size of the memory block */
210 U16 numBkts; /* Number of buckets in the Bucket Pool */
212 CmMmBktCfg bktCfg[CMM_MAX_BKT_ENT]; /* Bucket configuration structure */
215 /************************************************************************
216 Common Memory Manager Implementation Data Structures
217 ************************************************************************/
218 /* cm_mem_x_001.main_11: Additions */
219 #ifdef SS_HISTOGRAM_SUPPORT
220 struct cmMemEntries /* Entry information */
222 U32 line; /* Line Number where memory allocation primitive used */
223 U32 allocBytes; /* Granted Byte */
224 U32 allocOverFlow; /* If the value of allocBytes overflows then we use this variable */
225 U32 freedBytes; /* Freed Bytes */
226 U32 freeOverFlow; /* If the value of freeByte overflows then we use this value */
227 U32 wastedBytes; /* Difference between Granted and Requested bytes */
228 U32 bucketAllocReq; /* No of times this Bucket used */
229 U32 bucketFreeReq; /* No of times this Bucket freed */
230 U32 entId; /* Tapa task used this bucket */
231 U32 key; /* combination of file name and line */
232 U8 fileName[CMM_HIST_MAX_FILENAME]; /* File Name where memory allocation primitive used */
235 struct cmHstGrmHashListEnt /* hash list entry */
237 CmMemEntries entries[CMM_HIST_MAX_MEM_ENTRY_PER_BIN]; /* Number of entires in each bin */
238 U32 numOfEntries; /*Number of entries in hash list */
241 struct cmHstGrmHashListCp /* Hash List control pointer */
243 CmHstGrmHashListEnt hashList[CMM_HIST_MAX_MEM_BIN]; /* Number of bins in hash list */
244 U16 totalNumEntries; /* Total number of bins */
247 #endif /* SS_HISTOGRAM_SUPPORT */
249 /* cm_mem_x_001.main_9 - addition of memory header for blocks in buckets */
250 #ifdef SSI_DEBUG_LEVEL1
251 /* Memory Block Header */
254 /* trSignature shall always be maintained as the first element in this structure */
255 U8 trSignature[CMM_TRAMPLING_SIGNATURE_LEN]; /* signature to detect trampling */
256 CmMmBlkHdr *nextBlk; /* pointer to the next memory block header */
257 U32 memFlags; /* Free/Static/Dynamic */
258 Size requestedSize; /* requested size for which this mem blk has been allocated */
260 #endif /* SSI_DEBUG_LEVEL1 */
262 /* Memory bucket structure */
263 struct cmMmBkt /* Bucket Structure */
265 /* cm_mem_x_001.main_9 - addition of next block pointer */
266 #ifdef SSI_DEBUG_LEVEL1
267 CmMmBlkHdr *nextBlk; /* pointer to the next memory block header */
269 CmMmEntry *next; /* Pointer to the next memory block */
270 #endif /* SSI_DEBUG_LEVEL1 */
271 Size size; /* Size of the block */
272 U32 numBlks; /* Total number of blocks in the bucket */
273 U32 maxAlloc; /* Maximum number of blocks allocated till now */
274 U32 numAlloc; /* Number of blocks allocated */
275 SLockId bktLock; /* Lock to protect the bucket pool */
276 U32 bktFailCnt; /* bucket alloc failure count */
277 U32 bktNoFitCnt; /* number of blocks not fit */
278 /* cm_mem_x_001.main_9 - addition of statistics related data */
279 #ifdef SSI_DEBUG_LEVEL1
280 Data *bktStartPtr; /* maintains the start address of the memory block in the bucket */
281 StsCntr numAllocAttempts; /* total number of allocation attempts */
282 StsCntr numDeallocAttempts; /* total number of de-allocation attempts */
283 Size staticMemUsed; /* amount of memory used for static allocations */
284 Size dynamicMemUsed; /* amount of memory used for dynamic allocations */
285 U8 trampleCount; /* incremented everytime a trampling is detected in any block of the bucket */
286 #endif /*SSI_DEBUG_LEVEL1*/
287 /* cm_mem_x_001.main_11: Additions */
288 #ifdef SS_HISTOGRAM_SUPPORT
289 CmHstGrmHashListCp hstGrmHashListCp;
290 #endif /* SS_HISTOGRAM_SUPPORT */
294 /* Size-To-Bucket map table structure */
296 /* Heap entry structure linked in the heap control block */
299 /* cm_mem_x_001.main_9 - addition to provide trampling and double-free detections support */
300 #ifdef SSI_DEBUG_LEVEL1
301 /* trSignature shall always be maintianed as the first element in this structure */
302 U8 trSignature[CMM_TRAMPLING_SIGNATURE_LEN]; /* signature to detect trampling */
303 U32 memFlags; /* flag to maintain the memory status */
304 Size requestedSize; /* size of the heap entry block */
305 #endif /* SSI_DEBUG_LEVEL1 */
306 CmHEntry *next; /* Pointer to the next entry block */
307 Size size; /* size of the heap entry block */
310 /* Heap control block */
313 Data *vStart; /* Memory start address */
314 Data *vEnd; /* Memory end address */
315 CmHEntry *next; /* Next heap block entry */
316 Size avlSize; /* Total available memory */
317 Size minSize; /* Minimum size that can be allocated */
318 SLockId heapLock; /* Lock to protect the heap pool */
319 #if (ERRCLASS & ERRCLS_DEBUG)
320 U16 numFragBlk; /* Number of fragmented block */
321 U16 numReq; /* Number of allocation request */
322 U16 numFailure; /* Number of allocation failure */
324 U32 heapAllocCnt; /* Number of blocks from heap */
325 /* cm_mem_x_001.main_9 - addition of statistics related data */
326 #ifdef SSI_DEBUG_LEVEL1
327 Size staticHeapMemUsed; /* amount of heap memory used for static allocations */
328 Size dynamicHeapMemUsed; /* amount of heap memory used for dynamic allocations */
329 Size nextOffset; /* Offset to the next pointer in structure CmHEntry */
330 /* Update this in cmMmHeapInit if cmHEntry is changed */
331 StsCntr numAllocAttempts; /* total number of allocation attempts in heap */
332 StsCntr numDeallocAttempts; /* total number of de-allocation attempts in heap */
333 U8 trampleCount; /* incremented everytime a trampling is detected in any block of the heap */
334 #endif /* SSI_DEBUG_LEVEL1 */
335 /* cm_mem_x_001.main_11: Additions */
336 #ifdef SS_HISTOGRAM_SUPPORT
337 /* Hash list to support Heap Block histogram */
338 CmHstGrmHashListCp heapHstGrmHashListCp;
339 #endif /* SS_HISTOGRAM_SUPPORT */
343 /* cm_mem_x_001.main_9 - addition of hash list for maintaining size vs. numAttempts statistics */
344 #ifdef SSI_DEBUG_LEVEL1
345 struct cmMmHashListEnt /* hash list entry */
347 U32 size; /* pointer to key */
348 U32 numAttempts; /* number of attempts */
351 struct cmMmHashListCp
353 CmMmHashListEnt *hashList;
357 #endif /* SSI_DEBUG_LEVEL1 */
359 /* Memory region control block */
362 Region region; /* Region Id of the memory */
363 SRegInfo regInfo; /* Region information block */
365 U8 chFlag; /* Flag defines the region characteristics */
366 Data *pAddr; /* Physical address of the memory block.
367 Valid if CMM_REG_PHY_VALID bit is set */
369 Size bktSize; /* Size of the memory used for the bucket pool */
370 U16 bktQnPwr; /* Quantum size of the bucket pool */
371 Size bktMaxBlkSize; /* Maximum size of block in the bucket pool */
372 U16 numBkts; /* Number of buckets in the Bucket Pool */
374 CmMmMapBkt mapTbl[CMM_MAX_MAP_ENT]; /* size-to-bucket map table */
375 CmMmBkt bktTbl[CMM_MAX_BKT_ENT]; /* Pointer to the memory bkt tbl */
377 Bool heapFlag; /* Set to true if the heap pool is configured */
378 Size heapSize; /* Size of the heap pool */
379 CmMmHeapCb heapCb; /* Heap pool control block */
380 /* cm_mem_x_001.main_9 - addition of hash list control point in region control block */
381 #ifdef SSI_DEBUG_LEVEL1
382 CmMmHashListCp hashListCp; /* hast list to maintain the size statistics */
383 #endif /* SSI_DEBUG_LEVEL1 */
384 #ifdef SS_MULTICORE_SUPPORT /*cm_mem_x_001.main_10*/
386 #endif /* SS_MULTICORE_SUPPORT */
390 /* cm_mem_x_001.main_11: Additions */
391 #ifdef SS_MEM_LEAK_STS
392 typedef struct _memHash
396 CmHashListCp memHashCp;
399 typedef struct _memAllocInfo
411 typedef struct _memLkCb
415 MemHash memUsrMdl[CM_MEM_USR_MDL][CM_MAX_HASH_PER_TSK];
418 typedef struct _memUsrMdlStr
424 #ifdef SS_MEM_LEAK_SOL
425 typedef struct backtrace
431 #endif /* SS_MEM_LEAK_SOL */
433 #endif /* SS_MEM_LEAK_STS */
436 /* functions prototypes */
438 EXTERN S16 cmMmRegInit ARGS((
442 EXTERN S16 cmMmRegDeInit ARGS(( CmMmRegCb *regCb));
443 /* cm_mem_x_001.main_11: Additions */
444 #ifdef SS_MEM_LEAK_STS
445 EXTERN Void cmInitMemLeakMdl ARGS((Void));
446 /* cm_mem_x_001.main_12 : Additions */
447 EXTERN Void cmDeinitMemLeakMdl ARGS((Void));
448 EXTERN Void cmStorAllocBlk ARGS((U32 addr, Size reqSz, Size allocSz,
450 EXTERN Void cmRlsAllocBlk ARGS((U32 addr));
451 EXTERN U8 cmMemGetModuleId ARGS((S8 **funNm, S32 traceSize));
452 EXTERN S16 cmMemGetStrMtchIdx ARGS((U8 strtIdx, U8 endIdx,
453 S8 *str, S8 **strLst));
454 EXTERN Void cmMemOpenMemLkFile ARGS((S8 *arg));
455 EXTERN Void SLogLkInfo ARGS((Void));
456 EXTERN Void SFlushLkInfo ARGS((Void));
458 #ifdef SS_MEM_LEAK_SOL
459 EXTERN S32 cmAddrToSymStr ARGS((Void *pc, S8 *buffer, S32 size));
460 EXTERN S32 cmLeakCallBack ARGS((uintptr_t pc, S32 signo, Void *arg));
461 EXTERN S32 backtrace ARGS((Void **buffer, S32 count));
462 #endif /* SS_MEM_LEAK_SOL */
464 #endif /* SS_MEM_LEAK_STS */
465 /* cm_mem_x_001.main_9 - addition of an API prototype for sanity check */
466 #ifdef SSI_DEBUG_LEVEL1
467 EXTERN S16 cmMmRegIsBlkSane ARGS((CmMmBlkHdr *blkPtr));
468 #endif /* SSI_DEBUG_LEVEL1 */
471 EXTERN Void DumpLayersDebugInformation ARGS((Void));
472 EXTERN Void DumpSSIDemandQDebugInformation ARGS((Void));
473 EXTERN Void DumpPDCPDlDebugInformation ARGS((Void));
474 EXTERN Void DumpPDCPUlDebugInformation ARGS((Void));
475 EXTERN Void DumpRLCDlDebugInformation ARGS((Void));
476 EXTERN Void DumpRLCUlDebugInformation ARGS((Void));
477 EXTERN Void DumpRLCUlDebugInformation ARGS((Void));
478 EXTERN Void printMacCellInfo ARGS((Void));
479 EXTERN Void printSchCellInfo ARGS((Void));
481 EXTERN U32 isMemThreshReached ARGS((Region region));
483 EXTERN S16 cmMmStatRegInit ARGS((Region region, CmMmRegCb *regCb, CmMmRegCfg *cfg));
484 EXTERN S16 cmMmGlobRegInit ARGS((CmMmGlobRegCb *regCb));
485 EXTERN S16 cmMmDynRegInit ARGS((CmMmDynRegCb *regCb));
487 EXTERN S16 ssGetDynMemBlkSet ARGS((U8 bktIdx, CmMmBlkSetElement *dynMemSetElem));
488 EXTERN S16 ssPutDynMemBlkSet ARGS((U8 bktIdx, CmMmBlkSetElement *dynMemSetElem));
490 EXTERN S16 ssPutDynMemBlkSet ARGS((U8 bktIdx,CmMmBlkSetElement *dynMemSetElem,
491 U32 doNotBlockForLock));
492 EXTERN S16 ssGetDynMemBlkSet ARGS((U8 bktIdx, CmMmBlkSetElement *dynMemSetElem,
493 U32 doNotBlockForLock));
494 #endif /* USE_MALLOC */
495 #endif /* SS_LOCKLESS_MEMORY */
500 #ifdef T2K_MEM_LEAK_DBG
504 /**********************************************************************
506 *********************************************************************/