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 */
138 PUBLIC U32 memFreeCount=0;
139 PUBLIC U32 cmFreeCaller[4]={0};
140 PUBLIC U32 cmAllocCaller[4]={0};
141 PUBLIC Data *startPtr256=NULLP;
142 PUBLIC Data *startPtr128=NULLP;
143 PUBLIC U32 cmMemInfo128[100000][2]={0, 0};
144 PUBLIC U32 cmMemInfo256[100000][2]={0, 0};
145 PUBLIC Data *startPtr512=NULLP;
146 PUBLIC Data *startPtr768=NULLP;
147 PUBLIC Data *startPtr1664=NULLP;
148 PUBLIC Data *startPtr4800=NULLP;
149 PUBLIC Data *startPtr9920=NULLP;
150 PUBLIC Size regMemSize=0;
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.
465 PUBLIC S16 cmMmRegInit
472 PUBLIC S16 cmMmRegInit(region, regCb, cfg)
482 #if (ERRCLASS & ERRCLS_INT_PAR)
485 Txt errMsg[256] = {'\0'};
487 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
494 #if (ERRCLASS & ERRCLS_INT_PAR)
496 /* error check on parameters */
497 if ((regCb == NULLP) || (cfg == NULLP))
502 /* Error check on the configuration fields */
503 if ((!cfg->size) || (cfg->vAddr == NULLP) ||
504 (cfg->numBkts > CMM_MAX_BKT_ENT))
508 /* Check if the quantum size is power of 2 */
509 if ((cfg->numBkts) &&
510 ((cfg->bktQnSize - 1) & (cfg->bktQnSize)))
512 /* cm_mem_c_001.main_20 Addition */
513 sprintf(errMsg,"\n cmMmRegInit() failed, check if BktQuantum size might not be power of 2 \n");
519 * Check if the size of the memory region is enough, whether bucket sizes
520 * are multiples of quantumn size, and also whether two consecutive buckets
521 * falls within same quanta.
523 lstQnSize = cfg->bktQnSize;
526 for ( bktIdx =0; bktIdx < cfg->numBkts; bktIdx++)
528 /* check if bucket size is mutiple of quantum size */
529 if (cfg->bktCfg[bktIdx].size % cfg->bktQnSize)
531 /* cm_mem_c_001.main_20 Addition */
532 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
534 sprintf(errMsg,"\n cmMmRegInit() failed, Bkt:%d size:%u not multiple of quantum size:%u\
535 \n",bktIdx,cfg->bktCfg[bktIdx].size,cfg->bktQnSize);
537 sprintf(errMsg,"\n cmMmRegInit() failed, Bkt:%d size:%lu not multiple of quantum size:%lu\
538 \n",bktIdx,cfg->bktCfg[bktIdx].size,cfg->bktQnSize);
544 if ((bktBlkSize = cfg->bktCfg[bktIdx].size) < lstQnSize)
547 * Two consecutive buckets are not separated by quantum size.
549 /* cm_mem_c_001.main_20 Addition */
550 sprintf(errMsg,"\n cmMmRegInit() failed, Two consecutive buckets are not separated by quantum size \n");
554 /* cm_mem_c_001.main_20 Addition */
555 if (((cfg->bktCfg[bktIdx].size) /\
556 cfg->bktQnSize) > CMM_MAX_MAP_ENT)
558 /* Error check whether the size of the mapping table is sufficient */
559 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
561 sprintf(errMsg,"\n cmMmRegInit() failed, check maxBucketSize/BktQuantumSize(%u)\
562 \n should be less than CMM_MAX_MAP_ENT:%d \n",cfg->bktQnSize,CMM_MAX_MAP_ENT);
564 sprintf(errMsg,"\n cmMmRegInit() failed, check maxBucketSize/BktQuantumSize(%lu)\
565 \n should be less than CMM_MAX_MAP_ENT:%d \n",cfg->bktQnSize,CMM_MAX_MAP_ENT);
572 regCb->bktSize += (cfg->bktCfg[bktIdx].size *
573 cfg->bktCfg[bktIdx].numBlks);
575 if (regCb->bktSize > cfg->size)
577 /* Size of the memory region is less than the required size */
579 sprintf(errMsg,"\n cmMmRegInit() failed, Size of the memory region is less than the required size \n");
584 lstQnSize = ((bktBlkSize / cfg->bktQnSize) + 1) * cfg->bktQnSize;
589 /* Initialize the region control block */
590 regCb->region = region;
591 regCb->regInfo.regCb = regCb;
592 regCb->regInfo.start = cfg->vAddr;
593 regCb->regInfo.size = cfg->size;
596 avail_size = cfg->size;
597 #endif /* USE_PURE */
599 if ( cfg->chFlag & CMM_REG_OUTBOARD)
601 /* Out_of_board memory */
602 regCb->regInfo.flags = CMM_REG_OUTBOARD;
606 regCb->regInfo.flags = 0;
610 /* Initialize the memory manager function handlers */
611 /*cm_mem_c_001.main_21-registering new alloc function for new region*/
613 if(region == SS_WL_REGION)
615 regCb->regInfo.alloc = cmAllocWL;
616 regCb->regInfo.free = cmFreeWL;
621 /* Initialize the memory manager function handlers */
622 regCb->regInfo.alloc = cmAlloc;
623 regCb->regInfo.free = cmFree;
625 regCb->regInfo.ctl = cmCtl;
627 /* Initialize the physical address */
628 if ((regCb->chFlag = cfg->chFlag) & CMM_REG_PHY_VALID)
630 regCb->pAddr = cfg->pAddr;
633 /* Initial address of the memory region block */
634 memAddr = cfg->vAddr;
636 /* Initialize the fields related to the bucket pool */
637 regCb->bktMaxBlkSize = 0;
640 if (cfg->numBkts > 0 && cfg->numBkts < CMM_MAX_BKT_ENT)
642 /* Last bucket has the maximum size */
643 regCb->bktMaxBlkSize = cfg->bktCfg[cfg->numBkts - 1].size;
645 /* Get the power of the bktQnSize */
647 while( !((cfg->bktQnSize >> regCb->bktQnPwr) & 0x01))
652 /* Initilaize the bktIndex of the map entries to FF */
653 for ( lstMapIdx = 0; lstMapIdx < CMM_MAX_MAP_ENT; lstMapIdx++)
655 regCb->mapTbl[lstMapIdx].bktIdx = 0xFF;
659 for ( bktIdx = 0; bktIdx < cfg->numBkts; bktIdx++)
661 /* Allocate the lock for the bucket pool */
662 /* cm_mem_c_001.main_13 : Replaced SInitLock with WTInitLock for NT */
664 if (WTInitLock (&(regCb->bktTbl[bktIdx].bktLock), cfg->lType) != ROK)
666 if (SInitLock (&(regCb->bktTbl[bktIdx].bktLock), cfg->lType) != ROK)
669 /* Free the initialzed lock for the earlier buckets. */
672 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
673 WTDestroyLock for NT */
674 /* cm_mem_c_001.main_24 fix for memory corruption*/
677 WTDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
679 SDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
686 cmMmBktInit( &memAddr, regCb, cfg, bktIdx, &lstMapIdx);
689 /* Used while freeing the bktLock in cmMmRegDeInit */
690 regCb->numBkts = cfg->numBkts;
694 * Initialize the heap pool if size the memory region region is more
695 * than the size of the bucket pool
698 regCb->heapFlag = FALSE;
700 /* Align the memory address */
701 memAddr = (Data *)(PTRALIGN(memAddr));
703 regCb->heapSize = cfg->vAddr + cfg->size - memAddr;
706 * Round the heap size so that the heap size is multiple
709 regCb->heapSize -= (regCb->heapSize % CMM_MINBUFSIZE);
713 /* Allocate the lock for the heap pool */
714 /* cm_mem_c_001.main_13 : Replaced SInitLock with WTInitLock for NT */
716 if (WTInitLock (®Cb->heapCb.heapLock, cfg->lType) != ROK)
718 if (SInitLock (®Cb->heapCb.heapLock, cfg->lType) != ROK)
721 bktIdx = cfg->numBkts;/* ccpu00125353: warning fix */
724 /* Free the initialzed locks of the buckets */
727 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
728 WTDestroyLock for NT */
729 /* cm_mem_c_001.main_24 fix for memory corruption*/
732 WTDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
734 SDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
742 regCb->heapFlag = TRUE;
743 cmMmHeapInit(memAddr, &(regCb->heapCb), regCb->heapSize);
746 /* Call SRegRegion to register the memory region with SSI */
747 if (SRegRegion(region, ®Cb->regInfo) != ROK)
752 /* cm_mem_c_001.main_12 - addition for initializing the hash table */
753 #ifdef SSI_DEBUG_LEVEL1
754 /* Initialize the region level hash table for debug info storage */
755 if (cmMmHashListInit(®Cb->hashListCp, CMM_STAT_HASH_TBL_LEN, region, 0) != ROK)
759 #endif /* SSI_DEBUG_LEVEL1 */
760 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
761 /* Initialize the hast list to maintain the SSI memory information for Broadcom */
762 offset = (U16)((PTR)(&ptrHdr.ent) - (PTR) &ptrHdr);
763 printf("###########offset is %d region %d\n", offset, region);
764 if(cmHashListInit(®Cb->brdcmSsiLstCp, 1000, offset, FALSE,
765 CM_HASH_KEYTYPE_U32MOD, region, 0) != ROK)
769 #endif /* SSI_DEBUG_LEVEL1 */
772 } /* end of cmMmRegInit*/
780 * Desc: Deinitialize the memory region. The function call SDeregRegion
781 * to deregister the memory region with System Service.
784 * Ret: ROK - successful
785 * RFAILED - unsuccessful.
787 * Notes: The memory owner calls this function to deinitialize the region.
788 * The memory manager does not return the memory to the system.
789 * Before calling this function, the memory owner must be sure that
790 * no layer is using any memory block from this region. On
791 * successful return from the function, any request to the memory
792 * manager to allocate/deallocate memory will fail. The memory owner
793 * can reuse the memory for other region or return the memory to the
794 * system memory pool.
802 PUBLIC S16 cmMmRegDeInit
807 PUBLIC S16 cmMmRegDeInit(regCb)
815 #if (ERRCLASS & ERRCLS_INT_PAR)
817 /* error check on parameters */
825 /* cm_mem_c_001.main_12 - addition for deinitializing the hash table */
826 #ifdef SSI_DEBUG_LEVEL1
827 /* Deinitialize the hash table used for debug info storage at region level */
828 if (cmMmHashListDeinit(®Cb->hashListCp, regCb->region, 0) != ROK)
832 #endif /* SSI_DEBUG_LEVEL1 */
833 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
834 /* Deinitialize the hash table used for broadcom ssi instrumentation */
835 if (cmHashListDeinit(®Cb->brdcmSsiLstCp) != ROK)
841 /* Call SDeregRegion first to deregister the memory region with SSI */
842 (Void) SDeregRegion (regCb->region);
846 /* Bucket pool is configured */
848 /* Free the initialzed locks of the buckets */
849 for ( bktIdx = regCb->numBkts; bktIdx > 0;)
851 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
852 WTDestroyLock for NT */
853 /* cm_mem_c_001.main_24 fix for memory corruption*/
856 WTDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
858 SDestroyLock(&(regCb->bktTbl[bktIdx].bktLock));
860 /* cm_mem_c_001.main_15:Additions */
861 #ifdef SS_HISTOGRAM_SUPPORT
862 /* De-initialise the memory histogram hash list */
863 cmHstGrmHashListDeInit(&(regCb->bktTbl[bktIdx].hstGrmHashListCp));
864 #endif /* SS_HISTOGRAM_SUPPORT */
870 /* Heap pool is configured */
872 /* cm_mem_c_001.main_13: Replaced SDestroyLock with
873 WTDestroyLock for NT */
875 WTDestroyLock(®Cb->heapCb.heapLock);
877 SDestroyLock(®Cb->heapCb.heapLock);
883 } /* end of cmMmRegDeInit */
885 #ifdef CM_MEM_OVERUSED
886 #define OVERUSED(_bkt) (((_bkt)->numAlloc * 100) / (_bkt)->numBlks > 80)
888 int g_overused[5] = {0};
891 #ifdef CM_MEM_PRINT_DEFINED
892 volatile int gSubIndex = 0;
893 int regAllocBktSts[10][2][6]={{0}};
894 int regFreeBktSts[10][2][6]={{0}};
901 * Desc: Allocate a memory block for the memory region.
904 * Ret: ROK - successful
905 * RFAILED - unsuccessful.
908 * The function allocates a memory block of size atleast equal to
909 * the requested size. The size parameter will be updated with the
910 * actual size of the memory block allocated for the request. The
911 * CMM tries to allocate the memory block form the bucket pool. If
912 * there is no memory in the bucket the CMM allocates the memory
913 * block form the heap pool. This function is always called by the
914 * System Service module.
916 * The caller of the function should try to use the out value of
917 * the size while returning the memory block to the region. However
918 * the current design of the memory manager does not enforce to pass
919 * the actual size of the memory block. (Due to the SGetSBuf
920 * semantics the layer will not able to pass the correct size of the
921 * memory block while calling SPutSBuf).
927 /* cm_mem_c_001.main_12 - addition to accept new parameter memType(static/dynamic) */
929 /* cm_mem_c_001.main_15 : Additions */
930 #ifdef SS_HISTOGRAM_SUPPORT
931 #ifdef SSI_DEBUG_LEVEL1
946 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, memType, line, fileName, entId, hstReg)
971 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, line, fileName, entId, hstReg)
981 #endif /* SSI_DEBUG_LEVEL1 */
983 #ifdef SS_LIGHT_MEM_LEAK_STS
996 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr ,memType, lineNo, funcName)
1005 #else /*SS_LIGHT_MEM_LEAK_STS */
1006 #ifdef SSI_DEBUG_LEVEL1
1017 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, memType)
1025 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1036 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr, memType)
1044 #ifdef T2K_MEM_LEAK_DBG
1064 PRIVATE S16 cmAlloc(regionCb, size, flags, ptr)
1071 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
1072 #endif /* SSI_DEBUG_LEVEL1 */
1073 #endif /*SS_LIGHT_MEM_LEAK_STS */
1074 /* cm_mem_c_001.main_15: Additions */
1075 #endif /* SS_HISTOGRAM_SUPPORT */
1078 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
1084 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
1088 /* cm_mem_c_001.main_15 : Additions */
1089 #if (defined(SS_MEM_LEAK_STS) || defined( BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1091 #endif /* SS_MEM_LEAK_STS */
1092 /* cm_mem_c_001.main_12 - addition to hold the allocated block */
1093 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
1094 CmMmBlkHdr *alocBlk;
1095 #endif /* SSI_DEBUG_LEVEL1 */
1096 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1099 /* cm_mem_c_001.main_15 : Additions */
1100 #ifdef SS_HISTOGRAM_SUPPORT
1102 #endif /* SS_HISTOGRAM_SUPPORT */
1103 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
1118 /* cm_mem_c_001.main_15 : Additions */
1119 #if (defined(SS_MEM_LEAK_STS) || defined( BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1121 #endif /* SS_MEM_LEAK_STS */
1123 regCb = (CmMmRegCb *)regionCb;
1125 #if (ERRCLASS & ERRCLS_INT_PAR)
1127 /* error check on parameters */
1128 if ((regCb == NULLP) || (size == NULLP) || !(*size) || (ptr == NULLP))
1134 /* cm_mem_c_001.main_12 - addition for checking memType parameter */
1135 #ifdef SSI_DEBUG_LEVEL1
1136 #if (ERRCLASS & ERRCLS_INT_PAR)
1137 if ((memType != CMM_STATIC_MEM_FLAG) && (memType != CMM_DYNAMIC_MEM_FLAG))
1141 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
1142 #endif /* SSI_DEBUG_LEVEL1 */
1149 /* cm_mem_c_001.main_12 - addition to insert the size into hash list */
1150 #ifdef SSI_DEBUG_LEVEL1
1151 /* Update the hash list */
1152 if (cmMmHashListInsert(&(regCb->hashListCp), *size) != ROK)
1154 /* display that, this entry could not be made in the hash list */
1156 /* display an error message here */
1157 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1159 sprintf(dbgPrntBuf, "\n Could not make an entry for size %u in hash table of region %d \n",
1160 *size, regCb->region);
1162 sprintf(dbgPrntBuf, "\n Could not make an entry for size %lu in hash table of region %d \n",
1163 *size, regCb->region);
1165 SDisplay(0, dbgPrntBuf);
1168 #endif /* SSI_DEBUG_LEVEL1 */
1171 * Check if the requested size is less than or equal to the maximum block
1172 * size in the bucket.
1174 if ( *size <= regCb->bktMaxBlkSize)
1176 /* Get the map to the mapping table */
1177 idx = ((*size - 1) >> regCb->bktQnPwr);
1179 #if (ERRCLASS & ERRCLS_DEBUG)
1180 if (regCb->mapTbl[idx].bktIdx == 0xFF)
1182 /* Some fatal error in the map table initialization. */
1187 /* Dequeue the memory block and return it to the user */
1188 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
1191 /* While loop is introduced to use the "break statement inside */
1195 * Check if the size request is not greater than the size available
1198 if (*size > bkt->size)
1200 /* Try to go to the next bucket if available */
1201 if((idx < (CMM_MAX_MAP_ENT - 1)) &&
1202 (regCb->mapTbl[++idx].bktIdx != 0xFF))
1204 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
1208 /* This is the last bucket, try to allocate from heap */
1213 /* Acquire the bucket lock */
1214 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
1216 (Void) WTLock(&(bkt->bktLock));
1218 (Void) SLock(&(bkt->bktLock));
1220 #ifdef XEON_SPECIFIC_CHANGES
1221 CM_MEM_ALLOC_STS(regCb->region, idx);
1224 #if (ERRCLASS & ERRCLS_DEBUG)
1225 regCb->mapTbl[idx].numReq++;
1226 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
1228 /* cm_mem_c_001.main_12 - addition for sanity check before allocation */
1229 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1230 /* increment the allocation attempt counter at bucket level */
1231 bkt->numAllocAttempts++;
1233 /* detect trampling if any and call sanity check. This is done for (bkt->nextBlk) as
1234 the allocation is always from (bkt->nextBlk) */
1237 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1238 if(cmMmRegIsBlkSane(bkt->nextBlk, bkt->size) != ROK)
1240 if (cmMmRegIsBlkSane(bkt->nextBlk) != ROK)
1243 /* detected a trampled memory block in this bucket */
1245 /* display an error message here */
1246 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1248 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %u bytes \n",
1249 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
1251 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %lu bytes \n",
1252 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
1254 SDisplay(0, dbgPrntBuf);
1257 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1258 if (cmMmBktSanityChk(bkt) == RTRAMPLINGNOK)
1260 /* Release the lock */
1261 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1263 (Void) WTUnlock(&(bkt->bktLock));
1265 (Void) SUnlock(&(bkt->bktLock));
1267 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
1268 RETVALUE(RTRAMPLINGNOK);
1273 /* Release the lock */
1274 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1276 (Void) WTUnlock(&(bkt->bktLock));
1278 (Void) SUnlock(&(bkt->bktLock));
1280 /* return RFAILED */
1285 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr)); /* ccpu00125353: warning fix */
1286 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1287 ptrHdr = (CmMmBlkHdr *)bkt->nextBlk;
1289 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1290 /* Initialize the elements with 0xAB */
1291 cmMemset((U8 *)*ptr, 0xAB, *size);
1293 // printf("Pointer allocated %8p size %d\n", *ptr, *size);
1294 /* Store this pointer in hash list */
1295 if ((bkt->nextBlk) && *ptr)
1296 #elif SS_LIGHT_MEM_LEAK_STS
1297 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr)); /* ccpu00125353: warning fix */
1298 if ((bkt->nextBlk) && *ptr)
1300 *ptr = bkt->next;/* ccpu00125353: warning fix */
1302 #endif /* SSI_DEBUG_LEVEL1 */
1304 /* cm_mem_c_001.main_12 - addition for header */
1305 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
1306 /* point to next block header */
1307 alocBlk = bkt->nextBlk;
1308 bkt->nextBlk = (CmMmBlkHdr *)(bkt->nextBlk->nextBlk);
1310 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
1311 if(bkt->size == 128)
1313 memIndex = (*ptr - startPtr128) / 128;
1315 if(bkt->size == 256)
1317 memIndex = (*ptr - startPtr256) / 256;
1320 if (*((U32 *)(*ptr + 4)) != 0xDEADDEAD && *((U32 *)(*ptr + 80)) != 0xDEADDEAD && *((U32 *)(*ptr + 24)) != 0xDEADDEAD)
1323 if(bkt->size == 256)
1328 #endif /* MS_MBUF_CORRUPTION */
1329 #ifdef SSI_MEM_CORR_PREVENTION
1330 *(((U32 *)(*ptr)) + 2) = 0;
1333 #ifdef T2K_MEM_LEAK_DBG
1336 /* Lock before the transaction-start */
1337 pthread_mutex_lock(&(regMemLeakInfo.memLock[regCb->region]));
1338 InsertToT2kMemLeakInfo( (U64)*ptr,*size,line,file,regCb->region);
1339 /* UnLock after the transaction */
1340 pthread_mutex_unlock(&(regMemLeakInfo.memLock[regCb->region]));
1342 #endif /* T2K_MEM_LEAK_DBG */
1344 bkt->next = *((CmMmEntry **)(bkt->next));
1345 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
1346 *nextptr = bkt->next;
1347 if (*((U32 *)(*nextptr + 4)) != 0xDEADDEAD && *((U32 *)(*nextptr + 80)) != 0xDEADDEAD && *((U32 *)(*nextptr + 24)) != 0xDEADDEAD)
1349 if(bkt->size == 128)
1350 *prevptr = startPtr128 + ((memIndex-1)*128);
1351 if(bkt->size == 256)
1352 *prevptr = startPtr256 + ((memIndex-1)*256);
1353 if(bkt->size == 128)
1354 memIndex = (*nextptr - startPtr128) / 128;
1355 if(bkt->size == 256)
1356 memIndex = (*nextptr - startPtr256) / 256;
1360 if(bkt->size == 128)
1362 memIndex = (*ptr - startPtr128) / 128;
1363 cmMemInfo128[memIndex][0] = cmAllocCaller[MxGetCpuID()];
1365 if(bkt->size == 256)
1367 memIndex = (*ptr - startPtr256) / 256;
1368 cmMemInfo256[memIndex][0] = cmAllocCaller[MxGetCpuID()];
1370 cmAllocCaller[MxGetCpuID()] = NULLP;
1371 *((U32 *)(*ptr + 4)) = 0x00000000;
1372 *((U32 *)(*ptr + 124)) = 0;
1373 *((U32 *)(*ptr + 24)) = 0x00000000;
1374 *((U32 *)(*ptr + 44)) = 0x00000000;
1375 *((U32 *)(*ptr + 80)) = 0x00000000;
1376 *((U32 *)(*ptr + 116)) = 0x00000000;
1378 #endif /* SSI_DEBUG_LEVEL1 */
1380 /* cache_coherency_changes */
1385 * Increment the statistics variable of number of memory block
1389 if (bkt->numAlloc > bkt->maxAlloc)
1391 bkt->maxAlloc = bkt->numAlloc;
1393 #ifdef CM_MEM_OVERUSED
1395 if (g_overused[bktIdx] == 0 && OVERUSED(bkt))
1397 g_overused[bktIdx] = 1;
1398 /*printf("cmAlloc: bktIdx %u overused %u numAlloc %u\n", bktIdx, g_overused[bktIdx], bkt->numAlloc); */
1402 /* cm_mem_c_001.main_12 - addition for header manipulation */
1403 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1404 /* update the size for which this memory block has been allocated */
1405 alocBlk->requestedSize = *size;
1406 /* update the memory block header */
1407 CMM_RESET_FREE_FLAG(alocBlk->memFlags);
1408 if (memType == CMM_STATIC_MEM_FLAG)
1410 CMM_SET_STATIC_FLAG(alocBlk->memFlags);
1411 /* add it to the static memory allocated */
1412 bkt->staticMemUsed += bkt->size;
1416 CMM_SET_DYNAMIC_FLAG(alocBlk->memFlags);
1417 /* add it to the dynamic memory allocated */
1418 bkt->dynamicMemUsed += bkt->size;
1420 #elif SS_LIGHT_MEM_LEAK_STS
1421 alocBlk->requestedSize = *size;
1422 alocBlk->lineNo = lineNo;
1423 alocBlk->currFuncName = funcName;
1424 if(gmemLkCb.isStarted == TRUE)
1426 alocBlk->allocQueueIndx = cmStorAllocBlk(alocBlk);
1428 #endif /* SSI_DEBUG_LEVEL1 */
1430 if (((bkt->size - (*size)) >> regCb->bktQnPwr) && flags)
1434 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1437 "[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++);
1440 "[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++);
1442 SDisplay(0, prntBuf);
1450 "SGetSBuf:%08lu:Size Bucket Id:%03d Times:%05lu Pointer: %8p\n",
1451 *size, regCb->mapTbl[idx].bktIdx, num_times, *ptr);
1452 SDisplay(0, prntBuf);
1454 #endif /* MEMCAL_DEBUG */
1455 /* cm_mem_c_001.main_15 : Additions */
1456 #ifdef SS_HISTOGRAM_SUPPORT
1457 /* If If Tapa task (entId)is registerd for histogram then insert Memrory allocated
1458 * information into the hash list */
1461 if (cmHstGrmAllocInsert(&(bkt->hstGrmHashListCp), bkt->size, size, line, fileName, entId) != ROK)
1463 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
1468 #endif /* SS_HISTOGRAM_SUPPORT */
1470 /* Update the size parameter */
1472 #ifdef SS_MEM_LEAK_STS
1473 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
1474 cmStorAllocBlk((PTR)*ptr, (Size) reqSz, (Size) *size,
1475 regCb->mapTbl[idx].bktIdx);
1476 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1477 cmStorAllocBlk(ptrHdr, (Size)reqSz, (Size) *size,
1478 regCb->mapTbl[idx].bktIdx, regCb);
1479 #endif /* SS_MEM_LEAK_STS */
1481 /* cm_mem_c_008.104 - Addition for memory calculator tool */
1483 /* Release the lock */
1484 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1486 (Void) WTUnlock(&(bkt->bktLock));
1488 (Void) SUnlock(&(bkt->bktLock));
1497 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1500 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %u bytes], %u times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
1503 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %lu bytes], %lu times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
1505 SDisplay(0, prntBuf);
1509 #if (ERRCLASS & ERRCLS_DEBUG)
1510 regCb->mapTbl[idx].numFailure++;
1511 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
1513 /* Release the lock */
1514 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1516 (Void) WTUnlock(&(bkt->bktLock));
1518 (Void) SUnlock(&(bkt->bktLock));
1527 regCb->heapCb.heapAllocCnt++;
1529 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1532 "[MEM_CAL_CNTC] No bucket block configured for %u bytes \n Number of blocks allocated from heap = %u\n",*size,
1533 regCb->heapCb.heapAllocCnt);
1536 "[MEM_CAL_CNTC] No bucket block configured for %lu bytes \n Number of blocks allocated from heap = %lu\n",*size,
1537 regCb->heapCb.heapAllocCnt);
1539 SDisplay(0, prntBuf);
1544 /* Memory not available in the bucket pool */
1545 if (regCb->heapFlag && (*size < regCb->heapSize))
1548 if (flags) tryHeap = 1;
1551 * The heap memory block is available. Allocate the memory block from
1554 /* cm_mem_c_001.main_15: Additions */
1555 #ifdef SS_HISTOGRAM_SUPPORT
1556 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
1557 #ifdef SSI_DEBUG_LEVEL1
1558 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size, memType, line, fileName, entId, hstReg));
1560 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size, line, fileName, entId, hstReg));
1561 #endif /* SSI_DEBUG_LEVEL1 */
1563 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
1564 #ifdef SSI_DEBUG_LEVEL1
1565 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size, memType));
1567 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size));
1568 #endif /* SSI_DEBUG_LEVEL1 */
1569 #endif /* SS_HISTOGRAM_SUPPORT */
1572 /* No memory available */
1574 #else /* use pure is on */
1575 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
1576 #ifdef SS_4GMX_LCORE
1577 *ptr = (Data*) MxHeapAlloc(SsiHeap, *size);
1578 cmMemset((U8*)ptr, 0, *size);
1580 *ptr = (Data*) malloc(*size);
1582 if ( (*ptr) == NULLP)
1584 avail_size -= *size;
1586 #endif /* USE_PURE */
1588 } /* end of cmAlloc */
1595 * Desc: Return the memory block for the memory region.
1598 * Ret: ROK - successful
1599 * RFAILED - unsuccessful.
1601 * Notes: The user calls this function to return the previously allocated
1602 * memory block to the memory region. The memory manager does not
1603 * check the validity of the state of the memory block(like whether
1604 * it was allocated earlier). The caller must be sure that, the
1605 * address specified in the parameter 'ptr' is valid and was
1606 * allocated previously from same region.
1613 /* cm_mem_c_001.main_15 : Additions */
1614 #ifdef SS_LIGHT_MEM_LEAK_STS
1625 PRIVATE S16 cmFree(regionCb, ptr, size, lineNo, funcName)
1632 #else /*SS_LIGHT_MEM_LEAK_STS */
1633 #ifdef SS_HISTOGRAM_SUPPORT
1646 PRIVATE S16 cmFree(regionCb, ptr, size, line, fileName, entId, hstReg)
1657 #ifdef T2K_MEM_LEAK_DBG
1666 #else /* T2K_MEM_LEAK_DBG */
1675 PRIVATE S16 cmFree(regionCb, ptr, size)
1681 /* cm_mem_c_001.main_15 : Additions */
1682 #endif /* SS_HISTOGRAM_SUPPORT */
1683 #endif /*SS_LIGHT_MEM_LEAK_STS */
1686 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
1692 /* cm_mem_c_001.main_12 - addition for holding the free pointer */
1693 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
1695 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1696 CmMmBlkHdr *lastHdr;
1698 #endif /* SSI_DEBUG_LEVEL1 */
1699 /* cm_mem_c_001.main_15 : Additions */
1700 #ifdef SS_HISTOGRAM_SUPPORT
1702 #endif /* SS_HISTOGRAM_SUPPORT */
1703 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption*/
1709 regCb = (CmMmRegCb *)regionCb;
1712 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1713 /* Check if the memory block is from the memory region */
1714 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
1715 ((CmMmRegCb *)regCb)->regInfo.size)
1720 #if (ERRCLASS & ERRCLS_INT_PAR)
1722 /* error check on parameters */
1723 if ((regCb == NULLP) || (!size) || (ptr == NULLP))
1728 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1729 /* Check if the memory block is from the memory region */
1730 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
1731 ((CmMmRegCb *)regCb)->regInfo.size)
1736 /* cm_mem_c_001.main_20 Addition */
1737 if (ptr < regCb->regInfo.start)
1745 * Check if the memory block was allocated from the bucket pool.
1748 if (ptr < (regCb->regInfo.start + regCb->bktSize))
1750 #ifdef T2K_MEM_LEAK_DBG
1752 pthread_mutex_lock(&(regMemLeakInfo.memLock[regCb->region]));
1753 RemoveFromT2kMemLeakInfo((U64)ptr , file,line,regCb->region);
1754 pthread_mutex_unlock(&(regMemLeakInfo.memLock[regCb->region]));
1757 /* The memory block was allocated from the bucket pool */
1759 /* Get the map to the mapping table */
1760 idx = ((size - 1) >> regCb->bktQnPwr);
1762 #if (ERRCLASS & ERRCLS_DEBUG)
1763 if (regCb->mapTbl[idx].bktIdx == 0xFF)
1765 /* Some fatal error in the map table initialization. */
1770 /* Enqueue the memory block and return it to the user */
1771 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
1774 * Check if the size is not greater than the size available
1775 * in the bucket. If so, then the buffer must have been allocated
1776 * from next bucket. We don't need to check the validity of the
1777 * next bucket, otherwise buffer must have been allocated from heap
1780 if (size > bkt->size)
1782 bkt = &(regCb->bktTbl[regCb->mapTbl[++idx].bktIdx]);
1785 /* Acquire the bucket lock */
1786 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
1788 (Void) WTLock(&(bkt->bktLock));
1790 (Void) SLock(&(bkt->bktLock));
1792 #ifdef XEON_SPECIFIC_CHANGES
1793 CM_MEM_FREE_STS(regCb->region, idx);
1795 /* cache_coherency_changes */
1800 /* cm_mem_c_001.main_12 - addition for sanity check and free */
1801 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
1802 /* increment the dealloc attempt counter at bucket level */
1803 bkt->numDeallocAttempts++;
1805 /* Check the memFlags to see whether this block was allocated */
1806 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
1807 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
1808 cmRlsAllocBlk(ptrHdr, regCb);
1810 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1811 /* Check for ptr size */
1812 if(((ptrHdr->requestedSize - size) % size) != 0)
1815 sprintf(dbgPrntBuf, "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);
1819 printf("Passed size (%d) does not match with allocated \
1820 size(%d) %8p, Bucket Id:%03d\n",
1821 size, ptrHdr->requestedSize, ptr, regCb->mapTbl[idx].bktIdx);
1824 /* Validate the tail part to see if there is any over run */
1825 // printf("Pointer free request %8p, size %d\n", ptr, size);
1828 /* validate the block to be freed for trampling */
1829 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1830 if(cmMmRegIsBlkSane(ptrHdr, bkt->size) != ROK)
1832 if (cmMmRegIsBlkSane(ptrHdr) != ROK)
1835 /* Handle error case of Memory trampling */
1837 /* display an error message here */
1838 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1840 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %u bytes \n",
1841 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1843 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %lu bytes \n",
1844 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1846 SDisplay(0, dbgPrntBuf);
1850 * if sanity check returns RTRAMPLINGOK then there is nothing to do
1851 * as the memory blk is already invalidated in cmMmBktSanityChk
1853 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1854 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
1858 /* Release the lock */
1859 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1861 (Void) WTUnlock(&(bkt->bktLock));
1863 (Void) SUnlock(&(bkt->bktLock));
1872 * this is the case where in the entire bucket has been made unusable
1875 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1877 (Void) WTUnlock(&(bkt->bktLock));
1879 (Void) SUnlock(&(bkt->bktLock));
1882 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
1883 RETVALUE(RTRAMPLINGNOK);
1885 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1886 printf("Memory signature is invalid\n");
1891 /* reset the size */
1892 ptrHdr->requestedSize = 0;
1893 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1894 /* Initialize the elements with 0xAB */
1895 cmMemset((U8 *)ptr, 0xAB, size);
1897 /* check if the block to be freed is already having the state as FREE */
1898 if (CMM_IS_FREE(ptrHdr->memFlags))
1900 /* Handle double deallocation error case */
1902 /* display an error message here */
1903 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1905 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p, Bucket Id:%03d, size %u bytes \n",
1906 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1908 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p, Bucket Id:%03d, size %lu bytes \n",
1909 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1911 SDisplay(0, dbgPrntBuf);
1914 /* Release the lock */
1915 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1917 (Void) WTUnlock(&(bkt->bktLock));
1919 (Void) SUnlock(&(bkt->bktLock));
1921 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1922 printf("Attempt to double deallocate memory at: %8p, Bucket Id:%03d,\
1923 size %u bytes \n", ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
1926 /* handle RDBLFREE in SFree/SPutSBuf */
1929 if (CMM_IS_STATIC(ptrHdr->memFlags))
1931 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
1932 CMM_RESET_STATIC_FLAG(ptrHdr->memFlags);
1933 /* deduct it from the static memory count */
1934 bkt->staticMemUsed -= bkt->size;
1936 else if (CMM_IS_DYNAMIC(ptrHdr->memFlags))
1938 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
1939 CMM_RESET_DYNAMIC_FLAG(ptrHdr->memFlags);
1940 /* deduct it from the dynamic memory count */
1941 bkt->dynamicMemUsed -= bkt->size;
1945 /* This is a case similar to trampled memory */
1947 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
1949 sprintf(dbgPrntBuf, "Invalid memory flag: %u !!!\n", ptrHdr->memFlags);
1951 sprintf(dbgPrntBuf, "Invalid memory flag: %lu !!!\n", ptrHdr->memFlags);
1953 SDisplay(0, dbgPrntBuf);
1955 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1956 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
1958 /* do not add to the free list */
1961 /* Release the lock */
1962 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1964 (Void) WTUnlock(&(bkt->bktLock));
1966 (Void) SUnlock(&(bkt->bktLock));
1974 * this is the case where in the entire bucket has been made unusable
1977 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
1979 (Void) WTUnlock(&(bkt->bktLock));
1981 (Void) SUnlock(&(bkt->bktLock));
1984 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
1985 RETVALUE(RTRAMPLINGNOK);
1988 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1989 /* Return the block to memory */
1990 ptrHdr->nextBlk = bkt->nextBlk;
1991 bkt->nextBlk = ptrHdr;
1993 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
1994 /* Move the ptr to end of the bucket */
1995 lastHdr = (CmMmBlkHdr *)bkt->lastBlk;
1996 lastHdr->nextBlk = ptrHdr;
1997 bkt->lastBlk = ptrHdr;
1998 ptrHdr->nextBlk = NULLP;
2000 #elif SS_LIGHT_MEM_LEAK_STS
2001 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
2002 ptrHdr->lineNo = lineNo;
2003 ptrHdr->currFuncName = funcName;
2004 if(gmemLkCb.isStarted == TRUE)
2006 cmRlsAllocBlk(ptrHdr->allocQueueIndx);
2008 ptrHdr->nextBlk = bkt->nextBlk;
2009 bkt->nextBlk = ptrHdr;
2012 #ifndef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
2013 #ifdef SSI_MEM_CORR_PREVENTION
2014 if (*(((U32 *)(ptr)) + 2) == 0xdeaddead)
2016 /* Do not free an already freed block to avoid corruption */
2017 cmDblFreeAttempts++;
2022 *((CmMmEntry **)bkt->last) = ptr;
2023 bkt->last = (CmMmEntry *)ptr;
2024 *((CmMmEntry **)ptr) = NULLP;
2025 *(((U32 *)(ptr)) + 2) = 0xdeaddead;
2028 *((CmMmEntry **)ptr) = bkt->next;
2029 bkt->next = (CmMmEntry *)ptr;
2032 if(memFreeCount >= 125000)
2034 if(bkt->size == 128)
2036 Data *crashPtr=NULLP;
2037 if(((ptr - startPtr128) % 128) != 0)
2041 memIndex = (ptr - startPtr128) / 128;
2043 if(bkt->size == 256)
2045 Data *crashPtr=NULLP;
2046 if(((ptr - startPtr256) % 256) != 0)
2050 memIndex = (ptr - startPtr256) / 256;
2052 if(bkt->size == 512)
2054 Data *crashPtr=NULLP;
2055 if(((ptr - startPtr512) % 512) != 0)
2060 if(bkt->size == 768)
2062 Data *crashPtr=NULLP;
2063 if(((ptr - startPtr768) % 768) != 0)
2068 if(bkt->size == 1664)
2070 Data *crashPtr=NULLP;
2071 if(((ptr - startPtr1664) % 1664) != 0)
2076 if(bkt->size == 4800)
2078 Data *crashPtr=NULLP;
2079 if(((ptr - startPtr4800) % 4800) != 0)
2084 if(bkt->size == 9920)
2086 Data *crashPtr=NULLP;
2087 if(((ptr - startPtr9920) % 9920) != 0)
2092 if (*((U32 *)(ptr + 4)) != 0xDEADDEAD)
2094 *(U32 *)(ptr + 4) = 0xDEADDEAD;
2098 Data *crashPtr=NULLP;
2101 if (*((U32 *)(ptr + 24)) != 0xDEADDEAD)
2103 *(U32 *)(ptr + 24) = 0xDEADDEAD;
2107 Data *crashPtr=NULLP;
2110 if (*((U32 *)(ptr + 44)) != 0xDEADDEAD)
2112 *(U32 *)(ptr + 44) = 0xDEADDEAD;
2116 Data *crashPtr=NULLP;
2119 if (*((U32 *)(ptr + 80)) != 0xDEADDEAD)
2121 *(U32 *)(ptr + 80) = 0xDEADDEAD;
2125 Data *crashPtr=NULLP;
2127 /* Cause a crash to identify the caller */
2129 *(U32 *)(ptr + 124) = memFreeCount++;
2130 (*(U32 *)(ptr + 116)) = cmFreeCaller[MxGetCpuID()];
2131 if(bkt->size == 128)
2133 memIndex = (ptr - startPtr128) / 128;
2134 cmMemInfo128[memIndex][1] = cmFreeCaller[MxGetCpuID()];
2136 if(bkt->size == 256)
2138 memIndex = (ptr - startPtr256) / 256;
2139 cmMemInfo256[memIndex][1] = cmFreeCaller[MxGetCpuID()];
2141 cmFreeCaller[MxGetCpuID()] = NULLP;
2144 Reverted: Removed functionality to move freed buffer to end of free List in bucket.
2145 This is impacting throughput.
2148 *((CmMmEntry **)bkt->last) = ptr;
2149 bkt->last = (CmMmEntry *)ptr;
2150 *((CmMmEntry **)ptr) = NULLP;
2152 *((CmMmEntry **)ptr) = bkt->next;
2153 bkt->next = (CmMmEntry *)ptr;
2156 #endif /* SSI_DEBUG_LEVEL1 */
2158 /* cache_coherency_changes */
2163 * Decrement the statistics variable of number of memory block
2167 /* cm_mem_c_001.main_15 : Additions */
2168 #ifdef SS_HISTOGRAM_SUPPORT
2169 /* If If Tapa task (entId)is registerd for histogram then insert Memrory Freed
2170 * information into the hash list */
2173 if (cmHstGrmFreeInsert(&bkt->hstGrmHashListCp, bkt->size, line, fileName, entId) != ROK)
2175 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
2179 #endif /* SS_HISTOGRAM_SUPPORT */
2181 #ifdef SS_MEM_LEAK_STS
2182 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
2183 cmRlsAllocBlk((PTR)ptr);
2184 #endif /* SS_MEM_LEAK_STS */
2185 /* Release the lock */
2186 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
2188 (Void) WTUnlock(&(bkt->bktLock));
2190 (Void) SUnlock(&(bkt->bktLock));
2196 /* The memory block was allocated from the heap pool */
2197 /* cm_mem_c_001.main_15 : Additions */
2198 #ifdef SS_HISTOGRAM_SUPPORT
2199 RETVALUE(cmHeapFree (&(regCb->heapCb), ptr, size, line, fileName, entId, hstReg));
2201 RETVALUE(cmHeapFree (&(regCb->heapCb), ptr, size));
2202 #endif /* SS_HISTOGRAM_SUPPORT */
2203 #else /* use pure is on */
2205 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
2206 #ifdef SS_4GMX_LCORE
2207 (Void)MxHeapFree(SsiHeap, ptr);
2213 #endif /* USE_PURE */
2216 } /* end of cmFree */
2222 * Desc: Allocate a memory block for the memory region(No Lock).
2225 * Ret: ROK - successful
2226 * RFAILED - unsuccessful.
2229 * The function allocates a memory block of size atleast equal to
2230 * the requested size. The size parameter will be updated with the
2231 * actual size of the memory block allocated for the request. The
2232 * CMM tries to allocate the memory block form the bucket pool. If
2233 * there is no memory in the bucket the CMM allocates the memory
2234 * block form the heap pool. This function is always called by the
2235 * System Service module.
2237 * The caller of the function should try to use the out value of
2238 * the size while returning the memory block to the region. However
2239 * the current design of the memory manager does not enforce to pass
2240 * the actual size of the memory block. (Due to the SGetSBuf
2241 * semantics the layer will not able to pass the correct size of the
2242 * memory block while calling SPutSBuf).
2248 /* cm_mem_c_001.main_12 - addition to accept new parameter memType(static/dynamic) */
2250 /* cm_mem_c_001.main_15 : Additions */
2251 #ifdef SS_HISTOGRAM_SUPPORT
2252 #ifdef SSI_DEBUG_LEVEL1
2254 PUBLIC S16 cmAllocNL
2267 PUBLIC S16 cmAllocNL(regionCb, size, flags, ptr, memType,
2268 line, fileName, entId, hstReg)
2281 PUBLIC S16 cmAllocNL
2293 PUBLIC S16 cmAllocNL(regionCb, size, flags, ptr, line,
2294 fileName, entId, hstReg)
2304 #endif /* SSI_DEBUG_LEVEL1 */
2307 #ifdef SS_LIGHT_MEM_LEAK_STS
2309 PUBLIC S16 cmAllocNL
2320 PUBLIC S16 cmAllocNL(regionCb, size, flags, ptr ,memType, lineNo, funcName)
2329 #else /*SS_LIGHT_MEM_LEAK_STS */
2330 #ifdef SSI_DEBUG_LEVEL1
2332 PUBLIC S16 cmAllocNL
2341 PUBLIC S16 cmAllocNL(regionCb, size, flags, ptr, memType)
2349 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2351 PUBLIC S16 cmAllocNL
2360 PUBLIC S16 cmAllocNL(regionCb, size, flags, ptr, memType)
2369 PUBLIC S16 cmAllocNL
2377 PUBLIC S16 cmAllocNL(regionCb, size, flags, ptr)
2383 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
2384 #endif /* SSI_DEBUG_LEVEL1 */
2385 /* cm_mem_c_001.main_15: Additions */
2386 #endif /*SS_LIGHT_MEM_LEAK_STS */
2387 #endif /* SS_HISTOGRAM_SUPPORT */
2390 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
2396 /* cm_mem_c_001.main_26 : Fixes for Compilation Warnings */
2400 /* cm_mem_c_001.main_15 : Additions */
2401 #if (defined(SS_MEM_LEAK_STS) || defined( BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2403 #endif /* SS_MEM_LEAK_STS */
2404 /* cm_mem_c_001.main_12 - addition to hold the allocated block */
2405 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
2406 CmMmBlkHdr *alocBlk;
2407 #endif /* SSI_DEBUG_LEVEL1 */
2408 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2411 /* cm_mem_c_001.main_15 : Additions */
2412 #ifdef SS_HISTOGRAM_SUPPORT
2414 #endif /* SS_HISTOGRAM_SUPPORT */
2421 /* cm_mem_c_001.main_15 : Additions */
2422 #ifdef SS_MEM_LEAK_STS
2424 #endif /* SS_MEM_LEAK_STS */
2426 regCb = (CmMmRegCb *)regionCb;
2428 #if (ERRCLASS & ERRCLS_INT_PAR)
2430 /* error check on parameters */
2431 if ((regCb == NULLP) || (size == NULLP) || !(*size) || (ptr == NULLP))
2437 /* cm_mem_c_001.main_12 - addition for checking memType parameter */
2438 #ifdef SSI_DEBUG_LEVEL1
2439 #if (ERRCLASS & ERRCLS_INT_PAR)
2440 if ((memType != CMM_STATIC_MEM_FLAG) && (memType != CMM_DYNAMIC_MEM_FLAG))
2444 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
2445 #endif /* SSI_DEBUG_LEVEL1 */
2452 /* cm_mem_c_001.main_12 - addition to insert the size into hash list */
2453 #ifdef SSI_DEBUG_LEVEL1
2454 /* Update the hash list */
2455 if (cmMmHashListInsert(&(regCb->hashListCp), *size) != ROK)
2457 /* display that, this entry could not be made in the hash list */
2459 /* display an error message here */
2461 sprintf(dbgPrntBuf, "\n Could not make an entry for size %u \
2462 in hash table of region %d \n",
2463 *size, regCb->region);
2465 sprintf(dbgPrntBuf, "\n Could not make an entry for size %lu \
2466 in hash table of region %d \n",
2467 *size, regCb->region);
2469 SDisplay(0, dbgPrntBuf);
2472 #endif /* SSI_DEBUG_LEVEL1 */
2475 * Check if the requested size is less than or equal to the maximum block
2476 * size in the bucket.
2478 if ( *size <= regCb->bktMaxBlkSize)
2480 /* Get the map to the mapping table */
2481 idx = ((*size - 1) >> regCb->bktQnPwr);
2483 #if (ERRCLASS & ERRCLS_DEBUG)
2484 if (regCb->mapTbl[idx].bktIdx == 0xFF)
2486 /* Some fatal error in the map table initialization. */
2491 /* Dequeue the memory block and return it to the user */
2492 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
2495 /* While loop is introduced to use the "break statement inside */
2499 * Check if the size request is not greater than the size available
2502 if (*size > bkt->size)
2504 /* Try to go to the next bucket if available */
2505 if((idx < (CMM_MAX_MAP_ENT - 1)) &&
2506 (regCb->mapTbl[++idx].bktIdx != 0xFF))
2508 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
2512 /* This is the last bucket, try to allocate from heap */
2517 #if (ERRCLASS & ERRCLS_DEBUG)
2518 regCb->mapTbl[idx].numReq++;
2519 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2521 /* cm_mem_c_001.main_12 - addition for sanity check before allocation */
2522 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2523 /* increment the allocation attempt counter at bucket level */
2524 bkt->numAllocAttempts++;
2526 /* detect trampling if any and call sanity check. This is done for (bkt->nextBlk) as
2527 the allocation is always from (bkt->nextBlk) */
2530 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2531 if(cmMmRegIsBlkSane(bkt->nextBlk, bkt->size) != ROK)
2533 if (cmMmRegIsBlkSane(bkt->nextBlk) != ROK)
2536 /* detected a trampled memory block in this bucket */
2538 /* display an error message here */
2539 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
2541 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, \
2543 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
2545 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, \
2547 (void *)bkt->nextBlk, regCb->mapTbl[idx].bktIdx, *size);
2549 SDisplay(0, dbgPrntBuf);
2553 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2554 if (cmMmBktSanityChk(bkt) == RTRAMPLINGNOK)
2556 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
2557 RETVALUE(RTRAMPLINGNOK);
2561 /* return RFAILED */
2567 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr));
2568 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2569 ptrHdr = (CmMmBlkHdr *)bkt->nextBlk;
2571 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2572 /* Initialize the elements with 0xAB */
2573 cmMemset((U8 *)*ptr, 0xAB, *size);
2575 if ((bkt->nextBlk) && *ptr)
2576 #elif SS_LIGHT_MEM_LEAK_STS
2577 *ptr = (Data *)(bkt->nextBlk) + (sizeof(CmMmBlkHdr)); /* ccpu00125353: warning fix */
2578 if ((bkt->nextBlk) && *ptr)
2580 *ptr = bkt->next;/* ccpu00125353: warning fix */
2582 #endif /* SSI_DEBUG_LEVEL1 */
2584 /* cm_mem_c_001.main_12 - addition for header */
2585 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
2586 /* point to next block header */
2587 alocBlk = bkt->nextBlk;
2588 bkt->nextBlk = (CmMmBlkHdr *)(bkt->nextBlk->nextBlk);
2590 #ifdef SSI_MEM_CORR_PREVENTION
2591 *(((U32 *)(*ptr)) + 2) = 0;
2593 bkt->next = *((CmMmEntry **)(bkt->next));
2594 #endif /* SSI_DEBUG_LEVEL1 */
2596 /* cache_coherency_changes */
2601 * Increment the statistics variable of number of memory block
2605 if (bkt->numAlloc > bkt->maxAlloc)
2607 bkt->maxAlloc = bkt->numAlloc;
2609 #ifdef CM_MEM_OVERUSED
2611 if (g_overused[bktIdx] == 0 && OVERUSED(bkt))
2613 g_overused[bktIdx] = 1;
2617 /* cm_mem_c_001.main_12 - addition for header manipulation */
2618 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2619 /* update the size for which this memory block has been allocated */
2620 alocBlk->requestedSize = *size;
2621 /* update the memory block header */
2622 CMM_RESET_FREE_FLAG(alocBlk->memFlags);
2623 if (memType == CMM_STATIC_MEM_FLAG)
2625 CMM_SET_STATIC_FLAG(alocBlk->memFlags);
2626 /* add it to the static memory allocated */
2627 bkt->staticMemUsed += bkt->size;
2631 CMM_SET_DYNAMIC_FLAG(alocBlk->memFlags);
2632 /* add it to the dynamic memory allocated */
2633 bkt->dynamicMemUsed += bkt->size;
2635 #elif SS_LIGHT_MEM_LEAK_STS
2636 alocBlk->requestedSize = *size;
2637 alocBlk->lineNo = lineNo;
2638 alocBlk->currFuncName = funcName;
2639 if(gmemLkCb.isStarted == TRUE)
2641 alocBlk->allocQueueIndx = cmStorAllocBlk(alocBlk);
2643 #endif /* SSI_DEBUG_LEVEL1 */
2645 if (((bkt->size - (*size)) >> regCb->bktQnPwr) && flags)
2651 "[MEM_CAL_CNTA] %u bytes request not fitted in bkt %d \
2652 [size %u bytes] %u times\n",
2653 *size, regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktNoFitCnt++);
2656 "[MEM_CAL_CNTA] %lu bytes request not fitted in bkt %d \
2657 [size %lu bytes] %lu times\n",
2658 *size, regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktNoFitCnt++);
2660 SDisplay(0, prntBuf);
2668 "SGetSBuf:%08lu:Size Bucket Id:%03d Times:%05lu Pointer: %8p\n",
2669 *size, regCb->mapTbl[idx].bktIdx, num_times, *ptr);
2670 SDisplay(0, prntBuf);
2672 #endif /* MEMCAL_DEBUG */
2673 /* cm_mem_c_001.main_15 : Additions */
2674 #ifdef SS_HISTOGRAM_SUPPORT
2677 if (cmHstGrmAllocInsert(&(bkt->hstGrmHashListCp),
2678 bkt->size, size, line, fileName, entId) != ROK)
2680 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
2685 #endif /* SS_HISTOGRAM_SUPPORT */
2687 /* Update the size parameter */
2689 #ifdef SS_MEM_LEAK_STS
2690 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
2691 cmStorAllocBlk((PTR)*ptr, (Size) reqSz, (Size) *size,
2692 regCb->mapTbl[idx].bktIdx);
2693 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2694 cmStorAllocBlk(ptrHdr, (Size) reqSz, (Size) *size,
2695 regCb->mapTbl[idx].bktIdx, regCb);
2696 #endif /* SS_MEM_LEAK_STS */
2698 /* cm_mem_c_008.104 - Addition for memory calculator tool */
2708 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %u bytes], \
2709 %u times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
2712 "[MEM_CAL_CNTB] Allocation failed in bucket %d [ size %lu bytes], \
2713 %lu times\n", regCb->mapTbl[idx].bktIdx, bkt->size, bkt->bktFailCnt);
2715 SDisplay(0, prntBuf);
2719 #if (ERRCLASS & ERRCLS_DEBUG)
2720 regCb->mapTbl[idx].numFailure++;
2721 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2730 regCb->heapCb.heapAllocCnt++;
2734 "[MEM_CAL_CNTC] No bucket block configured for %u bytes \n \
2735 Number of blocks allocated from heap = %u\n",*size,
2736 regCb->heapCb.heapAllocCnt);
2739 "[MEM_CAL_CNTC] No bucket block configured for %lu bytes \n \
2740 Number of blocks allocated from heap = %lu\n",*size,
2741 regCb->heapCb.heapAllocCnt);
2743 SDisplay(0, prntBuf);
2748 /* Memory not available in the bucket pool */
2749 if (regCb->heapFlag && (*size < regCb->heapSize))
2752 if (flags) tryHeap = 1;
2755 * The heap memory block is available. Allocate the memory block from
2758 /* cm_mem_c_001.main_15: Additions */
2759 #ifdef SS_HISTOGRAM_SUPPORT
2760 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
2761 #ifdef SSI_DEBUG_LEVEL1
2762 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size,
2763 memType, line, fileName, entId, hstReg));
2765 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size,
2766 line, fileName, entId, hstReg));
2767 #endif /* SSI_DEBUG_LEVEL1 */
2769 /* cm_mem_c_001.main_12 - addition for passing an extra parameter */
2770 #ifdef SSI_DEBUG_LEVEL1
2771 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size, memType));
2773 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size));
2774 #endif /* SSI_DEBUG_LEVEL1 */
2775 #endif /* SS_HISTOGRAM_SUPPORT */
2778 /* No memory available */
2780 #else /* use pure is on */
2781 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
2782 #ifdef SS_4GMX_LCORE
2783 *ptr = (Data*) MxHeapAlloc(SsiHeap, *size);
2784 cmMemset((U8*)ptr, 0, *size);
2786 *ptr = (Data*) malloc(*size);
2788 if ( (*ptr) == NULLP)
2790 avail_size -= *size;
2792 #endif /* USE_PURE */
2794 } /* end of cmAllocNL */
2801 * Desc: Return the memory block for the memory region(No Lock).
2804 * Ret: ROK - successful
2805 * RFAILED - unsuccessful.
2807 * Notes: The user calls this function to return the previously allocated
2808 * memory block to the memory region. The memory manager does not
2809 * check the validity of the state of the memory block(like whether
2810 * it was allocated earlier). The caller must be sure that, the
2811 * address specified in the parameter 'ptr' is valid and was
2812 * allocated previously from same region.
2819 /* cm_mem_c_001.main_15 : Additions */
2820 #ifdef SS_LIGHT_MEM_LEAK_STS
2831 PUBLIC S16 cmFreeNL(regionCb, ptr, size, lineNo, funcName)
2838 #else /*SS_LIGHT_MEM_LEAK_STS */
2840 #ifdef SS_HISTOGRAM_SUPPORT
2853 PUBLIC S16 cmFreeNL(regionCb, ptr, size, line, fileName, entId, hstReg)
2873 PUBLIC S16 cmFreeNL(regionCb, ptr, size)
2878 /* cm_mem_c_001.main_15 : Additions */
2879 #endif /* SS_HISTOGRAM_SUPPORT */
2880 #endif /*SS_LIGHT_MEM_LEAK_STS */
2888 /* cm_mem_c_001.main_12 - addition for holding the free pointer */
2889 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
2891 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2892 CmMmBlkHdr *lastHdr;
2893 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
2894 #endif /* SSI_DEBUG_LEVEL1 */
2895 /* cm_mem_c_001.main_15 : Additions */
2896 #ifdef SS_HISTOGRAM_SUPPORT
2898 #endif /* SS_HISTOGRAM_SUPPORT */
2902 regCb = (CmMmRegCb *)regionCb;
2905 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2906 /* Check if the memory block is from the memory region */
2907 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
2908 ((CmMmRegCb *)regCb)->regInfo.size)
2913 #if (ERRCLASS & ERRCLS_INT_PAR)
2915 /* error check on parameters */
2916 if ((regCb == NULLP) || (!size) || (ptr == NULLP))
2920 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2921 /* Check if the memory block is from the memory region */
2922 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
2923 ((CmMmRegCb *)regCb)->regInfo.size)
2928 /* cm_mem_c_001.main_20 Addition */
2929 if (ptr < regCb->regInfo.start)
2937 * Check if the memory block was allocated from the bucket pool.
2940 if (ptr < (regCb->regInfo.start + regCb->bktSize))
2942 /* The memory block was allocated from the bucket pool */
2944 /* Get the map to the mapping table */
2945 idx = ((size - 1) >> regCb->bktQnPwr);
2947 #if (ERRCLASS & ERRCLS_DEBUG)
2948 if (regCb->mapTbl[idx].bktIdx == 0xFF)
2950 /* Some fatal error in the map table initialization. */
2955 /* Enqueue the memory block and return it to the user */
2956 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
2959 * Check if the size is not greater than the size available
2960 * in the bucket. If so, then the buffer must have been allocated
2961 * from next bucket. We don't need to check the validity of the
2962 * next bucket, otherwise buffer must have been allocated from heap
2965 if (size > bkt->size)
2967 bkt = &(regCb->bktTbl[regCb->mapTbl[++idx].bktIdx]);
2970 /* cache_coherency_changes */
2975 /* cm_mem_c_001.main_12 - addition for sanity check and free */
2976 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
2977 /* increment the dealloc attempt counter at bucket level */
2978 bkt->numDeallocAttempts++;
2980 /* Check the memFlags to see whether this block was allocated */
2981 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
2982 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
2983 cmRlsAllocBlk(ptrHdr, regCb);
2985 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
2986 /* Check for ptr size */
2987 if(((ptrHdr->requestedSize - size) % size) != 0)
2990 sprintf(dbgPrntBuf, "Passed size (%d) does not match with allocated size(%d):%8p, Bucket Id:%03d\n",
2991 size, ptrHdr->requestedSize, ptr, regCb->mapTbl[idx].bktIdx);
2993 printf("Passed size (%d) does not match with allocated size(%d):%8p, Bucket Id:%03d\n",
2994 size, ptrHdr->requestedSize, ptr, regCb->mapTbl[idx].bktIdx);
2999 /* validate the block to be freed for trampling */
3000 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3001 if(cmMmRegIsBlkSane(ptrHdr, bkt->size) != ROK)
3003 if (cmMmRegIsBlkSane(ptrHdr) != ROK)
3006 /* Handle error case of Memory trampling */
3008 /* display an error message here */
3010 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %u bytes \n",
3011 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3013 sprintf(dbgPrntBuf, "Memory Trampling at: %8p, Bucket Id:%03d, size %lu bytes \n",
3014 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3016 SDisplay(0, dbgPrntBuf);
3020 * if sanity check returns RTRAMPLINGOK then there is nothing to do
3021 * as the memory blk is already invalidated in cmMmBktSanityChk
3023 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3024 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
3032 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
3033 RETVALUE(RTRAMPLINGNOK);
3036 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3037 printf("Memory signature is invalid\n");
3041 /* reset the size */
3042 ptrHdr->requestedSize = 0;
3043 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3044 /* Initialize the elements with 0XAB */
3045 cmMemset((U8 *)ptr, 0xAB, size);
3047 /* check if the block to be freed is already having the state as FREE */
3048 if (CMM_IS_FREE(ptrHdr->memFlags))
3050 /* Handle double deallocation error case */
3052 /* display an error message here */
3053 /*cm_mem_c_001.main_23 Fix for specifier mismatch
3054 * warnings in 64BIT compilation*/
3056 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p,"
3057 "Bucket Id:%03d, size %u bytes \n",
3058 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3060 sprintf(dbgPrntBuf, "Attempt to double deallocate memory at: %8p,"
3061 "Bucket Id:%03d, size %lu bytes \n",
3062 ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3064 SDisplay(0, dbgPrntBuf);
3066 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3067 printf("Attempt to double deallocate memory at: %8p, Bucket Id:%03d,\
3068 size %u bytes \n", ptr, regCb->mapTbl[idx].bktIdx, bkt->size);
3072 /* handle RDBLFREE in SFree/SPutSBuf */
3075 if (CMM_IS_STATIC(ptrHdr->memFlags))
3077 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
3078 CMM_RESET_STATIC_FLAG(ptrHdr->memFlags);
3079 /* deduct it from the static memory count */
3080 bkt->staticMemUsed -= bkt->size;
3082 else if (CMM_IS_DYNAMIC(ptrHdr->memFlags))
3084 CMM_SET_FREE_FLAG(ptrHdr->memFlags);
3085 CMM_RESET_DYNAMIC_FLAG(ptrHdr->memFlags);
3086 /* deduct it from the dynamic memory count */
3087 bkt->dynamicMemUsed -= bkt->size;
3091 /* This is a case similar to trampled memory */
3093 /*cm_mem_c_001.main_23 Fix for specifier
3094 * mismatch warnings in 64BIT compilation*/
3096 sprintf(dbgPrntBuf, "Invalid memory flag: %u !!!\n", ptrHdr->memFlags);
3098 sprintf(dbgPrntBuf, "Invalid memory flag: %lu !!!\n", ptrHdr->memFlags);
3100 SDisplay(0, dbgPrntBuf);
3102 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3103 if (cmMmBktSanityChk(bkt) == RTRAMPLINGOK)
3105 /* do not add to the free list */
3111 /* handle RTRAMPLINGNOK in SFree/SPutSBuf */
3112 RETVALUE(RTRAMPLINGNOK);
3116 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3117 /* Return the block to memory */
3118 ptrHdr->nextBlk = bkt->nextBlk;
3119 bkt->nextBlk = ptrHdr;
3121 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3122 /* Move the ptr to end of the bucket */
3123 lastHdr = (CmMmBlkHdr *)bkt->lastBlk;
3124 lastHdr->nextBlk = ptrHdr;
3125 bkt->lastBlk = ptrHdr;
3126 ptrHdr->nextBlk = NULLP;
3128 #elif SS_LIGHT_MEM_LEAK_STS
3129 ptrHdr = (CmMmBlkHdr *) (ptr - sizeof(CmMmBlkHdr));
3130 ptrHdr->lineNo = lineNo;
3131 ptrHdr->currFuncName = funcName;
3132 if(gmemLkCb.isStarted == TRUE)
3134 cmRlsAllocBlk(ptrHdr->allocQueueIndx);
3136 ptrHdr->nextBlk = bkt->nextBlk;
3137 bkt->nextBlk = ptrHdr;
3140 #ifdef SSI_MEM_CORR_PREVENTION
3141 if (*(((U32 *)(ptr)) + 2) == 0xdeaddead)
3143 /* Do not free an already freed block to avoid corruption */
3144 cmDblFreeAttempts++;
3149 *((CmMmEntry **)bkt->last) = ptr;
3150 bkt->last = (CmMmEntry *)ptr;
3151 *((CmMmEntry **)ptr) = NULLP;
3152 *(((U32 *)(ptr)) + 2) = 0xdeaddead;
3155 *((CmMmEntry **)ptr) = bkt->next;
3156 bkt->next = (CmMmEntry *)ptr;
3158 #endif /* SSI_DEBUG_LEVEL1 */
3160 /* cache_coherency_changes */
3165 * Decrement the statistics variable of number of memory block
3169 /* cm_mem_c_001.main_15 : Additions */
3170 #ifdef SS_HISTOGRAM_SUPPORT
3171 /* If Tapa task (entId)is registerd for histogram then insert Memrory Freed
3172 * information into the hash list */
3175 if (cmHstGrmFreeInsert(&bkt->hstGrmHashListCp, bkt->size,
3176 line, fileName, entId) != ROK)
3178 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
3182 #endif /* SS_HISTOGRAM_SUPPORT */
3184 #ifdef SS_MEM_LEAK_STS
3185 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
3186 cmRlsAllocBlk((PTR)ptr);
3187 #endif /* SS_MEM_LEAK_STS */
3192 /* The memory block was allocated from the heap pool */
3193 /* cm_mem_c_001.main_15 : Additions */
3194 #ifdef SS_HISTOGRAM_SUPPORT
3195 RETVALUE(cmHeapFree (&(regCb->heapCb), ptr, size, line, fileName, entId, hstReg));
3197 RETVALUE(cmHeapFree (&(regCb->heapCb), ptr, size));
3198 #endif /* SS_HISTOGRAM_SUPPORT */
3199 #else /* use pure is on */
3201 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
3202 #ifdef SS_4GMX_LCORE
3203 (Void)MxHeapFree(SsiHeap, ptr);
3209 #endif /* USE_PURE */
3210 } /* end of cmFreeNL */
3217 * Desc: alloc without lock
3220 * Ret: ROK - successful
3221 * RFAILED - unsuccessful.
3227 /*cm_mem_c_001.main_21-added new function*/
3228 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3231 PRIVATE S16 cmAllocWL
3239 PRIVATE S16 cmAllocWL(regionCb, size, flags, ptr)
3249 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3253 /*cm_mem_c_001.main_23 Removed support of USE_MEMCAL and MEMCAL_DEBUG support for SS_FAP*/
3255 regCb = (CmMmRegCb *)regionCb;
3257 #if (ERRCLASS & ERRCLS_INT_PAR)
3259 /* error check on parameters */
3260 if ((regCb == NULLP) || (size == NULLP) || !(*size) || (ptr == NULLP))
3266 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3271 * Check if the requested size is less than or equal to the maximum block
3272 * size in the bucket.
3274 /* cm_mem_c_001.main_23 Adding check to compair size with Maximum block size*/
3275 if ( *size <= regCb->bktMaxBlkSize)
3277 /* Get the map to the mapping table */
3278 idx = ((*size - 1) >> regCb->bktQnPwr);
3280 /* Dequeue the memory block and return it to the user */
3281 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
3285 * Check if the size request is not greater than the size available
3288 /* cm_mem_c_001.main_23 combined If(*size <= bkt->size) and if(*ptr = bkt->next)*/
3289 if ((*size <= bkt->size)&&(*ptr = bkt->next))
3291 /* Try to go to the next bucket if available */
3292 bkt->next = *((CmMmEntry **)(bkt->next));
3295 * Increment the statistics variable of number of memory block
3300 /* Update the size parameter */
3308 /* Memory not available in the bucket pool */
3309 if (regCb->heapFlag && (*size < regCb->heapSize))
3311 /*cm_mem_c_001.main_23 Removed support of and MEMCAL_DEBUG support for SS_FAP*/
3313 * The heap memory block is available. Allocate the memory block from
3316 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3317 RETVALUE(cmHeapAlloc(&(regCb->heapCb), ptr, size));
3320 /* No memory available */
3322 #else /* use pure is on */
3323 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
3324 #ifdef SS_4GMX_LCORE
3325 *ptr = (Data*) MxHeapAlloc(SsiHeap, *size);
3326 cmMemset((U8*)ptr, 0, *size);
3328 *ptr = (Data*) malloc(*size);
3330 if ( (*ptr) == NULLP)
3332 avail_size -= *size;
3334 #endif /* USE_PURE */
3336 } /* end of cmAllocWL */
3343 * Desc: free without lock
3346 * Ret: ROK - successful
3347 * RFAILED - unsuccessful.
3355 PRIVATE S16 cmFreeWL
3362 PRIVATE S16 cmFreeWL(regionCb, ptr, size)
3371 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3375 regCb = (CmMmRegCb *)regionCb;
3378 #if (ERRCLASS & ERRCLS_INT_PAR)
3380 /* error check on parameters */
3381 if ((regCb == NULLP) || (!size) || (ptr == NULLP))
3386 /* Check if the memory block is from the memory region */
3387 if (ptr >= ((CmMmRegCb *)regCb)->regInfo.start +
3388 ((CmMmRegCb *)regCb)->regInfo.size)
3396 * Check if the memory block was allocated from the bucket pool.
3399 if (ptr < (regCb->regInfo.start + regCb->bktSize))
3401 /* The memory block was allocated from the bucket pool */
3403 /* Get the map to the mapping table */
3404 idx = ((size - 1) >> regCb->bktQnPwr);
3406 #if (ERRCLASS & ERRCLS_DEBUG)
3407 if (regCb->mapTbl[idx].bktIdx == 0xFF)
3409 /* Some fatal error in the map table initialization. */
3414 /* Enqueue the memory block and return it to the user */
3415 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
3418 * Check if the size is not greater than the size available
3419 * in the bucket. If so, then the buffer must have been allocated
3420 * from next bucket. We don't need to check the validity of the
3421 * next bucket, otherwise buffer must have been allocated from heap
3424 if (size > bkt->size)
3426 bkt = &(regCb->bktTbl[regCb->mapTbl[++idx].bktIdx]);
3429 /*cm_mem_c_001.main_23 Removed support of SSI_DEBUG_LEVEL1 and SS_HISTOGRAM_SUPPORT for SS_FAP*/
3430 *((CmMmEntry **)ptr) = bkt->next;
3431 bkt->next = (CmMmEntry *)ptr;
3434 * Decrement the statistics variable of number of memory block
3442 /* The memory block was allocated from the heap pool */
3443 RETVALUE(cmHeapFree (&(regCb->heapCb), ptr, size));
3444 #else /* use pure is on */
3446 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
3447 #ifdef SS_4GMX_LCORE
3448 (Void)MxHeapFree(SsiHeap, ptr);
3454 #endif /* USE_PURE */
3457 } /* end of cmFreeWL */
3465 * Desc: Control request function.
3468 * Ret: ROK - successful
3469 * RFAILED - unsuccessful.
3471 * Notes: The current semantics of the control function is defined for two
3472 * types of events: virtual address to physical address translation
3473 * and memory resource check.
3475 * The physical address translation is valid only for the memory
3476 * region physically contiguous and non pagable.
3492 PRIVATE S16 cmCtl(regionCb, event, memCtl)
3502 regCb = (CmMmRegCb *)regionCb;
3504 #if (ERRCLASS & ERRCLS_INT_PAR)
3506 /* error check on parameters */
3507 if ((regCb == NULLP) || (memCtl == NULLP))
3520 #if (ERRCLASS & ERRCLS_INT_PAR)
3521 if ((memCtl->u.vtop.vaddr == NULLP) ||
3522 (memCtl->u.vtop.paddr == NULLP))
3528 /* Check if the virtual to physical address translation is valid */
3529 if (regCb->chFlag & CMM_REG_PHY_VALID)
3531 offset = memCtl->u.vtop.vaddr - regCb->regInfo.start;
3532 *(memCtl->u.vtop.paddr) = regCb->pAddr + offset;
3539 case SS_MEM_CHK_RES:
3542 #if (ERRCLASS & ERRCLS_INT_PAR)
3543 if (!(memCtl->u.chkres.size) ||
3544 (memCtl->u.chkres.status == NULLP))
3550 /* Check if the Bucket pool is configured */
3555 U32 avlSize, totSize;
3557 * The bucket pool is configured. The status value returned
3558 * does reflect on the memory availabilty in the bucket pool.
3559 * The value does not consider the available memory in the
3562 idx = ((memCtl->u.chkres.size - 1) >> regCb->bktQnPwr);
3563 bkt = &(regCb->bktTbl[regCb->mapTbl[idx].bktIdx]);
3564 avlSize = (bkt->numBlks - bkt->numAlloc) * bkt->size;
3565 avlSize += regCb->heapCb.avlSize;
3566 totSize = (bkt->numBlks * bkt->size) + regCb->heapSize;
3567 *(memCtl->u.chkres.status) = (avlSize/(totSize/10));
3571 /* Bucket pool not configured */
3574 * Find the percentage memory available in the heap pool. The value
3575 * does not consider the fragmentation of the heap pool.
3577 *(memCtl->u.chkres.status) = ((regCb->heapCb.avlSize) /
3578 (regCb->heapSize/10));
3582 #else /* use pure is on */
3583 *(memCtl->u.chkres.status) = ((avail_size) /
3584 (regCb->regInfo.size/10));
3586 #endif /* USE_PURE */
3592 /* No other event is supported currently */
3597 /* shouldn't reach here */
3599 } /* end of cmCtl */
3606 * Desc: Initialize the bucket and the map table.
3609 * Ret: ROK - successful,
3610 * RFAILED - unsuccessful.
3612 * Notes: This function is called by the cmMmRegInit.
3618 PRIVATE Void cmMmBktInit
3627 PRIVATE Void cmMmBktInit (memAddr, regCb, cfg, bktIdx, lstMapIdx)
3639 /* cm_mem_c_001.main_12 - addition for temporary variables */
3640 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3641 CmMmBlkHdr **nextBlk;
3642 #ifdef SS_LIGHT_MEM_LEAK_STS
3643 CmMmBlkHdr *lastBlk;
3644 #endif /*SS_LIGHT_MEM_LEAK_STS */
3646 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3648 CmMmBlkTail *blkTail;
3652 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3655 #endif /* SSI_DEBUG_LEVEL1 */
3660 size = cfg->bktCfg[bktIdx].size;
3661 numBlks = cfg->bktCfg[bktIdx].numBlks;
3663 /* cm_mem_c_001.main_12 - addition for header initialization */
3664 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3665 /* Reset the next block pointer */
3666 regCb->bktTbl[bktIdx].nextBlk = NULLP;
3667 #if (defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3668 regCb->bktTbl[bktIdx].lastBlk = NULLP;
3670 /* Initialize the link list of the memory block */
3671 nextBlk = &(regCb->bktTbl[bktIdx].nextBlk);
3673 for (cnt = 0; cnt < numBlks; cnt++)
3675 *nextBlk = (CmMmBlkHdr *)*memAddr;
3676 #ifdef SS_LIGHT_MEM_LEAK_STS
3677 lastBlk = (CmMmBlkHdr *)*memAddr;
3678 #endif /*SS_LIGHT_MEM_LEAK_STS */
3680 /* initialize the memory block header */
3681 for (sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
3683 (*nextBlk)->trSignature[sigCnt] = 0xAB;
3685 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3686 /* Initialize memory block tail */
3687 blkTail = (CmMmBlkTail *)(*memAddr + sizeof(CmMmBlkHdr) + size);
3688 for (sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
3690 blkTail->trSignature[sigCnt] = 0xFE;
3693 CMM_SET_FREE_FLAG((*nextBlk)->memFlags);
3694 (*nextBlk)->requestedSize = 0;
3695 #ifdef SS_LIGHT_MEM_LEAK_STS
3696 (*nextBlk)->timeStamp = 0X7777;
3697 (*nextBlk)->lineNo = 0;
3698 (*nextBlk)->allocQueueIndx = 1;
3699 (*nextBlk)->currFuncName = NULL;
3700 #endif /*SS_LIGHT_MEM_LEAK_STS */
3702 #if defined(SSI_DEBUG_LEVEL1) || defined(SS_LIGHT_MEM_LEAK_STS)
3703 *memAddr = (Data *)((*memAddr) + ((sizeof(CmMmBlkHdr)) + size));
3704 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3705 *memAddr = (Data *)((*memAddr) + ((sizeof(CmMmBlkHdr)) + sizeof(CmMmBlkTail) + size));
3707 nextBlk = &((*nextBlk)->nextBlk);
3711 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3712 tmpMemAddr = (Data *)((*memAddr) - ((sizeof(CmMmBlkHdr)) + sizeof(U32) + size));
3713 regCb->bktTbl[bktIdx].lastBlk = (CmMmBlkHdr *)tmpMemAddr;
3717 /* Reset the next pointer */
3718 regCb->bktTbl[bktIdx].next = NULLP;
3719 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3720 regCb->bktTbl[bktIdx].last = NULLP;
3723 /* Initialize the link list of the memory block */
3724 next = &(regCb->bktTbl[bktIdx].next);
3725 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3726 last = &(regCb->bktTbl[bktIdx].last);
3727 if(regCb->region == 0)
3731 startPtr128 = *memAddr;
3732 regMemSize = regCb->regInfo.size;
3733 uart_printf("size of all pool=%u\n", regMemSize);
3734 uart_printf("startPtr128=%x\n", startPtr128);
3738 startPtr256 = *memAddr;
3739 uart_printf("startPtr256=%x\n", startPtr256);
3743 startPtr512 = *memAddr;
3744 uart_printf("startPtr512=%x\n", startPtr512);
3748 startPtr768 = *memAddr;
3749 uart_printf("startPtr768=%x\n", startPtr768);
3753 startPtr1664 = *memAddr;
3754 uart_printf("startPtr1664=%x\n", startPtr1664);
3758 startPtr4800 = *memAddr;
3759 uart_printf("startPtr4800=%x\n", startPtr4800);
3763 startPtr9920 = *memAddr;
3764 uart_printf("startPtr9920=%x\n", startPtr9920);
3768 for (cnt = 0; cnt < numBlks; cnt++)
3771 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3772 (*(U32 *)(*next + 4)) = 0xdeaddead;
3773 (*(U32 *)(*next + 124)) = 0;
3774 (*(U32 *)(*next + 116)) = 0xdeaddead;
3775 (*(U32 *)(*next + 24)) = 0xdeaddead;
3776 (*(U32 *)(*next + 44)) = 0xdeaddead;
3777 (*(U32 *)(*next + 80)) = 0xdeaddead;
3779 #ifdef SSI_MEM_CORR_PREVENTION
3780 *(((U32 *)(*next)) + 2) = 0xdeaddead;
3782 next = (CmMmEntry **)(*memAddr);
3783 *memAddr = (*memAddr) + size;
3786 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
3787 *last = (CmMmEntry *)next;
3789 #ifdef SSI_MEM_CORR_PREVENTION
3790 regCb->bktTbl[bktIdx].last = (CmMmEntry *)next;
3793 #endif /* SSI_DEBUG_LEVEL1 */
3795 /* Initialize the Map entry */
3796 idx = size / cfg->bktQnSize;
3799 * Check if the size is multiple of quantum size. If not we need to initialize
3800 * one more map table entry.
3802 if(size % cfg->bktQnSize)
3807 while ( *lstMapIdx < idx)
3809 regCb->mapTbl[*lstMapIdx].bktIdx = bktIdx;
3811 #if (ERRCLASS & ERRCLS_DEBUG)
3812 regCb->mapTbl[*lstMapIdx].numReq = 0;
3813 regCb->mapTbl[*lstMapIdx].numFailure = 0;
3819 /* Initialize the bucket structure */
3820 regCb->bktTbl[bktIdx].size = size;
3821 regCb->bktTbl[bktIdx].numBlks = numBlks;
3822 regCb->bktTbl[bktIdx].numAlloc = 0;
3824 /* Update the total bucket size */
3825 /* cm_mem_c_001.main_12 - addition for considering the header size */
3826 #if (defined(SSI_DEBUG_LEVEL1) || defined (SS_LIGHT_MEM_LEAK_STS))
3827 regCb->bktSize += ((size + sizeof(CmMmBlkHdr)) * numBlks);
3828 /* Addition for considering the header size and tail */
3829 #elif BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
3830 regCb->bktSize += ((size + sizeof(CmMmBlkHdr) + sizeof(U32)) * numBlks);
3832 regCb->bktSize += (size * numBlks);
3833 #endif /* SSI_DEBUG_LEVEL1 */
3835 regCb->bktTbl[bktIdx].bktFailCnt = 0;
3836 regCb->bktTbl[bktIdx].bktNoFitCnt = 0;
3838 /* cm_mem_c_001.main_12 - addition for statistics related variable initialization */
3839 #if (defined(SSI_DEBUG_LEVEL1) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1))
3840 /* Initialize other required pointers */
3841 regCb->bktTbl[bktIdx].bktStartPtr = (Data *)(regCb->bktTbl[bktIdx].nextBlk);
3842 regCb->bktTbl[bktIdx].numAllocAttempts = 0;
3843 regCb->bktTbl[bktIdx].numDeallocAttempts = 0;
3844 regCb->bktTbl[bktIdx].staticMemUsed = 0;
3845 regCb->bktTbl[bktIdx].dynamicMemUsed = 0;
3846 regCb->bktTbl[bktIdx].trampleCount = 0;
3847 #endif /*SSI_DEBUG_LEVEL1*/
3848 /* cm_mem_c_001.main_15 : Additions */
3849 #ifdef SS_HISTOGRAM_SUPPORT
3850 /* Initialise the memory histogram hash list */
3851 cmHstGrmHashListInit(&(regCb->bktTbl[bktIdx].hstGrmHashListCp));
3852 #endif /* SS_HISTOGRAM_SUPPORT */
3855 } /* end of cmMmBktInit */
3862 * Desc: Initialize the heap pool.
3865 * Ret: ROK - successful
3866 * RFAILED - unsuccessful.
3868 * Notes: This function is called by the cmMmRegInit.
3874 PRIVATE Void cmMmHeapInit
3881 PRIVATE Void cmMmHeapInit (memAddr, heapCb, size)
3887 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
3888 #ifdef SSI_DEBUG_LEVEL1
3890 #endif /* SSI_DEBUG_LEVEL1 */
3893 /* Initialize the heap control block */
3894 heapCb->vStart = memAddr;
3895 heapCb->vEnd = memAddr + size;
3896 heapCb->avlSize = size;
3897 heapCb->minSize = CMM_MINBUFSIZE;
3899 heapCb->next = (CmHEntry *)memAddr;
3900 heapCb->next->next = NULLP;
3901 /* cm_mem_c_001.main_12 - addition for header initialization */
3902 #ifdef SSI_DEBUG_LEVEL1
3903 heapCb->next->size = size - sizeof(CmHEntry);
3904 heapCb->next->requestedSize = 0;
3905 for (idx=0; idx < CMM_TRAMPLING_SIGNATURE_LEN; idx++)
3907 heapCb->next->trSignature[idx] = 0xAB;
3909 CMM_SET_FREE_FLAG(heapCb->next->memFlags);
3910 heapCb->staticHeapMemUsed = 0;
3911 heapCb->dynamicHeapMemUsed = 0;
3912 heapCb->nextOffset = sizeof(heapCb->next->trSignature) +
3913 sizeof(heapCb->next->memFlags) +
3914 sizeof(heapCb->next->requestedSize);
3915 heapCb->numAllocAttempts = 0;
3916 heapCb->numDeallocAttempts = 0;
3917 heapCb->trampleCount = 0;
3919 heapCb->next->size = size;
3920 #endif /* SSI_DEBUG_LEVEL1 */
3922 #if (ERRCLASS & ERRCLS_DEBUG)
3923 heapCb->numFragBlk = 0;
3925 heapCb->numFailure = 0;
3928 heapCb->heapAllocCnt = 0;
3929 /* cm_mem_c_001.main_15 : Additions */
3930 #ifdef SS_HISTOGRAM_SUPPORT
3931 /* Initialise the memory histogram hash list */
3932 cmHstGrmHashListInit(&(heapCb->heapHstGrmHashListCp));
3933 #endif /* SS_HISTOGRAM_SUPPORT */
3936 } /* end of cmMmHeapInit */
3943 * Desc: Allocates the memory block from the heap pool.
3946 * Ret: ROK - successful
3947 * RFAILED - unsuccessful.
3949 * Notes: This function is called by the cmAlloc. cmAlloc calls this
3950 * function when there is no memory block available in the bucket
3951 * and the heap pool is configured.
3958 /* cm_mem_c_001.main_12 - addition for taking another parameter memType(static/dynamic) */
3959 /* cm_mem_c_001.main_15 : Additions */
3960 #ifdef SS_4GMX_LCORE
3961 EXTERN U8 ysCellConfigDone;
3963 #ifdef SS_HISTOGRAM_SUPPORT
3964 #ifdef SSI_DEBUG_LEVEL1
3966 PRIVATE S16 cmHeapAlloc
3978 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size, memType, line, fileName, entId, hstReg)
3990 PRIVATE S16 cmHeapAlloc
4001 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size, line, fileName, entId, hstReg)
4010 #endif /* SSI_DEBUG_LEVEL1 */
4012 #ifdef SSI_DEBUG_LEVEL1
4014 PRIVATE S16 cmHeapAlloc
4022 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size, memType)
4030 PRIVATE S16 cmHeapAlloc
4037 PRIVATE S16 cmHeapAlloc (heapCb, ptr, size)
4042 #endif /* SSI_DEBUG_LEVEL1 */
4043 /* cm_mem_c_001.main_15 : Additions */
4044 #endif /* SS_HISTOGRAM_SUPPORT */
4046 CmHEntry *prvHBlk; /* Previous heap block */
4047 CmHEntry *curHBlk; /* Current heap block */
4049 /* cm_mem_c_001.main_15 : Additions */
4050 #ifdef SS_MEM_LEAK_STS
4052 #endif /* SS_MEM_LEAK_STS */
4053 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
4054 #ifdef SSI_DEBUG_LEVEL1
4055 CmHEntry *alocHeapBlk;
4059 #endif /* SSI_DEBUG_LEVEL1 */
4060 /* cm_mem_c_001.main_15 : Additions */
4061 #ifdef SS_HISTOGRAM_SUPPORT
4063 #endif /* SS_HISTOGRAM_SUPPORT */
4066 /* cm_mem_c_001.main_15 : Additions */
4067 /* Acquire the heap lock */
4068 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
4069 #ifdef SS_4GMX_LCORE
4070 if(1 == ysCellConfigDone)
4072 #ifdef SSI_DEBUG_LEVEL1
4073 /* display a message here */
4074 sprintf(dbgPrntBuf,"Allocating from heap size=%u\n", *size);
4075 SDisplay(0, dbgPrntBuf);
4076 #endif /* SSI_DEBUG_LEVEL1 */
4080 (Void) WTLock (&(heapCb->heapLock));
4082 (Void) SLock (&(heapCb->heapLock));
4085 #ifdef SS_MEM_LEAK_STS
4087 #endif /* SS_MEM_LEAK_STS */
4088 /* cm_mem_c_001.main_12 - addition for manipulation of statistics related data */
4089 #ifdef SSI_DEBUG_LEVEL1
4090 heapCb->numAllocAttempts++;
4091 requestedSize = *size;
4092 #endif /* SSI_DEBUG_LEVEL1 */
4094 /* Roundup the requested size */
4095 *size = CMM_DATALIGN(*size, (heapCb->minSize));
4097 /* Check if the available total size is adequate. */
4098 if ((*size) >= heapCb->avlSize)
4100 /* cm_mem_c_001.main_15 : Additions */
4102 (Void) WTUnlock (&(heapCb->heapLock));
4104 (Void) SUnlock (&(heapCb->heapLock));
4110 /* cm_mem_c_001.main_12 - addition for aligning the header size */
4111 #ifdef SSI_DEBUG_LEVEL1
4112 hdr = PTRALIGN(sizeof(CmHEntry));
4113 #endif /* SSI_DEBUG_LEVEL1 */
4116 * Search through the heap block list in the heap pool of size
4117 * greater than or equal to the requested size.
4120 /* cm_mem_c_001.main_12 - addition for accessing the heapCb->next */
4121 #ifdef SSI_DEBUG_LEVEL1
4122 prvHBlk = (CmHEntry *)((Data *)&(heapCb->next) - heapCb->nextOffset);
4124 prvHBlk = (CmHEntry *)&(heapCb->next);
4125 #endif /* SSI_DEBUG_LEVEL1 */
4126 for (curHBlk = prvHBlk->next; curHBlk; curHBlk = curHBlk->next,
4127 prvHBlk = prvHBlk->next)
4130 * Since the size of the block is always multiple of CMM_MINBUFSIZE
4131 * and the requested size is rounded to the size multiple of
4132 * CMM_MINBUFSIZE, the difference between the size of the heap block
4133 * and the size to allocate will be either zero or multiple of
4136 if ((*size) <= curHBlk->size)
4138 /* cm_mem_c_001.main_12 - addition for block size calculation */
4139 #ifdef SSI_DEBUG_LEVEL1
4140 tmpSize = curHBlk->size - (*size);
4142 tmpSize = tmpSize - hdr;
4145 /* cm_mem_c_001.main_28 : compilation warning fix */
4146 tmpSize = (curHBlk->size - (*size));
4148 #endif /* SSI_DEBUG_LEVEL1 */
4150 /* Heap block of bigger size */
4151 /* cm_mem_c_001.main_12 - addition for allocating memory */
4152 #ifdef SSI_DEBUG_LEVEL1
4153 *ptr = (Data *)curHBlk + hdr + tmpSize + hdr;
4154 alocHeapBlk = (CmHEntry *) ((Data *)curHBlk + hdr + tmpSize);
4156 * No need to look for memory trampling as this is a new block altogether
4157 * Update the header only for this case as it is new block formed
4159 for (idx=0; idx < CMM_TRAMPLING_SIGNATURE_LEN; idx++)
4161 alocHeapBlk->trSignature[idx] = 0xAB;
4163 alocHeapBlk->size = *size;
4165 *ptr = (Data *)curHBlk + tmpSize;
4166 #endif /* SSI_DEBUG_LEVEL1 */
4167 curHBlk->size = tmpSize;
4171 /* Heap block is same size of the requested size */
4172 /* cm_mem_c_001.main_12 - addition for sanity check and allocation. This is a fresh block */
4173 #ifdef SSI_DEBUG_LEVEL1
4174 /* look for memory trampling as this is a pure block*/
4177 if (cmMmRegIsBlkSane((CmMmBlkHdr *)curHBlk) != ROK)
4179 /* detected a trampled memory block in this bucket */
4181 /* display an error message here */
4182 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
4184 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %u bytes \n", (void *)curHBlk, requestedSize);
4186 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %lu bytes \n", (void *)curHBlk, requestedSize);
4188 SDisplay(0, dbgPrntBuf);
4191 if (cmMmHeapSanityChk(heapCb) == RTRAMPLINGNOK)
4193 /* Release the lock */
4194 /* cm_mem_c_001.main_13: Replaced SUnlock with
4197 (Void) WTUnlock (&(heapCb->heapLock));
4199 (Void) SUnlock (&(heapCb->heapLock));
4201 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
4202 RETVALUE(RTRAMPLINGNOK);
4206 /* Release the lock */
4207 /* cm_mem_c_001.main_13: Replaced SUnlock with
4210 (Void) WTUnlock (&(heapCb->heapLock));
4212 (Void) SUnlock (&(heapCb->heapLock));
4219 *ptr = (Data *)curHBlk + hdr;
4220 alocHeapBlk = curHBlk;
4221 *size = curHBlk->size;
4223 *ptr = (Data *)curHBlk;
4224 #endif /* SSI_DEBUG_LEVEL1 */
4225 prvHBlk->next = curHBlk->next;
4228 /* cm_mem_c_001.main_12 - addition for header updation */
4229 #ifdef SSI_DEBUG_LEVEL1
4230 /* update the header fields */
4231 alocHeapBlk->requestedSize = requestedSize;
4232 alocHeapBlk->memFlags = 0;
4233 if (memType == CMM_STATIC_MEM_FLAG)
4235 CMM_SET_STATIC_FLAG(alocHeapBlk->memFlags);
4236 heapCb->staticHeapMemUsed += (*size + hdr);
4240 CMM_SET_DYNAMIC_FLAG(alocHeapBlk->memFlags);
4241 heapCb->dynamicHeapMemUsed += (*size + hdr);
4243 heapCb->avlSize -= ((*size) + hdr);
4245 heapCb->avlSize -= (*size);
4246 #endif /* SSI_DEBUG_LEVEL1 */
4252 "SGetSBuf:%08lu:Size Heap Alloc Times:%05lu Pointer: %8p\n",
4253 *size, num_times, *ptr);
4254 SDisplay(0, prntBuf);
4258 /* cm_mem_c_001.main_15 : Additions */
4259 #ifdef SS_MEM_LEAK_STS
4260 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
4261 cmStorAllocBlk((PTR)*ptr, (Size) reqSz, (Size) *size, MT_MAX_BKTS);
4262 #endif /* SS_MEM_LEAK_STS */
4263 /* Release the lock */
4264 /* cm_mem_c_001.main_16 : cm_mem_c_001.main_18 Additions */
4266 (Void) WTUnlock (&(heapCb->heapLock));
4268 (Void) SUnlock (&(heapCb->heapLock));
4271 #ifdef SS_HISTOGRAM_SUPPORT
4272 /* If If Tapa task (entId)is registerd for histogram then insert Memrory allocated
4273 * information into the hash list */
4276 if (cmHstGrmAllocInsert(&(heapCb->heapHstGrmHashListCp), *size, size, line, fileName, entId) != ROK)
4278 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4283 #endif /* SS_HISTOGRAM_SUPPORT */
4289 /* cm_mem_c_008.104 - Addition for memory calculator tool */
4295 /* Release the lock */
4296 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4298 (Void) WTUnlock (&(heapCb->heapLock));
4300 (Void) SUnlock (&(heapCb->heapLock));
4305 } /* end of cmHeapAlloc */
4312 * Desc: Return the memory block from the heap pool.
4315 * Ret: ROK - successful
4316 * RFAILED - unsuccessful.
4318 * Notes: This function returns the memory block to the heap pool. This
4319 * function is called by cmFree. The function does not check the
4320 * validity of the memory block. The caller must be sure that the
4321 * block was previously allocated and belongs to the heap pool. The
4322 * function maintain the sorting order of the memory block on the
4323 * starting address of the block. This function also do compaction
4324 * if the neighbouring blocks are already in the heap.
4331 /* cm_mem_c_001.main_15 : Additions */
4332 #ifdef SS_HISTOGRAM_SUPPORT
4334 PRIVATE S16 cmHeapFree
4345 PRIVATE S16 cmHeapFree (heapCb, ptr, size, line, fileName, entId, hstReg)
4356 PRIVATE S16 cmHeapFree
4363 PRIVATE S16 cmHeapFree (heapCb, ptr, size)
4368 /* cm_mem_c_001.main_15 : Additions */
4369 #endif /* SS_HISTOGRAM_SUPPORT */
4372 CmHEntry *curHBlk; /* Current heap block */
4373 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
4374 #ifdef SSI_DEBUG_LEVEL1
4376 #endif /* SSI_DEBUG_LEVEL1 */
4377 /* cm_mem_c_001.main_15 : Additions */
4378 #ifdef SS_HISTOGRAM_SUPPORT
4379 Size allocSize = size;
4381 #endif /* SS_HISTOGRAM_SUPPORT */
4385 /* Roundup the requested size */
4386 size = CMM_DATALIGN(size, (heapCb->minSize));
4387 /* cm_mem_c_001.main_15: Additions */
4388 #ifdef SS_HISTOGRAM_SUPPORT
4390 #endif /* SS_HISTOGRAM_SUPPORT */
4392 /* Acquire the heap lock */
4393 /* cm_mem_c_001.main_13 : Replaced SLock with WTLock for NT */
4395 (Void) WTLock (&(heapCb->heapLock));
4397 (Void) SLock (&(heapCb->heapLock));
4400 /* increase the avlSize */
4401 /* cm_mem_c_001.main_12 - addition for manipulation of statistics related data */
4402 #ifdef SSI_DEBUG_LEVEL1
4403 hdr = PTRALIGN(sizeof(CmHEntry));
4404 heapCb->avlSize += (size + hdr);
4405 heapCb->numDeallocAttempts++;
4407 heapCb->avlSize += size;
4408 #endif /* SSI_DEBUG_LEVEL1 */
4410 /* cm_mem_c_001.main_12 - addition for pointing to the block */
4411 #ifdef SSI_DEBUG_LEVEL1
4412 p = (CmHEntry *)(ptr - hdr);
4414 p = (CmHEntry *)ptr;
4415 /* cm_mem_c_001.main_15 : Additions */
4416 #ifdef SS_MEM_LEAK_STS
4417 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
4418 cmRlsAllocBlk((PTR)ptr);
4419 #endif /* SS_MEM_LEAK_STS */
4420 #endif /* SSI_DEBUG_LEVEL1 */
4423 /* cm_mem_c_001.main_12 - addition for sanity and double-free checks */
4424 #ifdef SSI_DEBUG_LEVEL1
4425 /* look for memory trampling */
4426 if (cmMmRegIsBlkSane((CmMmBlkHdr *)p) != ROK)
4428 /* detected a trampled memory block in heap */
4430 /* display an error message here */
4431 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
4433 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %u bytes \n", (void *)p, size);
4435 sprintf(dbgPrntBuf, "Memory Trampling in heap at: %8p, size %lu bytes \n", (void *)p, size);
4437 SDisplay(0, dbgPrntBuf);
4440 if (cmMmHeapSanityChk(heapCb) == RTRAMPLINGNOK)
4442 /* Release the lock */
4443 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4445 (Void) WTUnlock (&(heapCb->heapLock));
4447 (Void) SUnlock (&(heapCb->heapLock));
4449 /* handle RTRAMPLINGNOK in SAlloc/SGetSBuf */
4450 RETVALUE(RTRAMPLINGNOK);
4454 /* do not add to the free heap */
4455 heapCb->avlSize -= (size + hdr);
4456 /* Release the heap lock */
4457 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4459 (Void) WTUnlock (&(heapCb->heapLock));
4461 (Void) SUnlock (&(heapCb->heapLock));
4468 /* look for any double free */
4469 if (CMM_IS_FREE(p->memFlags))
4472 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
4474 sprintf(dbgPrntBuf, "DOUBLE FREE at %8p for size %u in HEAP \n", (void *)p, size);
4476 sprintf(dbgPrntBuf, "DOUBLE FREE at %8p for size %lu in HEAP \n", (void *)p, size);
4478 SDisplay(0, dbgPrntBuf);
4481 heapCb->avlSize -= (size + hdr);
4482 /* cm_mem_c_001.main_15 : Additions */
4484 (Void) WTUnlock (&(heapCb->heapLock));
4486 (Void) SUnlock (&(heapCb->heapLock));
4491 #endif /* SSI_DEBUG_LEVEL1 */
4493 for ( curHBlk = heapCb->next; curHBlk; curHBlk = curHBlk->next)
4496 * The block will be inserted to maintain the sorted order on the
4497 * starting address of the block.
4501 if (!(curHBlk->next) ||
4502 (p < (curHBlk->next)))
4504 /* Heap block should be inserted here */
4507 * Check if the block to be returned can be merged with the
4510 /* cm_mem_c_001.main_12 - addition for header consideration */
4511 #ifdef SSI_DEBUG_LEVEL1
4512 if (((Data *)curHBlk + hdr + curHBlk->size) == (Data *)p)
4514 if (((Data *)curHBlk + curHBlk->size) == (Data *)p)
4515 #endif /* SSI_DEBUG_LEVEL1 */
4517 /* Merge the block */
4518 /* cm_mem_c_001.main_12 - addition for updating statistics related data */
4519 #ifdef SSI_DEBUG_LEVEL1
4520 /* update the flags */
4521 if (CMM_IS_STATIC(p->memFlags))
4522 heapCb->staticHeapMemUsed -= (size + hdr);
4523 else if (CMM_IS_DYNAMIC(p->memFlags))
4524 heapCb->dynamicHeapMemUsed -= (size + hdr);
4525 size = (curHBlk->size += (size + hdr));
4527 size = (curHBlk->size += size);
4528 #endif /*SSI_DEBUG_LEVEL1*/
4533 /* cm_mem_c_001.main_12 - addition for double-free check */
4534 #ifdef SSI_DEBUG_LEVEL1
4535 /* Check for double deallocation in heap */
4536 if ((Data *)p < ((Data *)curHBlk + curHBlk->size))
4538 /* Release the lock */
4539 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4541 (Void) WTUnlock (&(heapCb->heapLock));
4543 (Void) SUnlock (&(heapCb->heapLock));
4546 /* This block is already freed in the heap */
4549 /* update the flags as it is a new node */
4550 if (CMM_IS_STATIC(p->memFlags))
4552 heapCb->staticHeapMemUsed -= (size + hdr);
4553 CMM_RESET_STATIC_FLAG(p->memFlags);
4555 else if (CMM_IS_DYNAMIC(p->memFlags))
4557 heapCb->dynamicHeapMemUsed -= (size + hdr);
4558 CMM_RESET_DYNAMIC_FLAG(p->memFlags);
4560 CMM_SET_FREE_FLAG(p->memFlags);
4561 p->requestedSize = 0;
4562 #endif /*SSI_DEBUG_LEVEL1*/
4563 /* insert the block */
4564 p->next = curHBlk->next;
4569 /* Try to merge with the next block in the chain */
4570 /* cm_mem_c_001.main_12 - addition for ssi enhancements */
4571 #ifdef SSI_DEBUG_LEVEL1
4572 if (((Data *)p + hdr + size) == (Data *)(p->next) && (p->next))
4574 if (((Data *)p + size) == (Data *)(p->next) && (p->next))
4575 #endif /*SSI_DEBUG_LEVEL1*/
4577 /* p->next can not be NULL */
4578 /* cm_mem_c_001.main_12 - addition for header consideration */
4579 #ifdef SSI_DEBUG_LEVEL1
4580 p->size += (p->next->size + hdr);
4582 p->size += p->next->size;
4583 #endif /*SSI_DEBUG_LEVEL1*/
4584 p->next = p->next->next;
4587 /* Release the lock */
4588 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4590 (Void) WTUnlock (&(heapCb->heapLock));
4592 (Void) SUnlock (&(heapCb->heapLock));
4594 /* cm_mem_c_001.main_15 : Additions */
4595 #ifdef SS_HISTOGRAM_SUPPORT
4596 /* If If Tapa task (entId)is registerd for histogram then insert
4597 Memrory Freed information into the hash list */
4600 if (cmHstGrmFreeInsert(&heapCb->heapHstGrmHashListCp, allocSize, line,
4601 fileName, entId) != ROK)
4603 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4607 #endif /* SS_HISTOGRAM_SUPPORT */
4611 else if (p < curHBlk)
4614 * Check if the block to be returned can be merged with the
4617 /* cm_mem_c_001.main_12 - addition for header consideration */
4618 #ifdef SSI_DEBUG_LEVEL1
4619 if (((Data *)p + hdr + size) == (Data *)curHBlk)
4621 if (((Data *)p + size) == (Data *)curHBlk)
4622 #endif /* SSI_DEBUG_LEVEL1 */
4624 /* Merge the block */
4625 /* cm_mem_c_001.main_12 - addition for header consideration */
4626 #ifdef SSI_DEBUG_LEVEL1
4627 p->size = size + (curHBlk->size + hdr);
4629 p->size = size + curHBlk->size;
4630 #endif /* SSI_DEBUG_LEVEL1 */
4631 p->next = curHBlk->next;
4635 /* insert the block */
4639 /* cm_mem_c_001.main_12 - addition for header updation */
4640 #ifdef SSI_DEBUG_LEVEL1
4641 /* update the flags in both cases as they are new start nodes*/
4642 if (CMM_IS_STATIC(p->memFlags))
4644 heapCb->staticHeapMemUsed -= (size + hdr);
4645 CMM_RESET_STATIC_FLAG(p->memFlags);
4647 else if (CMM_IS_DYNAMIC(p->memFlags))
4649 heapCb->dynamicHeapMemUsed -= (size + hdr);
4650 CMM_RESET_DYNAMIC_FLAG(p->memFlags);
4652 CMM_SET_FREE_FLAG(p->memFlags);
4653 p->requestedSize = 0;
4654 #endif /* SSI_DEBUG_LEVEL1 */
4658 /* Release the lock */
4659 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4661 (Void) WTUnlock (&(heapCb->heapLock));
4663 (Void) SUnlock (&(heapCb->heapLock));
4665 /* cm_mem_c_001.main_15 : Additions */
4666 #ifdef SS_HISTOGRAM_SUPPORT
4667 /* If If Tapa task (entId)is registerd for histogram then insert
4668 Memrory Freed information into the hash list */
4671 if (cmHstGrmFreeInsert(&heapCb->heapHstGrmHashListCp, allocSize, line,
4672 fileName, entId) != ROK)
4674 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4678 #endif /* SS_HISTOGRAM_SUPPORT */
4684 if (heapCb->next == NULLP)
4686 /* Heap block is empty. Insert the block in the head. */
4691 /* cm_mem_c_001.main_12 - addition for header updation */
4692 #ifdef SSI_DEBUG_LEVEL1
4693 if (CMM_IS_STATIC(p->memFlags))
4695 heapCb->staticHeapMemUsed -= (size + hdr);
4696 CMM_RESET_STATIC_FLAG(p->memFlags);
4698 else if (CMM_IS_DYNAMIC(p->memFlags))
4700 heapCb->dynamicHeapMemUsed -= (size + hdr);
4701 CMM_RESET_DYNAMIC_FLAG(p->memFlags);
4703 CMM_SET_FREE_FLAG(p->memFlags);
4704 p->requestedSize = 0;
4705 #endif /* SSI_DEBUG_LEVEL1 */
4707 /* Release the heap lock */
4708 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4710 (Void) WTUnlock (&(heapCb->heapLock));
4712 (Void) SUnlock (&(heapCb->heapLock));
4714 /* cm_mem_c_001.main_15 : Additions */
4715 #ifdef SS_HISTOGRAM_SUPPORT
4716 /* If If Tapa task (entId)is registerd for histogram then insert
4717 Memrory Freed information into the hash list */
4720 if (cmHstGrmFreeInsert(&heapCb->heapHstGrmHashListCp, allocSize, line,
4721 fileName, entId) != ROK)
4723 sprintf(hstGrmBuf, "Unable to Insert into the histgram hash list\n");
4727 #endif /* SS_HISTOGRAM_SUPPORT */
4731 /* Release the lock */
4732 /* cm_mem_c_001.main_13: Replaced SUnlock with WTUnlock for NT */
4734 (Void) WTUnlock (&(heapCb->heapLock));
4736 (Void) SUnlock (&(heapCb->heapLock));
4740 } /* end of cmHeapFree */
4742 #ifdef SS_LIGHT_MEM_LEAK_STS
4744 PUBLIC U32 cmGetFreeIndx
4749 PUBLIC U32 cmGetFreeIndx(Void)
4753 if(gmemLkCb.head == gmemLkCb.tail)
4755 allocQueueEmptyCnt++;
4756 RETVALUE(CM_MAX_ALLOC_ENTERIES);
4760 U32 allocQIndx = gmemLkCb.queue[gmemLkCb.head];
4761 gmemLkCb.head = (gmemLkCb.head +1) % CM_MAX_ALLOC_ENTERIES;
4762 RETVALUE(allocQIndx);
4767 PUBLIC U32 cmPutFreeIndx
4772 PUBLIC U32 cmPutFreeIndx(allocQIndx)
4777 U32 tmpTail = (gmemLkCb.tail+1)% CM_MAX_ALLOC_ENTERIES;
4778 if(tmpTail == gmemLkCb.head)
4780 allocQueueFullCnt++;
4785 gmemLkCb.queue[gmemLkCb.tail] = allocQIndx;
4786 gmemLkCb.tail = tmpTail;
4792 * Fun: cmInitMemLeakMdl
4794 * Desc: Initializes the memory leak detection module
4799 * Notes: This function initializes the memory leak detection module.
4806 PUBLIC Void cmInitMemLeak
4811 PUBLIC Void cmInitMemLeak (Void)
4816 TRC3(cmInitMemLeak);
4818 gmemLkCb.isStarted = FALSE;
4821 SInitLock(&gmemLkCb.memLock, 1);
4822 for(indx = 0; indx < CM_MAX_ALLOC_ENTERIES; indx++)
4824 gmemLkCb.allocInfo[indx].used = FALSE;
4825 cmPutFreeIndx(indx);
4829 } /* cmInitMemLeak */
4832 * Fun: cmDeinitMemLeak
4834 * Desc: De-initializes the memory leak detection
4839 * Notes: This function de-initializes the memory leak detection module.
4846 PUBLIC Void cmDeinitMemLeak
4851 PUBLIC Void cmDeinitMemLeak (Void)
4856 TRC3(cmDeinitMemLeak);
4858 for(indx = 0; indx < CM_MAX_ALLOC_ENTERIES; indx++)
4860 gmemLkCb.allocInfo[indx].used = FALSE;
4862 SDestroyLock(&gmemLkCb.memLock);
4863 gmemLkCb.isStarted = FALSE;
4870 * Fun: cmStorAllocBlk
4872 * Desc: Initializes the memory leak detection module
4877 * Notes: This function initializes the memory leak detection module.
4884 PUBLIC U32 cmStorAllocBlk
4889 PUBLIC U32 cmStorAllocBlk (addr)
4896 (Void) SLock(&gmemLkCb.memLock);
4897 allocQIndx = cmGetFreeIndx();
4898 if(allocQIndx < CM_MAX_ALLOC_ENTERIES)
4900 queueIndxAllocCnt++;
4901 gmemLkCb.allocInfo[allocQIndx].memAddr = addr;
4902 gmemLkCb.allocInfo[allocQIndx].used = TRUE;
4904 (Void) SUnlock(&(gmemLkCb.memLock));
4906 RETVALUE(allocQIndx);
4907 } /* cmStorAllocBlk */
4912 * Fun: cmRlsAllocBlk
4914 * Desc: Initializes the memory leak detection module
4919 * Notes: This function initializes the memory leak detection module.
4926 PUBLIC Void cmRlsAllocBlk
4931 PUBLIC Void cmRlsAllocBlk(allocQIndx)
4935 TRC3(cmRlsAllocBlk);
4937 if(allocQIndx < CM_MAX_ALLOC_ENTERIES)
4939 if(gmemLkCb.allocInfo[allocQIndx].used == TRUE)
4941 (Void) SLock(&gmemLkCb.memLock);
4942 gmemLkCb.allocInfo[allocQIndx].used = FALSE;
4943 cmPutFreeIndx(allocQIndx);
4945 (Void) SUnlock(&(gmemLkCb.memLock));
4949 } /* cmRlsAllocBlk */
4953 * Fun: cmStartStopLeakLog
4963 PUBLIC Void cmStartStopLeakLog
4968 PUBLIC Void cmStartStopLeakLog(Void)
4971 if (FALSE == gmemLkCb.isStarted)
4973 printf("!!leak capturing started\n");
4974 gmemLkCb.isStarted = TRUE;
4978 gmemLkCb.isStarted = FALSE;
4979 printf("!!leak capturing stopped\n");
4987 * Fun: cmPrintLeakLog
4989 * Desc: Prints leak log
4999 PUBLIC Void cmPrintLeakLog
5004 PUBLIC Void cmPrintLeakLog(Void)
5010 static U32 leakCount =0;
5012 TRC3(cmPrintLeakLog);
5014 printf("---- START OF LEAK LOG ----");
5015 SLock(&gmemLkCb.memLock);
5016 printf("---- Lock Acquired ----");
5017 for(indx = 0; indx < CM_MAX_ALLOC_ENTERIES; indx++)
5019 if(gmemLkCb.allocInfo[indx].used == TRUE)
5022 aBkt =(CmMmBlkHdr *)gmemLkCb.allocInfo[indx].memAddr;
5023 printf("LeakCnt(%ld)Addr(0x%p)RqSz(%ld)",
5024 leakCount,gmemLkCb.allocInfo[indx].memAddr, aBkt->requestedSize);
5025 printf("LineNo(%ld)funcName(%s)\n",
5026 aBkt->lineNo, aBkt->currFuncName);
5027 gmemLkCb.allocInfo[indx].used = FALSE;
5028 cmPutFreeIndx(indx);
5030 //if(leakCount % 10 == 0)
5033 printf("---- END OF LEAK LOG ----");
5034 SUnlock(&gmemLkCb.memLock);
5035 printf("---- Lock Released ----");
5042 #if (defined(SS_MEM_LEAK_STS) || defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2))
5045 * Fun: cmRlsAllocBlk
5047 * Desc: Initializes the memory leak detection module
5052 * Notes: This function initializes the memory leak detection module.
5058 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5060 PUBLIC Void cmRlsAllocBlk
5066 PUBLIC Void cmRlsAllocBlk(ptrHdr, regCb)
5072 PUBLIC Void cmRlsAllocBlk
5081 PUBLIC Void cmRlsAllocBlk(addr)
5090 Ptr trace[CM_MAX_STACK_TRACE];
5096 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5097 MemAllocInfo *memAllocInfo;
5100 TRC3(cmRlsAllocBlk);
5102 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5104 retVal = cmHashListFind(®Cb->brdcmSsiLstCp,(U8 *)&ptrHdr,
5105 (U16)sizeof(U64), 0, (PTR *)&ptrHdr);
5107 retVal = cmHashListFind(®Cb->brdcmSsiLstCp,(U8 *)&ptrHdr,
5108 (U16)sizeof(U32), 0, (PTR *)&ptrHdr);
5112 cmHashListDelete(®Cb->brdcmSsiLstCp, (PTR)ptrHdr);
5115 if( memLkCb.memLkMdlInit == FALSE)
5119 for(idx = 0; idx < CM_MEM_USR_MDL; idx++)
5121 SLock(&memLkCb.memUsrMdl[idx][addr & 0x3].memLck);
5123 retVal = cmHashListFind(&memLkCb.memUsrMdl[idx][addr & 0x3].memHashCp,
5124 (U8 *)&addr, sizeof(U64), 0,
5125 (PTR *)&memAllocInfo);
5127 retVal = cmHashListFind(&memLkCb.memUsrMdl[idx][addr & 0x3].memHashCp,
5128 (U8 *)&addr, sizeof(U32), 0,
5129 (PTR *)&memAllocInfo);
5133 cmHashListDelete(&memLkCb.memUsrMdl[idx][addr & 0x3].memHashCp,
5135 SUnlock(&memLkCb.memUsrMdl[idx][addr & 0x3].memLck);
5136 funcNm = (S8 **) memAllocInfo->backTrace;
5137 #ifdef SS_MEM_LEAK_SOL
5138 for(i = 0; i < memAllocInfo->bTrcSz; i++)
5140 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5141 #ifdef SS_4GMX_LCORE
5142 MxHeapFree(SsiHeap, funcNm[i]);
5147 #endif /* SS_MEM_LEAK_SOL */
5148 #ifdef SS_MEM_LEAK_FREE_TRACE
5152 sprintf( prntBuf, "\n==============================\n");
5154 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
5156 sprintf( prntBuf, "Address: [%x]\n", addr);
5158 sprintf( prntBuf, "Address: [%lx]\n", addr);
5161 traceSize = backtrace(trace, CM_MAX_STACK_TRACE);
5162 funcNm = backtrace_symbols(trace, traceSize);
5163 sprintf( prntBuf, "[bt] Execution path:\n");
5165 for (i=0; i < traceSize; ++i)
5167 sprintf( prntBuf, "[bt] %s\n", funcNm[i]);
5170 sprintf( prntBuf, "\n==============================\n");
5173 #endif /* SS_MEM_LEAK_FREE_TRACE */
5174 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5175 #ifdef SS_4GMX_LCORE
5176 MxHeapFree(SsiHeap, funcNm);
5177 MxHeapFree(SsiHeap, memAllocInfo);
5184 SUnlock(&memLkCb.memUsrMdl[idx][addr & 0x3].memLck);
5187 #ifndef SS_MEM_LEAK_SOL
5188 if(idx == CM_MEM_USR_MDL)
5191 sprintf( prntBuf,"\nPossible Double-Deallocation.\n");
5193 /*cm_mem_c_001.main_23 Fix for specifier mismatch warnings in 64BIT compilation*/
5195 sprintf( prntBuf, "Address: [%u]\n", addr);
5197 sprintf( prntBuf, "Address: [%lu]\n", addr);
5200 traceSize = backtrace(trace, CM_MAX_STACK_TRACE);
5201 funcNm = backtrace_symbols(trace, traceSize);
5202 sprintf( prntBuf,"[bt] Execution path:\n");
5204 for (i=0; i < traceSize; ++i)
5206 sprintf( prntBuf,"[bt] %s\n", funcNm[i]);
5209 printf("\n==============================\n");
5210 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5211 #ifdef SS_4GMX_LCORE
5212 MxHeapFree(SsiHeap, funcNm);
5217 #endif /* SS_MEM_LEAK_SOL */
5218 #endif/* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
5219 /*cm_mem_c_001.main_25 : */
5221 } /* cmRlsAllocBlk */
5226 * Fun: cmStorAllocBlk
5228 * Desc: Initializes the memory leak detection module
5233 * Notes: This function initializes the memory leak detection module.
5239 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5241 PUBLIC Void cmStorAllocBlk
5250 PUBLIC Void cmStorAllocBlk (ptrHdr, reqSz, allocSz, bktIdx, regCb)
5259 PUBLIC Void cmStorAllocBlk
5271 PUBLIC Void cmStorAllocBlk (addr, reqSz, allocSz, bktIdx)
5281 #endif /* BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1 */
5283 #ifndef SS_MEM_LEAK_SOL
5284 void *trace[CM_MAX_STACK_TRACE];
5285 #endif /* SS_MEM_LEAK_SOL */
5286 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5289 MemAllocInfo *allocInfo;
5295 TRC3(cmStorAllocBlk);
5296 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5297 if( memLkCb.memLkMdlInit == FALSE)
5302 #ifdef SS_MEM_LEAK_SOL
5303 /* I need to do this for solaris, because it does not implement
5304 * backtrace. Here backtrace is my function. See below for the
5305 * implementation. */
5306 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5307 #ifdef SS_4GMX_LCORE
5308 funcNm = (S8 **)MxHeapAlloc(SsiHeap, (sizeof(U32) * CM_MAX_STACK_TRACE));
5309 cmMemset((U8*)funcNm, 0, (sizeof(U32) * CM_MAX_STACK_TRACE));
5311 funcNm = (S8 **)calloc(1, (sizeof(U32) * CM_MAX_STACK_TRACE));
5313 /* SGetSBuf(DFLT_REGION, DFLT_POOL, &funcNm, sizeof(U32) * CM_MAX_STACK_TRACE); */
5314 traceSize = backtrace((Void **)funcNm, CM_MAX_STACK_TRACE);
5315 #else /* SS_MEM_LEAK_SOL */
5316 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5317 traceSize = backtrace(trace, CM_MAX_STACK_TRACE);
5318 funcNm = backtrace_symbols(trace, traceSize);
5320 #endif /* SS_MEM_LEAK_SOL */
5322 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5323 moduleId = cmMemGetModuleId(funcNm, traceSize);
5324 (Void)SLock(&(memLkCb.memUsrMdl[moduleId][addr & 0x3].memLck));
5327 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5328 #ifndef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5329 #ifdef SS_4GMX_LCORE
5330 allocInfo = (MemAllocInfo *)MxHeapAlloc(SsiHeap, sizeof(MemAllocInfo));
5331 cmMemset((U8*)allocInfo, 0, sizeof(MemAllocInfo));
5333 allocInfo = (MemAllocInfo *)calloc(1, sizeof(MemAllocInfo));
5336 /* SGetSBuf(DFLT_REGION, DFLT_POOL, &allocInfo, sizeof(MemAllocInfo)); */
5337 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5338 /* check if hashListCp is initialised yet */
5339 if ( regCb->brdcmSsiLstCp.nmbBins == 0)
5343 ptrHdr->reqSz = reqSz;
5344 ptrHdr->allocSz = allocSz;
5345 ptrHdr->bktIdx = bktIdx;
5346 cmHashListInsert(®Cb->brdcmSsiLstCp, (PTR)ptrHdr,
5347 (U8 *)&(ptrHdr), sizeof(PTR));
5349 allocInfo->memAddr = addr;
5350 allocInfo->reqSz = reqSz;
5351 allocInfo->allocSz = allocSz;
5352 allocInfo->bktIdx = bktIdx;
5353 allocInfo->backTrace = (PTR) funcNm;
5354 allocInfo->moduleId = moduleId;
5355 allocInfo->bTrcSz = traceSize;
5356 cmHashListInsert(&memLkCb.memUsrMdl[moduleId][addr & 0x3].memHashCp,
5357 (PTR)allocInfo, (U8 *)&(allocInfo->memAddr),
5358 sizeof(allocInfo->memAddr));
5359 memLkCb.memUsrMdl[moduleId][addr & 0x3].used = TRUE;
5361 (Void) SUnlock(&(memLkCb.memUsrMdl[moduleId][addr & 0x3].memLck));
5364 } /* cmStorAllocBlk */
5369 } /* cmStorAllocBlk */
5375 * Desc: Initializes the memory leak detection module
5380 * Notes: This function initializes the memory leak detection module.
5387 PUBLIC Void SLogLkInfo
5392 PUBLIC Void SLogLkInfo (Void)
5395 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL2
5400 CmMmBlkHdr *newBlkHdr;
5401 CmMmBlkHdr *oldBlkHdr;
5402 CmMmRegCb *tmpRegCb;
5406 fp = fopen("meLeakLog.txt", "w");
5409 memLk.fileLkLog = (FILE *)stdout;
5413 memLk.fileLkLog = fp;
5415 sprintf(prntBuf, "\n------- START OF LEAK LOG -------\n");
5416 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5417 for(regionIdx = 0; regionIdx < SS_MAX_REGS; regionIdx++)
5419 // tmpRegCb = mtCMMRegCb[regionIdx];
5420 while(cmHashListGetNext(&tmpRegCb->brdcmSsiLstCp,
5421 (PTR)oldBlkHdr, (PTR *)&newBlkHdr) == ROK)
5423 sprintf(prntBuf, "[LBIS]\n");
5424 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5426 sprintf(prntBuf, "Address: 0x%u\n", newBlkHdr);
5428 sprintf(prntBuf, "Address: 0x%lu\n", newBlkHdr);
5430 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5431 sprintf(prntBuf, "Requested Size: %d\n", (S16)newBlkHdr->reqSz);
5432 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5433 sprintf(prntBuf, "Allocated Size: %d\n", (S16)newBlkHdr->allocSz);
5434 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5435 sprintf(prntBuf, "Bucket Idx: %d\n", newBlkHdr->bktIdx);
5436 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5437 sprintf(prntBuf,"Memory Allocation Path:\n");
5438 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5439 //funcNm = (S8 **)newBlkHdr->backTrace;
5440 for(idx = 0; idx < BRDCM_MEM_LEAK_BTRACE; idx ++)
5442 // sprintf(prntBuf,"==> %p\n", newBlkHdr->backTrace[idx]);
5443 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5445 sprintf(prntBuf, "[LBIE]\n\n");
5446 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5447 fflush(memLk.fileLkLog);
5448 oldBlkHdr = newBlkHdr;
5452 sprintf(prntBuf, "\n------- END OF LEAK LOG -------\n");
5453 fwrite(prntBuf, strlen(prntBuf), 1, memLk.fileLkLog);
5456 MemAllocInfo *oldMemInfo;
5457 MemAllocInfo *newMemInfo;
5464 if( memLkCb.memLkMdlInit == FALSE)
5468 sprintf(prntBuf, "\n------- START OF LEAK LOG -------\n");
5469 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5471 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5473 for (hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5475 if(memLkCb.memUsrMdl[memMdl][hashIdx].used == FALSE)
5481 SLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5482 while(cmHashListGetNext(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp,
5483 (PTR)oldMemInfo, (PTR *)&newMemInfo) == ROK)
5485 sprintf(prntBuf, "[LBIS]\n");
5486 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5487 /* cm_mem_c_001.main_25 - Fixed compilation warnings 32/64 bit */
5489 sprintf(prntBuf, "Address: 0x%u\n", newMemInfo->memAddr);
5491 sprintf(prntBuf, "Address: 0x%lu\n", newMemInfo->memAddr);
5493 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5494 sprintf(prntBuf, "Module Name: %s\n",
5495 memUsrMdlStr[newMemInfo->moduleId].mdlStr);
5496 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5497 sprintf(prntBuf, "Requested Size: %d\n", (S16)newMemInfo->reqSz);
5498 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5499 sprintf(prntBuf, "Allocated Size: %d\n", (S16)newMemInfo->allocSz);
5500 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5501 sprintf(prntBuf, "Bucket Idx: %d\n", newMemInfo->bktIdx);
5502 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5503 sprintf(prntBuf,"Memory Allocation Path:\n");
5504 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5505 funcNm = (S8 **)newMemInfo->backTrace;
5506 for(idx = 0; idx < newMemInfo->bTrcSz; idx ++)
5508 sprintf(prntBuf,"==> %s\n", funcNm[idx]);
5509 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5511 sprintf(prntBuf, "[LBIE]\n\n");
5512 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5513 fflush(memLkCb.fileLkLog);
5514 oldMemInfo = newMemInfo;
5517 SUnlock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5520 sprintf(prntBuf, "\n------- END OF LEAK LOG -------\n");
5521 fwrite(prntBuf, strlen(prntBuf), 1, memLkCb.fileLkLog);
5528 /* cm_mem_c_001.main_15 : Additions */
5529 #ifdef SS_MEM_LEAK_STS
5532 * Fun: cmInitMemLeakMdl
5534 * Desc: Initializes the memory leak detection module
5539 * Notes: This function initializes the memory leak detection module.
5546 PUBLIC Void cmInitMemLeakMdl
5551 PUBLIC Void cmInitMemLeakMdl (Void)
5557 TRC3(cmInitMemLeakMdl);
5559 memLkCb.memLkMdlInit = FALSE;
5560 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5562 for (hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5564 SInitLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck, 1);
5565 cmHashListInit(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp,
5566 500, 0, FALSE, CM_HASH_KEYTYPE_U32MOD, 0, 0);
5567 memLkCb.memUsrMdl[memMdl][hashIdx].used = FALSE;
5570 if(memLkCb.fileLkLog == NULLP)
5572 memLkCb.fileLkLog = (FILE *) stdout;
5574 memLkCb.memLkMdlInit = TRUE;
5577 } /* cmInitMemLeakMdl */
5578 /* cm_mem_c_002.main_21 Added for shutdown procedure */
5581 * Fun: cmDeinitMemLeakMdl
5583 * Desc: De-initializes the memory leak detection module
5588 * Notes: This function de-initializes the memory leak detection module.
5595 PUBLIC Void cmDeinitMemLeakMdl
5600 PUBLIC Void cmDeinitMemLeakMdl (Void)
5606 TRC3(cmDeinitMemLeakMdl);
5608 memLkCb.memLkMdlInit = FALSE;
5609 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5611 for (hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5613 SDestroyLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5614 cmHashListDeinit(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp);
5615 memLkCb.memUsrMdl[memMdl][hashIdx].used = FALSE;
5622 * Fun: cmMemOpenMemLkFile
5624 * Desc: Initializes the memory leak detection module
5629 * Notes: This function initializes the memory leak detection module.
5636 PUBLIC Void cmMemOpenMemLkFile
5641 PUBLIC Void cmMemOpenMemLkFile (arg)
5645 TRC3(cmMemOpenMemLkFile);
5646 memLkCb.fileLkLog = NULLP;
5647 memLkCb.fileLkLog = fopen(arg, "w");
5654 * Desc: Initializes the memory leak detection module
5659 * Notes: This function initializes the memory leak detection module.
5666 PUBLIC Void SFlushLkInfo
5671 PUBLIC Void SFlushLkInfo (Void)
5674 MemAllocInfo *newMemInfo;
5678 #ifdef SS_MEM_LEAK_SOL
5680 #endif /* SS_MEM_LEAK_SOL */
5683 if( memLkCb.memLkMdlInit == FALSE)
5688 for(memMdl = 0; memMdl < CM_MEM_USR_MDL; memMdl++)
5690 for(hashIdx = 0; hashIdx < CM_MAX_HASH_PER_TSK; hashIdx++)
5692 if(memLkCb.memUsrMdl[memMdl][hashIdx].used == FALSE)
5697 SLock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5698 while(cmHashListGetNext(&memLkCb.memUsrMdl[memMdl][hashIdx].memHashCp,
5699 (PTR)NULLP, (PTR *)&newMemInfo) == ROK)
5701 funcNm = (S8 **)newMemInfo->backTrace;
5702 #ifdef SS_MEM_LEAK_SOL
5703 for(i = 0; i < newMemInfo->bTrcSz; i++)
5705 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5706 #ifdef SS_4GMX_LCORE
5707 MxHeapFree(SsiHeap, funcNm[i]);
5711 /* SPutSBuf(DFLT_REGION, DFLT_POOL, funcNm[i], sizeof(U32) * CM_MAX_STACK_TRACE); */
5713 #endif /* SS_MEM_LEAK_SOl */
5714 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5715 #ifdef SS_4GMX_LCORE
5716 MxHeapFree(SsiHeap, funcNm);
5717 MxHeapFree(SsiHeap, newMemInfo);
5723 SUnlock(&memLkCb.memUsrMdl[memMdl][hashIdx].memLck);
5730 * Fun: cmMemGetModuleId
5732 * Desc: Initializes the memory leak detection module
5737 * Notes: This function initializes the memory leak detection module.
5744 PUBLIC U8 cmMemGetModuleId
5750 PUBLIC U8 cmMemGetModuleId (funNm, traceSize)
5762 Txt *memFn[]={"SGetMsg", "SGetSBuf", "SGetDBuf", NULLP};
5764 /*cm_mem_c_001.main_25 : Fix for TRACE5 feature crash due to missing TRC MACRO*/
5765 TRC3(cmMemGetModuleId)
5766 for(idx = 0; idx < traceSize; idx++)
5770 while((memReqIdx < 0) && (memFn[memStrIdx] != NULLP))
5772 memReqIdx = cmMemGetStrMtchIdx(0, traceSize, memFn[memStrIdx],
5777 while(memUsrMdlStr[mdlFunStrIdx].fPStr != NULLP)
5779 len = strlen((const S8 *)memUsrMdlStr[mdlFunStrIdx].fPStr);
5780 memReqIdx = cmMemGetStrMtchIdx((memReqIdx + 1), traceSize,
5781 memUsrMdlStr[mdlFunStrIdx].fPStr,
5785 RETVALUE(mdlFunStrIdx);
5790 while(memUsrMdlStr[mdlFunStrIdx].fPStr != NULLP)
5792 retVal = strcmp((const S8 *)"DEFAULT",
5793 (const S8 *)memUsrMdlStr[mdlFunStrIdx].fPStr);
5796 RETVALUE(mdlFunStrIdx);
5803 } /* cmMemGetModuleId */
5807 * Fun: cmMemGetStrMtchIdx
5809 * Desc: Initializes the memory leak detection module
5814 * Notes: This function initializes the memory leak detection module.
5821 PUBLIC S16 cmMemGetStrMtchIdx
5829 PUBLIC S16 cmMemGetStrMtchIdx(strtIdx, endIdx, str, strLst)
5843 TRC3(cmMemGetStrMtchIdx);
5845 len = strlen((const S8 *)str);
5847 strncpy((S8 *)&cmpStr[1], (const S8 *)str, len);
5848 cmpStr[len + 1] = '\0';
5851 for(;strtIdx < endIdx && !found; strtIdx++)
5854 tempLen = strlen((const S8 *)strLst[strtIdx]);
5858 while(*(strLst[strtIdx] + idx + len) != '\0')
5860 retVal = strncmp((const S8 *)cmpStr,
5861 ((const S8 *)strLst[strtIdx] + idx), len);
5877 } /* cmMemGetStrMtchIdx */
5878 #ifdef SS_MEM_LEAK_SOL
5881 * Fun: cmAddrToSymStr
5883 * Desc: Initializes the memory leak detection module
5888 * Notes: This function initializes the memory leak detection module.
5895 PUBLIC S32 cmAddrToSymStr
5902 PUBLIC S32 cmAddrToSymStr(pc, buffer, size)
5912 TRC3(cmAddrToSymStr);
5914 if (dladdr1(pc, &info, (Void **)&sym, RTLD_DL_SYMENT) == 0)
5916 RETVALUE(snprintf(buffer, size, "[0x%p]", pc));
5919 if ((info.dli_fname != NULLP && info.dli_sname != NULLP) &&
5920 ((uintptr_t)pc - (uintptr_t)info.dli_saddr < sym->st_size))
5922 RETVALUE(snprintf(buffer, size, "%s(%s+0x%x) [0x%p]",
5925 (unsigned long)pc - (unsigned long)info.dli_saddr, pc));
5929 RETVALUE(snprintf(buffer, size, "%s(0x%p [0x%p]",
5931 (unsigned long)pc - (unsigned long)info.dli_fbase, pc));
5934 } /* cmAddrToSymStr */
5938 * Fun: cmLeakCallBack
5940 * Desc: Initializes the memory leak detection module
5945 * Notes: This function initializes the memory leak detection module.
5952 PUBLIC S32 cmLeakCallBack
5959 PUBLIC S32 cmLeakCallBack(pc, sigNo, arg)
5966 TRC3(cmLeakCallBack);
5968 Backtrace_t *bt = (Backtrace_t *)arg;
5969 if (bt->bt_actcount >= bt->bt_maxcount)
5971 /*cm_mem_c_001.main_27 SSI-4GMX specfic changes*/
5972 #ifdef SS_4GMX_LCORE
5973 buffer = (S8 *)MxHeapAlloc(SsiHeap, 510);
5974 cmMemset((U8*)buffer, 0, 510);
5976 buffer = (S8 *)calloc(1, 510);
5978 /* SGetSBuf(DFLT_REGION, DFLT_POOL, &buffer, 510); */
5979 (void) cmAddrToSymStr((void *)pc, buffer, 505);
5980 bt->bt_buffer[bt->bt_actcount++] = (S8 *)buffer;
5983 } /* cmLeakCallBack */
5984 #endif /* SS_MEM_LEAK_SOL */
5986 #endif /* SS_MEM_LEAK_STS */
5987 /* cm_mem_c_001.main_12 - addition related to SSI enhancemens
5988 * These include sanity check functions for bucket and heap,
5989 * for printing several memory related statistics
5991 #if (defined(BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1) || defined(SSI_DEBUG_LEVEL1))
5994 * Fun: cmMmRegIsBlkSane
5996 * Desc: Performs the sanity check for the memory block by checking its header.
5998 * Ret: ROK - If no trampling is detected in the block
5999 * RFAILED - If trampling is detected in the block
6001 * Notes: This function performs the memory block sanity in a block.
6006 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
6008 PUBLIC S16 cmMmRegIsBlkSane
6014 PUBLIC S16 cmMmRegIsBlkSane(blkPtr, size)
6020 PUBLIC S16 cmMmRegIsBlkSane
6025 PUBLIC S16 cmMmRegIsBlkSane(blkPtr)
6031 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
6032 CmMmBlkTail *tailPtr;
6034 TRC2(cmMmRegIsBlkSane);
6036 for ( sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
6038 if (blkPtr->trSignature[sigCnt] != 0xAB)
6043 #ifdef BRDCM_SSI_MEM_LEAK_DEBUG_LEVEL1
6044 tailPtr = (CmMmBlkTail *)((Data *)blkPtr + (sizeof(CmMmBlkHdr) + size));
6045 for ( sigCnt=0; sigCnt < CMM_TRAMPLING_SIGNATURE_LEN; sigCnt++)
6047 if (tailPtr->trSignature[sigCnt] != 0xFE)
6056 #ifdef SSI_DEBUG_LEVEL1
6059 * Fun: cmMmBktSanityChk
6061 * Desc: Performs the sanity check for the memory blocks in a memory bucket.
6062 * This API gets called when trampling is detected in a memory block.
6064 * Ret: RTRAMPLINGNOK - Trampling, serious error
6065 * RTRAMPLINGOK - Trampling, but OK to proceed
6067 * Notes: This function performs the memory block sanity in a bucket. This
6068 * function is called by cmAlloc and cmFree as part of error handling mechanism.
6069 * Performs sanity check for the whole bucket by traversing each
6070 * of the memory blocks using the pointer bktStartPtr.
6071 * Keeps track of number of tramplings happened. If the count
6072 * exceeds the threshold decided, then invalidates this bucket.
6078 PRIVATE S16 cmMmBktSanityChk
6083 PRIVATE S16 cmMmBktSanityChk(bkt)
6090 TRC2(cmMmBktSanityChk);
6092 bkt->trampleCount = 0;
6094 /* scan the entire memory list of the bucket */
6095 for (blkCnt = 0, ptrBlk = (CmMmBlkHdr *)bkt->bktStartPtr;
6096 blkCnt < (bkt->numBlks); blkCnt++)
6098 if (cmMmRegIsBlkSane(ptrBlk) != ROK)
6100 bkt->trampleCount++;
6101 if (bkt->trampleCount > CMM_TRAMPLING_THRESHOLD)
6103 /* Take action to invalidate the entire bucket */
6104 RETVALUE(RTRAMPLINGNOK);
6107 /* reach next memory block in this bucket manually */
6108 ptrBlk = (CmMmBlkHdr *)((Data *)ptrBlk + ((bkt->size) + (sizeof(CmMmBlkHdr))));
6112 /* display an error message here */
6113 sprintf(dbgPrntBuf, " %d Memory tramplings detected in the bucket!\n", bkt->trampleCount);
6114 SDisplay(0, dbgPrntBuf);
6117 RETVALUE(RTRAMPLINGOK);
6122 * Fun: cmMmHeapSanityChk
6124 * Desc: Performs the sanity check for the memory blocks in the memory heap.
6125 * This API gets called when trampling is detected in heap(Alloc/Free).
6127 * Ret: RTRAMPLINGNOK - Trampling, serious error
6128 * RTRAMPLINGOK - Trampling, but OK to proceed
6130 * Notes: This function performs the memory block sanity in the heap. This
6131 * function is called by cmHeapAlloc and cmHeapFree as part of error
6132 * handling mechanism. Keeps track of number of tramplings happened.
6133 * If the count exceeds the threshold then return RTRAMPLINGNOK. If the
6134 * count is less than threshold, then return RTRAMPLINGOK.
6140 PRIVATE S16 cmMmHeapSanityChk
6145 PRIVATE S16 cmMmHeapSanityChk(heapCb)
6150 TRC2(cmMmHeapSanityChk);
6152 /* increment the trample count */
6153 heapCb->trampleCount++;
6155 if (heapCb->trampleCount > CMM_TRAMPLING_THRESHOLD)
6157 RETVALUE(RTRAMPLINGNOK);
6160 RETVALUE(RTRAMPLINGOK);
6166 * Desc: Computes the hash list index (bin number) for a specified
6167 * key of type (x % 101).
6169 * return (idx % hash_table_size);
6171 * Ret: ROK - successful, *idx contains computed index
6179 PRIVATE S16 cmMmHashFunc
6181 CmMmHashListCp *hashListCp,
6186 PRIVATE S16 cmMmHashFunc (hashListCp, key, idx)
6187 CmMmHashListCp *hashListCp; /* hash list control point */
6188 U32 key; /* key string */
6189 U16 *idx; /* idx to return */
6194 *idx = (U16)(key % hashListCp->numOfbins);
6198 } /* end of cmMmHashFunc () */
6202 * Fun: cmMmHashListInit
6204 * Desc: Initializes a hash list. Parameters are:
6206 * hashListCp control point for hash list
6207 * nmbBins number of bins in the hash list. Storage will
6208 * be allocated for them from the indicated memory
6211 * pool for allocating storage for bins.
6213 * Ret: ROK - initialization successful
6214 * RFAILED - initialization failed, lack of memory
6222 PRIVATE S16 cmMmHashListInit
6224 CmMmHashListCp *hashListCp, /* hash list to initialize */
6225 U16 nmbBins, /* number of hash list bins */
6226 Region region, /* memory region to allocate bins */
6227 Pool pool /* memory pool to allocate bins */
6230 PRIVATE S16 cmMmHashListInit(hashListCp, nmbBins, region, pool)
6231 CmMmHashListCp *hashListCp; /* hash list to initialize */
6232 U16 nmbBins; /* number of hash list bins */
6233 Region region; /* memory region to allocate bins */
6234 Pool pool; /* memory pool to allocate bins */
6238 CmMmHashListEnt *hl;
6240 TRC2(cmMmHashListInit);
6242 /* initialize control point fields */
6243 hashListCp->hashList = NULLP;
6244 hashListCp->numOfbins = 0;
6245 hashListCp->numOfEntries = 0;
6247 /* allocate memory for bins */
6250 if (SGetSBuf(region, pool, (Data **) &hashListCp->hashList,
6251 (Size)(nmbBins * sizeof(CmMmHashListEnt))) != ROK)
6254 /* initialize bin pointers */
6255 hl = hashListCp->hashList;
6256 for(i = 0; i < nmbBins; i++)
6258 hl[i].size = hl[i].numAttempts = 0;
6261 /* initialize bin size */
6262 hashListCp->numOfbins = nmbBins;
6270 * Fun: cmMmHashListDeinit
6272 * Desc: Deinitializes a hash list. Deallocates memory for bins
6273 * and resets header fields. Parameters are:
6275 * hashListCp control point for hash list
6277 * pool for allocating storage for bins.
6279 * Ret: ROK - successful
6280 * RFAILED - failure, invalid parameters
6288 PRIVATE S16 cmMmHashListDeinit
6290 CmMmHashListCp *hashListCp, /* hash list to deinitialize */
6291 Region region, /* memory region to allocate bins */
6292 Pool pool /* memory pool to allocate bins */
6295 PRIVATE S16 cmMmHashListDeinit(hashListCp, region, pool)
6296 CmMmHashListCp *hashListCp; /* hash list to deinitialize */
6297 Region region; /* memory region to allocate bins */
6298 Pool pool; /* memory pool to allocate bins */
6301 TRC2(cmMmHashListDeinit);
6303 /* deallocate memory for bins */
6304 if (hashListCp->numOfbins)
6305 (Void) SPutSBuf(region, pool,
6306 (Data *) hashListCp->hashList,
6307 (Size) (hashListCp->numOfbins * sizeof(CmMmHashListEnt)));
6309 /* deinitialize control point fields */
6310 hashListCp->hashList = NULLP;
6311 hashListCp->numOfbins = 0;
6312 hashListCp->numOfEntries = 0;
6315 } /* end of cmMmHashListDeinit */
6319 * Fun: cmMmHashListInsert
6321 * Desc: Inserts a new entry in the hash list. Parameters are:
6323 * hashListCp control point for hash list
6324 * key pointer to key string in the new entry
6326 * Ret: ROK - insertion successful
6327 * RFAILED - insertion failed (incorrect parameter values)
6335 PRIVATE S16 cmMmHashListInsert
6337 CmMmHashListCp *hashListCp, /* hash list to add to */
6338 U32 key /* pointer to key */
6341 PRIVATE S16 cmMmHashListInsert(hashListCp, key)
6342 CmMmHashListCp *hashListCp; /* hash list to add to */
6343 U32 key; /* pointer to key */
6346 CmMmHashListEnt *hashListEnt; /* pointer to hash list entry header */
6347 U16 idx; /* index for insertion into hash list */
6350 TRC2(cmMmHashListInsert);
6352 /* check if hashListCp is initialised yet */
6353 if ( hashListCp->numOfbins == 0)
6356 /* compute index for insertion */
6357 if (cmMmHashFunc(hashListCp, key, &idx) != ROK)
6360 hashListEnt = hashListCp->hashList;
6362 if (hashListEnt[idx].numAttempts == 0)
6364 /* new entry, insert here */
6365 hashListEnt[idx].size = key;
6366 hashListEnt[idx].numAttempts++;
6367 /* increment count of entries in hash list */
6368 hashListCp->numOfEntries++;
6372 /* this hash is occupied, re-hash it using linear probing */
6373 for (i=idx; i < CMM_STAT_HASH_TBL_LEN; i++)
6375 if (hashListEnt[i].size == key)
6377 hashListEnt[i].numAttempts++;
6381 if (hashListEnt[i].numAttempts == 0)
6383 hashListEnt[i].size = key;
6384 hashListEnt[i].numAttempts++;
6385 /* increment count of entries in hash list */
6386 hashListCp->numOfEntries++;
6391 if (i == CMM_STAT_HASH_TBL_LEN)
6393 /* there is no free slot for this key */
6399 } /* end of cmMmHashListInsert */
6401 #endif /* SSI_DEBUG_LEVEL1 */
6402 /* cm_mem_c_001.main_15 : Additions */
6403 #ifdef SS_HISTOGRAM_SUPPORT
6406 * Fun: cmHstGrmHashListInit
6408 * Desc: 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 cmHstGrmHashListInit
6422 CmHstGrmHashListCp *hashListCp /* hash list to initialize */
6425 PRIVATE S16 cmHstGrmHashListInit(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*/
6430 TRC2(cmHstGrmHashListInit)
6432 /* display an error message here */
6433 /*cm_mem_c_001.main_25: Fixed Warnings for 32/64 bit compilation*/
6435 sprintf(dbgPrntBuf, " %lu size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6437 sprintf(dbgPrntBuf, " %d size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6439 SDisplay(0, dbgPrntBuf);
6441 memset(hashListCp, 0, sizeof(CmHstGrmHashListCp));
6447 * Fun: cmHstGrmHashListDeInit
6449 * Desc: De-initializes a hash list. Parameters are:
6451 * hashListCp control point for hash list
6452 * Ret: ROK - initialization successful
6453 * RFAILED - initialization failed, lack of memory
6461 PRIVATE S16 cmHstGrmHashListDeInit
6463 CmHstGrmHashListCp *hashListCp /* hash list to initialize */
6466 PRIVATE S16 cmHstGrmHashListDeInit(hashListCp)
6467 CmHstGrmHashListCp *hashListCp; /* hash list to initialize */
6470 /*cm_mem_c_001.main_25 : Fix for TRACE5 feature crash due to missing TRC MACRO*/
6471 TRC2(cmHstGrmHashListDeInit)
6473 /* display an error message here */
6474 /*cm_mem_c_001.main_25: Fixed Warnings for 32/64 bit compilation*/
6476 sprintf(dbgPrntBuf, " %lu size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6478 sprintf(dbgPrntBuf, " %d size of memory histogram hash List\n", sizeof(CmHstGrmHashListCp));
6480 SDisplay(0, dbgPrntBuf);
6482 memset(hashListCp, 0, sizeof(CmHstGrmHashListCp));
6488 * Fun: cmHstGrmFreeInsert
6490 * Desc: Inserts a Freed information in into the hash list. Parameters are:
6492 * bkt : pointer to bucket for which memory is freed.
6493 * line : Line where memory is freed.
6494 * file : file where memory is freed.
6495 * entId : Tapa task which releases the memory.
6497 * Ret: ROK - insertion successful
6498 * RFAILED - insertion failed (incorrect parameter values)
6506 PRIVATE S16 cmHstGrmFreeInsert
6508 CmHstGrmHashListCp* hashListCp, /* hash list cp */
6509 U32 blkSz, /* size of the block freed */
6510 U32 line, /* Line number */
6511 U8 *fileName, /* file name */
6512 U8 entId /* Tapa task which free the memory */
6515 PRIVATE S16 cmHstGrmFreeInsert(hashListCp, blkSz, line, fileName, entId)
6516 CmHstGrmHashListCp* hashListCp; /* hash list cp */
6517 U32 blkSz; /* size of the block freed */
6518 U32 line; /* line number */
6519 U8 *fileName; /* file Name */
6520 U8 entId; /* Tapa task which frees the memory */
6523 U32 binIdx = 0; /* Bin index to insert the entry into the hash list */
6524 U32 key = 0; /* Key to fine the bin index */
6525 U32 ret = 0; /* Return value */
6526 CmMemEntries *entry = NULLP; /* Entry which contains the information */
6529 TRC2(cmHstGrmFreeInsert);
6531 /* check for the total number of entries in the hash list. *
6532 * If there is no place for new entry return failure */
6533 cmHstGrmGetHashIdxAndKey(fileName, line, &binIdx, &key);
6535 /* After comuting the hash bind and key, check the entity already *
6536 existing or not. if we found the entry then update the information */
6537 ret = cmHstGrmFindEntry(hashListCp, key, &binIdx, &entry);
6540 entry->freedBytes += blkSz;
6541 entry->bucketFreeReq++;
6545 /* If hash list is full then print the error tna continue */
6546 if(hashListCp->totalNumEntries == (CMM_HIST_MAX_MEM_BIN * CMM_HIST_MAX_MEM_ENTRY_PER_BIN))
6548 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");
6552 /* Take the address of next free entry in the hash bin */
6553 entry = &(hashListCp->hashList[binIdx].entries[hashListCp->hashList[binIdx].numOfEntries]);
6555 /* Increase the number of time frees called */
6556 entry->bucketFreeReq++;
6557 entry->freedBytes += blkSz;
6559 /* Fill the information into the entry structure */
6560 cmHstGrmFillEntry(entry, key, line, fileName, entId);
6561 /* Increase the total numbet of entries in the bin */
6562 hashListCp->hashList[binIdx].numOfEntries++;
6564 /* Increase the total number of entries in the hash list */
6565 hashListCp->totalNumEntries++;
6568 } /* end of cmHstGrmFreeInsert */
6573 * Fun: ret = cmHstGrmAllocInsert
6575 * Desc: Inserts a memory allocated information in the hash list. Parameters are:
6577 * hashListCp control point for hash list
6578 * key pointer to key string in the new entry
6580 * Ret: ROK - insertion successful
6581 * RFAILED - insertion failed (incorrect parameter values)
6589 PRIVATE S16 cmHstGrmAllocInsert
6591 CmHstGrmHashListCp *hashListCp,
6599 PRIVATE S16 cmHstGrmAllocInsert(hashListCp, blkSz, reqSz, line, fileName, entId)
6600 CmHstGrmHashListCp *hashListCp;
6611 CmMemEntries *entry = NULLP;
6613 TRC2(cmHstGrmAllocInsert);
6615 /* check for the total number of entries in the hash list. *
6616 * If there is no place for new entry return failure */
6617 cmHstGrmGetHashIdxAndKey(fileName, line, &binIdx, &key);
6619 /* After comuting the hash bind and key, check the entity already *
6620 existing or not. if we found the entry then update the information */
6621 ret = cmHstGrmFindEntry(hashListCp, key, &binIdx, &entry);
6625 entry->allocBytes += blkSz;
6626 entry->bucketAllocReq++;
6627 entry->wastedBytes += (blkSz - *reqSz);
6631 if(hashListCp->totalNumEntries == (CMM_HIST_MAX_MEM_BIN * CMM_HIST_MAX_MEM_ENTRY_PER_BIN))
6633 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");
6637 /* Take the address of next free entry in the hash bin */
6638 entry = &(hashListCp->hashList[binIdx].entries[hashListCp->hashList[binIdx].numOfEntries]);
6640 /* Clauculae the wasted bytes */
6641 /* Here wasted byte is differnce between the byte user
6642 * has requested and the byte the ssi allocated */
6643 entry->wastedBytes += (blkSz - *reqSz);
6644 entry->bucketAllocReq++;
6645 entry->allocBytes += blkSz;
6647 /* Fill the information into the entry structure */
6648 cmHstGrmFillEntry(entry, key, line, fileName, entId);
6649 /* Increase the total numbet of entries in the bin */
6650 hashListCp->hashList[binIdx].numOfEntries++;
6652 /* Increase the total number of entries in the hash list */
6653 hashListCp->totalNumEntries++;
6656 } /* end of cmHstGrmAllocInsert */
6661 * Fun: cmHstGrmGetHashIdxAndKey
6663 * Desc: Finds an entry in the hash list. Parameters are:
6665 * hashListCp control point for hash list
6666 * key pointer to key string in the new entry
6668 * Ret: ROK - insertion successful
6669 * RFAILED - insertion failed (incorrect parameter values)
6677 PRIVATE S16 cmHstGrmGetHashIdxAndKey
6685 PRIVATE S16 cmHstGrmGetHashIdxAndKey(fileName, line, binIdx, key)
6694 TRC2(cmHstGrmGetHashIdxAndKey);
6696 /* Calculate the key using file name and line number */
6697 for(i = 0 ; fileName[i] != '\0'; i++)
6699 *key += fileName[i];
6702 *binIdx = ( *key % CMM_HIST_MAX_MEM_BIN);
6704 } /* end of cmHstGrmFillEntry */
6708 * Fun: cmHstGrmFillEntry
6710 * Desc: Insert the entry into the hash list.
6712 * entry : Infornation which will be inserted into the hash list
6713 * key : Which will be used ti find the entry.
6714 * line : Line number
6715 * fileName : File name
6716 * entId : Tapa task Id
6718 * Ret: ROK - insertion successful
6719 * RFAILED - insertion failed (incorrect parameter values)
6727 PRIVATE S16 cmHstGrmFillEntry
6729 CmMemEntries *entry,
6736 PRIVATE S16 cmHstGrmFillEntry(entry, key, line, fileName, entId)
6737 CmMemEntries *entry;
6746 TRC2(cmHstGrmFillEntry);
6749 entry->entId = entId;
6750 for(idx = 0; fileName[idx] != '\0'; idx++)
6752 entry->fileName[idx] = fileName[idx];
6754 entry->fileName[idx] = '\0';
6756 } /* end of cmHstGrmFillEntry */
6760 * Fun: cmHstGrmFindEntry
6762 * Desc: Finds an entry in the hash list. Parameters are:
6764 * hashListCp control point for hash list
6765 * key pointer to key string in the new entry
6767 * Ret: ROK - insertion successful
6768 * RFAILED - insertion failed (incorrect parameter values)
6776 PRIVATE S16 cmHstGrmFindEntry
6778 CmHstGrmHashListCp *hashListCp,
6781 CmMemEntries **entry
6784 PRIVATE S16 cmHstGrmFindEntry(hashListCp, key, binIdx, entry)
6785 CmHstGrmHashListCp *hashListCp;
6788 CmMemEntries **entry;
6794 CmHstGrmHashListEnt *tmpBin = NULLP;
6796 TRC2(cmHstGrmFindEntry);
6799 for(numBin = 0; numBin < CMM_HIST_MAX_MEM_BIN; numBin++)
6801 /* find for the entry in the bin */
6802 tmpBin = &(hashListCp->hashList[*binIdx]);
6803 for(numEnt = 0; numEnt < tmpBin->numOfEntries; numEnt++)
6805 /* If key supplied is matched with the stored key then
6806 * return that entity */
6807 if(tmpBin->entries[numEnt].key == key)
6809 *entry = &(tmpBin->entries[numEnt]);
6811 }/* End of if (tmpBin->entries[numEnt].key) */
6812 }/* end of for (numEnt = 0) */
6814 /* Here we are checking for any room left in the bin. If the room *
6815 exists its mean that there is no entry with the Key. so return *
6817 If there is no room in the bin, then check the other bins to find *
6819 if(numEnt == CMM_HIST_MAX_MEM_ENTRY_PER_BIN)
6821 if(*binIdx == CMM_HIST_MAX_MEM_BIN)
6824 }/* End of if (binIdx) */
6828 }/* End of else (binIdx) */
6829 } /* End of if (numEnt) */
6832 printf ("Unable to find the entry in hash list\n");
6834 }/* End of else (numEnt) */
6835 }/* end of for (numBin = 0) */
6837 printf("Unable to find the entry in the hash list\n");
6839 } /* end of cmHstGrmFindEntry */
6841 #endif /* SS_HISTOGRAM_SUPPORT */
6843 /**********************************************************************
6845 **********************************************************************/