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 */
79 /* This structre is used for the storing the bucket set information in the
80 * system task region. At present the number of array is used for two.
81 * The array is indexed using the crntBktNodeIdx value during allocation
85 U32 numBkt; /* Number of buckets avilable in the current
87 CmMmEntry *nextBktPtr; /* Address of the first bucket which will be
88 used for the allocation */
92 /* The following structure is used for the storing the buckets/pools
93 * this will be present for each bucket which is configured and
94 * will contains the all the information about the bucket. This
95 * will be used in global region */
96 struct cmMmGlobalBktCb
98 U8 poolId; /* Pool Id */
99 Size size; /* Size of the pool */
100 CmLListCp listValidBktSet; /* LList Cp used to store the nodes of memory element
101 node which holds valid pointers */
102 CmLListCp listFreeBktSet; /* LList Cp used to store the nodes of memory element
103 node which holds invalid information */
104 CmMmEntry *startAddr; /* Starting address */
105 CmMmEntry *next; /* Next address which will be allocated */
106 U32 numBlks; /* Total number of buckets configured */
108 U32 bktFailCnt; /* bucket alloc failure count */
109 U32 bktNoFitCnt; /* number of blocks not fit */
110 SLockId bucketLock; /* Lock used for the allocation/freeing of
111 the set of buckets */
114 /* The following structure is used for the storing the buckets/pools
115 * this will be present for each bucket which is configured and
116 * will contains the all the information about the bucket. This
117 * is used in the system taks local region */
120 U8 poolId; /* Pool Id */
121 Size size; /* Size of the pool */
122 CmLListCp memBlkSetElem; /* Memory set element likend list */
123 CmMmBlkSetElement *crntMemBlkSetElem; /* Pointer to the current memort block set */
124 CmMmEntry *startAddr; /* Starting address */
125 CmMmEntry *next; /* Next address which will be allocated */
126 U32 numBktAlloc; /* Total number of buckets allocted */
127 U32 numBkt; /* Total number of buckets configured */
128 U16 bucketSetSize; /* Size of bucket sets */
129 U16 blkSetRelThreshold; /* Upper threshold of bucket count upon
130 reaching will free the set to global region */
131 U16 blkSetAcquireThreshold; /* Lower threshold of bucket count upon
132 reaching will request the set from
134 U32 bktFailCnt; /* bucket alloc failure count */
135 U32 bktNoFitCnt; /* number of blocks not fit */
138 /* The individual Task regionCb which will be associate with every system
139 * task which will be created. This contains the mapping of the size to
140 * to bucket index and the different bucket informations.*/
141 #ifdef SS_USE_ICC_MEMORY
144 Region region; /* Region Id of the memory */
145 U16 bktSize[CMM_MAX_BKT_ENT]; /* Bucket Size */
146 void *iccHdl; /* Handler used for ICC memory */
147 SsAlloc alloc; /* allocation function pointer */
148 SsFree free; /* deallocation function pointer */
149 SsCtl ctl; /* control request function pointer */
154 Region region; /* Region Id of the memory */
155 U8 regType; /* Region Type, static or dynamic or global */
156 U8 numBktBlk; /* Keeps the count of number of bucket set blocks */
157 U16 numBkts; /* Number of buckets in the Bucket Pool */
158 Size bktSize; /* Size of the memory used for the bucket pool */
159 U16 bktQnPwr; /* Quantum size of the bucket pool */
160 Size bktMaxBlkSize; /* Maximum size of block in the bucket pool */
161 CmMmDynBktCb bktTbl[CMM_MAX_BKT_ENT]; /* Pointer to the memory bkt tbl */
162 SsAlloc alloc; /* allocation function pointer */
163 SsFree free; /* deallocation function pointer */
164 SsCtl ctl; /* control request function pointer */
165 CmMmMapBkt mapTbl[CMM_MAX_MAP_ENT]; /* size-to-bucket map table */
167 #endif /* SS_USE_ICC_MEMORY */
169 /* The global region Cb which holds the entire buckets configured */
172 Region region; /* Region Id of the memory */
173 U16 numBkts; /* Number of buckets in the Bucket Pool */
174 CmMmGlobalBktCb bktTbl[CMM_MAX_BKT_ENT]; /* Pointer to the memory bkt tbl */
180 typedef struct cmMmRegCfg CmMmRegCfg;
181 typedef struct cmMmBktCfg CmMmBktCfg;
184 typedef struct cmMmRegCb CmMmRegCb;
185 typedef struct cmMmHeapCb CmMmHeapCb;
186 typedef struct cmMmBkt CmMmBkt;
187 typedef struct cmHEntry CmHEntry;
188 /* cm_mem_x_001.main_9 - addition of new data types for providing
189 * header for memory blocks in buckets and a hash list to maintain
190 * size vs. numAttempts statistics
192 /* cm_mem_x_001.main_11: Additions */
193 #ifdef SS_HISTOGRAM_SUPPORT
194 typedef struct cmHstGrmHashListCp CmHstGrmHashListCp;
195 typedef struct cmHstGrmHashListEnt CmHstGrmHashListEnt;
196 typedef struct cmMemEntries CmMemEntries;
197 #endif /* SS_HISTOGRAM_SUPPORT */
199 /* forward definitions */
202 /************************************************************************
203 Common Memory Manager Configuration Data Structures
204 ************************************************************************/
206 /* Bucket configuration structure. */
209 Size size; /* Size of the memory block */
210 U32 numBlks; /* Number of the block in the bucket */
213 /* Memory Region configuration structure. */
216 Size size; /* Size of the memory */
217 Data *vAddr; /* Start address of the memory */
218 U8 lType; /* Lock Type to be used */
220 U8 chFlag; /* Flag defines the memory region characteristics */
221 Data *pAddr; /* Physical address of the memory block: Valid
222 if CMM_REG_PHY_VALID bit of chFlag is set */
223 Size bktQnSize; /* Quatum size of the memory block */
224 U16 numBkts; /* Number of buckets in the Bucket Pool */
226 CmMmBktCfg bktCfg[CMM_MAX_BKT_ENT]; /* Bucket configuration structure */
229 /************************************************************************
230 Common Memory Manager Implementation Data Structures
231 ************************************************************************/
232 /* cm_mem_x_001.main_11: Additions */
233 #ifdef SS_HISTOGRAM_SUPPORT
234 struct cmMemEntries /* Entry information */
236 U32 line; /* Line Number where memory allocation primitive used */
237 U32 allocBytes; /* Granted Byte */
238 U32 allocOverFlow; /* If the value of allocBytes overflows then we use this variable */
239 U32 freedBytes; /* Freed Bytes */
240 U32 freeOverFlow; /* If the value of freeByte overflows then we use this value */
241 U32 wastedBytes; /* Difference between Granted and Requested bytes */
242 U32 bucketAllocReq; /* No of times this Bucket used */
243 U32 bucketFreeReq; /* No of times this Bucket freed */
244 U32 entId; /* Tapa task used this bucket */
245 U32 key; /* combination of file name and line */
246 U8 fileName[CMM_HIST_MAX_FILENAME]; /* File Name where memory allocation primitive used */
249 struct cmHstGrmHashListEnt /* hash list entry */
251 CmMemEntries entries[CMM_HIST_MAX_MEM_ENTRY_PER_BIN]; /* Number of entires in each bin */
252 U32 numOfEntries; /*Number of entries in hash list */
255 struct cmHstGrmHashListCp /* Hash List control pointer */
257 CmHstGrmHashListEnt hashList[CMM_HIST_MAX_MEM_BIN]; /* Number of bins in hash list */
258 U16 totalNumEntries; /* Total number of bins */
261 #endif /* SS_HISTOGRAM_SUPPORT */
263 /* cm_mem_x_001.main_9 - addition of memory header for blocks in buckets */
264 #ifdef SSI_DEBUG_LEVEL1
265 /* Memory Block Header */
268 /* trSignature shall always be maintained as the first element in this structure */
269 U8 trSignature[CMM_TRAMPLING_SIGNATURE_LEN]; /* signature to detect trampling */
270 CmMmBlkHdr *nextBlk; /* pointer to the next memory block header */
271 U32 memFlags; /* Free/Static/Dynamic */
272 Size requestedSize; /* requested size for which this mem blk has been allocated */
274 #endif /* SSI_DEBUG_LEVEL1 */
276 /* Memory bucket structure */
277 struct cmMmBkt /* Bucket Structure */
279 /* cm_mem_x_001.main_9 - addition of next block pointer */
280 #ifdef SSI_DEBUG_LEVEL1
281 CmMmBlkHdr *nextBlk; /* pointer to the next memory block header */
283 CmMmEntry *next; /* Pointer to the next memory block */
284 #endif /* SSI_DEBUG_LEVEL1 */
285 Size size; /* Size of the block */
286 U32 numBlks; /* Total number of blocks in the bucket */
287 U32 maxAlloc; /* Maximum number of blocks allocated till now */
288 U32 numAlloc; /* Number of blocks allocated */
289 SLockId bktLock; /* Lock to protect the bucket pool */
290 U32 bktFailCnt; /* bucket alloc failure count */
291 U32 bktNoFitCnt; /* number of blocks not fit */
292 /* cm_mem_x_001.main_9 - addition of statistics related data */
293 #ifdef SSI_DEBUG_LEVEL1
294 Data *bktStartPtr; /* maintains the start address of the memory block in the bucket */
295 StsCntr numAllocAttempts; /* total number of allocation attempts */
296 StsCntr numDeallocAttempts; /* total number of de-allocation attempts */
297 Size staticMemUsed; /* amount of memory used for static allocations */
298 Size dynamicMemUsed; /* amount of memory used for dynamic allocations */
299 U8 trampleCount; /* incremented everytime a trampling is detected in any block of the bucket */
300 #endif /*SSI_DEBUG_LEVEL1*/
301 /* cm_mem_x_001.main_11: Additions */
302 #ifdef SS_HISTOGRAM_SUPPORT
303 CmHstGrmHashListCp hstGrmHashListCp;
304 #endif /* SS_HISTOGRAM_SUPPORT */
308 /* Size-To-Bucket map table structure */
310 /* Heap entry structure linked in the heap control block */
313 /* cm_mem_x_001.main_9 - addition to provide trampling and double-free detections support */
314 #ifdef SSI_DEBUG_LEVEL1
315 /* trSignature shall always be maintianed as the first element in this structure */
316 U8 trSignature[CMM_TRAMPLING_SIGNATURE_LEN]; /* signature to detect trampling */
317 U32 memFlags; /* flag to maintain the memory status */
318 Size requestedSize; /* size of the heap entry block */
319 #endif /* SSI_DEBUG_LEVEL1 */
320 CmHEntry *next; /* Pointer to the next entry block */
321 Size size; /* size of the heap entry block */
324 /* Heap control block */
327 Data *vStart; /* Memory start address */
328 Data *vEnd; /* Memory end address */
329 CmHEntry *next; /* Next heap block entry */
330 Size avlSize; /* Total available memory */
331 Size minSize; /* Minimum size that can be allocated */
332 SLockId heapLock; /* Lock to protect the heap pool */
333 #if (ERRCLASS & ERRCLS_DEBUG)
334 U16 numFragBlk; /* Number of fragmented block */
335 U16 numReq; /* Number of allocation request */
336 U16 numFailure; /* Number of allocation failure */
338 U32 heapAllocCnt; /* Number of blocks from heap */
339 /* cm_mem_x_001.main_9 - addition of statistics related data */
340 #ifdef SSI_DEBUG_LEVEL1
341 Size staticHeapMemUsed; /* amount of heap memory used for static allocations */
342 Size dynamicHeapMemUsed; /* amount of heap memory used for dynamic allocations */
343 Size nextOffset; /* Offset to the next pointer in structure CmHEntry */
344 /* Update this in cmMmHeapInit if cmHEntry is changed */
345 StsCntr numAllocAttempts; /* total number of allocation attempts in heap */
346 StsCntr numDeallocAttempts; /* total number of de-allocation attempts in heap */
347 U8 trampleCount; /* incremented everytime a trampling is detected in any block of the heap */
348 #endif /* SSI_DEBUG_LEVEL1 */
349 /* cm_mem_x_001.main_11: Additions */
350 #ifdef SS_HISTOGRAM_SUPPORT
351 /* Hash list to support Heap Block histogram */
352 CmHstGrmHashListCp heapHstGrmHashListCp;
353 #endif /* SS_HISTOGRAM_SUPPORT */
357 /* cm_mem_x_001.main_9 - addition of hash list for maintaining size vs. numAttempts statistics */
358 #ifdef SSI_DEBUG_LEVEL1
359 struct cmMmHashListEnt /* hash list entry */
361 U32 size; /* pointer to key */
362 U32 numAttempts; /* number of attempts */
365 struct cmMmHashListCp
367 CmMmHashListEnt *hashList;
371 #endif /* SSI_DEBUG_LEVEL1 */
373 /* Memory region control block */
376 Region region; /* Region Id of the memory */
377 SRegInfo regInfo; /* Region information block */
379 U8 chFlag; /* Flag defines the region characteristics */
380 Data *pAddr; /* Physical address of the memory block.
381 Valid if CMM_REG_PHY_VALID bit is set */
383 Size bktSize; /* Size of the memory used for the bucket pool */
384 U16 bktQnPwr; /* Quantum size of the bucket pool */
385 Size bktMaxBlkSize; /* Maximum size of block in the bucket pool */
386 U16 numBkts; /* Number of buckets in the Bucket Pool */
388 CmMmMapBkt mapTbl[CMM_MAX_MAP_ENT]; /* size-to-bucket map table */
389 CmMmBkt bktTbl[CMM_MAX_BKT_ENT]; /* Pointer to the memory bkt tbl */
391 Bool heapFlag; /* Set to true if the heap pool is configured */
392 Size heapSize; /* Size of the heap pool */
393 CmMmHeapCb heapCb; /* Heap pool control block */
394 /* cm_mem_x_001.main_9 - addition of hash list control point in region control block */
395 #ifdef SSI_DEBUG_LEVEL1
396 CmMmHashListCp hashListCp; /* hast list to maintain the size statistics */
397 #endif /* SSI_DEBUG_LEVEL1 */
398 #ifdef SS_MULTICORE_SUPPORT /*cm_mem_x_001.main_10*/
400 #endif /* SS_MULTICORE_SUPPORT */
404 /* cm_mem_x_001.main_11: Additions */
405 #ifdef SS_MEM_LEAK_STS
406 typedef struct _memHash
410 CmHashListCp memHashCp;
413 typedef struct _memAllocInfo
425 typedef struct _memLkCb
429 MemHash memUsrMdl[CM_MEM_USR_MDL][CM_MAX_HASH_PER_TSK];
432 typedef struct _memUsrMdlStr
438 #ifdef SS_MEM_LEAK_SOL
439 typedef struct backtrace
445 #endif /* SS_MEM_LEAK_SOL */
447 #endif /* SS_MEM_LEAK_STS */
450 /* functions prototypes */
452 EXTERN S16 cmMmRegInit ARGS((
456 EXTERN S16 cmMmRegDeInit ARGS(( CmMmRegCb *regCb));
457 /* cm_mem_x_001.main_11: Additions */
458 #ifdef SS_MEM_LEAK_STS
459 EXTERN Void cmInitMemLeakMdl ARGS((Void));
460 /* cm_mem_x_001.main_12 : Additions */
461 EXTERN Void cmDeinitMemLeakMdl ARGS((Void));
462 EXTERN Void cmStorAllocBlk ARGS((U32 addr, Size reqSz, Size allocSz,
464 EXTERN Void cmRlsAllocBlk ARGS((U32 addr));
465 EXTERN U8 cmMemGetModuleId ARGS((S8 **funNm, S32 traceSize));
466 EXTERN S16 cmMemGetStrMtchIdx ARGS((U8 strtIdx, U8 endIdx,
467 S8 *str, S8 **strLst));
468 EXTERN Void cmMemOpenMemLkFile ARGS((S8 *arg));
469 EXTERN Void SLogLkInfo ARGS((Void));
470 EXTERN Void SFlushLkInfo ARGS((Void));
472 #ifdef SS_MEM_LEAK_SOL
473 EXTERN S32 cmAddrToSymStr ARGS((Void *pc, S8 *buffer, S32 size));
474 EXTERN S32 cmLeakCallBack ARGS((uintptr_t pc, S32 signo, Void *arg));
475 EXTERN S32 backtrace ARGS((Void **buffer, S32 count));
476 #endif /* SS_MEM_LEAK_SOL */
478 #endif /* SS_MEM_LEAK_STS */
479 /* cm_mem_x_001.main_9 - addition of an API prototype for sanity check */
480 #ifdef SSI_DEBUG_LEVEL1
481 EXTERN S16 cmMmRegIsBlkSane ARGS((CmMmBlkHdr *blkPtr));
482 #endif /* SSI_DEBUG_LEVEL1 */
485 EXTERN Void DumpLayersDebugInformation ARGS((Void));
486 EXTERN Void DumpSSIDemandQDebugInformation ARGS((Void));
487 EXTERN Void DumpPDCPDlDebugInformation ARGS((Void));
488 EXTERN Void DumpPDCPUlDebugInformation ARGS((Void));
489 EXTERN Void DumpRLCDlDebugInformation ARGS((Void));
490 EXTERN Void DumpRLCUlDebugInformation ARGS((Void));
491 EXTERN Void DumpRLCUlDebugInformation ARGS((Void));
492 EXTERN Void printMacCellInfo ARGS((Void));
493 EXTERN Void printSchCellInfo ARGS((Void));
495 EXTERN U32 isMemThreshReached ARGS((Region region));
497 EXTERN S16 cmMmStatRegInit ARGS((Region region, CmMmRegCb *regCb, CmMmRegCfg *cfg));
498 EXTERN S16 cmMmGlobRegInit ARGS((CmMmGlobRegCb *regCb));
499 EXTERN S16 cmMmDynRegInit ARGS((CmMmDynRegCb *regCb));
501 EXTERN S16 ssGetDynMemBlkSet ARGS((U8 bktIdx, CmMmBlkSetElement *dynMemSetElem));
502 EXTERN S16 ssPutDynMemBlkSet ARGS((U8 bktIdx, CmMmBlkSetElement *dynMemSetElem));
504 EXTERN S16 ssPutDynMemBlkSet ARGS((U8 bktIdx,CmMmBlkSetElement *dynMemSetElem,
505 U32 doNotBlockForLock));
506 EXTERN S16 ssGetDynMemBlkSet ARGS((U8 bktIdx, CmMmBlkSetElement *dynMemSetElem,
507 U32 doNotBlockForLock));
508 #endif /* USE_MALLOC */
509 #endif /* SS_LOCKLESS_MEMORY */
514 #ifdef T2K_MEM_LEAK_DBG
516 typedef struct _t2kMemLeakInfo
518 U32 address; /* 0 means it is free */
519 U32 size; /* size of the block */
520 U32 age; /* in ticks, when it was allocated */
521 U32 lineNo; /* lineNo in the file from where allocation was done */
522 char* fileName; /* from where allocation was done */
523 U32 prevRemLineNo; /* lineNo in the file from where allocation was done */
524 char* prevRemFileName; /* from where allocation was done */
525 U32 lastDelLineNum; /* lineNo in the file from where allocation was done */
526 char* lastDelFileName; /* from where allocation was done */
533 /**********************************************************************
535 *********************************************************************/