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 *******************************************************************************/
19 /********************************************************************20**
21 Name: Common Memory Manager
25 Desc: C source code for the Commom Memory Manager module.
29 Sid: cm_mem.c@@/main/28 - Fri Aug 26 13:52:41 2011
33 *********************************************************************21*/
36 /************************************************************************
38 The following functions are provided in this file.
40 cmMmRegInit Memory Region Initialization.
41 cmMmRegDeInit Memory Region Deinitialization.
43 ************************************************************************/
46 /* header include files (.h) */
47 #include "envopt.h" /* environment options */
48 #include "envdep.h" /* environment dependent */
49 #include "envind.h" /* environment independent */
51 #include "gen.h" /* general */
52 #include "ssi.h" /* system services */
53 #include "cm_mem.h" /* Common memory manager cm_mem_c_001.main_15 */
54 #ifdef SS_MEM_LEAK_STS
58 #ifdef SS_MEM_LEAK_SOL
61 #include <sys/machelf.h>
62 #else /* SS_MEM_LEAK_SOL */
64 #endif /* SS_MEM_LEAK_SOL */
65 #include <sys/types.h>
67 #endif /* SS_MEM_LEAK_STS */
69 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
70 #include "cm_hash.h" /* common hash functions */
72 #ifdef SS_MULTICORE_SUPPORT /* cm_mem_c_001.main_14 */
73 #include "ss_dep.h" /* implementation-specific */
74 #include "ss_queue.h" /* queues */
75 #include "ss_task.h" /* tasking */
77 #ifdef SS_MULTICORE_SUPPORT
78 #include "ss_dep.h" /* implementation-specific */
79 #include "ss_queue.h" /* queues */
80 #include "ss_task.h" /* tasking */
83 /* header/extern include files (.x) */
84 #include "gen.x" /* general */
85 #include "ssi.x" /* system services */
86 #ifdef SS_MULTICORE_SUPPORT
87 #include "ss_dep.x" /* implementation-specific */
88 #include "ss_queue.x" /* queues */
89 #include "ss_task.x" /* system services */
91 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
92 #include "cm_hash.x" /* common hash functions */
94 #include "cm_mem.x" /* Common memory manager */
95 /* cm_mem_c_001.main_28 : Fix for compilation warning */
96 #include "cm_lib.x" /* common library functions */
97 /* cm_mem_c_001.main_15: Addition */
98 #ifdef SS_MEM_LEAK_STS
99 #include "cm_hash.x" /* common hash functions */
100 #endif /* SS_MEM_LEAK_STS */
104 #endif /* USE_PURE */
105 #ifdef SS_MULTICORE_SUPPORT
106 #include "ss_dep.x" /* implementation-specific */
107 #include "ss_queue.x" /* queues */
108 #include "ss_task.x" /* system services */
113 #endif /* USE_PURE */
115 #ifdef SS_LIGHT_MEM_LEAK_STS
117 U32 queueIndxAllocCnt =0;
118 U32 queueIndxFreeCnt =0;
119 U32 allocQueueFullCnt =0;
120 U32 allocQueueEmptyCnt =0;
129 /* forward references */
130 /* cm_mem_c_001.main_12 - prototype is changed to accept memType(static/dynamic) */
131 /* cm_mem_c_001.main_15: Addition */
132 /* cm_mem_c_001.main_22: Fixing warnings on GCC compiler*/
137 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
139 U32 cmFreeCaller[4]={0};
140 U32 cmAllocCaller[4]={0};
141 Data *startPtr256=NULLP;
142 Data *startPtr128=NULLP;
143 U32 cmMemInfo128[100000][2]={0, 0};
144 U32 cmMemInfo256[100000][2]={0, 0};
145 Data *startPtr512=NULLP;
146 Data *startPtr768=NULLP;
147 Data *startPtr1664=NULLP;
148 Data *startPtr4800=NULLP;
149 Data *startPtr9920=NULLP;
152 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
153 //extern CmMmRegCb *mtCMMRegCb[SS_MAX_REGS];
155 #ifdef SS_HISTOGRAM_SUPPORT
156 #ifdef SSI_DEBUG_LEVEL1
157 PRIVATE S16 cmAlloc ARGS((Void *regionCb, Size *size, U32 flags, Data **ptr,
158 U32 memType, U32 line, U8 *fileName, U8 entId, Bool hstReg));
159 PRIVATE S16 cmHeapAlloc ARGS((CmMmHeapCb *heapCb, Data **ptr, Size *size, U32 memType, U32 line, U8 *fileName, U8 entId, Bool hstReg));
160 /*cm_mem_c_001.main_20-added new functionto allocate memory from new region*/
162 PRIVATE S16 cmHeapAlloc ARGS((CmMmHeapCb *heapCb, Data **ptr, Size *size,
163 U32 line, U8 *fileName, U8 entId, Bool hstReg));
164 PRIVATE S16 cmAlloc ARGS((Void *regionCb, Size *size, U32 flags, Data **ptr,
165 U32 line, U8 *fileName, U8 entId, Bool hstReg));
166 #endif /* SSI_DEBUG_LEVEL1 */
168 PRIVATE S16 cmFree ARGS((Void *regionCb, Data *ptr, Size size, U32 line,
169 U8 *fileName, U8 entId, Bool hstReg));
171 PRIVATE S16 cmHeapFree ARGS((CmMmHeapCb *heapCb, Data *ptr, Size size,
172 U32 line, U8 *fileName, U8 entId, Bool hstReg));
173 #else /* no histogram support */
174 /* cm_mem_c_001.main_12 - prototype is changed to accept memType(static/dynamic) */
175 #ifdef SSI_DEBUG_LEVEL1
176 PRIVATE S16 cmHeapAlloc ARGS((CmMmHeapCb *heapCb, Data **ptr, Size *size, U32 memType));
179 PRIVATE S16 cmHeapAlloc ARGS((CmMmHeapCb *heapCb, Data **ptr, Size *size));
181 #endif /* SSI_DEBUG_LEVEL1 */
183 PRIVATE S16 cmHeapFree ARGS((CmMmHeapCb *heapCb, Data *ptr, Size size));
185 /* cm_mem_c_001.main_15 :Additions */
186 #ifdef SS_LIGHT_MEM_LEAK_STS
187 PRIVATE S16 cmAlloc ARGS((Void *regionCb, Size *size, U32 flags, Data **ptr, U32 memType, U32 lineNo,U8 *funcName ));
188 PRIVATE S16 cmFree ARGS((Void *regionCb, Data *ptr, Size size, U32 lineNo, U8* funcName));
189 #else /*SS_LIGHT_MEM_LEAK_STS */
190 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
191 PRIVATE S16 cmAlloc ARGS((Void *regionCb, Size *size, U32 flags, Data **ptr, U32 memType));
193 #ifdef T2K_MEM_LEAK_DBG
194 PRIVATE S16 cmAlloc ARGS((Void *regionCb, Size *size, U32 flags, Data **ptr, char* file, U32 line));
196 PRIVATE S16 cmAlloc ARGS((Void *regionCb, Size *size, U32 flags, Data **ptr));
198 #endif /* SSI_DEBUG_LEVEL1 */
199 #ifdef T2K_MEM_LEAK_DBG
200 PRIVATE S16 cmFree ARGS((Void *regionCb, Data *ptr, Size size, char* file, U32 line));
202 PRIVATE S16 cmFree ARGS((Void *regionCb, Data *ptr, Size size));
204 #endif /* SS_HISTOGRAM_SUPPORT */
205 #endif /*SS_LIGHT_MEM_LEAK_STS*/
206 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
208 PRIVATE S16 cmAllocWL ARGS((Void *regionCb, Size *size, U32 flags, Data **ptr));
209 PRIVATE S16 cmFreeWL ARGS((Void *regionCb, Data *ptr, Size size));
212 PRIVATE S16 cmCtl ARGS((Void *regionCb, Event event, SMemCtl *memCtl));
214 PRIVATE Void cmMmHeapInit ARGS((Data *memAddr, CmMmHeapCb *heapCb, Size size));
215 PRIVATE Void cmMmBktInit ARGS((Data **memAddr, CmMmRegCb *regCb,
216 CmMmRegCfg *cfg, U16 bktIdx, U16 *lstMapIdx));
218 /* cm_mem_c_001.main_12 - addition of protoypes for sanity check and hash list functions */
219 #ifdef SSI_DEBUG_LEVEL1
220 PRIVATE S16 cmMmBktSanityChk ARGS((CmMmBkt *bkt));
221 PRIVATE S16 cmMmHeapSanityChk ARGS((CmMmHeapCb *heapCb));
222 PRIVATE S16 cmMmHashFunc ARGS((CmMmHashListCp *hashListCp, U32 key, U16 *idx ));
223 PRIVATE S16 cmMmHashListInit ARGS((CmMmHashListCp *hashListCp, U16 nmbBins,
224 Region region, Pool pool));
225 PRIVATE S16 cmMmHashListDeinit ARGS((CmMmHashListCp *hashListCp, Region region, Pool pool));
226 PRIVATE S16 cmMmHashListInsert ARGS((CmMmHashListCp *hashListCp, U32 key));
227 #endif /* SSI_DEBUG_LEVEL1 */
228 /* cm_mem_c_001.main_15 : Addtions */
229 #ifdef SS_HISTOGRAM_SUPPORT
230 PRIVATE S16 cmHstGrmAllocInsert ARGS((CmHstGrmHashListCp *hashListCp, U32 blkSz, U32 *reqSz, U32 line, U8 *fileName, U8 entId));
231 PRIVATE S16 cmHstGrmFreeInsert ARGS((CmHstGrmHashListCp* hashListCp, U32 blkSz, U32 line, U8 *fileName, U8 entId));
232 PRIVATE S16 cmHstGrmHashListInit ARGS((CmHstGrmHashListCp *hashListCp));
233 PRIVATE S16 cmHstGrmHashListDeInit ARGS((CmHstGrmHashListCp *hashListCp));
234 PRIVATE S16 cmHstGrmGetHashIdxAndKey ARGS((U8 *fileName, U32 line, U32 *binIdx, U32 *key));
235 PRIVATE S16 cmHstGrmFindEntry ARGS((CmHstGrmHashListCp *hashListCp, U32 key, U32 *binIdx, CmMemEntries **entry));
236 PRIVATE S16 cmHstGrmFillEntry ARGS((CmMemEntries *entry, U32 key, U32 line, U8 *fileName, U8 entId));
237 #endif /* SS_HISTOGRAM_SUPPORT */
239 /* cm_mem_c_001.main_22: Fixing warnings on GCC compiler */
244 /* public variable declarations */
247 #endif /* USE_PURE */
248 /* cm_mem_c_001.main_15:Additions */
249 #ifdef SS_MEM_LEAK_STS
250 MemUsrMdlStr memUsrMdlStr[]=
252 MEMRAW2STR(DEFAULT, STACK),
253 MEMRAW2STR(tc, PDCP_LAYER),
254 MEMRAW2STR(Tc, PDCP_LAYER),
255 MEMRAW2STR(mg, GCP_LAYER),
256 MEMRAW2STR(Mg, GCP_LAYER),
261 #endif /* SS_MEM_LEAK_STS */
262 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
268 #ifdef T2K_MEM_LEAK_DBG
270 U8 minBktSzBitMask; /* minimum allocation size in Log(x)base 2, where X is minimum bucket size in region */
271 U16 minBktSzMins1; /* X-1 */
273 static RegMinBktSzInfo regMinBktSzInfo[SS_MAX_REGS] = {{8,0xFF},{7,0x7F},{7,0x7F},{7,0x7F}};
274 RegionMemLeakInfo regMemLeakInfo;
276 U32 getT2kMemLeakIndex(U64 address, Region region)
278 return ((address - regMemLeakInfo.regStartAddr[region]) >> regMinBktSzInfo[region].minBktSzBitMask);
281 static U32 t2kMemAllocTick;
282 static U32 smallTick;
284 void InsertToT2kMemLeakInfo(U64 address, U32 size, U32 lineNo, char* fileName, Region region)
287 T2kMeamLeakInfo *leakInfo;
293 U32 index1 = getT2kMemLeakIndex(address,region);
295 if(((U64)(address - regMemLeakInfo.regStartAddr[region]) & regMinBktSzInfo[region].minBktSzMins1) !=0)
297 printf("address in InsertToT2kMemLeakInfo is %ld size = %d file is %s line is %d \n", address, size, fileName, lineNo);
300 leakInfo = (((T2kMeamLeakInfo*)(regMemLeakInfo.gMemLeakInfo[region])) + index1);
301 if(leakInfo->address == 0)
303 leakInfo->address = address;
304 leakInfo->size = size;
305 leakInfo->lineNo = lineNo;
306 leakInfo->fileName = fileName;
307 leakInfo->age = t2kMemAllocTick;
308 leakInfo->prevRemLineNo = 0;
309 leakInfo->prevRemFileName = '\0';
311 //printf("InsertToT2kMemLeakInfo the adress from List Address = %x, index1 = %d from File=%s, line=%d \n",address,index1,fileName,lineNo);
312 if(smallTick++ == 4096)
315 leakInfo->age = (++t2kMemAllocTick);
320 printf("Something is wrong, trying to insert %ld index1 = %d file is %s line is %d \n",address, index1, fileName, lineNo);
321 printf("Address present :%ld, from File:%s, Line:%d, Size:%d, Age:%d",
322 leakInfo->address, leakInfo->fileName,
323 leakInfo->lineNo, leakInfo->size,
329 void RemoveFromT2kMemLeakInfo(U64 address, char *file, U32 line,Region region)
331 T2kMeamLeakInfo *leakInfo;
338 U32 index1 = getT2kMemLeakIndex(address, region);
340 if(index1 >= T2K_MEM_LEAK_INFO_TABLE_SIZE)
342 printf("index1 out of range = %d address is %ld file = %s line = %d. We are going to crash!!!\n",
348 leakInfo = (((T2kMeamLeakInfo*)(regMemLeakInfo.gMemLeakInfo[region])) + index1);
349 if(leakInfo->address == address)
352 leakInfo->address = 0;
354 leakInfo->prevRemLineNo = leakInfo->lineNo;
355 leakInfo->prevRemFileName = leakInfo->fileName;
356 leakInfo->lastDelLineNum = line;
357 leakInfo->lastDelFileName = file;
361 printf("Something is wrong, trying to remove %ld index1 = %d from File=%s, line=%d address present is %ld region%d \n",address, index1, file,line,leakInfo->address,region);
363 printf("\n Last Del file %s line %d\n",leakInfo->lastDelFileName,
364 leakInfo->lastDelLineNum);
366 if(leakInfo->prevRemFileName != NULLP)
368 printf("Previous File:%s, Previous Line:%d\n",
369 leakInfo->prevRemFileName, leakInfo->prevRemLineNo);
374 void DumpT2kMemLeakInfoToFile()
377 T2kMeamLeakInfo *leakInfo;
379 FILE *fp = fopen("memLeakInfo_reg.txt","wb");
383 printf("Could not open file for dumping mem leak info\n");
386 for(reg=0; reg <regMemLeakInfo.numActvRegions; reg++)
388 fprintf(fp, "REGION %d LEAKS START\n",reg);
391 for(i = 0; i< T2K_MEM_LEAK_INFO_TABLE_SIZE; i++)
393 leakInfo = (((T2kMeamLeakInfo*)(regMemLeakInfo.gMemLeakInfo[reg])) + i);
394 if(leakInfo->address != 0)
396 char* onlyFileName = rindex(leakInfo->fileName,'/');
397 if(onlyFileName == NULL)
399 onlyFileName = leakInfo->fileName;
402 fprintf(fp, "%ld s=%d a=%d l=%d f=%s\n",leakInfo->address,
409 fprintf(fp, "REGION %d LEAKS END\n",reg);
411 fprintf(fp,"Current t2kMemAllocTick = %d\n",t2kMemAllocTick);
415 #endif /* T2K_MEM_LEAK_DBG */
417 /* cm_mem_c_008.104 - Addition for memory calculator tool */
419 PRIVATE Txt prntBuf[200]; /* print buffer */
420 PRIVATE U8 tryHeap=0;
423 /* cm_mem_c_001.main_12 - addition for ssi enhancements prints */
424 /* cm_mem_c_001.main_20 Additions */
425 #if (defined(SSI_DEBUG_LEVEL1) || defined(SS_HISTOGRAM_SUPPORT) || \
426 defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
428 PRIVATE Txt dbgPrntBuf[200]; /* print buffer */
430 #endif /*SSI_DEBUG_LEVEL1 || SS_HISTOGRAM_SUPPORT */
433 #ifdef SSI_MEM_CORR_PREVENTION
434 U32 cmDblFreeAttempts = 0;
436 /* private variable declarations */
443 * Desc: Configure the memory region for allocation. The function
444 * registers the memory region with System Service by calling
448 * Ret: ROK - successful,
449 * RFAILED - unsuccessful.
451 * Notes: The memory owner calls this function to initialize the memory
452 * manager with the information of the memory region. Before
453 * calling this function, the memory owner should allocate memory
454 * for the memory region. The memory owner should also provide the
455 * memory for the control block needed by the memory manager. The
456 * memory owner should allocate the memory for the region control
457 * block as cachable memory. This may increase the average
458 * throughput in allocation and deallocation as the region control
459 * block is mostly accessed by the CMM.
472 S16 cmMmRegInit(region, regCb, cfg)
482 #if (ERRCLASS & ERRCLS_INT_PAR)
485 Txt errMsg[256] = {'\0'};
487 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
493 #if (ERRCLASS & ERRCLS_INT_PAR)
495 /* error check on parameters */
496 if ((regCb == NULLP) || (cfg == NULLP))
501 /* Error check on the configuration fields */
502 if ((!cfg->size) || (cfg->vAddr == NULLP) ||
503 (cfg->numBkts > CMM_MAX_BKT_ENT))
507 /* Check if the quantum size is power of 2 */
508 if ((cfg->numBkts) &&
509 ((cfg->bktQnSize - 1) & (cfg->bktQnSize)))
511 /* cm_mem_c_001.main_20 Addition */
512 sprintf(errMsg,"\n cmMmRegInit() failed, check if BktQuantum size might not be power of 2 \n");
518 * Check if the size of the memory region is enough, whether bucket sizes
519 * are multiples of quantumn size, and also whether two consecutive buckets
520 * falls within same quanta.
522 lstQnSize = cfg->bktQnSize;
525 for ( bktIdx =0; bktIdx < cfg->numBkts; bktIdx++)
527 /* check if bucket size is mutiple of quantum size */
528 if (cfg->bktCfg[bktIdx].size % cfg->bktQnSize)
530 /* cm_mem_c_001.main_20 Addition */
531 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
533 sprintf(errMsg,"\n cmMmRegInit() failed, Bkt:%d size:%u not multiple of quantum size:%u\
534 \n",bktIdx,cfg->bktCfg[bktIdx].size,cfg->bktQnSize);
536 sprintf(errMsg,"\n cmMmRegInit() failed, Bkt:%d size:%lu not multiple of quantum size:%lu\
537 \n",bktIdx,cfg->bktCfg[bktIdx].size,cfg->bktQnSize);
543 if ((bktBlkSize = cfg->bktCfg[bktIdx].size) < lstQnSize)
546 * Two consecutive buckets are not separated by quantum size.
548 /* cm_mem_c_001.main_20 Addition */
549 sprintf(errMsg,"\n cmMmRegInit() failed, Two consecutive buckets are not separated by quantum size \n");
553 /* cm_mem_c_001.main_20 Addition */
554 if (((cfg->bktCfg[bktIdx].size) /\
555 cfg->bktQnSize) > CMM_MAX_MAP_ENT)
557 /* Error check whether the size of the mapping table is sufficient */
558 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
560 sprintf(errMsg,"\n cmMmRegInit() failed, check maxBucketSize/BktQuantumSize(%u)\
561 \n should be less than CMM_MAX_MAP_ENT:%d \n",cfg->bktQnSize,CMM_MAX_MAP_ENT);
563 sprintf(errMsg,"\n cmMmRegInit() failed, check maxBucketSize/BktQuantumSize(%lu)\
564 \n should be less than CMM_MAX_MAP_ENT:%d \n",cfg->bktQnSize,CMM_MAX_MAP_ENT);
571 regCb->bktSize += (cfg->bktCfg[bktIdx].size *
572 cfg->bktCfg[bktIdx].numBlks);
574 if (regCb->bktSize > cfg->size)
576 /* Size of the memory region is less than the required size */
578 sprintf(errMsg,"\n cmMmRegInit() failed, Size of the memory region is less than the required size \n");
583 lstQnSize = ((bktBlkSize / cfg->bktQnSize) + 1) * cfg->bktQnSize;
588 /* Initialize the region control block */
589 regCb->region = region;
590 regCb->regInfo.regCb = regCb;
591 regCb->regInfo.start = cfg->vAddr;
592 regCb->regInfo.size = cfg->size;
595 avail_size = cfg->size;
596 #endif /* USE_PURE */
598 if ( cfg->chFlag & CMM_REG_OUTBOARD)
600 /* Out_of_board memory */
601 regCb->regInfo.flags = CMM_REG_OUTBOARD;
605 regCb->regInfo.flags = 0;
609 /* Initialize the memory manager function handlers */
610 /*cm_mem_c_001.main_21-registering new alloc function for new region*/
612 if(region == SS_WL_REGION)
614 regCb->regInfo.alloc = cmAllocWL;
615 regCb->regInfo.free = cmFreeWL;
620 /* Initialize the memory manager function handlers */
621 regCb->regInfo.alloc = cmAlloc;
622 regCb->regInfo.free = cmFree;
624 regCb->regInfo.ctl = cmCtl;
626 /* Initialize the physical address */
627 if ((regCb->chFlag = cfg->chFlag) & CMM_REG_PHY_VALID)
629 regCb->pAddr = cfg->pAddr;
632 /* Initial address of the memory region block */
633 memAddr = cfg->vAddr;
635 /* Initialize the fields related to the bucket pool */
636 regCb->bktMaxBlkSize = 0;
639 if (cfg->numBkts > 0 && cfg->numBkts < CMM_MAX_BKT_ENT)
641 /* Last bucket has the maximum size */
642 regCb->bktMaxBlkSize = cfg->bktCfg[cfg->numBkts - 1].size;
644 /* Get the power of the bktQnSize */
646 while( !((cfg->bktQnSize >> regCb->bktQnPwr) & 0x01))
651 /* Initilaize the bktIndex of the map entries to FF */
652 for ( lstMapIdx = 0; lstMapIdx < CMM_MAX_MAP_ENT; lstMapIdx++)
654 regCb->mapTbl[lstMapIdx].bktIdx = 0xFF;
658 for ( bktIdx = 0; bktIdx < cfg->numBkts; bktIdx++)
660 /* Allocate the lock for the bucket pool */
661 /* cm_mem_c_001.main_13 : Replaced SInitLock with WTInitLock for NT */
663 if (WTInitLock (&(regCb->bktTbl[bktIdx].bktLock), cfg->lType) != ROK)
665 if (SInitLock (&(regCb->bktTbl[bktIdx].bktLock), cfg->lType) != ROK)
668 /* Free the initialzed lock for the earlier buckets. */
671 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
672 WTDestroyLock for NT */
673 /* cm_mem_c_001.main_24 fix for memory corruption*/
676 WTDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
678 SDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
685 cmMmBktInit( &memAddr, regCb, cfg, bktIdx, &lstMapIdx);
688 /* Used while freeing the bktLock in cmMmRegDeInit */
689 regCb->numBkts = cfg->numBkts;
693 * Initialize the heap pool if size the memory region region is more
694 * than the size of the bucket pool
697 regCb->heapFlag = FALSE;
699 /* Align the memory address */
700 memAddr = (Data *)(PTRALIGN(memAddr));
702 regCb->heapSize = cfg->vAddr + cfg->size - memAddr;
705 * Round the heap size so that the heap size is multiple
708 regCb->heapSize -= (regCb->heapSize % CMM_MINBUFSIZE);
712 /* Allocate the lock for the heap pool */
713 /* cm_mem_c_001.main_13 : Replaced SInitLock with WTInitLock for NT */
715 if (WTInitLock (®Cb->heapCb.heapLock, cfg->lType) != ROK)
717 if (SInitLock (®Cb->heapCb.heapLock, cfg->lType) != ROK)
720 bktIdx = cfg->numBkts;/* ccpu00125353: warning fix */
723 /* Free the initialzed locks of the buckets */
726 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
727 WTDestroyLock for NT */
728 /* cm_mem_c_001.main_24 fix for memory corruption*/
731 WTDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
733 SDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
741 regCb->heapFlag = TRUE;
742 cmMmHeapInit(memAddr, &(regCb->heapCb), regCb->heapSize);
745 /* Call SRegRegion to register the memory region with SSI */
746 if (SRegRegion(region, ®Cb->regInfo) != ROK)
751 /* cm_mem_c_001.main_12 - addition for initializing the hash table */
752 #ifdef SSI_DEBUG_LEVEL1
753 /* Initialize the region level hash table for debug info storage */
754 if (cmMmHashListInit(®Cb->hashListCp, CMM_STAT_HASH_TBL_LEN, region, 0) != ROK)
758 #endif /* SSI_DEBUG_LEVEL1 */
759 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
760 /* Initialize the hast list to maintain the SSI memory information for Broadcom */
761 offset = (U16)((PTR)(&ptrHdr.ent) - (PTR) &ptrHdr);
762 printf("###########offset is %d region %d\n", offset, region);
763 if(cmHashListInit(®Cb->brdcmSsiLstCp, 1000, offset, FALSE,
764 CM_HASH_KEYTYPE_U32MOD, region, 0) != ROK)
768 #endif /* SSI_DEBUG_LEVEL1 */
771 } /* end of cmMmRegInit*/
779 * Desc: Deinitialize the memory region. The function call SDeregRegion
780 * to deregister the memory region with System Service.
783 * Ret: ROK - successful
784 * RFAILED - unsuccessful.
786 * Notes: The memory owner calls this function to deinitialize the region.
787 * The memory manager does not return the memory to the system.
788 * Before calling this function, the memory owner must be sure that
789 * no layer is using any memory block from this region. On
790 * successful return from the function, any request to the memory
791 * manager to allocate/deallocate memory will fail. The memory owner
792 * can reuse the memory for other region or return the memory to the
793 * system memory pool.
806 S16 cmMmRegDeInit(regCb)
813 #if (ERRCLASS & ERRCLS_INT_PAR)
815 /* error check on parameters */
823 /* cm_mem_c_001.main_12 - addition for deinitializing the hash table */
824 #ifdef SSI_DEBUG_LEVEL1
825 /* Deinitialize the hash table used for debug info storage at region level */
826 if (cmMmHashListDeinit(®Cb->hashListCp, regCb->region, 0) != ROK)
830 #endif /* SSI_DEBUG_LEVEL1 */
831 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
832 /* Deinitialize the hash table used for broadcom ssi instrumentation */
833 if (cmHashListDeinit(®Cb->brdcmSsiLstCp) != ROK)
839 /* Call SDeregRegion first to deregister the memory region with SSI */
840 (Void) SDeregRegion (regCb->region);
844 /* Bucket pool is configured */
846 /* Free the initialzed locks of the buckets */
847 for ( bktIdx = regCb->numBkts; bktIdx > 0;)
849 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
850 WTDestroyLock for NT */
851 /* cm_mem_c_001.main_24 fix for memory corruption*/
854 WTDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
856 SDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
858 /* cm_mem_c_001.main_15:Additions */
859 #ifdef SS_HISTOGRAM_SUPPORT
860 /* De-initialise the memory histogram hash list */
861 cmHstGrmHashListDeInit(&(regCb->bktTbl[bktIdx].hstGrmHashListCp));
862 #endif /* SS_HISTOGRAM_SUPPORT */
868 /* Heap pool is configured */
870 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
871 WTDestroyLock for NT */
873 WTDestroyLock(®Cb->heapCb.heapLock);
875 SDestroyLock(®Cb->heapCb.heapLock);
881 } /* end of cmMmRegDeInit */
883 #ifdef CM_MEM_OVERUSED
884 #define OVERUSED(_bkt) (((_bkt)->numAlloc * 100) / (_bkt)->numBlks > 80)
886 int g_overused[5] = {0};
889 #ifdef CM_MEM_PRINT_DEFINED
890 volatile int gSubIndex = 0;
891 int regAllocBktSts[10][2][6]={{0}};
892 int regFreeBktSts[10][2][6]={{0}};
899 * Desc: Allocate a memory block for the memory region.
902 * Ret: ROK - successful
903 * RFAILED - unsuccessful.
906 * The function allocates a memory block of size atleast equal to
907 * the requested size. The size parameter will be updated with the
908 * actual size of the memory block allocated for the request. The
909 * CMM tries to allocate the memory block form the bucket pool. If
910 * there is no memory in the bucket the CMM allocates the memory
911 * block form the heap pool. This function is always called by the
912 * System Service module.
914 * The caller of the function should try to use the out value of
915 * the size while returning the memory block to the region. However
916 * the current design of the memory manager does not enforce to pass
917 * the actual size of the memory block. (Due to the SGetSBuf
918 * semantics the layer will not able to pass the correct size of the
919 * memory block while calling SPutSBuf).
925 /* cm_mem_c_001.main_12 - addition to accept new parameter memType(static/dynamic) */
927 /* cm_mem_c_001.main_15 : Additions */
928 #ifdef SS_HISTOGRAM_SUPPORT
929 #ifdef SSI_DEBUG_LEVEL1
944 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, memType, line, fileName, entId, hstReg)
969 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, line, fileName, entId, hstReg)
979 #endif /* SSI_DEBUG_LEVEL1 */
981 #ifdef SS_LIGHT_MEM_LEAK_STS
994 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr ,memType, lineNo, funcName)
1003 #else /*SS_LIGHT_MEM_LEAK_STS */
1004 #ifdef SSI_DEBUG_LEVEL1
1015 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, memType)
1023 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1034 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, memType)
1042 #ifdef T2K_MEM_LEAK_DBG
1062 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr)
1069 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
1070 #endif /* SSI_DEBUG_LEVEL1 */
1071 #endif /*SS_LIGHT_MEM_LEAK_STS */
1072 /* cm_mem_c_001.main_15: Additions */
1073 #endif /* SS_HISTOGRAM_SUPPORT */
1076 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
1082 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
1086 /* cm_mem_c_001.main_15 : Additions */
1087 #if (defined(SS_MEM_LEAK_STS) || defined( BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1089 #endif /* SS_MEM_LEAK_STS */
1090 /* cm_mem_c_001.main_12 - addition to hold the allocated block */
1091 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
1092 CmMmBlkHdr *alocBlk;
1093 #endif /* SSI_DEBUG_LEVEL1 */
1094 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1097 /* cm_mem_c_001.main_15 : Additions */
1098 #ifdef SS_HISTOGRAM_SUPPORT
1100 #endif /* SS_HISTOGRAM_SUPPORT */
1101 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
1115 /* cm_mem_c_001.main_15 : Additions */
1116 #if (defined(SS_MEM_LEAK_STS) || defined( BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1118 #endif /* SS_MEM_LEAK_STS */
1120 regCb = (CmMmRegCb *)regionCb;
1122 #if (ERRCLASS & ERRCLS_INT_PAR)
1124 /* error check on parameters */
1125 if ((regCb == NULLP) || (size == NULLP) || !(*size) || (ptr == NULLP))
1131 /* cm_mem_c_001.main_12 - addition for checking memType parameter */
1132 #ifdef SSI_DEBUG_LEVEL1
1133 #if (ERRCLASS & ERRCLS_INT_PAR)
1134 if ((memType != CMM_STATIC_MEM_FLAG) && (memType != CMM_DYNAMIC_MEM_FLAG))
1138 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
1139 #endif /* SSI_DEBUG_LEVEL1 */
1146 /* cm_mem_c_001.main_12 - addition to insert the size into hash list */
1147 #ifdef SSI_DEBUG_LEVEL1
1148 /* Update the hash list */
1149 if (cmMmHashListInsert(&(regCb->hashListCp), *size) != ROK)
1151 /* display that, this entry could not be made in the hash list */
1153 /* display an error message here */
1154 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1156 sprintf(dbgPrntBuf, "\n Could not make an entry for size %u in hash table of region %d \n",
1157 *size, regCb->region);
1159 sprintf(dbgPrntBuf, "\n Could not make an entry for size %lu in hash table of region %d \n",
1160 *size, regCb->region);
1162 SDisplay(0, dbgPrntBuf);
1165 #endif /* SSI_DEBUG_LEVEL1 */
1168 * Check if the requested size is less than or equal to the maximum block
1169 * size in the bucket.
1171 if ( *size <= regCb->bktMaxBlkSize)
1173 /* Get the map to the mapping table */
1174 idx = ((*size - 1) >> regCb->bktQnPwr);
1176 #if (ERRCLASS & ERRCLS_DEBUG)
1177 if (regCb->mapTbl[idx].bktIdx == 0xFF)
1179 /* Some fatal error in the map table initialization. */
1184 /* Dequeue the memory block and return it to the user */
1185 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
1188 /* While loop is introduced to use the "break statement inside */
1192 * Check if the size request is not greater than the size available
1195 if (*size > bkt->size)
1197 /* Try to go to the next bucket if available */
1198 if((idx < (CMM_MAX_MAP_ENT - 1)) &&
1199 (regCb->mapTbl[++idx].bktIdx != 0xFF))
1201 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
1205 /* This is the last bucket, try to allocate from heap */
1210 /* Acquire the bucket lock */
1211 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
1213 (Void) WTLock(&(bkt->bktLock));
1215 (Void) SLock(&(bkt->bktLock));
1217 #ifdef XEON_SPECIFIC_CHANGES
1218 CM_MEM_ALLOC_STS(regCb->region, idx);
1221 #if (ERRCLASS & ERRCLS_DEBUG)
1222 regCb->mapTbl[idx].numReq++;
1223 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
1225 /* cm_mem_c_001.main_12 - addition for sanity check before allocation */
1226 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1227 /* increment the allocation attempt counter at bucket level */
1228 bkt->numAllocAttempts++;
1230 /* detect trampling if any and call sanity check. This is done for (bkt->nextBlk) as
1231 the allocation is always from (bkt->nextBlk) */
1234 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1235 if(cmMmRegIsBlkSane(bkt->nextBlk, bkt->size) != ROK)
1237 if (cmMmRegIsBlkSane(bkt->nextBlk) != ROK)
1240 /* detected a trampled memory block in this bucket */
1242 /* display an error message here */
1243 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1245 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %u bytes \n",
1246 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
1248 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %lu bytes \n",
1249 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
1251 SDisplay(0, dbgPrntBuf);
1254 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1255 if (cmMmBktSanityChk(bkt) == RTRAMPLINGNOK)
1257 /* Release the lock */
1258 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1260 (Void) WTUnlock(&(bkt->bktLock));
1262 (Void) SUnlock(&(bkt->bktLock));
1264 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
1265 return (RTRAMPLINGNOK);
1270 /* Release the lock */
1271 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1273 (Void) WTUnlock(&(bkt->bktLock));
1275 (Void) SUnlock(&(bkt->bktLock));
1277 /* return RFAILED */
1282 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr)); /* ccpu00125353: warning fix */
1283 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1284 ptrHdr = (CmMmBlkHdr *)bkt->nextBlk;
1286 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1287 /* Initialize the elements with 0xAB */
1288 memset(*ptr, 0xAB, *size);
1290 // printf("Pointer allocated %8p size %d\n", *ptr, *size);
1291 /* Store this pointer in hash list */
1292 if ((bkt->nextBlk) && *ptr)
1293 #elif SS_LIGHT_MEM_LEAK_STS
1294 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr)); /* ccpu00125353: warning fix */
1295 if ((bkt->nextBlk) && *ptr)
1297 *ptr = bkt->next;/* ccpu00125353: warning fix */
1299 #endif /* SSI_DEBUG_LEVEL1 */
1301 /* cm_mem_c_001.main_12 - addition for header */
1302 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
1303 /* point to next block header */
1304 alocBlk = bkt->nextBlk;
1305 bkt->nextBlk = (CmMmBlkHdr *)(bkt->nextBlk->nextBlk);
1307 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
1308 if(bkt->size == 128)
1310 memIndex = (*ptr - startPtr128) / 128;
1312 if(bkt->size == 256)
1314 memIndex = (*ptr - startPtr256) / 256;
1317 if (*((U32 *)(*ptr + 4)) != 0xDEADDEAD && *((U32 *)(*ptr + 80)) != 0xDEADDEAD && *((U32 *)(*ptr + 24)) != 0xDEADDEAD)
1320 if(bkt->size == 256)
1325 #endif /* MS_MBUF_CORRUPTION */
1326 #ifdef SSI_MEM_CORR_PREVENTION
1327 *(((U32 *)(*ptr)) + 2) = 0;
1330 #ifdef T2K_MEM_LEAK_DBG
1333 /* Lock before the transaction-start */
1334 pthread_mutex_lock(&(regMemLeakInfo.memLock[regCb->region]));
1335 InsertToT2kMemLeakInfo( (U64)*ptr,*size,line,file,regCb->region);
1336 /* UnLock after the transaction */
1337 pthread_mutex_unlock(&(regMemLeakInfo.memLock[regCb->region]));
1339 #endif /* T2K_MEM_LEAK_DBG */
1341 bkt->next = *((CmMmEntry **)(bkt->next));
1342 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
1343 *nextptr = bkt->next;
1344 if (*((U32 *)(*nextptr + 4)) != 0xDEADDEAD && *((U32 *)(*nextptr + 80)) != 0xDEADDEAD && *((U32 *)(*nextptr + 24)) != 0xDEADDEAD)
1346 if(bkt->size == 128)
1347 *prevptr = startPtr128 + ((memIndex-1)*128);
1348 if(bkt->size == 256)
1349 *prevptr = startPtr256 + ((memIndex-1)*256);
1350 if(bkt->size == 128)
1351 memIndex = (*nextptr - startPtr128) / 128;
1352 if(bkt->size == 256)
1353 memIndex = (*nextptr - startPtr256) / 256;
1357 if(bkt->size == 128)
1359 memIndex = (*ptr - startPtr128) / 128;
1360 cmMemInfo128[memIndex][0] = cmAllocCaller[MxGetCpuID()];
1362 if(bkt->size == 256)
1364 memIndex = (*ptr - startPtr256) / 256;
1365 cmMemInfo256[memIndex][0] = cmAllocCaller[MxGetCpuID()];
1367 cmAllocCaller[MxGetCpuID()] = NULLP;
1368 *((U32 *)(*ptr + 4)) = 0x00000000;
1369 *((U32 *)(*ptr + 124)) = 0;
1370 *((U32 *)(*ptr + 24)) = 0x00000000;
1371 *((U32 *)(*ptr + 44)) = 0x00000000;
1372 *((U32 *)(*ptr + 80)) = 0x00000000;
1373 *((U32 *)(*ptr + 116)) = 0x00000000;
1375 #endif /* SSI_DEBUG_LEVEL1 */
1377 /* cache_coherency_changes */
1382 * Increment the statistics variable of number of memory block
1386 if (bkt->numAlloc > bkt->maxAlloc)
1388 bkt->maxAlloc = bkt->numAlloc;
1390 #ifdef CM_MEM_OVERUSED
1392 if (g_overused[bktIdx] == 0 && OVERUSED(bkt))
1394 g_overused[bktIdx] = 1;
1395 /*printf("cmAlloc: bktIdx %u overused %u numAlloc %u\n", bktIdx, g_overused[bktIdx], bkt->numAlloc); */
1399 /* cm_mem_c_001.main_12 - addition for header manipulation */
1400 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1401 /* update the size for which this memory block has been allocated */
1402 alocBlk->requestedSize = *size;
1403 /* update the memory block header */
1404 CMM_RESET_FREE_FLAG(alocBlk->memFlags);
1405 if (memType == CMM_STATIC_MEM_FLAG)
1407 CMM_SET_STATIC_FLAG(alocBlk->memFlags);
1408 /* add it to the static memory allocated */
1409 bkt->staticMemUsed += bkt->size;
1413 CMM_SET_DYNAMIC_FLAG(alocBlk->memFlags);
1414 /* add it to the dynamic memory allocated */
1415 bkt->dynamicMemUsed += bkt->size;
1417 #elif SS_LIGHT_MEM_LEAK_STS
1418 alocBlk->requestedSize = *size;
1419 alocBlk->lineNo = lineNo;
1420 alocBlk->currFuncName = funcName;
1421 if(gmemLkCb.isStarted == TRUE)
1423 alocBlk->allocQueueIndx = cmStorAllocBlk(alocBlk);
1425 #endif /* SSI_DEBUG_LEVEL1 */
1427 if (((bkt->size - (*size)) >> regCb->bktQnPwr) && flags)
1431 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1434 "[MEM_CAL_CNTA] %u bytes request not fitted in bkt %d [size %u bytes] %u times\n", *size, regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktNoFitCnt++);
1437 "[MEM_CAL_CNTA] %lu bytes request not fitted in bkt %d [size %lu bytes] %lu times\n", *size, regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktNoFitCnt++);
1439 SDisplay(0, prntBuf);
1447 "SGetSBuf:%08lu:Size Bucket Id:%03d Times:%05lu Pointer: %8p\n",
1448 *size, regCb->mapTbl[idx].bktIdx, num_times, *ptr);
1449 SDisplay(0, prntBuf);
1451 #endif /* MEMCAL_DEBUG */
1452 /* cm_mem_c_001.main_15 : Additions */
1453 #ifdef SS_HISTOGRAM_SUPPORT
1454 /* If If Tapa task (entId)is registerd for histogram then insert Memrory allocated
1455 * information into the hash list */
1458 if (cmHstGrmAllocInsert(&(bkt->hstGrmHashListCp), bkt->size, size, line, fileName, entId) != ROK)
1460 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
1465 #endif /* SS_HISTOGRAM_SUPPORT */
1467 /* Update the size parameter */
1469 #ifdef SS_MEM_LEAK_STS
1470 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
1471 cmStorAllocBlk((PTR)*ptr, (Size) reqSz, (Size) *size,
1472 regCb->mapTbl[idx].bktIdx);
1473 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1474 cmStorAllocBlk(ptrHdr, (Size)reqSz, (Size) *size,
1475 regCb->mapTbl[idx].bktIdx, regCb);
1476 #endif /* SS_MEM_LEAK_STS */
1478 /* cm_mem_c_008.104 - Addition for memory calculator tool */
1480 /* Release the lock */
1481 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1483 (Void) WTUnlock(&(bkt->bktLock));
1485 (Void) SUnlock(&(bkt->bktLock));
1494 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1497 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %u bytes], %u times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
1500 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %lu bytes], %lu times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
1502 SDisplay(0, prntBuf);
1506 #if (ERRCLASS & ERRCLS_DEBUG)
1507 regCb->mapTbl[idx].numFailure++;
1508 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
1510 /* Release the lock */
1511 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1513 (Void) WTUnlock(&(bkt->bktLock));
1515 (Void) SUnlock(&(bkt->bktLock));
1524 regCb->heapCb.heapAllocCnt++;
1526 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1529 "[MEM_CAL_CNTC] No bucket block configured for %u bytes \n Number of blocks allocated from heap = %u\n",*size,
1530 regCb->heapCb.heapAllocCnt);
1533 "[MEM_CAL_CNTC] No bucket block configured for %lu bytes \n Number of blocks allocated from heap = %lu\n",*size,
1534 regCb->heapCb.heapAllocCnt);
1536 SDisplay(0, prntBuf);
1541 /* Memory not available in the bucket pool */
1542 if (regCb->heapFlag && (*size < regCb->heapSize))
1545 if (flags) tryHeap = 1;
1548 * The heap memory block is available. Allocate the memory block from
1551 /* cm_mem_c_001.main_15: Additions */
1552 #ifdef SS_HISTOGRAM_SUPPORT
1553 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
1554 #ifdef SSI_DEBUG_LEVEL1
1555 return (cmHeapAlloc(&(regCb->heapCb), ptr, size, memType, line, fileName, entId, hstReg));
1557 return (cmHeapAlloc(&(regCb->heapCb), ptr, size, line, fileName, entId, hstReg));
1558 #endif /* SSI_DEBUG_LEVEL1 */
1560 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
1561 #ifdef SSI_DEBUG_LEVEL1
1562 return (cmHeapAlloc(&(regCb->heapCb), ptr, size, memType));
1564 return (cmHeapAlloc(&(regCb->heapCb), ptr, size));
1565 #endif /* SSI_DEBUG_LEVEL1 */
1566 #endif /* SS_HISTOGRAM_SUPPORT */
1569 /* No memory available */
1571 #else /* use pure is on */
1572 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
1573 #ifdef SS_4GMX_LCORE
1574 *ptr = (Data*) MxHeapAlloc(SsiHeap, *size);
1575 memset(ptr, 0, *size);
1577 *ptr = (Data*) malloc(*size);
1579 if ( (*ptr) == NULLP)
1581 avail_size -= *size;
1583 #endif /* USE_PURE */
1585 } /* end of cmAlloc */
1592 * Desc: Return the memory block for the memory region.
1595 * Ret: ROK - successful
1596 * RFAILED - unsuccessful.
1598 * Notes: The user calls this function to return the previously allocated
1599 * memory block to the memory region. The memory manager does not
1600 * check the validity of the state of the memory block(like whether
1601 * it was allocated earlier). The caller must be sure that, the
1602 * address specified in the parameter 'ptr' is valid and was
1603 * allocated previously from same region.
1610 /* cm_mem_c_001.main_15 : Additions */
1611 #ifdef SS_LIGHT_MEM_LEAK_STS
1622 PRIVATE S16 cmFree(regionCb, ptr, size, lineNo, funcName)
1629 #else /*SS_LIGHT_MEM_LEAK_STS */
1630 #ifdef SS_HISTOGRAM_SUPPORT
1643 PRIVATE S16 cmFree(regionCb, ptr, size, line, fileName, entId, hstReg)
1654 #ifdef T2K_MEM_LEAK_DBG
1663 #else /* T2K_MEM_LEAK_DBG */
1672 PRIVATE S16 cmFree(regionCb, ptr, size)
1678 /* cm_mem_c_001.main_15 : Additions */
1679 #endif /* SS_HISTOGRAM_SUPPORT */
1680 #endif /*SS_LIGHT_MEM_LEAK_STS */
1683 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
1689 /* cm_mem_c_001.main_12 - addition for holding the free pointer */
1690 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
1692 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1693 CmMmBlkHdr *lastHdr;
1695 #endif /* SSI_DEBUG_LEVEL1 */
1696 /* cm_mem_c_001.main_15 : Additions */
1697 #ifdef SS_HISTOGRAM_SUPPORT
1699 #endif /* SS_HISTOGRAM_SUPPORT */
1700 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption*/
1705 regCb = (CmMmRegCb *)regionCb;
1708 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1709 /* Check if the memory block is from the memory region */
1710 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
1711 ((CmMmRegCb *)regCb)->regInfo.size)
1716 #if (ERRCLASS & ERRCLS_INT_PAR)
1718 /* error check on parameters */
1719 if ((regCb == NULLP) || (!size) || (ptr == NULLP))
1724 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1725 /* Check if the memory block is from the memory region */
1726 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
1727 ((CmMmRegCb *)regCb)->regInfo.size)
1732 /* cm_mem_c_001.main_20 Addition */
1733 if (ptr < regCb->regInfo.start)
1741 * Check if the memory block was allocated from the bucket pool.
1744 if (ptr < (regCb->regInfo.start + regCb->bktSize))
1746 #ifdef T2K_MEM_LEAK_DBG
1748 pthread_mutex_lock(&(regMemLeakInfo.memLock[regCb->region]));
1749 RemoveFromT2kMemLeakInfo((U64)ptr , file,line,regCb->region);
1750 pthread_mutex_unlock(&(regMemLeakInfo.memLock[regCb->region]));
1753 /* The memory block was allocated from the bucket pool */
1755 /* Get the map to the mapping table */
1756 idx = ((size - 1) >> regCb->bktQnPwr);
1758 #if (ERRCLASS & ERRCLS_DEBUG)
1759 if (regCb->mapTbl[idx].bktIdx == 0xFF)
1761 /* Some fatal error in the map table initialization. */
1766 /* Enqueue the memory block and return it to the user */
1767 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
1770 * Check if the size is not greater than the size available
1771 * in the bucket. If so, then the buffer must have been allocated
1772 * from next bucket. We don't need to check the validity of the
1773 * next bucket, otherwise buffer must have been allocated from heap
1776 if (size > bkt->size)
1778 bkt = &(regCb->bktTbl[regCb->mapTbl[++idx].bktIdx]);
1781 /* Acquire the bucket lock */
1782 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
1784 (Void) WTLock(&(bkt->bktLock));
1786 (Void) SLock(&(bkt->bktLock));
1788 #ifdef XEON_SPECIFIC_CHANGES
1789 CM_MEM_FREE_STS(regCb->region, idx);
1791 /* cache_coherency_changes */
1796 /* cm_mem_c_001.main_12 - addition for sanity check and free */
1797 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1798 /* increment the dealloc attempt counter at bucket level */
1799 bkt->numDeallocAttempts++;
1801 /* Check the memFlags to see whether this block was allocated */
1802 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
1803 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1804 cmRlsAllocBlk(ptrHdr, regCb);
1806 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1807 /* Check for ptr size */
1808 if(((ptrHdr->requestedSize - size) % size) != 0)
1811 sprintf(dbgPrntBuf, "Passed size (%d) does not match with allocated \
1812 size(%d) %8p, Bucket Id:%03d\n",
1813 size, ptrHdr->requestedSize, ptr, regCb->mapTbl[idx].bktIdx);
1815 printf("Passed size (%d) does not match with allocated \
1816 size(%d) %8p, Bucket Id:%03d\n",
1817 size, ptrHdr->requestedSize, ptr, regCb->mapTbl[idx].bktIdx);
1820 /* Validate the tail part to see if there is any over run */
1821 // printf("Pointer free request %8p, size %d\n", ptr, size);
1824 /* validate the block to be freed for trampling */
1825 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1826 if(cmMmRegIsBlkSane(ptrHdr, bkt->size) != ROK)
1828 if (cmMmRegIsBlkSane(ptrHdr) != ROK)
1831 /* Handle error case of Memory trampling */
1833 /* display an error message here */
1834 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1836 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %u bytes \n",
1837 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1839 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %lu bytes \n",
1840 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1842 SDisplay(0, dbgPrntBuf);
1846 * if sanity check returns RTRAMPLINGOK then there is nothing to do
1847 * as the memory blk is already invalidated in cmMmBktSanityChk
1849 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1850 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
1854 /* Release the lock */
1855 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1857 (Void) WTUnlock(&(bkt->bktLock));
1859 (Void) SUnlock(&(bkt->bktLock));
1868 * this is the case where in the entire bucket has been made unusable
1871 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1873 (Void) WTUnlock(&(bkt->bktLock));
1875 (Void) SUnlock(&(bkt->bktLock));
1878 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
1879 return (RTRAMPLINGNOK);
1881 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1882 printf("Memory signature is invalid\n");
1887 /* reset the size */
1888 ptrHdr->requestedSize = 0;
1889 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1890 /* Initialize the elements with 0xAB */
1891 memset(ptr, 0xAB, size);
1893 /* check if the block to be freed is already having the state as FREE */
1894 if (CMM_IS_FREE(ptrHdr->memFlags))
1896 /* Handle double deallocation error case */
1898 /* display an error message here */
1899 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1901 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p, Bucket Id:%03d, size %u bytes \n",
1902 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1904 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p, Bucket Id:%03d, size %lu bytes \n",
1905 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1907 SDisplay(0, dbgPrntBuf);
1910 /* Release the lock */
1911 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1913 (Void) WTUnlock(&(bkt->bktLock));
1915 (Void) SUnlock(&(bkt->bktLock));
1917 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1918 printf("Attempt to double deallocate memory at: %8p, Bucket Id:%03d,\
1919 size %u bytes \n", ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1922 /* handle RDBLFREE in SFree/SPutSBuf */
1925 if (CMM_IS_STATIC(ptrHdr->memFlags))
1927 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
1928 CMM_RESET_STATIC_FLAG(ptrHdr->memFlags);
1929 /* deduct it from the static memory count */
1930 bkt->staticMemUsed -= bkt->size;
1932 else if (CMM_IS_DYNAMIC(ptrHdr->memFlags))
1934 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
1935 CMM_RESET_DYNAMIC_FLAG(ptrHdr->memFlags);
1936 /* deduct it from the dynamic memory count */
1937 bkt->dynamicMemUsed -= bkt->size;
1941 /* This is a case similar to trampled memory */
1943 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1945 sprintf(dbgPrntBuf, "Invalid memory flag: %u !!!\n", ptrHdr->memFlags);
1947 sprintf(dbgPrntBuf, "Invalid memory flag: %lu !!!\n", ptrHdr->memFlags);
1949 SDisplay(0, dbgPrntBuf);
1951 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1952 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
1954 /* do not add to the free list */
1957 /* Release the lock */
1958 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1960 (Void) WTUnlock(&(bkt->bktLock));
1962 (Void) SUnlock(&(bkt->bktLock));
1970 * this is the case where in the entire bucket has been made unusable
1973 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1975 (Void) WTUnlock(&(bkt->bktLock));
1977 (Void) SUnlock(&(bkt->bktLock));
1980 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
1981 return (RTRAMPLINGNOK);
1984 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1985 /* Return the block to memory */
1986 ptrHdr->nextBlk = bkt->nextBlk;
1987 bkt->nextBlk = ptrHdr;
1989 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1990 /* Move the ptr to end of the bucket */
1991 lastHdr = (CmMmBlkHdr *)bkt->lastBlk;
1992 lastHdr->nextBlk = ptrHdr;
1993 bkt->lastBlk = ptrHdr;
1994 ptrHdr->nextBlk = NULLP;
1996 #elif SS_LIGHT_MEM_LEAK_STS
1997 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
1998 ptrHdr->lineNo = lineNo;
1999 ptrHdr->currFuncName = funcName;
2000 if(gmemLkCb.isStarted == TRUE)
2002 cmRlsAllocBlk(ptrHdr->allocQueueIndx);
2004 ptrHdr->nextBlk = bkt->nextBlk;
2005 bkt->nextBlk = ptrHdr;
2008 #ifndef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
2009 #ifdef SSI_MEM_CORR_PREVENTION
2010 if (*(((U32 *)(ptr)) + 2) == 0xdeaddead)
2012 /* Do not free an already freed block to avoid corruption */
2013 cmDblFreeAttempts++;
2018 *((CmMmEntry **)bkt->last) = ptr;
2019 bkt->last = (CmMmEntry *)ptr;
2020 *((CmMmEntry **)ptr) = NULLP;
2021 *(((U32 *)(ptr)) + 2) = 0xdeaddead;
2024 *((CmMmEntry **)ptr) = bkt->next;
2025 bkt->next = (CmMmEntry *)ptr;
2028 if(memFreeCount >= 125000)
2030 if(bkt->size == 128)
2032 Data *crashPtr=NULLP;
2033 if(((ptr - startPtr128) % 128) != 0)
2037 memIndex = (ptr - startPtr128) / 128;
2039 if(bkt->size == 256)
2041 Data *crashPtr=NULLP;
2042 if(((ptr - startPtr256) % 256) != 0)
2046 memIndex = (ptr - startPtr256) / 256;
2048 if(bkt->size == 512)
2050 Data *crashPtr=NULLP;
2051 if(((ptr - startPtr512) % 512) != 0)
2056 if(bkt->size == 768)
2058 Data *crashPtr=NULLP;
2059 if(((ptr - startPtr768) % 768) != 0)
2064 if(bkt->size == 1664)
2066 Data *crashPtr=NULLP;
2067 if(((ptr - startPtr1664) % 1664) != 0)
2072 if(bkt->size == 4800)
2074 Data *crashPtr=NULLP;
2075 if(((ptr - startPtr4800) % 4800) != 0)
2080 if(bkt->size == 9920)
2082 Data *crashPtr=NULLP;
2083 if(((ptr - startPtr9920) % 9920) != 0)
2088 if (*((U32 *)(ptr + 4)) != 0xDEADDEAD)
2090 *(U32 *)(ptr + 4) = 0xDEADDEAD;
2094 Data *crashPtr=NULLP;
2097 if (*((U32 *)(ptr + 24)) != 0xDEADDEAD)
2099 *(U32 *)(ptr + 24) = 0xDEADDEAD;
2103 Data *crashPtr=NULLP;
2106 if (*((U32 *)(ptr + 44)) != 0xDEADDEAD)
2108 *(U32 *)(ptr + 44) = 0xDEADDEAD;
2112 Data *crashPtr=NULLP;
2115 if (*((U32 *)(ptr + 80)) != 0xDEADDEAD)
2117 *(U32 *)(ptr + 80) = 0xDEADDEAD;
2121 Data *crashPtr=NULLP;
2123 /* Cause a crash to identify the caller */
2125 *(U32 *)(ptr + 124) = memFreeCount++;
2126 (*(U32 *)(ptr + 116)) = cmFreeCaller[MxGetCpuID()];
2127 if(bkt->size == 128)
2129 memIndex = (ptr - startPtr128) / 128;
2130 cmMemInfo128[memIndex][1] = cmFreeCaller[MxGetCpuID()];
2132 if(bkt->size == 256)
2134 memIndex = (ptr - startPtr256) / 256;
2135 cmMemInfo256[memIndex][1] = cmFreeCaller[MxGetCpuID()];
2137 cmFreeCaller[MxGetCpuID()] = NULLP;
2140 Reverted: Removed functionality to move freed buffer to end of free List in bucket.
2141 This is impacting throughput.
2144 *((CmMmEntry **)bkt->last) = ptr;
2145 bkt->last = (CmMmEntry *)ptr;
2146 *((CmMmEntry **)ptr) = NULLP;
2148 *((CmMmEntry **)ptr) = bkt->next;
2149 bkt->next = (CmMmEntry *)ptr;
2152 #endif /* SSI_DEBUG_LEVEL1 */
2154 /* cache_coherency_changes */
2159 * Decrement the statistics variable of number of memory block
2163 /* cm_mem_c_001.main_15 : Additions */
2164 #ifdef SS_HISTOGRAM_SUPPORT
2165 /* If If Tapa task (entId)is registerd for histogram then insert Memrory Freed
2166 * information into the hash list */
2169 if (cmHstGrmFreeInsert(&bkt->hstGrmHashListCp, bkt->size, line, fileName, entId) != ROK)
2171 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
2175 #endif /* SS_HISTOGRAM_SUPPORT */
2177 #ifdef SS_MEM_LEAK_STS
2178 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
2179 cmRlsAllocBlk((PTR)ptr);
2180 #endif /* SS_MEM_LEAK_STS */
2181 /* Release the lock */
2182 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
2184 (Void) WTUnlock(&(bkt->bktLock));
2186 (Void) SUnlock(&(bkt->bktLock));
2192 /* The memory block was allocated from the heap pool */
2193 /* cm_mem_c_001.main_15 : Additions */
2194 #ifdef SS_HISTOGRAM_SUPPORT
2195 return (cmHeapFree (&(regCb->heapCb), ptr, size, line, fileName, entId, hstReg));
2197 return (cmHeapFree (&(regCb->heapCb), ptr, size));
2198 #endif /* SS_HISTOGRAM_SUPPORT */
2199 #else /* use pure is on */
2200 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
2201 #ifdef SS_4GMX_LCORE
2202 (Void)MxHeapFree(SsiHeap, ptr);
2208 #endif /* USE_PURE */
2211 } /* end of cmFree */
2217 * Desc: Allocate a memory block for the memory region(No Lock).
2220 * Ret: ROK - successful
2221 * RFAILED - unsuccessful.
2224 * The function allocates a memory block of size atleast equal to
2225 * the requested size. The size parameter will be updated with the
2226 * actual size of the memory block allocated for the request. The
2227 * CMM tries to allocate the memory block form the bucket pool. If
2228 * there is no memory in the bucket the CMM allocates the memory
2229 * block form the heap pool. This function is always called by the
2230 * System Service module.
2232 * The caller of the function should try to use the out value of
2233 * the size while returning the memory block to the region. However
2234 * the current design of the memory manager does not enforce to pass
2235 * the actual size of the memory block. (Due to the SGetSBuf
2236 * semantics the layer will not able to pass the correct size of the
2237 * memory block while calling SPutSBuf).
2243 /* cm_mem_c_001.main_12 - addition to accept new parameter memType(static/dynamic) */
2245 /* cm_mem_c_001.main_15 : Additions */
2246 #ifdef SS_HISTOGRAM_SUPPORT
2247 #ifdef SSI_DEBUG_LEVEL1
2262 S16 cmAllocNL(regionCb, size, flags, ptr, memType,
2263 line, fileName, entId, hstReg)
2288 S16 cmAllocNL(regionCb, size, flags, ptr, line,
2289 fileName, entId, hstReg)
2299 #endif /* SSI_DEBUG_LEVEL1 */
2302 #ifdef SS_LIGHT_MEM_LEAK_STS
2315 S16 cmAllocNL(regionCb, size, flags, ptr ,memType, lineNo, funcName)
2324 #else /*SS_LIGHT_MEM_LEAK_STS */
2325 #ifdef SSI_DEBUG_LEVEL1
2336 S16 cmAllocNL(regionCb, size, flags, ptr, memType)
2344 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2355 S16 cmAllocNL(regionCb, size, flags, ptr, memType)
2372 S16 cmAllocNL(regionCb, size, flags, ptr)
2378 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
2379 #endif /* SSI_DEBUG_LEVEL1 */
2380 /* cm_mem_c_001.main_15: Additions */
2381 #endif /*SS_LIGHT_MEM_LEAK_STS */
2382 #endif /* SS_HISTOGRAM_SUPPORT */
2385 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
2391 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
2395 /* cm_mem_c_001.main_15 : Additions */
2396 #if (defined(SS_MEM_LEAK_STS) || defined( BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2398 #endif /* SS_MEM_LEAK_STS */
2399 /* cm_mem_c_001.main_12 - addition to hold the allocated block */
2400 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
2401 CmMmBlkHdr *alocBlk;
2402 #endif /* SSI_DEBUG_LEVEL1 */
2403 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2406 /* cm_mem_c_001.main_15 : Additions */
2407 #ifdef SS_HISTOGRAM_SUPPORT
2409 #endif /* SS_HISTOGRAM_SUPPORT */
2415 /* cm_mem_c_001.main_15 : Additions */
2416 #ifdef SS_MEM_LEAK_STS
2418 #endif /* SS_MEM_LEAK_STS */
2420 regCb = (CmMmRegCb *)regionCb;
2422 #if (ERRCLASS & ERRCLS_INT_PAR)
2424 /* error check on parameters */
2425 if ((regCb == NULLP) || (size == NULLP) || !(*size) || (ptr == NULLP))
2431 /* cm_mem_c_001.main_12 - addition for checking memType parameter */
2432 #ifdef SSI_DEBUG_LEVEL1
2433 #if (ERRCLASS & ERRCLS_INT_PAR)
2434 if ((memType != CMM_STATIC_MEM_FLAG) && (memType != CMM_DYNAMIC_MEM_FLAG))
2438 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
2439 #endif /* SSI_DEBUG_LEVEL1 */
2446 /* cm_mem_c_001.main_12 - addition to insert the size into hash list */
2447 #ifdef SSI_DEBUG_LEVEL1
2448 /* Update the hash list */
2449 if (cmMmHashListInsert(&(regCb->hashListCp), *size) != ROK)
2451 /* display that, this entry could not be made in the hash list */
2453 /* display an error message here */
2455 sprintf(dbgPrntBuf, "\n Could not make an entry for size %u \
2456 in hash table of region %d \n",
2457 *size, regCb->region);
2459 sprintf(dbgPrntBuf, "\n Could not make an entry for size %lu \
2460 in hash table of region %d \n",
2461 *size, regCb->region);
2463 SDisplay(0, dbgPrntBuf);
2466 #endif /* SSI_DEBUG_LEVEL1 */
2469 * Check if the requested size is less than or equal to the maximum block
2470 * size in the bucket.
2472 if ( *size <= regCb->bktMaxBlkSize)
2474 /* Get the map to the mapping table */
2475 idx = ((*size - 1) >> regCb->bktQnPwr);
2477 #if (ERRCLASS & ERRCLS_DEBUG)
2478 if (regCb->mapTbl[idx].bktIdx == 0xFF)
2480 /* Some fatal error in the map table initialization. */
2485 /* Dequeue the memory block and return it to the user */
2486 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
2489 /* While loop is introduced to use the "break statement inside */
2493 * Check if the size request is not greater than the size available
2496 if (*size > bkt->size)
2498 /* Try to go to the next bucket if available */
2499 if((idx < (CMM_MAX_MAP_ENT - 1)) &&
2500 (regCb->mapTbl[++idx].bktIdx != 0xFF))
2502 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
2506 /* This is the last bucket, try to allocate from heap */
2511 #if (ERRCLASS & ERRCLS_DEBUG)
2512 regCb->mapTbl[idx].numReq++;
2513 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2515 /* cm_mem_c_001.main_12 - addition for sanity check before allocation */
2516 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2517 /* increment the allocation attempt counter at bucket level */
2518 bkt->numAllocAttempts++;
2520 /* detect trampling if any and call sanity check. This is done for (bkt->nextBlk) as
2521 the allocation is always from (bkt->nextBlk) */
2524 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2525 if(cmMmRegIsBlkSane(bkt->nextBlk, bkt->size) != ROK)
2527 if (cmMmRegIsBlkSane(bkt->nextBlk) != ROK)
2530 /* detected a trampled memory block in this bucket */
2532 /* display an error message here */
2533 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
2535 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, \
2537 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
2539 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, \
2541 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
2543 SDisplay(0, dbgPrntBuf);
2547 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2548 if (cmMmBktSanityChk(bkt) == RTRAMPLINGNOK)
2550 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
2551 return (RTRAMPLINGNOK);
2555 /* return RFAILED */
2561 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr));
2562 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2563 ptrHdr = (CmMmBlkHdr *)bkt->nextBlk;
2565 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2566 /* Initialize the elements with 0xAB */
2567 memset(*ptr, 0xAB, *size);
2569 if ((bkt->nextBlk) && *ptr)
2570 #elif SS_LIGHT_MEM_LEAK_STS
2571 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr)); /* ccpu00125353: warning fix */
2572 if ((bkt->nextBlk) && *ptr)
2574 *ptr = bkt->next;/* ccpu00125353: warning fix */
2576 #endif /* SSI_DEBUG_LEVEL1 */
2578 /* cm_mem_c_001.main_12 - addition for header */
2579 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
2580 /* point to next block header */
2581 alocBlk = bkt->nextBlk;
2582 bkt->nextBlk = (CmMmBlkHdr *)(bkt->nextBlk->nextBlk);
2584 #ifdef SSI_MEM_CORR_PREVENTION
2585 *(((U32 *)(*ptr)) + 2) = 0;
2587 bkt->next = *((CmMmEntry **)(bkt->next));
2588 #endif /* SSI_DEBUG_LEVEL1 */
2590 /* cache_coherency_changes */
2595 * Increment the statistics variable of number of memory block
2599 if (bkt->numAlloc > bkt->maxAlloc)
2601 bkt->maxAlloc = bkt->numAlloc;
2603 #ifdef CM_MEM_OVERUSED
2605 if (g_overused[bktIdx] == 0 && OVERUSED(bkt))
2607 g_overused[bktIdx] = 1;
2611 /* cm_mem_c_001.main_12 - addition for header manipulation */
2612 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2613 /* update the size for which this memory block has been allocated */
2614 alocBlk->requestedSize = *size;
2615 /* update the memory block header */
2616 CMM_RESET_FREE_FLAG(alocBlk->memFlags);
2617 if (memType == CMM_STATIC_MEM_FLAG)
2619 CMM_SET_STATIC_FLAG(alocBlk->memFlags);
2620 /* add it to the static memory allocated */
2621 bkt->staticMemUsed += bkt->size;
2625 CMM_SET_DYNAMIC_FLAG(alocBlk->memFlags);
2626 /* add it to the dynamic memory allocated */
2627 bkt->dynamicMemUsed += bkt->size;
2629 #elif SS_LIGHT_MEM_LEAK_STS
2630 alocBlk->requestedSize = *size;
2631 alocBlk->lineNo = lineNo;
2632 alocBlk->currFuncName = funcName;
2633 if(gmemLkCb.isStarted == TRUE)
2635 alocBlk->allocQueueIndx = cmStorAllocBlk(alocBlk);
2637 #endif /* SSI_DEBUG_LEVEL1 */
2639 if (((bkt->size - (*size)) >> regCb->bktQnPwr) && flags)
2645 "[MEM_CAL_CNTA] %u bytes request not fitted in bkt %d \
2646 [size %u bytes] %u times\n",
2647 *size, regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktNoFitCnt++);
2650 "[MEM_CAL_CNTA] %lu bytes request not fitted in bkt %d \
2651 [size %lu bytes] %lu times\n",
2652 *size, regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktNoFitCnt++);
2654 SDisplay(0, prntBuf);
2662 "SGetSBuf:%08lu:Size Bucket Id:%03d Times:%05lu Pointer: %8p\n",
2663 *size, regCb->mapTbl[idx].bktIdx, num_times, *ptr);
2664 SDisplay(0, prntBuf);
2666 #endif /* MEMCAL_DEBUG */
2667 /* cm_mem_c_001.main_15 : Additions */
2668 #ifdef SS_HISTOGRAM_SUPPORT
2671 if (cmHstGrmAllocInsert(&(bkt->hstGrmHashListCp),
2672 bkt->size, size, line, fileName, entId) != ROK)
2674 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
2679 #endif /* SS_HISTOGRAM_SUPPORT */
2681 /* Update the size parameter */
2683 #ifdef SS_MEM_LEAK_STS
2684 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
2685 cmStorAllocBlk((PTR)*ptr, (Size) reqSz, (Size) *size,
2686 regCb->mapTbl[idx].bktIdx);
2687 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2688 cmStorAllocBlk(ptrHdr, (Size) reqSz, (Size) *size,
2689 regCb->mapTbl[idx].bktIdx, regCb);
2690 #endif /* SS_MEM_LEAK_STS */
2692 /* cm_mem_c_008.104 - Addition for memory calculator tool */
2702 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %u bytes], \
2703 %u times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
2706 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %lu bytes], \
2707 %lu times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
2709 SDisplay(0, prntBuf);
2713 #if (ERRCLASS & ERRCLS_DEBUG)
2714 regCb->mapTbl[idx].numFailure++;
2715 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2724 regCb->heapCb.heapAllocCnt++;
2728 "[MEM_CAL_CNTC] No bucket block configured for %u bytes \n \
2729 Number of blocks allocated from heap = %u\n",*size,
2730 regCb->heapCb.heapAllocCnt);
2733 "[MEM_CAL_CNTC] No bucket block configured for %lu bytes \n \
2734 Number of blocks allocated from heap = %lu\n",*size,
2735 regCb->heapCb.heapAllocCnt);
2737 SDisplay(0, prntBuf);
2742 /* Memory not available in the bucket pool */
2743 if (regCb->heapFlag && (*size < regCb->heapSize))
2746 if (flags) tryHeap = 1;
2749 * The heap memory block is available. Allocate the memory block from
2752 /* cm_mem_c_001.main_15: Additions */
2753 #ifdef SS_HISTOGRAM_SUPPORT
2754 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
2755 #ifdef SSI_DEBUG_LEVEL1
2756 return (cmHeapAlloc(&(regCb->heapCb), ptr, size,
2757 memType, line, fileName, entId, hstReg));
2759 return (cmHeapAlloc(&(regCb->heapCb), ptr, size,
2760 line, fileName, entId, hstReg));
2761 #endif /* SSI_DEBUG_LEVEL1 */
2763 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
2764 #ifdef SSI_DEBUG_LEVEL1
2765 return (cmHeapAlloc(&(regCb->heapCb), ptr, size, memType));
2767 return (cmHeapAlloc(&(regCb->heapCb), ptr, size));
2768 #endif /* SSI_DEBUG_LEVEL1 */
2769 #endif /* SS_HISTOGRAM_SUPPORT */
2772 /* No memory available */
2774 #else /* use pure is on */
2775 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
2776 #ifdef SS_4GMX_LCORE
2777 *ptr = (Data*) MxHeapAlloc(SsiHeap, *size);
2778 memset(ptr, 0, *size);
2780 *ptr = (Data*) malloc(*size);
2782 if ( (*ptr) == NULLP)
2784 avail_size -= *size;
2786 #endif /* USE_PURE */
2788 } /* end of cmAllocNL */
2795 * Desc: Return the memory block for the memory region(No Lock).
2798 * Ret: ROK - successful
2799 * RFAILED - unsuccessful.
2801 * Notes: The user calls this function to return the previously allocated
2802 * memory block to the memory region. The memory manager does not
2803 * check the validity of the state of the memory block(like whether
2804 * it was allocated earlier). The caller must be sure that, the
2805 * address specified in the parameter 'ptr' is valid and was
2806 * allocated previously from same region.
2813 /* cm_mem_c_001.main_15 : Additions */
2814 #ifdef SS_LIGHT_MEM_LEAK_STS
2825 S16 cmFreeNL(regionCb, ptr, size, lineNo, funcName)
2832 #else /*SS_LIGHT_MEM_LEAK_STS */
2834 #ifdef SS_HISTOGRAM_SUPPORT
2847 S16 cmFreeNL(regionCb, ptr, size, line, fileName, entId, hstReg)
2867 S16 cmFreeNL(regionCb, ptr, size)
2872 /* cm_mem_c_001.main_15 : Additions */
2873 #endif /* SS_HISTOGRAM_SUPPORT */
2874 #endif /*SS_LIGHT_MEM_LEAK_STS */
2882 /* cm_mem_c_001.main_12 - addition for holding the free pointer */
2883 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
2885 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2886 CmMmBlkHdr *lastHdr;
2887 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
2888 #endif /* SSI_DEBUG_LEVEL1 */
2889 /* cm_mem_c_001.main_15 : Additions */
2890 #ifdef SS_HISTOGRAM_SUPPORT
2892 #endif /* SS_HISTOGRAM_SUPPORT */
2895 regCb = (CmMmRegCb *)regionCb;
2898 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2899 /* Check if the memory block is from the memory region */
2900 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
2901 ((CmMmRegCb *)regCb)->regInfo.size)
2906 #if (ERRCLASS & ERRCLS_INT_PAR)
2908 /* error check on parameters */
2909 if ((regCb == NULLP) || (!size) || (ptr == NULLP))
2913 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2914 /* Check if the memory block is from the memory region */
2915 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
2916 ((CmMmRegCb *)regCb)->regInfo.size)
2921 /* cm_mem_c_001.main_20 Addition */
2922 if (ptr < regCb->regInfo.start)
2930 * Check if the memory block was allocated from the bucket pool.
2933 if (ptr < (regCb->regInfo.start + regCb->bktSize))
2935 /* The memory block was allocated from the bucket pool */
2937 /* Get the map to the mapping table */
2938 idx = ((size - 1) >> regCb->bktQnPwr);
2940 #if (ERRCLASS & ERRCLS_DEBUG)
2941 if (regCb->mapTbl[idx].bktIdx == 0xFF)
2943 /* Some fatal error in the map table initialization. */
2948 /* Enqueue the memory block and return it to the user */
2949 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
2952 * Check if the size is not greater than the size available
2953 * in the bucket. If so, then the buffer must have been allocated
2954 * from next bucket. We don't need to check the validity of the
2955 * next bucket, otherwise buffer must have been allocated from heap
2958 if (size > bkt->size)
2960 bkt = &(regCb->bktTbl[regCb->mapTbl[++idx].bktIdx]);
2963 /* cache_coherency_changes */
2968 /* cm_mem_c_001.main_12 - addition for sanity check and free */
2969 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2970 /* increment the dealloc attempt counter at bucket level */
2971 bkt->numDeallocAttempts++;
2973 /* Check the memFlags to see whether this block was allocated */
2974 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
2975 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2976 cmRlsAllocBlk(ptrHdr, regCb);
2978 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2979 /* Check for ptr size */
2980 if(((ptrHdr->requestedSize - size) % size) != 0)
2983 sprintf(dbgPrntBuf, "Passed size (%d) does not match with allocated size(%d):%8p, Bucket Id:%03d\n",
2984 size, ptrHdr->requestedSize, ptr, regCb->mapTbl[idx].bktIdx);
2986 printf("Passed size (%d) does not match with allocated size(%d):%8p, Bucket Id:%03d\n",
2987 size, ptrHdr->requestedSize, ptr, regCb->mapTbl[idx].bktIdx);
2992 /* validate the block to be freed for trampling */
2993 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2994 if(cmMmRegIsBlkSane(ptrHdr, bkt->size) != ROK)
2996 if (cmMmRegIsBlkSane(ptrHdr) != ROK)
2999 /* Handle error case of Memory trampling */
3001 /* display an error message here */
3003 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %u bytes \n",
3004 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3006 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %lu bytes \n",
3007 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3009 SDisplay(0, dbgPrntBuf);
3013 * if sanity check returns RTRAMPLINGOK then there is nothing to do
3014 * as the memory blk is already invalidated in cmMmBktSanityChk
3016 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3017 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
3025 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
3026 return (RTRAMPLINGNOK);
3029 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3030 printf("Memory signature is invalid\n");
3034 /* reset the size */
3035 ptrHdr->requestedSize = 0;
3036 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3037 /* Initialize the elements with 0XAB */
3038 memset(ptr, 0xAB, size);
3040 /* check if the block to be freed is already having the state as FREE */
3041 if (CMM_IS_FREE(ptrHdr->memFlags))
3043 /* Handle double deallocation error case */
3045 /* display an error message here */
3046 /*cm_mem_c_001.main_23 Fix for specifier mismatch
3047 * warnings in 64BIT compilation*/
3049 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p,"
3050 "Bucket Id:%03d, size %u bytes \n",
3051 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3053 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p,"
3054 "Bucket Id:%03d, size %lu bytes \n",
3055 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3057 SDisplay(0, dbgPrntBuf);
3059 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3060 printf("Attempt to double deallocate memory at: %8p, Bucket Id:%03d,\
3061 size %u bytes \n", ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3065 /* handle RDBLFREE in SFree/SPutSBuf */
3068 if (CMM_IS_STATIC(ptrHdr->memFlags))
3070 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
3071 CMM_RESET_STATIC_FLAG(ptrHdr->memFlags);
3072 /* deduct it from the static memory count */
3073 bkt->staticMemUsed -= bkt->size;
3075 else if (CMM_IS_DYNAMIC(ptrHdr->memFlags))
3077 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
3078 CMM_RESET_DYNAMIC_FLAG(ptrHdr->memFlags);
3079 /* deduct it from the dynamic memory count */
3080 bkt->dynamicMemUsed -= bkt->size;
3084 /* This is a case similar to trampled memory */
3086 /*cm_mem_c_001.main_23 Fix for specifier
3087 * mismatch warnings in 64BIT compilation*/
3089 sprintf(dbgPrntBuf, "Invalid memory flag: %u !!!\n", ptrHdr->memFlags);
3091 sprintf(dbgPrntBuf, "Invalid memory flag: %lu !!!\n", ptrHdr->memFlags);
3093 SDisplay(0, dbgPrntBuf);
3095 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3096 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
3098 /* do not add to the free list */
3104 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
3105 return (RTRAMPLINGNOK);
3109 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3110 /* Return the block to memory */
3111 ptrHdr->nextBlk = bkt->nextBlk;
3112 bkt->nextBlk = ptrHdr;
3114 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3115 /* Move the ptr to end of the bucket */
3116 lastHdr = (CmMmBlkHdr *)bkt->lastBlk;
3117 lastHdr->nextBlk = ptrHdr;
3118 bkt->lastBlk = ptrHdr;
3119 ptrHdr->nextBlk = NULLP;
3121 #elif SS_LIGHT_MEM_LEAK_STS
3122 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
3123 ptrHdr->lineNo = lineNo;
3124 ptrHdr->currFuncName = funcName;
3125 if(gmemLkCb.isStarted == TRUE)
3127 cmRlsAllocBlk(ptrHdr->allocQueueIndx);
3129 ptrHdr->nextBlk = bkt->nextBlk;
3130 bkt->nextBlk = ptrHdr;
3133 #ifdef SSI_MEM_CORR_PREVENTION
3134 if (*(((U32 *)(ptr)) + 2) == 0xdeaddead)
3136 /* Do not free an already freed block to avoid corruption */
3137 cmDblFreeAttempts++;
3142 *((CmMmEntry **)bkt->last) = ptr;
3143 bkt->last = (CmMmEntry *)ptr;
3144 *((CmMmEntry **)ptr) = NULLP;
3145 *(((U32 *)(ptr)) + 2) = 0xdeaddead;
3148 *((CmMmEntry **)ptr) = bkt->next;
3149 bkt->next = (CmMmEntry *)ptr;
3151 #endif /* SSI_DEBUG_LEVEL1 */
3153 /* cache_coherency_changes */
3158 * Decrement the statistics variable of number of memory block
3162 /* cm_mem_c_001.main_15 : Additions */
3163 #ifdef SS_HISTOGRAM_SUPPORT
3164 /* If Tapa task (entId)is registerd for histogram then insert Memrory Freed
3165 * information into the hash list */
3168 if (cmHstGrmFreeInsert(&bkt->hstGrmHashListCp, bkt->size,
3169 line, fileName, entId) != ROK)
3171 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
3175 #endif /* SS_HISTOGRAM_SUPPORT */
3177 #ifdef SS_MEM_LEAK_STS
3178 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
3179 cmRlsAllocBlk((PTR)ptr);
3180 #endif /* SS_MEM_LEAK_STS */
3185 /* The memory block was allocated from the heap pool */
3186 /* cm_mem_c_001.main_15 : Additions */
3187 #ifdef SS_HISTOGRAM_SUPPORT
3188 return (cmHeapFree (&(regCb->heapCb), ptr, size, line, fileName, entId, hstReg));
3190 return (cmHeapFree (&(regCb->heapCb), ptr, size));
3191 #endif /* SS_HISTOGRAM_SUPPORT */
3192 #else /* use pure is on */
3193 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
3194 #ifdef SS_4GMX_LCORE
3195 (Void)MxHeapFree(SsiHeap, ptr);
3201 #endif /* USE_PURE */
3202 } /* end of cmFreeNL */
3209 * Desc: alloc without lock
3212 * Ret: ROK - successful
3213 * RFAILED - unsuccessful.
3219 /*cm_mem_c_001.main_21-added new function*/
3220 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3223 PRIVATE S16 cmAllocWL
3231 PRIVATE S16 cmAllocWL(regionCb, size, flags, ptr)
3241 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3244 /*cm_mem_c_001.main_23 Removed support of USE_MEMCAL and MEMCAL_DEBUG support for SS_FAP*/
3246 regCb = (CmMmRegCb *)regionCb;
3248 #if (ERRCLASS & ERRCLS_INT_PAR)
3250 /* error check on parameters */
3251 if ((regCb == NULLP) || (size == NULLP) || !(*size) || (ptr == NULLP))
3257 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3262 * Check if the requested size is less than or equal to the maximum block
3263 * size in the bucket.
3265 /* cm_mem_c_001.main_23 Adding check to compair size with Maximum block size*/
3266 if ( *size <= regCb->bktMaxBlkSize)
3268 /* Get the map to the mapping table */
3269 idx = ((*size - 1) >> regCb->bktQnPwr);
3271 /* Dequeue the memory block and return it to the user */
3272 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
3276 * Check if the size request is not greater than the size available
3279 /* cm_mem_c_001.main_23 combined If(*size <= bkt->size) and if(*ptr = bkt->next)*/
3280 if ((*size <= bkt->size)&&(*ptr = bkt->next))
3282 /* Try to go to the next bucket if available */
3283 bkt->next = *((CmMmEntry **)(bkt->next));
3286 * Increment the statistics variable of number of memory block
3291 /* Update the size parameter */
3299 /* Memory not available in the bucket pool */
3300 if (regCb->heapFlag && (*size < regCb->heapSize))
3302 /*cm_mem_c_001.main_23 Removed support of and MEMCAL_DEBUG support for SS_FAP*/
3304 * The heap memory block is available. Allocate the memory block from
3307 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3308 return (cmHeapAlloc(&(regCb->heapCb), ptr, size));
3311 /* No memory available */
3313 #else /* use pure is on */
3314 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
3315 #ifdef SS_4GMX_LCORE
3316 *ptr = (Data*) MxHeapAlloc(SsiHeap, *size);
3317 memset(ptr, 0, *size);
3319 *ptr = (Data*) malloc(*size);
3321 if ( (*ptr) == NULLP)
3323 avail_size -= *size;
3325 #endif /* USE_PURE */
3327 } /* end of cmAllocWL */
3334 * Desc: free without lock
3337 * Ret: ROK - successful
3338 * RFAILED - unsuccessful.
3346 PRIVATE S16 cmFreeWL
3353 PRIVATE S16 cmFreeWL(regionCb, ptr, size)
3362 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3365 regCb = (CmMmRegCb *)regionCb;
3368 #if (ERRCLASS & ERRCLS_INT_PAR)
3370 /* error check on parameters */
3371 if ((regCb == NULLP) || (!size) || (ptr == NULLP))
3376 /* Check if the memory block is from the memory region */
3377 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
3378 ((CmMmRegCb *)regCb)->regInfo.size)
3386 * Check if the memory block was allocated from the bucket pool.
3389 if (ptr < (regCb->regInfo.start + regCb->bktSize))
3391 /* The memory block was allocated from the bucket pool */
3393 /* Get the map to the mapping table */
3394 idx = ((size - 1) >> regCb->bktQnPwr);
3396 #if (ERRCLASS & ERRCLS_DEBUG)
3397 if (regCb->mapTbl[idx].bktIdx == 0xFF)
3399 /* Some fatal error in the map table initialization. */
3404 /* Enqueue the memory block and return it to the user */
3405 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
3408 * Check if the size is not greater than the size available
3409 * in the bucket. If so, then the buffer must have been allocated
3410 * from next bucket. We don't need to check the validity of the
3411 * next bucket, otherwise buffer must have been allocated from heap
3414 if (size > bkt->size)
3416 bkt = &(regCb->bktTbl[regCb->mapTbl[++idx].bktIdx]);
3419 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3420 *((CmMmEntry **)ptr) = bkt->next;
3421 bkt->next = (CmMmEntry *)ptr;
3424 * Decrement the statistics variable of number of memory block
3432 /* The memory block was allocated from the heap pool */
3433 return (cmHeapFree (&(regCb->heapCb), ptr, size));
3434 #else /* use pure is on */
3435 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
3436 #ifdef SS_4GMX_LCORE
3437 (Void)MxHeapFree(SsiHeap, ptr);
3443 #endif /* USE_PURE */
3446 } /* end of cmFreeWL */
3454 * Desc: Control request function.
3457 * Ret: ROK - successful
3458 * RFAILED - unsuccessful.
3460 * Notes: The current semantics of the control function is defined for two
3461 * types of events: virtual address to physical address translation
3462 * and memory resource check.
3464 * The physical address translation is valid only for the memory
3465 * region physically contiguous and non pagable.
3481 PRIVATE S16 cmCtl(regionCb, event, memCtl)
3490 regCb = (CmMmRegCb *)regionCb;
3492 #if (ERRCLASS & ERRCLS_INT_PAR)
3494 /* error check on parameters */
3495 if ((regCb == NULLP) || (memCtl == NULLP))
3508 #if (ERRCLASS & ERRCLS_INT_PAR)
3509 if ((memCtl->u.vtop.vaddr == NULLP) ||
3510 (memCtl->u.vtop.paddr == NULLP))
3516 /* Check if the virtual to physical address translation is valid */
3517 if (regCb->chFlag & CMM_REG_PHY_VALID)
3519 offset = memCtl->u.vtop.vaddr - regCb->regInfo.start;
3520 *(memCtl->u.vtop.paddr) = regCb->pAddr + offset;
3527 case SS_MEM_CHK_RES:
3530 #if (ERRCLASS & ERRCLS_INT_PAR)
3531 if (!(memCtl->u.chkres.size) ||
3532 (memCtl->u.chkres.status == NULLP))
3538 /* Check if the Bucket pool is configured */
3543 U32 avlSize, totSize;
3545 * The bucket pool is configured. The status value returned
3546 * does reflect on the memory availabilty in the bucket pool.
3547 * The value does not consider the available memory in the
3550 idx = ((memCtl->u.chkres.size - 1) >> regCb->bktQnPwr);
3551 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
3552 avlSize = (bkt->numBlks - bkt->numAlloc) * bkt->size;
3553 avlSize += regCb->heapCb.avlSize;
3554 totSize = (bkt->numBlks * bkt->size) + regCb->heapSize;
3555 *(memCtl->u.chkres.status) = (avlSize/(totSize/10));
3559 /* Bucket pool not configured */
3562 * Find the percentage memory available in the heap pool. The value
3563 * does not consider the fragmentation of the heap pool.
3565 *(memCtl->u.chkres.status) = ((regCb->heapCb.avlSize) /
3566 (regCb->heapSize/10));
3570 #else /* use pure is on */
3571 *(memCtl->u.chkres.status) = ((avail_size) /
3572 (regCb->regInfo.size/10));
3574 #endif /* USE_PURE */
3580 /* No other event is supported currently */
3585 /* shouldn't reach here */
3587 } /* end of cmCtl */
3594 * Desc: Initialize the bucket and the map table.
3597 * Ret: ROK - successful,
3598 * RFAILED - unsuccessful.
3600 * Notes: This function is called by the cmMmRegInit.
3606 PRIVATE Void cmMmBktInit
3615 PRIVATE Void cmMmBktInit (memAddr, regCb, cfg, bktIdx, lstMapIdx)
3627 /* cm_mem_c_001.main_12 - addition for temporary variables */
3628 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3629 CmMmBlkHdr **nextBlk;
3630 #ifdef SS_LIGHT_MEM_LEAK_STS
3631 CmMmBlkHdr *lastBlk;
3632 #endif /*SS_LIGHT_MEM_LEAK_STS */
3634 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3636 CmMmBlkTail *blkTail;
3640 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3643 #endif /* SSI_DEBUG_LEVEL1 */
3647 size = cfg->bktCfg[bktIdx].size;
3648 numBlks = cfg->bktCfg[bktIdx].numBlks;
3650 /* cm_mem_c_001.main_12 - addition for header initialization */
3651 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3652 /* Reset the next block pointer */
3653 regCb->bktTbl[bktIdx].nextBlk = NULLP;
3654 #if (defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3655 regCb->bktTbl[bktIdx].lastBlk = NULLP;
3657 /* Initialize the link list of the memory block */
3658 nextBlk = &(regCb->bktTbl[bktIdx].nextBlk);
3660 for (cnt = 0; cnt < numBlks; cnt++)
3662 *nextBlk = (CmMmBlkHdr *)*memAddr;
3663 #ifdef SS_LIGHT_MEM_LEAK_STS
3664 lastBlk = (CmMmBlkHdr *)*memAddr;
3665 #endif /*SS_LIGHT_MEM_LEAK_STS */
3667 /* initialize the memory block header */
3668 for (sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
3670 (*nextBlk)->trSignature[sigCnt] = 0xAB;
3672 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3673 /* Initialize memory block tail */
3674 blkTail = (CmMmBlkTail *)(*memAddr + sizeof(CmMmBlkHdr) + size);
3675 for (sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
3677 blkTail->trSignature[sigCnt] = 0xFE;
3680 CMM_SET_FREE_FLAG((*nextBlk)->memFlags);
3681 (*nextBlk)->requestedSize = 0;
3682 #ifdef SS_LIGHT_MEM_LEAK_STS
3683 (*nextBlk)->timeStamp = 0X7777;
3684 (*nextBlk)->lineNo = 0;
3685 (*nextBlk)->allocQueueIndx = 1;
3686 (*nextBlk)->currFuncName = NULL;
3687 #endif /*SS_LIGHT_MEM_LEAK_STS */
3689 #if defined(SSI_DEBUG_LEVEL1) || defined(SS_LIGHT_MEM_LEAK_STS)
3690 *memAddr = (Data *)((*memAddr) + ((sizeof(CmMmBlkHdr)) + size));
3691 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3692 *memAddr = (Data *)((*memAddr) + ((sizeof(CmMmBlkHdr)) + sizeof(CmMmBlkTail) + size));
3694 nextBlk = &((*nextBlk)->nextBlk);
3698 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3699 tmpMemAddr = (Data *)((*memAddr) - ((sizeof(CmMmBlkHdr)) + sizeof(U32) + size));
3700 regCb->bktTbl[bktIdx].lastBlk = (CmMmBlkHdr *)tmpMemAddr;
3704 /* Reset the next pointer */
3705 regCb->bktTbl[bktIdx].next = NULLP;
3706 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3707 regCb->bktTbl[bktIdx].last = NULLP;
3710 /* Initialize the link list of the memory block */
3711 next = &(regCb->bktTbl[bktIdx].next);
3712 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3713 last = &(regCb->bktTbl[bktIdx].last);
3714 if(regCb->region == 0)
3718 startPtr128 = *memAddr;
3719 regMemSize = regCb->regInfo.size;
3720 uart_printf("size of all pool=%u\n", regMemSize);
3721 uart_printf("startPtr128=%x\n", startPtr128);
3725 startPtr256 = *memAddr;
3726 uart_printf("startPtr256=%x\n", startPtr256);
3730 startPtr512 = *memAddr;
3731 uart_printf("startPtr512=%x\n", startPtr512);
3735 startPtr768 = *memAddr;
3736 uart_printf("startPtr768=%x\n", startPtr768);
3740 startPtr1664 = *memAddr;
3741 uart_printf("startPtr1664=%x\n", startPtr1664);
3745 startPtr4800 = *memAddr;
3746 uart_printf("startPtr4800=%x\n", startPtr4800);
3750 startPtr9920 = *memAddr;
3751 uart_printf("startPtr9920=%x\n", startPtr9920);
3755 for (cnt = 0; cnt < numBlks; cnt++)
3758 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3759 (*(U32 *)(*next + 4)) = 0xdeaddead;
3760 (*(U32 *)(*next + 124)) = 0;
3761 (*(U32 *)(*next + 116)) = 0xdeaddead;
3762 (*(U32 *)(*next + 24)) = 0xdeaddead;
3763 (*(U32 *)(*next + 44)) = 0xdeaddead;
3764 (*(U32 *)(*next + 80)) = 0xdeaddead;
3766 #ifdef SSI_MEM_CORR_PREVENTION
3767 *(((U32 *)(*next)) + 2) = 0xdeaddead;
3769 next = (CmMmEntry **)(*memAddr);
3770 *memAddr = (*memAddr) + size;
3773 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3774 *last = (CmMmEntry *)next;
3776 #ifdef SSI_MEM_CORR_PREVENTION
3777 regCb->bktTbl[bktIdx].last = (CmMmEntry *)next;
3780 #endif /* SSI_DEBUG_LEVEL1 */
3782 /* Initialize the Map entry */
3783 idx = size / cfg->bktQnSize;
3786 * Check if the size is multiple of quantum size. If not we need to initialize
3787 * one more map table entry.
3789 if(size % cfg->bktQnSize)
3794 while ( *lstMapIdx < idx)
3796 regCb->mapTbl[*lstMapIdx].bktIdx = bktIdx;
3798 #if (ERRCLASS & ERRCLS_DEBUG)
3799 regCb->mapTbl[*lstMapIdx].numReq = 0;
3800 regCb->mapTbl[*lstMapIdx].numFailure = 0;
3806 /* Initialize the bucket structure */
3807 regCb->bktTbl[bktIdx].size = size;
3808 regCb->bktTbl[bktIdx].numBlks = numBlks;
3809 regCb->bktTbl[bktIdx].numAlloc = 0;
3811 /* Update the total bucket size */
3812 /* cm_mem_c_001.main_12 - addition for considering the header size */
3813 #if (defined(SSI_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3814 regCb->bktSize += ((size + sizeof(CmMmBlkHdr)) * numBlks);
3815 /* Addition for considering the header size and tail */
3816 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3817 regCb->bktSize += ((size + sizeof(CmMmBlkHdr) + sizeof(U32)) * numBlks);
3819 regCb->bktSize += (size * numBlks);
3820 #endif /* SSI_DEBUG_LEVEL1 */
3822 regCb->bktTbl[bktIdx].bktFailCnt = 0;
3823 regCb->bktTbl[bktIdx].bktNoFitCnt = 0;
3825 /* cm_mem_c_001.main_12 - addition for statistics related variable initialization */
3826 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
3827 /* Initialize other required pointers */
3828 regCb->bktTbl[bktIdx].bktStartPtr = (Data *)(regCb->bktTbl[bktIdx].nextBlk);
3829 regCb->bktTbl[bktIdx].numAllocAttempts = 0;
3830 regCb->bktTbl[bktIdx].numDeallocAttempts = 0;
3831 regCb->bktTbl[bktIdx].staticMemUsed = 0;
3832 regCb->bktTbl[bktIdx].dynamicMemUsed = 0;
3833 regCb->bktTbl[bktIdx].trampleCount = 0;
3834 #endif /*SSI_DEBUG_LEVEL1*/
3835 /* cm_mem_c_001.main_15 : Additions */
3836 #ifdef SS_HISTOGRAM_SUPPORT
3837 /* Initialise the memory histogram hash list */
3838 cmHstGrmHashListInit(&(regCb->bktTbl[bktIdx].hstGrmHashListCp));
3839 #endif /* SS_HISTOGRAM_SUPPORT */
3842 } /* end of cmMmBktInit */
3849 * Desc: Initialize the heap pool.
3852 * Ret: ROK - successful
3853 * RFAILED - unsuccessful.
3855 * Notes: This function is called by the cmMmRegInit.
3861 PRIVATE Void cmMmHeapInit
3868 PRIVATE Void cmMmHeapInit (memAddr, heapCb, size)
3874 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
3875 #ifdef SSI_DEBUG_LEVEL1
3877 #endif /* SSI_DEBUG_LEVEL1 */
3879 /* Initialize the heap control block */
3880 heapCb->vStart = memAddr;
3881 heapCb->vEnd = memAddr + size;
3882 heapCb->avlSize = size;
3883 heapCb->minSize = CMM_MINBUFSIZE;
3885 heapCb->next = (CmHEntry *)memAddr;
3886 heapCb->next->next = NULLP;
3887 /* cm_mem_c_001.main_12 - addition for header initialization */
3888 #ifdef SSI_DEBUG_LEVEL1
3889 heapCb->next->size = size - sizeof(CmHEntry);
3890 heapCb->next->requestedSize = 0;
3891 for (idx=0; idx < CMM_TRAMPLING_SIGNATURE_LEN; idx++)
3893 heapCb->next->trSignature[idx] = 0xAB;
3895 CMM_SET_FREE_FLAG(heapCb->next->memFlags);
3896 heapCb->staticHeapMemUsed = 0;
3897 heapCb->dynamicHeapMemUsed = 0;
3898 heapCb->nextOffset = sizeof(heapCb->next->trSignature) +
3899 sizeof(heapCb->next->memFlags) +
3900 sizeof(heapCb->next->requestedSize);
3901 heapCb->numAllocAttempts = 0;
3902 heapCb->numDeallocAttempts = 0;
3903 heapCb->trampleCount = 0;
3905 heapCb->next->size = size;
3906 #endif /* SSI_DEBUG_LEVEL1 */
3908 #if (ERRCLASS & ERRCLS_DEBUG)
3909 heapCb->numFragBlk = 0;
3911 heapCb->numFailure = 0;
3914 heapCb->heapAllocCnt = 0;
3915 /* cm_mem_c_001.main_15 : Additions */
3916 #ifdef SS_HISTOGRAM_SUPPORT
3917 /* Initialise the memory histogram hash list */
3918 cmHstGrmHashListInit(&(heapCb->heapHstGrmHashListCp));
3919 #endif /* SS_HISTOGRAM_SUPPORT */
3922 } /* end of cmMmHeapInit */
3929 * Desc: Allocates the memory block from the heap pool.
3932 * Ret: ROK - successful
3933 * RFAILED - unsuccessful.
3935 * Notes: This function is called by the cmAlloc. cmAlloc calls this
3936 * function when there is no memory block available in the bucket
3937 * and the heap pool is configured.
3944 /* cm_mem_c_001.main_12 - addition for taking another parameter memType(static/dynamic) */
3945 /* cm_mem_c_001.main_15 : Additions */
3946 #ifdef SS_4GMX_LCORE
3947 EXTERN U8 ysCellConfigDone;
3949 #ifdef SS_HISTOGRAM_SUPPORT
3950 #ifdef SSI_DEBUG_LEVEL1
3952 PRIVATE S16 cmHeapAlloc
3964 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size, memType, line, fileName, entId, hstReg)
3976 PRIVATE S16 cmHeapAlloc
3987 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size, line, fileName, entId, hstReg)
3996 #endif /* SSI_DEBUG_LEVEL1 */
3998 #ifdef SSI_DEBUG_LEVEL1
4000 PRIVATE S16 cmHeapAlloc
4008 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size, memType)
4016 PRIVATE S16 cmHeapAlloc
4023 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size)
4028 #endif /* SSI_DEBUG_LEVEL1 */
4029 /* cm_mem_c_001.main_15 : Additions */
4030 #endif /* SS_HISTOGRAM_SUPPORT */
4032 CmHEntry *prvHBlk; /* Previous heap block */
4033 CmHEntry *curHBlk; /* Current heap block */
4035 /* cm_mem_c_001.main_15 : Additions */
4036 #ifdef SS_MEM_LEAK_STS
4038 #endif /* SS_MEM_LEAK_STS */
4039 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
4040 #ifdef SSI_DEBUG_LEVEL1
4041 CmHEntry *alocHeapBlk;
4045 #endif /* SSI_DEBUG_LEVEL1 */
4046 /* cm_mem_c_001.main_15 : Additions */
4047 #ifdef SS_HISTOGRAM_SUPPORT
4049 #endif /* SS_HISTOGRAM_SUPPORT */
4051 /* cm_mem_c_001.main_15 : Additions */
4052 /* Acquire the heap lock */
4053 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
4054 #ifdef SS_4GMX_LCORE
4055 if(1 == ysCellConfigDone)
4057 #ifdef SSI_DEBUG_LEVEL1
4058 /* display a message here */
4059 sprintf(dbgPrntBuf,"Allocating from heap size=%u\n", *size);
4060 SDisplay(0, dbgPrntBuf);
4061 #endif /* SSI_DEBUG_LEVEL1 */
4065 (Void) WTLock (&(heapCb->heapLock));
4067 (Void) SLock (&(heapCb->heapLock));
4070 #ifdef SS_MEM_LEAK_STS
4072 #endif /* SS_MEM_LEAK_STS */
4073 /* cm_mem_c_001.main_12 - addition for manipulation of statistics related data */
4074 #ifdef SSI_DEBUG_LEVEL1
4075 heapCb->numAllocAttempts++;
4076 requestedSize = *size;
4077 #endif /* SSI_DEBUG_LEVEL1 */
4079 /* Roundup the requested size */
4080 *size = CMM_DATALIGN(*size, (heapCb->minSize));
4082 /* Check if the available total size is adequate. */
4083 if ((*size) >= heapCb->avlSize)
4085 /* cm_mem_c_001.main_15 : Additions */
4087 (Void) WTUnlock (&(heapCb->heapLock));
4089 (Void) SUnlock (&(heapCb->heapLock));
4095 /* cm_mem_c_001.main_12 - addition for aligning the header size */
4096 #ifdef SSI_DEBUG_LEVEL1
4097 hdr = PTRALIGN(sizeof(CmHEntry));
4098 #endif /* SSI_DEBUG_LEVEL1 */
4101 * Search through the heap block list in the heap pool of size
4102 * greater than or equal to the requested size.
4105 /* cm_mem_c_001.main_12 - addition for accessing the heapCb->next */
4106 #ifdef SSI_DEBUG_LEVEL1
4107 prvHBlk = (CmHEntry *)((Data *)&(heapCb->next) - heapCb->nextOffset);
4109 prvHBlk = (CmHEntry *)&(heapCb->next);
4110 #endif /* SSI_DEBUG_LEVEL1 */
4111 for (curHBlk = prvHBlk->next; curHBlk; curHBlk = curHBlk->next,
4112 prvHBlk = prvHBlk->next)
4115 * Since the size of the block is always multiple of CMM_MINBUFSIZE
4116 * and the requested size is rounded to the size multiple of
4117 * CMM_MINBUFSIZE, the difference between the size of the heap block
4118 * and the size to allocate will be either zero or multiple of
4121 if ((*size) <= curHBlk->size)
4123 /* cm_mem_c_001.main_12 - addition for block size calculation */
4124 #ifdef SSI_DEBUG_LEVEL1
4125 tmpSize = curHBlk->size - (*size);
4127 tmpSize = tmpSize - hdr;
4130 /* cm_mem_c_001.main_28 : compilation warning fix */
4131 tmpSize = (curHBlk->size - (*size));
4133 #endif /* SSI_DEBUG_LEVEL1 */
4135 /* Heap block of bigger size */
4136 /* cm_mem_c_001.main_12 - addition for allocating memory */
4137 #ifdef SSI_DEBUG_LEVEL1
4138 *ptr = (Data *)curHBlk + hdr + tmpSize + hdr;
4139 alocHeapBlk = (CmHEntry *) ((Data *)curHBlk + hdr + tmpSize);
4141 * No need to look for memory trampling as this is a new block altogether
4142 * Update the header only for this case as it is new block formed
4144 for (idx=0; idx < CMM_TRAMPLING_SIGNATURE_LEN; idx++)
4146 alocHeapBlk->trSignature[idx] = 0xAB;
4148 alocHeapBlk->size = *size;
4150 *ptr = (Data *)curHBlk + tmpSize;
4151 #endif /* SSI_DEBUG_LEVEL1 */
4152 curHBlk->size = tmpSize;
4156 /* Heap block is same size of the requested size */
4157 /* cm_mem_c_001.main_12 - addition for sanity check and allocation. This is a fresh block */
4158 #ifdef SSI_DEBUG_LEVEL1
4159 /* look for memory trampling as this is a pure block*/
4162 if (cmMmRegIsBlkSane((CmMmBlkHdr *)curHBlk) != ROK)
4164 /* detected a trampled memory block in this bucket */
4166 /* display an error message here */
4167 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
4169 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %u bytes \n", (void *)curHBlk, requestedSize);
4171 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %lu bytes \n", (void *)curHBlk, requestedSize);
4173 SDisplay(0, dbgPrntBuf);
4176 if (cmMmHeapSanityChk(heapCb) == RTRAMPLINGNOK)
4178 /* Release the lock */
4179 /* cm_mem_c_001.main_13: Replaced SUnlock with
4182 (Void) WTUnlock (&(heapCb->heapLock));
4184 (Void) SUnlock (&(heapCb->heapLock));
4186 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
4187 return (RTRAMPLINGNOK);
4191 /* Release the lock */
4192 /* cm_mem_c_001.main_13: Replaced SUnlock with
4195 (Void) WTUnlock (&(heapCb->heapLock));
4197 (Void) SUnlock (&(heapCb->heapLock));
4204 *ptr = (Data *)curHBlk + hdr;
4205 alocHeapBlk = curHBlk;
4206 *size = curHBlk->size;
4208 *ptr = (Data *)curHBlk;
4209 #endif /* SSI_DEBUG_LEVEL1 */
4210 prvHBlk->next = curHBlk->next;
4213 /* cm_mem_c_001.main_12 - addition for header updation */
4214 #ifdef SSI_DEBUG_LEVEL1
4215 /* update the header fields */
4216 alocHeapBlk->requestedSize = requestedSize;
4217 alocHeapBlk->memFlags = 0;
4218 if (memType == CMM_STATIC_MEM_FLAG)
4220 CMM_SET_STATIC_FLAG(alocHeapBlk->memFlags);
4221 heapCb->staticHeapMemUsed += (*size + hdr);
4225 CMM_SET_DYNAMIC_FLAG(alocHeapBlk->memFlags);
4226 heapCb->dynamicHeapMemUsed += (*size + hdr);
4228 heapCb->avlSize -= ((*size) + hdr);
4230 heapCb->avlSize -= (*size);
4231 #endif /* SSI_DEBUG_LEVEL1 */
4237 "SGetSBuf:%08lu:Size Heap Alloc Times:%05lu Pointer: %8p\n",
4238 *size, num_times, *ptr);
4239 SDisplay(0, prntBuf);
4243 /* cm_mem_c_001.main_15 : Additions */
4244 #ifdef SS_MEM_LEAK_STS
4245 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
4246 cmStorAllocBlk((PTR)*ptr, (Size) reqSz, (Size) *size, MT_MAX_BKTS);
4247 #endif /* SS_MEM_LEAK_STS */
4248 /* Release the lock */
4249 /* cm_mem_c_001.main_16 : cm_mem_c_001.main_18 Additions */
4251 (Void) WTUnlock (&(heapCb->heapLock));
4253 (Void) SUnlock (&(heapCb->heapLock));
4256 #ifdef SS_HISTOGRAM_SUPPORT
4257 /* If If Tapa task (entId)is registerd for histogram then insert Memrory allocated
4258 * information into the hash list */
4261 if (cmHstGrmAllocInsert(&(heapCb->heapHstGrmHashListCp), *size, size, line, fileName, entId) != ROK)
4263 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4268 #endif /* SS_HISTOGRAM_SUPPORT */
4274 /* cm_mem_c_008.104 - Addition for memory calculator tool */
4280 /* Release the lock */
4281 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4283 (Void) WTUnlock (&(heapCb->heapLock));
4285 (Void) SUnlock (&(heapCb->heapLock));
4290 } /* end of cmHeapAlloc */
4297 * Desc: Return the memory block from the heap pool.
4300 * Ret: ROK - successful
4301 * RFAILED - unsuccessful.
4303 * Notes: This function returns the memory block to the heap pool. This
4304 * function is called by cmFree. The function does not check the
4305 * validity of the memory block. The caller must be sure that the
4306 * block was previously allocated and belongs to the heap pool. The
4307 * function maintain the sorting order of the memory block on the
4308 * starting address of the block. This function also do compaction
4309 * if the neighbouring blocks are already in the heap.
4316 /* cm_mem_c_001.main_15 : Additions */
4317 #ifdef SS_HISTOGRAM_SUPPORT
4319 PRIVATE S16 cmHeapFree
4330 PRIVATE S16 cmHeapFree (heapCb, ptr, size, line, fileName, entId, hstReg)
4341 PRIVATE S16 cmHeapFree
4348 PRIVATE S16 cmHeapFree (heapCb, ptr, size)
4353 /* cm_mem_c_001.main_15 : Additions */
4354 #endif /* SS_HISTOGRAM_SUPPORT */
4357 CmHEntry *curHBlk; /* Current heap block */
4358 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
4359 #ifdef SSI_DEBUG_LEVEL1
4361 #endif /* SSI_DEBUG_LEVEL1 */
4362 /* cm_mem_c_001.main_15 : Additions */
4363 #ifdef SS_HISTOGRAM_SUPPORT
4364 Size allocSize = size;
4366 #endif /* SS_HISTOGRAM_SUPPORT */
4369 /* Roundup the requested size */
4370 size = CMM_DATALIGN(size, (heapCb->minSize));
4371 /* cm_mem_c_001.main_15: Additions */
4372 #ifdef SS_HISTOGRAM_SUPPORT
4374 #endif /* SS_HISTOGRAM_SUPPORT */
4376 /* Acquire the heap lock */
4377 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
4379 (Void) WTLock (&(heapCb->heapLock));
4381 (Void) SLock (&(heapCb->heapLock));
4384 /* increase the avlSize */
4385 /* cm_mem_c_001.main_12 - addition for manipulation of statistics related data */
4386 #ifdef SSI_DEBUG_LEVEL1
4387 hdr = PTRALIGN(sizeof(CmHEntry));
4388 heapCb->avlSize += (size + hdr);
4389 heapCb->numDeallocAttempts++;
4391 heapCb->avlSize += size;
4392 #endif /* SSI_DEBUG_LEVEL1 */
4394 /* cm_mem_c_001.main_12 - addition for pointing to the block */
4395 #ifdef SSI_DEBUG_LEVEL1
4396 p = (CmHEntry *)(ptr - hdr);
4398 p = (CmHEntry *)ptr;
4399 /* cm_mem_c_001.main_15 : Additions */
4400 #ifdef SS_MEM_LEAK_STS
4401 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
4402 cmRlsAllocBlk((PTR)ptr);
4403 #endif /* SS_MEM_LEAK_STS */
4404 #endif /* SSI_DEBUG_LEVEL1 */
4407 /* cm_mem_c_001.main_12 - addition for sanity and double-free checks */
4408 #ifdef SSI_DEBUG_LEVEL1
4409 /* look for memory trampling */
4410 if (cmMmRegIsBlkSane((CmMmBlkHdr *)p) != ROK)
4412 /* detected a trampled memory block in heap */
4414 /* display an error message here */
4415 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
4417 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %u bytes \n", (void *)p, size);
4419 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %lu bytes \n", (void *)p, size);
4421 SDisplay(0, dbgPrntBuf);
4424 if (cmMmHeapSanityChk(heapCb) == RTRAMPLINGNOK)
4426 /* Release the lock */
4427 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4429 (Void) WTUnlock (&(heapCb->heapLock));
4431 (Void) SUnlock (&(heapCb->heapLock));
4433 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
4434 return (RTRAMPLINGNOK);
4438 /* do not add to the free heap */
4439 heapCb->avlSize -= (size + hdr);
4440 /* Release the heap lock */
4441 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4443 (Void) WTUnlock (&(heapCb->heapLock));
4445 (Void) SUnlock (&(heapCb->heapLock));
4452 /* look for any double free */
4453 if (CMM_IS_FREE(p->memFlags))
4456 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
4458 sprintf(dbgPrntBuf, "DOUBLE FREE at %8p for size %u in HEAP \n", (void *)p, size);
4460 sprintf(dbgPrntBuf, "DOUBLE FREE at %8p for size %lu in HEAP \n", (void *)p, size);
4462 SDisplay(0, dbgPrntBuf);
4465 heapCb->avlSize -= (size + hdr);
4466 /* cm_mem_c_001.main_15 : Additions */
4468 (Void) WTUnlock (&(heapCb->heapLock));
4470 (Void) SUnlock (&(heapCb->heapLock));
4475 #endif /* SSI_DEBUG_LEVEL1 */
4477 for ( curHBlk = heapCb->next; curHBlk; curHBlk = curHBlk->next)
4480 * The block will be inserted to maintain the sorted order on the
4481 * starting address of the block.
4485 if (!(curHBlk->next) ||
4486 (p < (curHBlk->next)))
4488 /* Heap block should be inserted here */
4491 * Check if the block to be returned can be merged with the
4494 /* cm_mem_c_001.main_12 - addition for header consideration */
4495 #ifdef SSI_DEBUG_LEVEL1
4496 if (((Data *)curHBlk + hdr + curHBlk->size) == (Data *)p)
4498 if (((Data *)curHBlk + curHBlk->size) == (Data *)p)
4499 #endif /* SSI_DEBUG_LEVEL1 */
4501 /* Merge the block */
4502 /* cm_mem_c_001.main_12 - addition for updating statistics related data */
4503 #ifdef SSI_DEBUG_LEVEL1
4504 /* update the flags */
4505 if (CMM_IS_STATIC(p->memFlags))
4506 heapCb->staticHeapMemUsed -= (size + hdr);
4507 else if (CMM_IS_DYNAMIC(p->memFlags))
4508 heapCb->dynamicHeapMemUsed -= (size + hdr);
4509 size = (curHBlk->size += (size + hdr));
4511 size = (curHBlk->size += size);
4512 #endif /*SSI_DEBUG_LEVEL1*/
4517 /* cm_mem_c_001.main_12 - addition for double-free check */
4518 #ifdef SSI_DEBUG_LEVEL1
4519 /* Check for double deallocation in heap */
4520 if ((Data *)p < ((Data *)curHBlk + curHBlk->size))
4522 /* Release the lock */
4523 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4525 (Void) WTUnlock (&(heapCb->heapLock));
4527 (Void) SUnlock (&(heapCb->heapLock));
4530 /* This block is already freed in the heap */
4533 /* update the flags as it is a new node */
4534 if (CMM_IS_STATIC(p->memFlags))
4536 heapCb->staticHeapMemUsed -= (size + hdr);
4537 CMM_RESET_STATIC_FLAG(p->memFlags);
4539 else if (CMM_IS_DYNAMIC(p->memFlags))
4541 heapCb->dynamicHeapMemUsed -= (size + hdr);
4542 CMM_RESET_DYNAMIC_FLAG(p->memFlags);
4544 CMM_SET_FREE_FLAG(p->memFlags);
4545 p->requestedSize = 0;
4546 #endif /*SSI_DEBUG_LEVEL1*/
4547 /* insert the block */
4548 p->next = curHBlk->next;
4553 /* Try to merge with the next block in the chain */
4554 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
4555 #ifdef SSI_DEBUG_LEVEL1
4556 if (((Data *)p + hdr + size) == (Data *)(p->next) && (p->next))
4558 if (((Data *)p + size) == (Data *)(p->next) && (p->next))
4559 #endif /*SSI_DEBUG_LEVEL1*/
4561 /* p->next can not be NULL */
4562 /* cm_mem_c_001.main_12 - addition for header consideration */
4563 #ifdef SSI_DEBUG_LEVEL1
4564 p->size += (p->next->size + hdr);
4566 p->size += p->next->size;
4567 #endif /*SSI_DEBUG_LEVEL1*/
4568 p->next = p->next->next;
4571 /* Release the lock */
4572 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4574 (Void) WTUnlock (&(heapCb->heapLock));
4576 (Void) SUnlock (&(heapCb->heapLock));
4578 /* cm_mem_c_001.main_15 : Additions */
4579 #ifdef SS_HISTOGRAM_SUPPORT
4580 /* If If Tapa task (entId)is registerd for histogram then insert
4581 Memrory Freed information into the hash list */
4584 if (cmHstGrmFreeInsert(&heapCb->heapHstGrmHashListCp, allocSize, line,
4585 fileName, entId) != ROK)
4587 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4591 #endif /* SS_HISTOGRAM_SUPPORT */
4595 else if (p < curHBlk)
4598 * Check if the block to be returned can be merged with the
4601 /* cm_mem_c_001.main_12 - addition for header consideration */
4602 #ifdef SSI_DEBUG_LEVEL1
4603 if (((Data *)p + hdr + size) == (Data *)curHBlk)
4605 if (((Data *)p + size) == (Data *)curHBlk)
4606 #endif /* SSI_DEBUG_LEVEL1 */
4608 /* Merge the block */
4609 /* cm_mem_c_001.main_12 - addition for header consideration */
4610 #ifdef SSI_DEBUG_LEVEL1
4611 p->size = size + (curHBlk->size + hdr);
4613 p->size = size + curHBlk->size;
4614 #endif /* SSI_DEBUG_LEVEL1 */
4615 p->next = curHBlk->next;
4619 /* insert the block */
4623 /* cm_mem_c_001.main_12 - addition for header updation */
4624 #ifdef SSI_DEBUG_LEVEL1
4625 /* update the flags in both cases as they are new start nodes*/
4626 if (CMM_IS_STATIC(p->memFlags))
4628 heapCb->staticHeapMemUsed -= (size + hdr);
4629 CMM_RESET_STATIC_FLAG(p->memFlags);
4631 else if (CMM_IS_DYNAMIC(p->memFlags))
4633 heapCb->dynamicHeapMemUsed -= (size + hdr);
4634 CMM_RESET_DYNAMIC_FLAG(p->memFlags);
4636 CMM_SET_FREE_FLAG(p->memFlags);
4637 p->requestedSize = 0;
4638 #endif /* SSI_DEBUG_LEVEL1 */
4642 /* Release the lock */
4643 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4645 (Void) WTUnlock (&(heapCb->heapLock));
4647 (Void) SUnlock (&(heapCb->heapLock));
4649 /* cm_mem_c_001.main_15 : Additions */
4650 #ifdef SS_HISTOGRAM_SUPPORT
4651 /* If If Tapa task (entId)is registerd for histogram then insert
4652 Memrory Freed information into the hash list */
4655 if (cmHstGrmFreeInsert(&heapCb->heapHstGrmHashListCp, allocSize, line,
4656 fileName, entId) != ROK)
4658 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4662 #endif /* SS_HISTOGRAM_SUPPORT */
4668 if (heapCb->next == NULLP)
4670 /* Heap block is empty. Insert the block in the head. */
4675 /* cm_mem_c_001.main_12 - addition for header updation */
4676 #ifdef SSI_DEBUG_LEVEL1
4677 if (CMM_IS_STATIC(p->memFlags))
4679 heapCb->staticHeapMemUsed -= (size + hdr);
4680 CMM_RESET_STATIC_FLAG(p->memFlags);
4682 else if (CMM_IS_DYNAMIC(p->memFlags))
4684 heapCb->dynamicHeapMemUsed -= (size + hdr);
4685 CMM_RESET_DYNAMIC_FLAG(p->memFlags);
4687 CMM_SET_FREE_FLAG(p->memFlags);
4688 p->requestedSize = 0;
4689 #endif /* SSI_DEBUG_LEVEL1 */
4691 /* Release the heap lock */
4692 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4694 (Void) WTUnlock (&(heapCb->heapLock));
4696 (Void) SUnlock (&(heapCb->heapLock));
4698 /* cm_mem_c_001.main_15 : Additions */
4699 #ifdef SS_HISTOGRAM_SUPPORT
4700 /* If If Tapa task (entId)is registerd for histogram then insert
4701 Memrory Freed information into the hash list */
4704 if (cmHstGrmFreeInsert(&heapCb->heapHstGrmHashListCp, allocSize, line,
4705 fileName, entId) != ROK)
4707 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4711 #endif /* SS_HISTOGRAM_SUPPORT */
4715 /* Release the lock */
4716 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4718 (Void) WTUnlock (&(heapCb->heapLock));
4720 (Void) SUnlock (&(heapCb->heapLock));
4724 } /* end of cmHeapFree */
4726 #ifdef SS_LIGHT_MEM_LEAK_STS
4733 U32 cmGetFreeIndx(Void)
4737 if(gmemLkCb.head == gmemLkCb.tail)
4739 allocQueueEmptyCnt++;
4740 return (CM_MAX_ALLOC_ENTERIES);
4744 U32 allocQIndx = gmemLkCb.queue[gmemLkCb.head];
4745 gmemLkCb.head = (gmemLkCb.head +1) % CM_MAX_ALLOC_ENTERIES;
4746 return (allocQIndx);
4756 U32 cmPutFreeIndx(allocQIndx)
4761 U32 tmpTail = (gmemLkCb.tail+1)% CM_MAX_ALLOC_ENTERIES;
4762 if(tmpTail == gmemLkCb.head)
4764 allocQueueFullCnt++;
4769 gmemLkCb.queue[gmemLkCb.tail] = allocQIndx;
4770 gmemLkCb.tail = tmpTail;
4776 * Fun: cmInitMemLeakMdl
4778 * Desc: Initializes the memory leak detection module
4783 * Notes: This function initializes the memory leak detection module.
4795 Void cmInitMemLeak (Void)
4801 gmemLkCb.isStarted = FALSE;
4804 SInitLock(&gmemLkCb.memLock, 1);
4805 for(indx = 0; indx < CM_MAX_ALLOC_ENTERIES; indx++)
4807 gmemLkCb.allocInfo[indx].used = FALSE;
4808 cmPutFreeIndx(indx);
4812 } /* cmInitMemLeak */
4815 * Fun: cmDeinitMemLeak
4817 * Desc: De-initializes the memory leak detection
4822 * Notes: This function de-initializes the memory leak detection module.
4829 Void cmDeinitMemLeak
4834 Void cmDeinitMemLeak (Void)
4840 for(indx = 0; indx < CM_MAX_ALLOC_ENTERIES; indx++)
4842 gmemLkCb.allocInfo[indx].used = FALSE;
4844 SDestroyLock(&gmemLkCb.memLock);
4845 gmemLkCb.isStarted = FALSE;
4852 * Fun: cmStorAllocBlk
4854 * Desc: Initializes the memory leak detection module
4859 * Notes: This function initializes the memory leak detection module.
4871 U32 cmStorAllocBlk (addr)
4878 (Void) SLock(&gmemLkCb.memLock);
4879 allocQIndx = cmGetFreeIndx();
4880 if(allocQIndx < CM_MAX_ALLOC_ENTERIES)
4882 queueIndxAllocCnt++;
4883 gmemLkCb.allocInfo[allocQIndx].memAddr = addr;
4884 gmemLkCb.allocInfo[allocQIndx].used = TRUE;
4886 (Void) SUnlock(&(gmemLkCb.memLock));
4888 return (allocQIndx);
4889 } /* cmStorAllocBlk */
4894 * Fun: cmRlsAllocBlk
4896 * Desc: Initializes the memory leak detection module
4901 * Notes: This function initializes the memory leak detection module.
4913 Void cmRlsAllocBlk(allocQIndx)
4918 if(allocQIndx < CM_MAX_ALLOC_ENTERIES)
4920 if(gmemLkCb.allocInfo[allocQIndx].used == TRUE)
4922 (Void) SLock(&gmemLkCb.memLock);
4923 gmemLkCb.allocInfo[allocQIndx].used = FALSE;
4924 cmPutFreeIndx(allocQIndx);
4926 (Void) SUnlock(&(gmemLkCb.memLock));
4930 } /* cmRlsAllocBlk */
4934 * Fun: cmStartStopLeakLog
4944 Void cmStartStopLeakLog
4949 Void cmStartStopLeakLog(Void)
4952 if (FALSE == gmemLkCb.isStarted)
4954 printf("!!leak capturing started\n");
4955 gmemLkCb.isStarted = TRUE;
4959 gmemLkCb.isStarted = FALSE;
4960 printf("!!leak capturing stopped\n");
4968 * Fun: cmPrintLeakLog
4970 * Desc: Prints leak log
4985 Void cmPrintLeakLog(Void)
4991 static U32 leakCount =0;
4994 printf("---- START OF LEAK LOG ----");
4995 SLock(&gmemLkCb.memLock);
4996 printf("---- Lock Acquired ----");
4997 for(indx = 0; indx < CM_MAX_ALLOC_ENTERIES; indx++)
4999 if(gmemLkCb.allocInfo[indx].used == TRUE)
5002 aBkt =(CmMmBlkHdr *)gmemLkCb.allocInfo[indx].memAddr;
5003 printf("LeakCnt(%ld)Addr(0x%p)RqSz(%ld)",
5004 leakCount,gmemLkCb.allocInfo[indx].memAddr, aBkt->requestedSize);
5005 printf("LineNo(%ld)funcName(%s)\n",
5006 aBkt->lineNo, aBkt->currFuncName);
5007 gmemLkCb.allocInfo[indx].used = FALSE;
5008 cmPutFreeIndx(indx);
5010 //if(leakCount % 10 == 0)
5013 printf("---- END OF LEAK LOG ----");
5014 SUnlock(&gmemLkCb.memLock);
5015 printf("---- Lock Released ----");
5022 #if (defined(SS_MEM_LEAK_STS) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2))
5025 * Fun: cmRlsAllocBlk
5027 * Desc: Initializes the memory leak detection module
5032 * Notes: This function initializes the memory leak detection module.
5038 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5046 Void cmRlsAllocBlk(ptrHdr, regCb)
5061 Void cmRlsAllocBlk(addr)
5070 Ptr trace[CM_MAX_STACK_TRACE];
5076 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5077 MemAllocInfo *memAllocInfo;
5081 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5083 retVal = cmHashListFind(®Cb->brdcmSsiLstCp,(U8 *)&ptrHdr,
5084 (U16)sizeof(U64), 0, (PTR *)&ptrHdr);
5086 retVal = cmHashListFind(®Cb->brdcmSsiLstCp,(U8 *)&ptrHdr,
5087 (U16)sizeof(U32), 0, (PTR *)&ptrHdr);
5091 cmHashListDelete(®Cb->brdcmSsiLstCp, (PTR)ptrHdr);
5094 if( memLkCb.memLkMdlInit == FALSE)
5098 for(idx = 0; idx < CM_MEM_USR_MDL; idx++)
5100 SLock(&memLkCb.memUsrMdl[idx][addr & 0x3].memLck);
5102 retVal = cmHashListFind(&memLkCb.memUsrMdl[idx][addr & 0x3].memHashCp,
5103 (U8 *)&addr, sizeof(U64), 0,
5104 (PTR *)&memAllocInfo);
5106 retVal = cmHashListFind(&memLkCb.memUsrMdl[idx][addr & 0x3].memHashCp,
5107 (U8 *)&addr, sizeof(U32), 0,
5108 (PTR *)&memAllocInfo);
5112 cmHashListDelete(&memLkCb.memUsrMdl[idx][addr & 0x3].memHashCp,
5114 SUnlock(&memLkCb.memUsrMdl[idx][addr & 0x3].memLck);
5115 funcNm = (S8 **) memAllocInfo->backTrace;
5116 #ifdef SS_MEM_LEAK_SOL
5117 for(i = 0; i < memAllocInfo->bTrcSz; i++)
5119 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5120 #ifdef SS_4GMX_LCORE
5121 MxHeapFree(SsiHeap, funcNm[i]);
5126 #endif /* SS_MEM_LEAK_SOL */
5127 #ifdef SS_MEM_LEAK_FREE_TRACE
5131 sprintf( prntBuf, "\n==============================\n");
5133 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
5135 sprintf( prntBuf, "Address: [%x]\n", addr);
5137 sprintf( prntBuf, "Address: [%lx]\n", addr);
5140 traceSize = backtrace(trace, CM_MAX_STACK_TRACE);
5141 funcNm = backtrace_symbols(trace, traceSize);
5142 sprintf( prntBuf, "[bt] Execution path:\n");
5144 for (i=0; i < traceSize; ++i)
5146 sprintf( prntBuf, "[bt] %s\n", funcNm[i]);
5149 sprintf( prntBuf, "\n==============================\n");
5152 #endif /* SS_MEM_LEAK_FREE_TRACE */
5153 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5154 #ifdef SS_4GMX_LCORE
5155 MxHeapFree(SsiHeap, funcNm);
5156 MxHeapFree(SsiHeap, memAllocInfo);
5163 SUnlock(&memLkCb.memUsrMdl[idx][addr & 0x3].memLck);
5166 #ifndef SS_MEM_LEAK_SOL
5167 if(idx == CM_MEM_USR_MDL)
5170 sprintf( prntBuf,"\nPossible Double-Deallocation.\n");
5172 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
5174 sprintf( prntBuf, "Address: [%u]\n", addr);
5176 sprintf( prntBuf, "Address: [%lu]\n", addr);
5179 traceSize = backtrace(trace, CM_MAX_STACK_TRACE);
5180 funcNm = backtrace_symbols(trace, traceSize);
5181 sprintf( prntBuf,"[bt] Execution path:\n");
5183 for (i=0; i < traceSize; ++i)
5185 sprintf( prntBuf,"[bt] %s\n", funcNm[i]);
5188 printf("\n==============================\n");
5189 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5190 #ifdef SS_4GMX_LCORE
5191 MxHeapFree(SsiHeap, funcNm);
5196 #endif /* SS_MEM_LEAK_SOL */
5197 #endif/* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
5198 /*cm_mem_c_001.main_25 : */
5200 } /* cmRlsAllocBlk */
5205 * Fun: cmStorAllocBlk
5207 * Desc: Initializes the memory leak detection module
5212 * Notes: This function initializes the memory leak detection module.
5218 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5229 Void cmStorAllocBlk (ptrHdr, reqSz, allocSz, bktIdx, regCb)
5250 Void cmStorAllocBlk (addr, reqSz, allocSz, bktIdx)
5260 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
5262 #ifndef SS_MEM_LEAK_SOL
5263 void *trace[CM_MAX_STACK_TRACE];
5264 #endif /* SS_MEM_LEAK_SOL */
5265 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5268 MemAllocInfo *allocInfo;
5274 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5275 if( memLkCb.memLkMdlInit == FALSE)
5280 #ifdef SS_MEM_LEAK_SOL
5281 /* I need to do this for solaris, because it does not implement
5282 * backtrace. Here backtrace is my function. See below for the
5283 * implementation. */
5284 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5285 #ifdef SS_4GMX_LCORE
5286 funcNm = (S8 **)MxHeapAlloc(SsiHeap, (sizeof(U32) * CM_MAX_STACK_TRACE));
5287 memset(funcNm, 0, (sizeof(U32) * CM_MAX_STACK_TRACE));
5289 funcNm = (S8 **)calloc(1, (sizeof(U32) * CM_MAX_STACK_TRACE));
5291 /* SGetSBuf(DFLT_REGION, DFLT_POOL, &funcNm, sizeof(U32) * CM_MAX_STACK_TRACE); */
5292 traceSize = backtrace((Void **)funcNm, CM_MAX_STACK_TRACE);
5293 #else /* SS_MEM_LEAK_SOL */
5294 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5295 traceSize = backtrace(trace, CM_MAX_STACK_TRACE);
5296 funcNm = backtrace_symbols(trace, traceSize);
5298 #endif /* SS_MEM_LEAK_SOL */
5300 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5301 moduleId = cmMemGetModuleId(funcNm, traceSize);
5302 (Void)SLock(&(memLkCb.memUsrMdl[moduleId][addr & 0x3].memLck));
5305 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5306 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5307 #ifdef SS_4GMX_LCORE
5308 allocInfo = (MemAllocInfo *)MxHeapAlloc(SsiHeap, sizeof(MemAllocInfo));
5309 memset(allocInfo, 0, sizeof(MemAllocInfo));
5311 allocInfo = (MemAllocInfo *)calloc(1, sizeof(MemAllocInfo));
5314 /* SGetSBuf(DFLT_REGION, DFLT_POOL, &allocInfo, sizeof(MemAllocInfo)); */
5315 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5316 /* check if hashListCp is initialised yet */
5317 if ( regCb->brdcmSsiLstCp.nmbBins == 0)
5321 ptrHdr->reqSz = reqSz;
5322 ptrHdr->allocSz = allocSz;
5323 ptrHdr->bktIdx = bktIdx;
5324 cmHashListInsert(®Cb->brdcmSsiLstCp, (PTR)ptrHdr,
5325 (U8 *)&(ptrHdr), sizeof(PTR));
5327 allocInfo->memAddr = addr;
5328 allocInfo->reqSz = reqSz;
5329 allocInfo->allocSz = allocSz;
5330 allocInfo->bktIdx = bktIdx;
5331 allocInfo->backTrace = (PTR) funcNm;
5332 allocInfo->moduleId = moduleId;
5333 allocInfo->bTrcSz = traceSize;
5334 cmHashListInsert(&memLkCb.memUsrMdl[moduleId][addr & 0x3].memHashCp,
5335 (PTR)allocInfo, (U8 *)&(allocInfo->memAddr),
5336 sizeof(allocInfo->memAddr));
5337 memLkCb.memUsrMdl[moduleId][addr & 0x3].used = TRUE;
5339 (Void) SUnlock(&(memLkCb.memUsrMdl[moduleId][addr & 0x3].memLck));
5342 } /* cmStorAllocBlk */
5347 } /* cmStorAllocBlk */
5353 * Desc: Initializes the memory leak detection module
5358 * Notes: This function initializes the memory leak detection module.
5370 Void SLogLkInfo (Void)
5373 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5378 CmMmBlkHdr *newBlkHdr;
5379 CmMmBlkHdr *oldBlkHdr;
5380 CmMmRegCb *tmpRegCb;
5383 fp = fopen("meLeakLog.txt", "w");
5386 memLk.fileLkLog = (FILE *)stdout;
5390 memLk.fileLkLog = fp;
5392 sprintf(prntBuf, "\n------- START OF LEAK LOG -------\n");
5393 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5394 for(regionIdx = 0; regionIdx < SS_MAX_REGS; regionIdx++)
5396 // tmpRegCb = mtCMMRegCb[regionIdx];
5397 while(cmHashListGetNext(&tmpRegCb->brdcmSsiLstCp,
5398 (PTR)oldBlkHdr, (PTR *)&newBlkHdr) == ROK)
5400 sprintf(prntBuf, "[LBIS]\n");
5401 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5403 sprintf(prntBuf, "Address: 0x%u\n", newBlkHdr);
5405 sprintf(prntBuf, "Address: 0x%lu\n", newBlkHdr);
5407 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5408 sprintf(prntBuf, "Requested Size: %d\n", (S16)newBlkHdr->reqSz);
5409 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5410 sprintf(prntBuf, "Allocated Size: %d\n", (S16)newBlkHdr->allocSz);
5411 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5412 sprintf(prntBuf, "Bucket Idx: %d\n", newBlkHdr->bktIdx);
5413 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5414 sprintf(prntBuf,"Memory Allocation Path:\n");
5415 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5416 //funcNm = (S8 **)newBlkHdr->backTrace;
5417 for(idx = 0; idx < BRDCM_MEM_LEAK_BTRACE; idx ++)
5419 // sprintf(prntBuf,"==> %p\n", newBlkHdr->backTrace[idx]);
5420 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5422 sprintf(prntBuf, "[LBIE]\n\n");
5423 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5424 fflush(memLk.fileLkLog);
5425 oldBlkHdr = newBlkHdr;
5429 sprintf(prntBuf, "\n------- END OF LEAK LOG -------\n");
5430 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5433 MemAllocInfo *oldMemInfo;
5434 MemAllocInfo *newMemInfo;
5440 if( memLkCb.memLkMdlInit == FALSE)
5444 sprintf(prntBuf, "\n------- START OF LEAK LOG -------\n");
5445 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5447 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5449 for (hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5451 if(memLkCb.memUsrMdl[memMdl][hashIdx].used == FALSE)
5457 SLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5458 while(cmHashListGetNext(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp,
5459 (PTR)oldMemInfo, (PTR *)&newMemInfo) == ROK)
5461 sprintf(prntBuf, "[LBIS]\n");
5462 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5463 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
5465 sprintf(prntBuf, "Address: 0x%u\n", newMemInfo->memAddr);
5467 sprintf(prntBuf, "Address: 0x%lu\n", newMemInfo->memAddr);
5469 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5470 sprintf(prntBuf, "Module Name: %s\n",
5471 memUsrMdlStr[newMemInfo->moduleId].mdlStr);
5472 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5473 sprintf(prntBuf, "Requested Size: %d\n", (S16)newMemInfo->reqSz);
5474 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5475 sprintf(prntBuf, "Allocated Size: %d\n", (S16)newMemInfo->allocSz);
5476 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5477 sprintf(prntBuf, "Bucket Idx: %d\n", newMemInfo->bktIdx);
5478 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5479 sprintf(prntBuf,"Memory Allocation Path:\n");
5480 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5481 funcNm = (S8 **)newMemInfo->backTrace;
5482 for(idx = 0; idx < newMemInfo->bTrcSz; idx ++)
5484 sprintf(prntBuf,"==> %s\n", funcNm[idx]);
5485 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5487 sprintf(prntBuf, "[LBIE]\n\n");
5488 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5489 fflush(memLkCb.fileLkLog);
5490 oldMemInfo = newMemInfo;
5493 SUnlock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5496 sprintf(prntBuf, "\n------- END OF LEAK LOG -------\n");
5497 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5504 /* cm_mem_c_001.main_15 : Additions */
5505 #ifdef SS_MEM_LEAK_STS
5508 * Fun: cmInitMemLeakMdl
5510 * Desc: Initializes the memory leak detection module
5515 * Notes: This function initializes the memory leak detection module.
5522 Void cmInitMemLeakMdl
5527 Void cmInitMemLeakMdl (Void)
5534 memLkCb.memLkMdlInit = FALSE;
5535 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5537 for (hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5539 SInitLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck, 1);
5540 cmHashListInit(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp,
5541 500, 0, FALSE, CM_HASH_KEYTYPE_U32MOD, 0, 0);
5542 memLkCb.memUsrMdl[memMdl][hashIdx].used = FALSE;
5545 if(memLkCb.fileLkLog == NULLP)
5547 memLkCb.fileLkLog = (FILE *) stdout;
5549 memLkCb.memLkMdlInit = TRUE;
5552 } /* cmInitMemLeakMdl */
5553 /* cm_mem_c_002.main_21 Added for shutdown procedure */
5556 * Fun: cmDeinitMemLeakMdl
5558 * Desc: De-initializes the memory leak detection module
5563 * Notes: This function de-initializes the memory leak detection module.
5570 Void cmDeinitMemLeakMdl
5575 Void cmDeinitMemLeakMdl (Void)
5582 memLkCb.memLkMdlInit = FALSE;
5583 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5585 for (hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5587 SDestroyLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5588 cmHashListDeinit(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp);
5589 memLkCb.memUsrMdl[memMdl][hashIdx].used = FALSE;
5596 * Fun: cmMemOpenMemLkFile
5598 * Desc: Initializes the memory leak detection module
5603 * Notes: This function initializes the memory leak detection module.
5610 Void cmMemOpenMemLkFile
5615 Void cmMemOpenMemLkFile (arg)
5619 memLkCb.fileLkLog = NULLP;
5620 memLkCb.fileLkLog = fopen(arg, "w");
5627 * Desc: Initializes the memory leak detection module
5632 * Notes: This function initializes the memory leak detection module.
5644 Void SFlushLkInfo (Void)
5647 MemAllocInfo *newMemInfo;
5651 #ifdef SS_MEM_LEAK_SOL
5653 #endif /* SS_MEM_LEAK_SOL */
5655 if( memLkCb.memLkMdlInit == FALSE)
5660 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5662 for(hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5664 if(memLkCb.memUsrMdl[memMdl][hashIdx].used == FALSE)
5669 SLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5670 while(cmHashListGetNext(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp,
5671 (PTR)NULLP, (PTR *)&newMemInfo) == ROK)
5673 funcNm = (S8 **)newMemInfo->backTrace;
5674 #ifdef SS_MEM_LEAK_SOL
5675 for(i = 0; i < newMemInfo->bTrcSz; i++)
5677 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5678 #ifdef SS_4GMX_LCORE
5679 MxHeapFree(SsiHeap, funcNm[i]);
5683 /* SPutSBuf(DFLT_REGION, DFLT_POOL, funcNm[i], sizeof(U32) * CM_MAX_STACK_TRACE); */
5685 #endif /* SS_MEM_LEAK_SOl */
5686 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5687 #ifdef SS_4GMX_LCORE
5688 MxHeapFree(SsiHeap, funcNm);
5689 MxHeapFree(SsiHeap, newMemInfo);
5695 SUnlock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5702 * Fun: cmMemGetModuleId
5704 * Desc: Initializes the memory leak detection module
5709 * Notes: This function initializes the memory leak detection module.
5722 U8 cmMemGetModuleId (funNm, traceSize)
5734 Txt *memFn[]={"SGetMsg", "SGetSBuf", "SGetDBuf", NULLP};
5736 /*cm_mem_c_001.main_25 : Fix for TRACE5 feature crash due to missing TRC MACRO*/
5737 for(idx = 0; idx < traceSize; idx++)
5741 while((memReqIdx < 0) && (memFn[memStrIdx] != NULLP))
5743 memReqIdx = cmMemGetStrMtchIdx(0, traceSize, memFn[memStrIdx],
5748 while(memUsrMdlStr[mdlFunStrIdx].fPStr != NULLP)
5750 len = strlen((const S8 *)memUsrMdlStr[mdlFunStrIdx].fPStr);
5751 memReqIdx = cmMemGetStrMtchIdx((memReqIdx + 1), traceSize,
5752 memUsrMdlStr[mdlFunStrIdx].fPStr,
5756 return (mdlFunStrIdx);
5761 while(memUsrMdlStr[mdlFunStrIdx].fPStr != NULLP)
5763 retVal = strcmp((const S8 *)"DEFAULT",
5764 (const S8 *)memUsrMdlStr[mdlFunStrIdx].fPStr);
5767 return (mdlFunStrIdx);
5774 } /* cmMemGetModuleId */
5778 * Fun: cmMemGetStrMtchIdx
5780 * Desc: Initializes the memory leak detection module
5785 * Notes: This function initializes the memory leak detection module.
5792 S16 cmMemGetStrMtchIdx
5800 S16 cmMemGetStrMtchIdx(strtIdx, endIdx, str, strLst)
5815 len = strlen((const S8 *)str);
5817 strncpy((S8 *)&cmpStr[1], (const S8 *)str, len);
5818 cmpStr[len + 1] = '\0';
5821 for(;strtIdx < endIdx && !found; strtIdx++)
5824 tempLen = strlen((const S8 *)strLst[strtIdx]);
5828 while(*(strLst[strtIdx] + idx + len) != '\0')
5830 retVal = strncmp((const S8 *)cmpStr,
5831 ((const S8 *)strLst[strtIdx] + idx), len);
5847 } /* cmMemGetStrMtchIdx */
5848 #ifdef SS_MEM_LEAK_SOL
5851 * Fun: cmAddrToSymStr
5853 * Desc: Initializes the memory leak detection module
5858 * Notes: This function initializes the memory leak detection module.
5872 S32 cmAddrToSymStr(pc, buffer, size)
5883 if (dladdr1(pc, &info, (Void **)&sym, RTLD_DL_SYMENT) == 0)
5885 return (snprintf(buffer, size, "[0x%p]", pc));
5888 if ((info.dli_fname != NULLP && info.dli_sname != NULLP) &&
5889 ((uintptr_t)pc - (uintptr_t)info.dli_saddr < sym->st_size))
5891 return (snprintf(buffer, size, "%s(%s+0x%x) [0x%p]",
5894 (unsigned long)pc - (unsigned long)info.dli_saddr, pc));
5898 return (snprintf(buffer, size, "%s(0x%p [0x%p]",
5900 (unsigned long)pc - (unsigned long)info.dli_fbase, pc));
5903 } /* cmAddrToSymStr */
5907 * Fun: cmLeakCallBack
5909 * Desc: Initializes the memory leak detection module
5914 * Notes: This function initializes the memory leak detection module.
5928 S32 cmLeakCallBack(pc, sigNo, arg)
5936 Backtrace_t *bt = (Backtrace_t *)arg;
5937 if (bt->bt_actcount >= bt->bt_maxcount)
5939 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5940 #ifdef SS_4GMX_LCORE
5941 buffer = (S8 *)MxHeapAlloc(SsiHeap, 510);
5942 memset(buffer, 0, 510);
5944 buffer = (S8 *)calloc(1, 510);
5946 /* SGetSBuf(DFLT_REGION, DFLT_POOL, &buffer, 510); */
5947 (void) cmAddrToSymStr((void *)pc, buffer, 505);
5948 bt->bt_buffer[bt->bt_actcount++] = (S8 *)buffer;
5951 } /* cmLeakCallBack */
5952 #endif /* SS_MEM_LEAK_SOL */
5954 #endif /* SS_MEM_LEAK_STS */
5955 /* cm_mem_c_001.main_12 - addition related to SSI enhancemens
5956 * These include sanity check functions for bucket and heap,
5957 * for printing several memory related statistics
5959 #if (defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined(SSI_DEBUG_LEVEL1))
5962 * Fun: cmMmRegIsBlkSane
5964 * Desc: Performs the sanity check for the memory block by checking its header.
5966 * Ret: ROK - If no trampling is detected in the block
5967 * RFAILED - If trampling is detected in the block
5969 * Notes: This function performs the memory block sanity in a block.
5974 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
5976 S16 cmMmRegIsBlkSane
5982 S16 cmMmRegIsBlkSane(blkPtr, size)
5988 S16 cmMmRegIsBlkSane
5993 S16 cmMmRegIsBlkSane(blkPtr)
5999 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
6000 CmMmBlkTail *tailPtr;
6003 for ( sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
6005 if (blkPtr->trSignature[sigCnt] != 0xAB)
6010 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
6011 tailPtr = (CmMmBlkTail *)((Data *)blkPtr + (sizeof(CmMmBlkHdr) + size));
6012 for ( sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
6014 if (tailPtr->trSignature[sigCnt] != 0xFE)
6023 #ifdef SSI_DEBUG_LEVEL1
6026 * Fun: cmMmBktSanityChk
6028 * Desc: Performs the sanity check for the memory blocks in a memory bucket.
6029 * This API gets called when trampling is detected in a memory block.
6031 * Ret: RTRAMPLINGNOK - Trampling, serious error
6032 * RTRAMPLINGOK - Trampling, but OK to proceed
6034 * Notes: This function performs the memory block sanity in a bucket. This
6035 * function is called by cmAlloc and cmFree as part of error handling mechanism.
6036 * Performs sanity check for the whole bucket by traversing each
6037 * of the memory blocks using the pointer bktStartPtr.
6038 * Keeps track of number of tramplings happened. If the count
6039 * exceeds the threshold decided, then invalidates this bucket.
6045 PRIVATE S16 cmMmBktSanityChk
6050 PRIVATE S16 cmMmBktSanityChk(bkt)
6057 bkt->trampleCount = 0;
6059 /* scan the entire memory list of the bucket */
6060 for (blkCnt = 0, ptrBlk = (CmMmBlkHdr *)bkt->bktStartPtr;
6061 blkCnt < (bkt->numBlks); blkCnt++)
6063 if (cmMmRegIsBlkSane(ptrBlk) != ROK)
6065 bkt->trampleCount++;
6066 if (bkt->trampleCount > CMM_TRAMPLING_THRESHOLD)
6068 /* Take action to invalidate the entire bucket */
6069 return (RTRAMPLINGNOK);
6072 /* reach next memory block in this bucket manually */
6073 ptrBlk = (CmMmBlkHdr *)((Data *)ptrBlk + ((bkt->size) + (sizeof(CmMmBlkHdr))));
6077 /* display an error message here */
6078 sprintf(dbgPrntBuf, " %d Memory tramplings detected in the bucket!\n", bkt->trampleCount);
6079 SDisplay(0, dbgPrntBuf);
6082 return (RTRAMPLINGOK);
6087 * Fun: cmMmHeapSanityChk
6089 * Desc: Performs the sanity check for the memory blocks in the memory heap.
6090 * This API gets called when trampling is detected in heap(Alloc/Free).
6092 * Ret: RTRAMPLINGNOK - Trampling, serious error
6093 * RTRAMPLINGOK - Trampling, but OK to proceed
6095 * Notes: This function performs the memory block sanity in the heap. This
6096 * function is called by cmHeapAlloc and cmHeapFree as part of error
6097 * handling mechanism. Keeps track of number of tramplings happened.
6098 * If the count exceeds the threshold then return RTRAMPLINGNOK. If the
6099 * count is less than threshold, then return RTRAMPLINGOK.
6105 PRIVATE S16 cmMmHeapSanityChk
6110 PRIVATE S16 cmMmHeapSanityChk(heapCb)
6116 /* increment the trample count */
6117 heapCb->trampleCount++;
6119 if (heapCb->trampleCount > CMM_TRAMPLING_THRESHOLD)
6121 return (RTRAMPLINGNOK);
6124 return (RTRAMPLINGOK);
6130 * Desc: Computes the hash list index (bin number) for a specified
6131 * key of type (x % 101).
6133 * return (idx % hash_table_size);
6135 * Ret: ROK - successful, *idx contains computed index
6143 PRIVATE S16 cmMmHashFunc
6145 CmMmHashListCp *hashListCp,
6150 PRIVATE S16 cmMmHashFunc (hashListCp, key, idx)
6151 CmMmHashListCp *hashListCp; /* hash list control point */
6152 U32 key; /* key string */
6153 U16 *idx; /* idx to return */
6157 *idx = (U16)(key % hashListCp->numOfbins);
6161 } /* end of cmMmHashFunc () */
6165 * Fun: cmMmHashListInit
6167 * Desc: Initializes a hash list. Parameters are:
6169 * hashListCp control point for hash list
6170 * nmbBins number of bins in the hash list. Storage will
6171 * be allocated for them from the indicated memory
6174 * pool for allocating storage for bins.
6176 * Ret: ROK - initialization successful
6177 * RFAILED - initialization failed, lack of memory
6185 PRIVATE S16 cmMmHashListInit
6187 CmMmHashListCp *hashListCp, /* hash list to initialize */
6188 U16 nmbBins, /* number of hash list bins */
6189 Region region, /* memory region to allocate bins */
6190 Pool pool /* memory pool to allocate bins */
6193 PRIVATE S16 cmMmHashListInit(hashListCp, nmbBins, region, pool)
6194 CmMmHashListCp *hashListCp; /* hash list to initialize */
6195 U16 nmbBins; /* number of hash list bins */
6196 Region region; /* memory region to allocate bins */
6197 Pool pool; /* memory pool to allocate bins */
6201 CmMmHashListEnt *hl;
6204 /* initialize control point fields */
6205 hashListCp->hashList = NULLP;
6206 hashListCp->numOfbins = 0;
6207 hashListCp->numOfEntries = 0;
6209 /* allocate memory for bins */
6212 if (SGetSBuf(region, pool, (Data **) &hashListCp->hashList,
6213 (Size)(nmbBins * sizeof(CmMmHashListEnt))) != ROK)
6216 /* initialize bin pointers */
6217 hl = hashListCp->hashList;
6218 for(i = 0; i < nmbBins; i++)
6220 hl[i].size = hl[i].numAttempts = 0;
6223 /* initialize bin size */
6224 hashListCp->numOfbins = nmbBins;
6232 * Fun: cmMmHashListDeinit
6234 * Desc: Deinitializes a hash list. Deallocates memory for bins
6235 * and resets header fields. Parameters are:
6237 * hashListCp control point for hash list
6239 * pool for allocating storage for bins.
6241 * Ret: ROK - successful
6242 * RFAILED - failure, invalid parameters
6250 PRIVATE S16 cmMmHashListDeinit
6252 CmMmHashListCp *hashListCp, /* hash list to deinitialize */
6253 Region region, /* memory region to allocate bins */
6254 Pool pool /* memory pool to allocate bins */
6257 PRIVATE S16 cmMmHashListDeinit(hashListCp, region, pool)
6258 CmMmHashListCp *hashListCp; /* hash list to deinitialize */
6259 Region region; /* memory region to allocate bins */
6260 Pool pool; /* memory pool to allocate bins */
6264 /* deallocate memory for bins */
6265 if (hashListCp->numOfbins)
6266 (Void) SPutSBuf(region, pool,
6267 (Data *) hashListCp->hashList,
6268 (Size) (hashListCp->numOfbins * sizeof(CmMmHashListEnt)));
6270 /* deinitialize control point fields */
6271 hashListCp->hashList = NULLP;
6272 hashListCp->numOfbins = 0;
6273 hashListCp->numOfEntries = 0;
6276 } /* end of cmMmHashListDeinit */
6280 * Fun: cmMmHashListInsert
6282 * Desc: Inserts a new entry in the hash list. Parameters are:
6284 * hashListCp control point for hash list
6285 * key pointer to key string in the new entry
6287 * Ret: ROK - insertion successful
6288 * RFAILED - insertion failed (incorrect parameter values)
6296 PRIVATE S16 cmMmHashListInsert
6298 CmMmHashListCp *hashListCp, /* hash list to add to */
6299 U32 key /* pointer to key */
6302 PRIVATE S16 cmMmHashListInsert(hashListCp, key)
6303 CmMmHashListCp *hashListCp; /* hash list to add to */
6304 U32 key; /* pointer to key */
6307 CmMmHashListEnt *hashListEnt; /* pointer to hash list entry header */
6308 U16 idx; /* index for insertion into hash list */
6312 /* check if hashListCp is initialised yet */
6313 if ( hashListCp->numOfbins == 0)
6316 /* compute index for insertion */
6317 if (cmMmHashFunc(hashListCp, key, &idx) != ROK)
6320 hashListEnt = hashListCp->hashList;
6322 if (hashListEnt[idx].numAttempts == 0)
6324 /* new entry, insert here */
6325 hashListEnt[idx].size = key;
6326 hashListEnt[idx].numAttempts++;
6327 /* increment count of entries in hash list */
6328 hashListCp->numOfEntries++;
6332 /* this hash is occupied, re-hash it using linear probing */
6333 for (i=idx; i < CMM_STAT_HASH_TBL_LEN; i++)
6335 if (hashListEnt[i].size == key)
6337 hashListEnt[i].numAttempts++;
6341 if (hashListEnt[i].numAttempts == 0)
6343 hashListEnt[i].size = key;
6344 hashListEnt[i].numAttempts++;
6345 /* increment count of entries in hash list */
6346 hashListCp->numOfEntries++;
6351 if (i == CMM_STAT_HASH_TBL_LEN)
6353 /* there is no free slot for this key */
6359 } /* end of cmMmHashListInsert */
6361 #endif /* SSI_DEBUG_LEVEL1 */
6362 /* cm_mem_c_001.main_15 : Additions */
6363 #ifdef SS_HISTOGRAM_SUPPORT
6366 * Fun: cmHstGrmHashListInit
6368 * Desc: Initializes a hash list. Parameters are:
6370 * hashListCp control point for hash list
6371 * Ret: ROK - initialization successful
6372 * RFAILED - initialization failed, lack of memory
6380 PRIVATE S16 cmHstGrmHashListInit
6382 CmHstGrmHashListCp *hashListCp /* hash list to initialize */
6385 PRIVATE S16 cmHstGrmHashListInit(hashListCp)
6386 CmHstGrmHashListCp *hashListCp; /* hash list to initialize */
6389 /*cm_mem_c_001.main_25 : Fix for TRACE5 feature crash due to missing TRC MACRO*/
6391 /* display an error message here */
6392 /*cm_mem_c_001.main_25: Fixed Warnings for 32/64 bit compilation*/
6394 sprintf(dbgPrntBuf, " %lu size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6396 sprintf(dbgPrntBuf, " %d size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6398 SDisplay(0, dbgPrntBuf);
6400 memset(hashListCp, 0, sizeof(CmHstGrmHashListCp));
6406 * Fun: cmHstGrmHashListDeInit
6408 * Desc: De-initializes a hash list. Parameters are:
6410 * hashListCp control point for hash list
6411 * Ret: ROK - initialization successful
6412 * RFAILED - initialization failed, lack of memory
6420 PRIVATE S16 cmHstGrmHashListDeInit
6422 CmHstGrmHashListCp *hashListCp /* hash list to initialize */
6425 PRIVATE S16 cmHstGrmHashListDeInit(hashListCp)
6426 CmHstGrmHashListCp *hashListCp; /* hash list to initialize */
6429 /*cm_mem_c_001.main_25 : Fix for TRACE5 feature crash due to missing TRC MACRO*/
6431 /* display an error message here */
6432 /*cm_mem_c_001.main_25: Fixed Warnings for 32/64 bit compilation*/
6434 sprintf(dbgPrntBuf, " %lu size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6436 sprintf(dbgPrntBuf, " %d size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6438 SDisplay(0, dbgPrntBuf);
6440 memset(hashListCp, 0, sizeof(CmHstGrmHashListCp));
6446 * Fun: cmHstGrmFreeInsert
6448 * Desc: Inserts a Freed information in into the hash list. Parameters are:
6450 * bkt : pointer to bucket for which memory is freed.
6451 * line : Line where memory is freed.
6452 * file : file where memory is freed.
6453 * entId : Tapa task which releases the memory.
6455 * Ret: ROK - insertion successful
6456 * RFAILED - insertion failed (incorrect parameter values)
6464 PRIVATE S16 cmHstGrmFreeInsert
6466 CmHstGrmHashListCp* hashListCp, /* hash list cp */
6467 U32 blkSz, /* size of the block freed */
6468 U32 line, /* Line number */
6469 U8 *fileName, /* file name */
6470 U8 entId /* Tapa task which free the memory */
6473 PRIVATE S16 cmHstGrmFreeInsert(hashListCp, blkSz, line, fileName, entId)
6474 CmHstGrmHashListCp* hashListCp; /* hash list cp */
6475 U32 blkSz; /* size of the block freed */
6476 U32 line; /* line number */
6477 U8 *fileName; /* file Name */
6478 U8 entId; /* Tapa task which frees the memory */
6481 U32 binIdx = 0; /* Bin index to insert the entry into the hash list */
6482 U32 key = 0; /* Key to fine the bin index */
6483 U32 ret = 0; /* Return value */
6484 CmMemEntries *entry = NULLP; /* Entry which contains the information */
6488 /* check for the total number of entries in the hash list. *
6489 * If there is no place for new entry return failure */
6490 cmHstGrmGetHashIdxAndKey(fileName, line, &binIdx, &key);
6492 /* After comuting the hash bind and key, check the entity already *
6493 existing or not. if we found the entry then update the information */
6494 ret = cmHstGrmFindEntry(hashListCp, key, &binIdx, &entry);
6497 entry->freedBytes += blkSz;
6498 entry->bucketFreeReq++;
6502 /* If hash list is full then print the error tna continue */
6503 if(hashListCp->totalNumEntries == (CMM_HIST_MAX_MEM_BIN * CMM_HIST_MAX_MEM_ENTRY_PER_BIN))
6505 printf("No place in the hash list. Increase the value of macro CMM_HIST_MAX_MEM_BIN and CMM_HIST_MAX_MEM_ENTRY_PER_BIN \n");
6509 /* Take the address of next free entry in the hash bin */
6510 entry = &(hashListCp->hashList[binIdx].entries[hashListCp->hashList[binIdx].numOfEntries]);
6512 /* Increase the number of time frees called */
6513 entry->bucketFreeReq++;
6514 entry->freedBytes += blkSz;
6516 /* Fill the information into the entry structure */
6517 cmHstGrmFillEntry(entry, key, line, fileName, entId);
6518 /* Increase the total numbet of entries in the bin */
6519 hashListCp->hashList[binIdx].numOfEntries++;
6521 /* Increase the total number of entries in the hash list */
6522 hashListCp->totalNumEntries++;
6525 } /* end of cmHstGrmFreeInsert */
6530 * Fun: ret = cmHstGrmAllocInsert
6532 * Desc: Inserts a memory allocated information in the hash list. Parameters are:
6534 * hashListCp control point for hash list
6535 * key pointer to key string in the new entry
6537 * Ret: ROK - insertion successful
6538 * RFAILED - insertion failed (incorrect parameter values)
6546 PRIVATE S16 cmHstGrmAllocInsert
6548 CmHstGrmHashListCp *hashListCp,
6556 PRIVATE S16 cmHstGrmAllocInsert(hashListCp, blkSz, reqSz, line, fileName, entId)
6557 CmHstGrmHashListCp *hashListCp;
6568 CmMemEntries *entry = NULLP;
6571 /* check for the total number of entries in the hash list. *
6572 * If there is no place for new entry return failure */
6573 cmHstGrmGetHashIdxAndKey(fileName, line, &binIdx, &key);
6575 /* After comuting the hash bind and key, check the entity already *
6576 existing or not. if we found the entry then update the information */
6577 ret = cmHstGrmFindEntry(hashListCp, key, &binIdx, &entry);
6581 entry->allocBytes += blkSz;
6582 entry->bucketAllocReq++;
6583 entry->wastedBytes += (blkSz - *reqSz);
6587 if(hashListCp->totalNumEntries == (CMM_HIST_MAX_MEM_BIN * CMM_HIST_MAX_MEM_ENTRY_PER_BIN))
6589 printf("No place in the hash list. Increase the value of macro CMM_HIST_MAX_MEM_BIN and CMM_HIST_MAX_MEM_ENTRY_PER_BIN\n");
6593 /* Take the address of next free entry in the hash bin */
6594 entry = &(hashListCp->hashList[binIdx].entries[hashListCp->hashList[binIdx].numOfEntries]);
6596 /* Clauculae the wasted bytes */
6597 /* Here wasted byte is differnce between the byte user
6598 * has requested and the byte the ssi allocated */
6599 entry->wastedBytes += (blkSz - *reqSz);
6600 entry->bucketAllocReq++;
6601 entry->allocBytes += blkSz;
6603 /* Fill the information into the entry structure */
6604 cmHstGrmFillEntry(entry, key, line, fileName, entId);
6605 /* Increase the total numbet of entries in the bin */
6606 hashListCp->hashList[binIdx].numOfEntries++;
6608 /* Increase the total number of entries in the hash list */
6609 hashListCp->totalNumEntries++;
6612 } /* end of cmHstGrmAllocInsert */
6617 * Fun: cmHstGrmGetHashIdxAndKey
6619 * Desc: Finds an entry in the hash list. Parameters are:
6621 * hashListCp control point for hash list
6622 * key pointer to key string in the new entry
6624 * Ret: ROK - insertion successful
6625 * RFAILED - insertion failed (incorrect parameter values)
6633 PRIVATE S16 cmHstGrmGetHashIdxAndKey
6641 PRIVATE S16 cmHstGrmGetHashIdxAndKey(fileName, line, binIdx, key)
6651 /* Calculate the key using file name and line number */
6652 for(i = 0 ; fileName[i] != '\0'; i++)
6654 *key += fileName[i];
6657 *binIdx = ( *key % CMM_HIST_MAX_MEM_BIN);
6659 } /* end of cmHstGrmFillEntry */
6663 * Fun: cmHstGrmFillEntry
6665 * Desc: Insert the entry into the hash list.
6667 * entry : Infornation which will be inserted into the hash list
6668 * key : Which will be used ti find the entry.
6669 * line : Line number
6670 * fileName : File name
6671 * entId : Tapa task Id
6673 * Ret: ROK - insertion successful
6674 * RFAILED - insertion failed (incorrect parameter values)
6682 PRIVATE S16 cmHstGrmFillEntry
6684 CmMemEntries *entry,
6691 PRIVATE S16 cmHstGrmFillEntry(entry, key, line, fileName, entId)
6692 CmMemEntries *entry;
6703 entry->entId = entId;
6704 for(idx = 0; fileName[idx] != '\0'; idx++)
6706 entry->fileName[idx] = fileName[idx];
6708 entry->fileName[idx] = '\0';
6710 } /* end of cmHstGrmFillEntry */
6714 * Fun: cmHstGrmFindEntry
6716 * Desc: Finds an entry in the hash list. Parameters are:
6718 * hashListCp control point for hash list
6719 * key pointer to key string in the new entry
6721 * Ret: ROK - insertion successful
6722 * RFAILED - insertion failed (incorrect parameter values)
6730 PRIVATE S16 cmHstGrmFindEntry
6732 CmHstGrmHashListCp *hashListCp,
6735 CmMemEntries **entry
6738 PRIVATE S16 cmHstGrmFindEntry(hashListCp, key, binIdx, entry)
6739 CmHstGrmHashListCp *hashListCp;
6742 CmMemEntries **entry;
6748 CmHstGrmHashListEnt *tmpBin = NULLP;
6750 for(numBin = 0; numBin < CMM_HIST_MAX_MEM_BIN; numBin++)
6752 /* find for the entry in the bin */
6753 tmpBin = &(hashListCp->hashList[*binIdx]);
6754 for(numEnt = 0; numEnt < tmpBin->numOfEntries; numEnt++)
6756 /* If key supplied is matched with the stored key then
6757 * return that entity */
6758 if(tmpBin->entries[numEnt].key == key)
6760 *entry = &(tmpBin->entries[numEnt]);
6762 }/* End of if (tmpBin->entries[numEnt].key) */
6763 }/* end of for (numEnt = 0) */
6765 /* Here we are checking for any room left in the bin. If the room *
6766 exists its mean that there is no entry with the Key. so return *
6768 If there is no room in the bin, then check the other bins to find *
6770 if(numEnt == CMM_HIST_MAX_MEM_ENTRY_PER_BIN)
6772 if(*binIdx == CMM_HIST_MAX_MEM_BIN)
6775 }/* End of if (binIdx) */
6779 }/* End of else (binIdx) */
6780 } /* End of if (numEnt) */
6783 printf ("Unable to find the entry in hash list\n");
6785 }/* End of else (numEnt) */
6786 }/* end of for (numBin = 0) */
6788 printf("Unable to find the entry in the hash list\n");
6790 } /* end of cmHstGrmFindEntry */
6792 #endif /* SS_HISTOGRAM_SUPPORT */
6794 /**********************************************************************
6796 **********************************************************************/