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: System Services -- general functions
25 Desc: Source code for System Services startup and general
30 *********************************************************************21*/
33 /* header include files (.h) */
37 #include "envopt.h" /* environment options */
38 #include "envdep.h" /* environment dependent */
39 #include "envind.h" /* environment independent */
41 #include "gen.h" /* general layer */
42 #include "ssi.h" /* system services */
44 #include "ss_err.h" /* errors */
45 #include "ss_dep.h" /* implementation-specific */
46 #include "ss_queue.h" /* queues */
47 #include "ss_task.h" /* tasking */
48 #include "ss_msg.h" /* messaging */
49 #include "ss_mem.h" /* memory management interface */
50 #include "ss_gen.h" /* general */
51 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
52 #ifdef SS_FBSED_TSK_REG
54 #endif /* SS_FBSED_TSK_REG */
57 /* ss001.301: additions */
58 #include "cm_mem.h" /* memory management */
60 /* header/extern include files (.x) */
62 #include "gen.x" /* general layer */
63 #include "ssi.x" /* system services */
65 #include "ss_dep.x" /* implementation-specific */
66 #include "ss_queue.x" /* queues */
67 #include "ss_task.x" /* tasking */
68 #include "ss_timer.x" /* timers */
69 #include "ss_strm.x" /* STREAMS */
70 #include "ss_msg.x" /* messaging */
71 #include "ss_mem.x" /* memory management interface */
72 #include "ss_drvr.x" /* driver tasks */
73 #ifdef SS_LOCKLESS_MEMORY
76 #include "cm_mem_wl.x" /* common memory manager */
78 #include "cm_mem.x" /* common memory manager */
79 #endif /* SS_LOCKLESS_MEMORY */
80 #include "ss_gen.x" /* general */
81 /* ss001.301: additions */
82 #ifdef SS_LOGGER_SUPPORT
84 #endif /* SS_LOGGER_SUPPORT */
85 #ifdef SS_MULTICORE_SUPPORT
89 #include "cm_mem_wl.x"
93 /* Cavium Changes:ss004.301 */
95 #include "cvmx-config.h"
97 #endif /* SS_SEUM_CAVIUM */
99 /*ss011.301 : RMIOS release related changes*/
103 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
104 #ifdef SS_FBSED_TSK_REG
106 #endif /* SS_FBSED_TSK_REG */
109 /* public variable declarations */
111 /*ss014.301: SSI-4GMX related changes*/
113 volatile SsOs osCp; /* common OS control point */
115 SsOs osCp; /* common OS control point */
120 SsRegCfg cfgRegInfo[SS_MAX_REGS];
123 /* ss029.103: modification: multiple procId related changes */
124 #ifdef SS_MULTIPLE_PROCS
125 /* static functions */
126 static S16 SInsProcId ARGS((ProcId proc));
127 static S16 SRemProcId ARGS((ProcId proc));
128 static S16 SLockOsCp ARGS((Void));
129 static S16 SULockOsCp ARGS((Void));
130 #endif /* SS_MULTIPLE_PROCS */
132 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
133 static void InitializeForStaticMemLeak ARGS((void));
134 static void InitializeStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo));
135 uint32_t GetNextFreeIdx ARGS((StaticMemAllocInfo * memAllocInfo));
136 void FreeIdx ARGS((uint8_t* ptr, uint32_t idx, StaticMemAllocInfo* memAllocInfo,uint32_t size, char*
137 file, uint32_t line));
138 void LogForStaticMemLeak ARGS((StaticMemAllocInfo* memAllocInfo, char* file,
139 uint32_t line, uint32_t size, void* ptr, uint32_t idx));
140 static void PrintStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo, FILE
143 /* ss001.301: additions */
145 void DumpSSIDemandQDebugInformation()
148 RTLIN_DUMP_DEBUG("Demand Q Information\n");
149 RTLIN_DUMP_DEBUG("====================\n");
150 for(i = 0; i < osCp.numSTsks; i++)
152 SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
154 for(j = 0; j < SS_MAX_NUM_DQ; j++)
157 RTLIN_DUMP_DEBUG("Task[%lu] Q[%lu] QSize = %lu region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
159 RTLIN_DUMP_DEBUG("Task[%u] Q[%u] QSize = %u region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
165 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
166 pthread_mutex_t dumpingLock = PTHREAD_MUTEX_INITIALIZER;
168 Void mtSigSegvHndlr()
172 printf("\nBacktrace for thread Id (%lu) total threads = %d\n", (unsigned long) pthread_self(), osCp.numSTsks);
174 for(i = 0; i < osCp.numSTsks; i++)
176 SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
177 if((tskEntry->dep.tId != pthread_self()) && (tskEntry->dep.tId != 0))
179 pthread_kill(tskEntry->dep.tId, SIGUSR2);
186 Void mtSigUsr2Hndlr()
188 printf("\nBacktrace for thread Id (%lu) cause:SIGUSR2(%d)\n",(unsigned long) pthread_self(),SIGUSR2);
190 pthread_mutex_lock(&dumpingLock);
192 pthread_mutex_unlock(&dumpingLock);
204 * Fun: System Services initialization function
206 * Desc: This is the general initialization function for
207 * all System Services implementations. It initializes
208 * all the common global data structures and calls the
209 * implementation-specific initialization and start
229 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
230 Txt prntBufLoc[1000];
231 #ifdef SS_DRVR_SUPPORT
232 SsDrvrTskEntry *drvrTsk;
234 /* ss002.301 : Modications */
236 osCp.configFilePath = "/mnt/tmp/configFile";
238 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
240 /* ss019.103 - Modified for correct initialization of OS control point */
241 /* start initializing OS control point */
242 /* ss029.103: modification: multiple procId related changes */
243 #ifndef SS_MULTIPLE_PROCS
244 /* ss004.301: Cavium changes */
245 #ifdef SS_SEUM_CAVIUM
246 osCp.procId = cvmx_get_core_num();
248 osCp.procId = SS_PROC_ID;
249 #endif /* SS_SEUM_CAVIUM */
250 #else /* SS_MULTIPLE_PROCS */
251 for (i = 0; i < SS_MAX_PROCS; i++)
252 osCp.procLst.procId[i] = PROCNC;
254 osCp.procLst.free = SS_MAX_PROCS;
255 #endif /* SS_MULTIPLE_PROCS */
257 #ifdef SS_THR_REG_MAP
258 memset(osCp.threadMemoryRegionMap, SS_INVALID_THREAD_REG_MAP,
259 (sizeof(Region) * SS_MAX_THREAD_REGION_MAP));
263 /* implementation specific general initialization */
267 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
268 sprintf(prntBufLoc,"\n SInit(): ssdInitGen failed to initialize\
269 implementation specific general information \n");
270 SDisplay(1,prntBufLoc);
274 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
275 InitializeForStaticMemLeak();
277 /* initialize memory information */
280 for (i = 0; i < SS_MAX_REGS; i++)
282 reg = &osCp.regionTbl[i];
293 /* ss007.301 initializing the per region mBufRefLock */
294 SInitLock(®->mBufRefLock, SS_LOCK_MUTEX);
296 /* zero the pool information */
298 for (j = 0; j < SS_MAX_POOLS_PER_REG; j++)
299 reg->poolTbl[j].type = SS_POOL_UND;
301 /* find this region ID in the region configuration structure */
302 for (j = 0; j < cfgNumRegs; j++)
303 if (cfgRegInfo[j].region == i)
306 /* this region is not configured */
310 /* Load the configuration information into the region table.
311 * Note, the region still has to be registered, for it to
314 for (k = 0; k < cfgRegInfo[j].numPools; k++)
316 reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
317 if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
318 reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
322 /* Initialization of dynamic regions */
323 for (i = 0; i < SS_MAX_REGS; i++)
325 reg = &osCp.dynRegionTbl[i];
336 /* ss007.301 initializing the per region mBufRefLock */
337 SInitLock(®->mBufRefLock, SS_LOCK_MUTEX);
339 /* zero the pool information */
341 for (j = 0; j < SS_MAX_POOLS_PER_REG; j++)
342 reg->poolTbl[j].type = SS_POOL_UND;
344 /* find this region ID in the region configuration structure */
345 for (j = 0; j < cfgNumRegs; j++)
346 if (cfgRegInfo[j].region == i)
349 /* this region is not configured */
353 /* Load the configuration information into the region table.
354 * Note, the region still has to be registered, for it to
357 for (k = 0; k < cfgRegInfo[j].numPools; k++)
359 reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
360 if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
361 reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
365 ret = ssInitSema(&osCp.regionTblSem, SS_MAX_STSKS);
368 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
369 sprintf(prntBufLoc,"\n SInit(): Could not initialize the region Table Semaphore \n");
370 SDisplay(1,prntBufLoc);
374 /* implementation specific memory initialization */
378 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
379 sprintf(prntBufLoc,"\n SInit(): Memory initialization failed \n");
380 SDisplay(1,prntBufLoc);
385 /* initialize TAPA and system task information */
386 /* ss029.103: modification: multiple procId related changes */
387 #ifndef SS_MULTIPLE_PROCS
388 for (i = 0; i < SS_MAX_ENT; i++)
389 for (j = 0; j < SS_MAX_INST; j++)
390 osCp.tTskIds[i][j] = SS_TSKNC;
391 #else /* SS_MULTIPLE_PROCS */
392 for (i = 0; i < SS_MAX_PROCS; i++)
393 for (j = 0; j < SS_MAX_ENT; j++)
394 for (k = 0; k < SS_MAX_INST; k++)
395 osCp.tTskIds[i][j][k] = SS_TSKNC;
396 #endif /* SS_MULTIPLE_PROCS */
398 for (i = 0; i < SS_MAX_TTSKS; i++)
400 tTsk = &osCp.tTskTbl[i];
405 tTsk->tskType = TTUND;
407 tTsk->initTsk = NULLP;
408 tTsk->actvTsk = NULLP;
410 /* ss029.103: addition: TAPA task control block added */
411 #ifdef SS_MULTIPLE_PROCS
413 #endif /* SS_MULTIPLE_PROCS */
419 osCp.nxtTTskEntry = 0;
421 ret = ssInitSema(&osCp.tTskTblSem, SS_MAX_STSKS);
424 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
425 sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
426 SDisplay(1,prntBufLoc);
430 #ifdef SS_MULTICORE_SUPPORT
431 /* check whether number of system tasks is
432 * equal to number of (regions-1).
433 * The last region is meant for timer task
434 * which under the current feature has as entry
435 * in system task table.
437 if(SS_MAX_STSKS > SS_MAX_REGS)
439 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
444 /* initialize system task information */
445 for (i = 0; i < SS_MAX_STSKS; i++)
447 sTsk = &osCp.sTskTbl[i];
450 sTsk->termPend = FALSE;
452 for (j = 0; j < SS_MAX_TTSKS; j++)
453 sTsk->tTsks[j] = SS_INVALID_IDX;
457 /* ss002.301 : Modifications */
458 #ifdef SS_MULTICORE_SUPPORT
461 sTsk->region = (SS_MAX_REGS - 1);
471 osCp.nxtSTskEntry = 0;
473 ret = SInitLock(&osCp.sTskTblLock, SS_STSKTBL_LOCK);
476 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
477 sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
478 SDisplay(1,prntBufLoc);
482 /* ss028.103 - Addition of lock for mBuf reference count */
483 /* ss007.301 moving the mBufRefLock from common to per region */
484 /* SInitLock(&osCp.mBufRefLock, SS_LOCK_MUTEX);*/
486 /* implementation specific task initialization */
490 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
491 sprintf(prntBufLoc,"\n SInit(): implementation specific task initialization Failed \n");
492 SDisplay(1,prntBufLoc);
496 #ifdef SS_DRVR_SUPPORT
497 /* initialize driver task information */
498 for (i = 0; i < SS_MAX_DRVRTSKS; i++)
500 drvrTsk = &osCp.drvrTskTbl[i];
502 drvrTsk->used = FALSE;
504 drvrTsk->channel = 0;
505 drvrTsk->actvTsk = NULLP;
506 drvrTsk->isTsk = NULLP;
511 osCp.numDrvrTsks = 0;
513 /* implementation specific driver initialization */
517 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
518 sprintf(prntBufLoc,"\n SInit(): ssdInitDrvr failed \n");
519 SDisplay(1,prntBufLoc);
524 /*ss004.301: Cavium Changes */
525 #ifdef SS_SEUM_CAVIUM
526 ret = ssInitRcvWork();
529 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
532 #endif /* SS_SEUM_CAVIUM */
535 /* initialize the demand queue lookup table */
536 osCp.dmndQLookupTbl[0] = 255;
537 osCp.dmndQLookupTbl[1] = 0;
538 osCp.dmndQLookupTbl[2] = 1;
539 osCp.dmndQLookupTbl[3] = 1;
540 for (i = 4; i < 256; i++)
542 if (i >= 128 && i <= 255)
543 osCp.dmndQLookupTbl[i] = 7;
544 if (i >= 64 && i <= 127)
545 osCp.dmndQLookupTbl[i] = 6;
546 if (i >= 32 && i <= 63)
547 osCp.dmndQLookupTbl[i] = 5;
548 if (i >= 16 && i <= 31)
549 osCp.dmndQLookupTbl[i] = 4;
550 if (i >= 8 && i <= 15)
551 osCp.dmndQLookupTbl[i] = 3;
552 if (i >= 4 && i <= 7)
553 osCp.dmndQLookupTbl[i] = 2;
557 /* initialize timer information */
558 for (i = 0; i < SS_MAX_TMRS; i++)
560 tmr = &osCp.tmrTbl[i];
564 tmr->ownerEnt = ENTNC;
565 tmr->ownerInst = INSTNC;
568 * ss015.301 - Modifed in initialization as timer activation
569 * functions enclosed in a union. Also initialized the mtFlag
572 tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
573 #ifndef SS_MULTIPLE_PROCS
575 tmr->ssTmrActvFn.mtFlag = FALSE;
576 tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
583 osCp.nxtTmrEntry = 0;
585 ret = SInitLock(&osCp.tmrTblLock, SS_TMRTBL_LOCK);
588 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
592 /* implementation specific timer initialization */
596 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
597 sprintf(prntBufLoc,"\n SInit(): Could not initialize the timer \n");
598 SDisplay(1,prntBufLoc);
602 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
603 /* ss005.201: Initialize logging streams */
604 /* implementation specific logging initialization */
608 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
609 sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logging streams \n");
610 SDisplay(1,prntBufLoc);
614 #ifdef SS_LOGGER_SUPPORT /* ss001.301: additions */
615 /* Initialize the lock, return on failure */
616 if( SInitLock(&(osCp.logger.bufLock),SS_LOCK_MUTEX) != ROK)
618 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
619 sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logger Buffer Lock \n");
620 SDisplay(1,prntBufLoc);
624 /* Initialize the logger configuration flag */
625 osCp.logger.configured = FALSE;
626 /* Ss002.301 : Initialised */
627 osCp.logger.started = FALSE;
628 #endif /* SS_LOGGER_SUPPORT */
629 /* ss001.301: additions */
631 #ifdef SS_HISTOGRAM_SUPPORT
632 /* Here we are filling all the tapa entity Ids, which will be
633 * helpful to get the entity Id using file name. */
635 #endif /* SS_HISTOGRAM_SUPPORT */
638 #ifdef SS_FBSED_TSK_REG
639 /* Configure task registration based on the configuration */
640 /*ss013.301 : Fixed warnings for 32/64 bit compilation*/
641 cmCfgrTskReg((uint8_t *)"task_info.t");
642 #endif /* SS_FBSED_TSK_REG */
644 /*ss011.301 : RMIOS release related changes*/
649 /* call tst() function */
653 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
658 /* call implementation-specific starter function */
666 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
668 #ifdef SS_LOGGER_SUPPORT
669 /* ss005.301: Deinitialize the logging at the end */
670 SDestroyLock(&(osCp.logger.bufLock));
671 /*ss013.301 : Fix for compile time warning*/
673 #endif /* SS_LOGGER_SUPPORT */
678 SDestroyLock(&osCp.tmrTblLock);
681 #ifdef SS_DRVR_SUPPORT
687 SDestroyLock(&osCp.sTskTblLock);
689 if ( (ssDestroySema(&osCp.tTskTblSem)) != ROK)
691 #if (ERRCLASS & ERRCLS_DEBUG)
692 SSLOGERROR(ERRCLS_DEBUG, ESS012, ERRZERO,
693 "Could not destroy the Semaphore");
694 /* ss005.301: Changes, clean the threads and exit */
701 /* ss007.301 destroying the per region mBufRefLock */
702 for (i= 0;i<SS_MAX_REGS;i++)
704 SDestroyLock(&osCp.regionTbl[i].mBufRefLock);
706 /* ss006.13: addition */
707 if ( (ssDestroySema(&osCp.regionTblSem)) != ROK)
709 #if (ERRCLASS & ERRCLS_DEBUG)
710 SSLOGERROR(ERRCLS_DEBUG, ESS013, ERRZERO,
711 "Could not destroy the Semaphore");
712 /* ss005.301: Changes, clean the threads and exit */
723 /* ss033.103: Added SDeInit API to free all the resources */
726 * Fun: System Services de-initialization function
728 * Desc: This is the de-initialization function for System
729 * Services implementations. It releases all the common
730 * global data structures.
746 SDestroyLock(&osCp.tmrTblLock);
748 #ifdef SS_DRVR_SUPPORT
753 SDestroyLock(&osCp.sTskTblLock);
755 if ((ssDestroySema(&osCp.tTskTblSem)) != ROK)
757 #if (ERRCLASS & ERRCLS_DEBUG)
758 SSLOGERROR(ERRCLS_DEBUG, ESS014, ERRZERO,
759 "Could not destroy the Semaphore");
767 if ((ssDestroySema(&osCp.regionTblSem)) != ROK)
769 #if (ERRCLASS & ERRCLS_DEBUG)
770 SSLOGERROR(ERRCLS_DEBUG, ESS015, ERRZERO,
771 "Could not destroy the Semaphore");
778 /* ss007.301 destroying the per region mBufRefLock */
779 for (regCnt = 0; regCnt < SS_MAX_REGS; regCnt++)
781 SDestroyLock(&osCp.regionTbl[regCnt].mBufRefLock);
784 /* ss005.301: Deinitialize the logging at the end */
785 #ifdef SS_LOGGER_SUPPORT
786 SDestroyLock(&(osCp.logger.bufLock));
787 #endif /* SS_LOGGER_SUPPORT */
792 /* ss001.301: additions */
793 #ifdef SS_LOGGER_SUPPORT
796 Txt *buf /* buffer */
800 /* buffer synchronisation*/
801 bufSz = cmStrlen((uint8_t *)buf);
802 SLock(&osCp.logger.bufLock);
803 if(osCp.logger.started == FALSE)
805 (Void)SUnlock(&(osCp.logger.bufLock));
809 * Append the buffer to the global buffer
810 * and increment the current buffer size of the global buffer
812 if(((osCp.logger.curBufSiz) + bufSz) >= osCp.logger.maxBufSiz)
814 SFlushBufToLog(osCp.logger.buffer);
815 osCp.logger.curBufSiz = 0;
816 memset(osCp.logger.buffer, '\0', osCp.logger.maxBufSiz);
817 sprintf(osCp.logger.buffer, "%s", buf);
818 osCp.logger.curBufSiz += bufSz;
822 strcat(osCp.logger.buffer,buf);
823 osCp.logger.curBufSiz += bufSz;
825 (Void)SUnlock(&(osCp.logger.bufLock));
828 #endif /* SS_LOGGER_SUPPORT */
833 * Desc: Print a string.
835 * This function should be used for debugging only.
839 * Notes: Text buffer should be null terminated.
841 * SDisplay will replace SPrint.
843 * Typical usage consists of a call to sprintf to
844 * format the string into a buffer followed by a
852 Txt *buf /* buffer */
856 /* ss001.301: additions */
858 #ifdef SS_LOGGER_SUPPORT
860 #endif /* SS_LOGGER_SUPPORT */
864 } /* end of SPrint */
871 * Desc: Invoked by layer when an unrecoverable
872 * software error is detected. This function should
884 Seq seq, /* sequence */
885 Reason reason /* reason */
893 sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
894 (int)dt.month,(int)dt.day,(int)dt.year + 1900,
895 (int)dt.hour,(int)dt.min,(int)dt.sec);
899 ret = ssdError(seq, reason);
910 * Desc: Invoked by layer to log an error.
921 Ent ent, /* Calling layer's entity id */
922 Inst inst, /* Calling layer's instance id */
923 ProcId procId, /* Calling layer's processor id */
924 Txt *file, /* file name where error occured */
925 S32 line, /* line in file where error occured */
926 ErrCls errCls, /* error class */
927 ErrCode errCode, /* layer unique error code */
928 ErrVal errVal, /* error value */
929 Txt *errDesc /* description of error */
936 /*ss014.301: SSI-4GMX related changes*/
937 #ifndef SS_4GMX_LCORE
939 sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
940 (int)dt.month,(int)dt.day,(int)dt.year + 1900,
941 (int)dt.hour,(int)dt.min,(int)dt.sec);
945 /* ss001.301: additions */
946 #ifdef SS_LOGGER_SUPPORT
948 #endif /* SS_LOGGER_SUPPORT */
950 ssdLogError(ent, inst, procId, file, line,
951 errCls, errCode, errVal, errDesc);
957 /* ss029.103: modification:
958 SFndProcId function is not supported with multiple procIds */
959 #ifndef SS_MULTIPLE_PROCS
965 * Desc: This function finds the local processor ID.
967 * Ret: local processor id
974 ProcId SFndProcId(void)
977 return (osCp.procId);
978 } /* end of SFndProcId */
985 * Desc: This function stores the local processor ID.
994 Void SSetProcId(ProcId procId)
997 osCp.procId = procId;
1002 #endif /* SS_MULTIPLE_PROCS */
1004 /* ss029.103: addition: New SSI functions with multiple proc support */
1005 #ifdef SS_MULTIPLE_PROCS
1009 * Fun: SGetProcIdIdx
1011 * Desc: This function finds index of procId in the process id table
1020 uint16_t SGetProcIdIdx(ProcId proc)
1025 idx = SS_HASH_IDX(proc);
1027 for (i = idx; i < SS_MAX_PROCS; i++)
1028 if (osCp.procLst.procId[i] == proc)
1031 /* search upto idx */
1032 for (i = 0; i < idx; i++)
1033 if (osCp.procLst.procId[i] == proc)
1036 return (SS_INV_PROCID_IDX);
1037 } /* SGetProcIdIdx */
1044 * Desc: This function inserts procId in the process id table
1053 static S16 SInsProcId(ProcId proc)
1059 idx = SS_HASH_IDX(proc);
1061 for (i = idx; i < SS_MAX_PROCS; i++)
1062 if (osCp.procLst.procId[i] == SS_INV_PROCID)
1064 osCp.procLst.procId[i] = proc;
1065 osCp.procLst.free--;
1069 /* search for free entry upto idx */
1070 for (i = 0; i < idx; i++)
1071 if (osCp.procLst.procId[i] == SS_INV_PROCID)
1073 osCp.procLst.procId[i] = proc;
1074 osCp.procLst.free--;
1086 * Desc: This function inserts procId in the process id table
1095 static S16 SRemProcId(ProcId proc)
1101 idx = SS_HASH_IDX(proc);
1103 for (i = idx; i < SS_MAX_PROCS; i++)
1104 if (osCp.procLst.procId[i] == proc)
1106 osCp.procLst.procId[i] = SS_INV_PROCID;
1107 osCp.procLst.free++;
1111 /* search upto idx */
1112 for (i = 0; i < idx; i++)
1113 if (osCp.procLst.procId[i] == proc)
1115 osCp.procLst.procId[i] = SS_INV_PROCID;
1116 osCp.procLst.free++;
1128 * Desc: This function locks OsCp
1137 static S16 SLockOsCp(void)
1142 ret = SLock(&osCp.sTskTblLock);
1145 SSLOGERROR(ERRCLS_DEBUG, ESS016, ERRZERO,
1146 "Could not lock system task table");
1150 SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
1154 #if (ERRCLASS & ERRCLS_DEBUG)
1155 SSLOGERROR(ERRCLS_DEBUG, ESS017, ERRZERO,
1156 "Could not lock TAPA task table");
1159 if ( SUnlock(&osCp.sTskTblLock) != ROK)
1161 #if (ERRCLASS & ERRCLS_DEBUG)
1162 SSLOGERROR(ERRCLS_DEBUG, ESS018, ERRZERO,
1163 "Could not give the Semaphore");
1180 * Desc: This function locks OsCp
1189 static S16 SULockOsCp(Void)
1192 /* unlock the table */
1193 SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1195 if ( SUnlock(&osCp.sTskTblLock) != ROK)
1197 #if (ERRCLASS & ERRCLS_DEBUG)
1198 SSLOGERROR(ERRCLS_DEBUG, ESS019, ERRZERO,
1199 "Could not give the Semaphore");
1212 * Fun: SAddProcIdLst
1214 * Desc: This function adds given proc ids to the list
1223 S16 SAddProcIdLst(uint16_t numPIds,ProcId *pIdLst)
1229 #if (ERRCLASS & ERRCLS_INT_PAR)
1231 if (numPIds > SS_MAX_PROCS)
1233 SSLOGERROR(ERRCLS_INT_PAR, ESS020, ERRZERO, "number of proc Ids exceeds\
1238 /* find if the entry exist in the table */
1239 for (i = 0; i < numPIds; i++)
1241 if (pIdLst[i] == SS_INV_PROCID)
1243 SSLOGERROR(ERRCLS_INT_PAR, ESS021, ERRZERO, "Invalid proc Ids");
1250 if (SLockOsCp() != ROK)
1253 #if (ERRCLASS & ERRCLS_INT_PAR)
1254 for (i = 0; i < numPIds; i++)
1255 if (SGetProcIdIdx(pIdLst[i]) != SS_INV_PROCID_IDX)
1257 SSLOGERROR(ERRCLS_INT_PAR, ESS022, ERRZERO, "Duplicate proc id");
1258 (Void) SULockOsCp();
1262 if (numPIds > osCp.procLst.free)
1264 SSLOGERROR(ERRCLS_INT_PAR, ESS023, ERRZERO, "Total number of proc id \
1266 (Void) SULockOsCp();
1271 /* insert the entries in the table */
1274 for (i = 0; i < numPIds; i++)
1276 if (SInsProcId(pIdLst[i]) == RFAILED)
1278 #if (ERRCLASS & ERRCLS_DEBUG)
1279 SSLOGERROR(ERRCLS_DEBUG, ESS024, ERRZERO,
1280 "Could not insert the proc id");
1282 (Void) SULockOsCp();
1287 /* unlock the table */
1288 if (SULockOsCp() != ROK)
1292 } /* SAddProcIdLst */
1297 * Fun: SRemProcIdLst
1299 * Desc: This function adds given proc ids to the list
1308 S16 SRemProcIdLst(uint16_t numPIds,ProcId *pIdLst)
1313 #if (ERRCLASS & ERRCLS_INT_PAR)
1315 if (numPIds > SS_MAX_PROCS)
1319 if (SLockOsCp() != ROK)
1322 if (numPIds > (SS_MAX_PROCS - osCp.procLst.free))
1324 (Void) SULockOsCp();
1328 /* find if the entry exist in the table */
1329 for (i = 0; i < numPIds; i++)
1331 if (SGetProcIdIdx(pIdLst[i]) == SS_INV_PROCID_IDX)
1333 (Void) SULockOsCp();
1338 /* insert the entries in the table */
1339 for (i = 0; i < numPIds; i++)
1340 SRemProcId(pIdLst[i]);
1342 if (SULockOsCp() != ROK)
1346 } /* SRemProcIdLst */
1351 * Fun: SGetProcIdLst
1353 * Desc: This function retrieves proc Id list
1362 S16 SGetProcIdLst(uint16_t *numPIds,ProcId *pIdLst)
1368 #if (ERRCLASS & ERRCLS_INT_PAR)
1369 if ((numPIds == NULLP) || (pIdLst == NULLP))
1371 SSLOGERROR(ERRCLS_INT_PAR, ESS025, ERRZERO, "Invalid numPIds/pIdLst");
1376 if (SLockOsCp() != ROK)
1379 for (i = 0; i < SS_MAX_PROCS; i++)
1381 if (osCp.procLst.procId[i] != PROCNC)
1382 pIdLst[count++] = osCp.procLst.procId[i];
1387 if (SULockOsCp() != ROK)
1394 } /* SGetProcIdLst */
1401 * Desc: This function retrieves protocol layer control block for given proc,
1423 #if (ERRCLASS & ERRCLS_INT_PAR)
1424 if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) || (inst >= SS_MAX_INST))
1426 SSLOGERROR(ERRCLS_INT_PAR, ESS026, ERRZERO, "Invalid proc/entity/instance");
1432 * ss030.103: delete: locking/unlocking removed as it causes
1433 * deadlock/blockage in some cases
1436 procIdIdx = SGetProcIdIdx(proc);
1438 if (procIdIdx == SS_INV_PROCID_IDX)
1440 #if (ERRCLASS & ERRCLS_INT_PAR)
1441 SSLOGERROR(ERRCLS_INT_PAR, ESS027, ERRZERO, "Could not get proc table idx");
1446 idx = osCp.tTskIds[procIdIdx][ent][inst];
1447 if (idx == SS_TSKNC)
1453 *xxCb = osCp.tTskTbl[idx].xxCb;
1454 /*ss032.103 added a check for NULLP */
1461 #endif /* SS_MULTIPLE_PROCS */
1463 /* ss001.301: additions */
1464 #ifdef SS_HISTOGRAM_SUPPORT
1469 * Desc: It is static data base contains all entity Ids of tapa task.
1470 * This Data base is used to find the entity id using two letter
1471 * prifix product code.
1480 S16 SFillEntIds(Void)
1483 uint8_t entInfo[26][26] = {
1484 /* A B C D E F G H I J K *
1485 L M N O P Q R S T U V *
1487 {ENTAA, ENTAB, ENTAC, ENTNC, ENTAE, ENTAF, ENTNC, ENTAH, ENTNC, ENTNC, ENTNC,
1488 /* A */ ENTAL, ENTAM, ENTNC, ENTNC, ENTAP, ENTAQ, ENTAR, ENTAS, ENTNC, ENTAU, ENTNC,
1489 ENTAW, ENTNC, ENTNC, ENTNC},
1491 /* A B C D E F G H I J K *
1492 L M N O P Q R S T U V *
1494 {ENTNC, ENTNC, ENTNC, ENTBD, ENTNC, ENTNC, ENTNC, ENTNC, ENTBI, ENTNC, ENTNC,
1495 /* B */ ENTNC, ENTBM, ENTNC, ENTNC, ENTNC, ENTNC, ENTBR, ENTBS, ENTNC, ENTNC, ENTBV,
1496 ENTBW, ENTNC, ENTNC, ENTNC},
1497 /* A B C D E F G H I J K *
1498 L M N O P Q R S T U V *
1500 {ENTNC, ENTNC, ENTCC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCH, ENTNC, ENTNC, ENTNC,
1501 /* C */ ENTCL, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCS, ENTNC, ENTCU, ENTCV,
1502 ENTNC, ENTNC, ENTNC, ENTNC},
1503 /* A B C D E F G H I J K *
1504 L M N O P Q R S T U V *
1506 {ENTNC, ENTDB, ENTNC, ENTNC, ENTNC, ENTNC, ENTDG, ENTNC, ENTDI, ENTNC, ENTDK,
1507 /* D */ ENTNC, ENTDM, ENTDN, ENTNC, ENTDP, ENTNC, ENTNC, ENTNC, ENTDT, ENTDU, ENTDV,
1508 ENTNC, ENTNC, ENTNC, ENTNC},
1509 /* A B C D E F G H I J K *
1510 L M N O P Q R S T U V *
1512 {ENTNC, ENTNC, ENTNC, ENTNC, ENTEC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1513 /* E */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTER, ENTES, ENTNC, ENTNC, ENTEV,
1514 ENTNC, ENTNC, ENTNC, ENTNC},
1515 /* A B C D E F G H I J K *
1516 L M N O P Q R S T U V *
1518 {ENTFA, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1519 /* F */ ENTNC, ENTFM, ENTFN, ENTNC, ENTFP, ENTNC, ENTFR, ENTNC, ENTNC, ENTFU, ENTNC,
1520 ENTFW, ENTNC, ENTNC, ENTNC},
1521 /* A B C D E F G H I J K *
1522 L M N O P Q R S T U V *
1524 {ENTGA, ENTGB, ENTGC, ENTGD, ENTGE, ENTGF, ENTGG, ENTGH, ENTGI, ENTNC, ENTNC,
1525 /* G */ ENTGL, ENTGM, ENTGN, ENTGO, ENTGP, ENTNC, ENTGR, ENTGS, ENTGT, ENTGU, ENTNC,
1526 ENTGW, ENTGX, ENTGY, ENTGZ},
1527 /* A B C D E F G H I J K *
1528 L M N O P Q R S T U V *
1530 {ENTNC, ENTNC, ENTHC, ENTNC, ENTHE, ENTNC, ENTHG, ENTNC, ENTHI, ENTNC, ENTNC,
1531 /* H */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTHR, ENTHS, ENTNC, ENTHU, ENTNC,
1532 ENTNC, ENTNC, ENTNC, ENTNC},
1533 /* A B C D E F G H I J K *
1534 L M N O P Q R S T U V *
1536 {ENTIA, ENTIB, ENTNC, ENTID, ENTIE, ENTNC, ENTNC, ENTNC, ENTII, ENTNC, ENTNC,
1537 /* I */ ENTNC, ENTIM, ENTIN, ENTNC, ENTNC, ENTIQ, ENTNC, ENTIS, ENTIT, ENTIU, ENTNC,
1538 ENTIW, ENTIX, ENTNC, ENTNC},
1539 /* A B C D E F G H I J K *
1540 L M N O P Q R S T U V *
1542 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1543 /* J */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1544 ENTNC, ENTNC, ENTNC, ENTNC},
1545 /* A B C D E F G H I J K *
1546 L M N O P Q R S T U V *
1548 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1549 /* K */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1550 ENTRLC, ENTNC, ENTNC, ENTNC},
1551 /* A B C D E F G H I J K *
1552 L M N O P Q R S T U V *
1554 {ENTLA, ENTLB, ENTLC, ENTLD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTLK,
1555 /* L */ ENTNC, ENTLM, ENTLN, ENTNC, ENTNC, ENTNC, ENTLR, ENTNC, ENTLT, ENTLU, ENTLV,
1556 ENTNC, ENTLX, ENTNC, ENTNC},
1557 /* A B C D E F G H I J K *
1558 L M N O P Q R S T U V *
1560 {ENTMA, ENTNC, ENTMC, ENTMD, ENTME, ENTNC, ENTMG, ENTNC, ENTNC, ENTNC, ENTMK,
1561 /* M */ ENTML, ENTMM, ENTNC, ENTNC, ENTNC, ENTNC, ENTMR, ENTMS, ENTMT, ENTMU, ENTMV,
1562 ENTMW, ENTMX, ENTNC, ENTMZ},
1563 /* A B C D E F G H I J K *
1564 L M N O P Q R S T U V *
1566 {ENTNC, ENTNC, ENTNC, ENTND, ENTNC, ENTNF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1567 /* N */ ENTNC, ENTNM, ENTNC, ENTNC, ENTNP, ENTNC, ENTNC, ENTNS, ENTNC, ENTNC, ENTNV,
1568 ENTNW, ENTNC, ENTNC, ENTNC},
1569 /* A B C D E F G H I J K *
1570 L M N O P Q R S T U V *
1572 {ENTNC, ENTNC, ENTNC, ENTOD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1573 /* O */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1574 ENTNC, ENTNC, ENTNC, ENTNC},
1575 /* A B C D E F G H I J K *
1576 L M N O P Q R S T U V *
1578 {ENTPA, ENTNC, ENTNC, ENTPD, ENTNC, ENTNC, ENTNC, ENTPH, ENTNC, ENTNC, ENTNC,
1579 /* P */ ENTPL, ENTNC, ENTPN, ENTNC, ENTPN, ENTPQ, ENTPR, ENTNC, ENTNC, ENTPU, ENTPV,
1580 ENTNC, ENTNC, ENTNC, ENTNC},
1581 /* A B C D E F G H I J K *
1582 L M N O P Q R S T U V *
1584 {ENTNC, ENTNC, ENTQC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTQI, ENTNC, ENTNC,
1585 /* Q */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1586 ENTQW, ENTNC, ENTNC, ENTNC},
1587 /* A B C D E F G H I J K *
1588 L M N O P Q R S T U V *
1590 {ENTRA, ENTNC, ENTNC, ENTRD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1591 /* R */ ENTRL, ENTRM, ENTRN, ENTNC, ENTRP, ENTNC, ENTRR, ENTNC, ENTRT, ENTRU, ENTNC,
1592 ENTNC, ENTRX, ENTRY, ENTNC},
1593 /* A B C D E F G H I J K *
1594 L M N O P Q R S T U V *
1596 {ENTSA, ENTSB, ENTSC, ENTSD, ENTSE, ENTSF, ENTSG, ENTSH, ENTSI, ENTNC, ENTNC,
1597 /* S */ ENTNC, ENTSM, ENTSN, ENTSO, ENTSP, ENTNC, ENTSR, ENTSS, ENTST, ENTSU, ENTSV,
1598 ENTNC, ENTNC, ENTNC, ENTSZ},
1599 /* A B C D E F G H I J K *
1600 L M N O P Q R S T U V *
1602 {ENTNC, ENTNC, ENTTC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1603 /* T */ ENTNC, ENTTM, ENTNC, ENTNC, ENTTP, ENTNC, ENTNC, ENTTS, ENTTT, ENTTU, ENTNC,
1604 ENTNC, ENTNC, ENTNC, ENTNC},
1605 /* A B C D E F G H I J K *
1606 L M N O P Q R S T U V *
1608 {ENTNC, ENTNC, ENTNC, ENTUD, ENTNC, ENTNC, ENTNC, ENTUH, ENTNC, ENTNC, ENTNC,
1609 /* U */ ENTUL, ENTUM, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTUS, ENTNC, ENTNC, ENTNC,
1610 ENTNC, ENTNC, ENTNC, ENTUZ},
1611 /* A B C D E F G H I J K *
1612 L M N O P Q R S T U V *
1614 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1615 /* V */ ENTNC, ENTVM, ENTNC, ENTVO, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVU, ENTNC,
1616 ENTNC, ENTNC, ENTNC, ENTNC},
1617 /* A B C D E F G H I J K *
1618 L M N O P Q R S T U V *
1620 {ENTNC, ENTNC, ENTWC, ENTWD, ENTNC, ENTNC, ENTNC, ENTNC, ENTWI, ENTNC, ENTNC,
1621 /* W */ ENTNC, ENTNC, ENTWN, ENTNC, ENTNC, ENTNC, ENTNC, ENTWS, ENTNC, ENTWU, ENTNC,
1622 ENTNC, ENTNC, ENTNC, ENTNC},
1623 /* A B C D E F G H I J K *
1624 L M N O P Q R S T U V *
1626 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXG, ENTNC, ENTXI, ENTNC, ENTNC,
1627 /* X */ ENTNC, ENTXM, ENTXN, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXU, ENTNC,
1628 ENTNC, ENTXX, ENTXY, ENTNC},
1629 /* A B C D E F G H I J K *
1630 L M N O P Q R S T U V *
1632 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1633 /* Y */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1634 ENTNC, ENTNC, ENTNC, ENTNC},
1635 /* A B C D E F G H I J K *
1636 L M N O P Q R S T U V *
1638 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1639 /* Z */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1640 ENTNC, ENTNC, ENTNC, ENTNC}
1643 /*ss013.301 :Adding TRC MACRO*/
1644 memcpy(osCp.entId, entInfo, sizeof(entInfo));
1654 * Desc: This function gives the entity Id depending in the
1655 * file name. This function uses the first two letter
1656 * of file name to find the entity id.
1661 * RFAILED Region not registered
1665 S16 SGetEntInd(Ent *entId,uint8_t *fileName)
1669 uint8_t *letter = NULLP;
1670 /* ss002.301 Additions */
1671 S8 *strippedName = NULLP;
1673 uint8_t tempIdx = 0;
1674 uint8_t firstIdx = 0;
1675 uint8_t secondIdx = 0;
1678 /* ss002.301 Additions */
1679 if ((strippedName = strrchr((const char *)fileName, '/')))
1681 fileName = (uint8_t *)strippedName + 1;
1684 if(fileName[0] =='l' && fileName[3] == '.')
1686 /* Usally layer manager interface files starts
1687 * with l. so leave the first letter and take
1689 * Eg. Layer manger inteface file name for TUCL is lhi.c.
1690 * so here we leave l and we take hi to get the entity Id. */
1691 letter = ++fileName;
1696 /* Handle exceptional file names */
1700 if (letter[1] == 'g' && letter[2] == 'u')
1712 /* here first two charactes of file name should be alphabets.
1713 * if any one of the letter is non alphabet then we return ENTNC
1714 * as an entity Id */
1715 /* Eg. In fileName l4_ptui.c, second letter is numeral. so we consider
1716 * this file belogs to entity Id ENTNC. */
1717 for(count = 0; count < 2; count++)
1719 /* ss002.301 - Optimizations */
1720 if(letter[count] < 'a' || letter[count] > 'z')
1727 tempIdx = letter[count] - 'a';
1735 secondIdx = tempIdx;
1738 /* First two letter of file name are alphabets the get the
1739 * entity id from the static data base which is loaded in sFillEntIds() */
1740 *entId = osCp.entId[firstIdx][secondIdx];
1744 #endif /* SS_HISTOGRAM_SUPPORT */
1745 #ifdef SS_LOCK_SUPPORT
1746 /* ss002.301 Readwrite lock additions */
1751 * Desc: This function is used to aquire the read write lock
1760 S16 SLockNew(SLockInfo *lockId,uint8_t lockType)
1765 if((retVal = ssdLockNew(lockId, lockType)) != ROK)
1767 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SLockNew(): Failed to aquire the lock\n");
1777 * Desc: This function is used to aquire the read write lock
1786 S16 SInitLockNew(SLockInfo *lockId,uint8_t lockType)
1791 if((retVal = ssdInitLockNew(lockId, lockType)) != ROK)
1793 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SInitLockNew(): Initialization of lock Failed\n");
1803 * Desc: This function is used to Unlock the read write lock
1812 S16 SUnlockNew(SLockInfo *lockId,uint8_t lockType)
1817 if((retVal = ssdUnlockNew(lockId, lockType)) != ROK)
1819 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SUnlockNew(): Failed to release the lock\n");
1827 * Fun: SDestroyLockNew
1829 * Desc: This function is used to destroy the read write lock
1838 S16 SDestroyLockNew(SLockInfo *lockId,uint8_t lockType)
1843 if((retVal = ssdDestroyLockNew(lockId, lockType)) != ROK)
1845 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SDestroyLockNew(): Failed to destroy the lock\n");
1850 #endif /* SS_LOCK_SUPPORT */
1852 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1853 /* Static memory leak detection changes */
1854 static uint32_t StaticMemLeakAge;
1855 static uint32_t StaticMemLeakIntCount = 1;
1857 void PrintStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo, FILE *opFile)
1861 fprintf(opFile, "Current Time = %ld\n",StaticMemLeakAge);
1863 for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
1865 if(memAllocInfo->allocations[i].ptr)
1867 fprintf(opFile, "p = %p f = %s l = %ld s = %ld a = %ld\n",
1868 memAllocInfo->allocations[i].ptr,
1869 memAllocInfo->allocations[i].file,
1870 memAllocInfo->allocations[i].lineNo,
1871 memAllocInfo->allocations[i].size,
1872 memAllocInfo->allocations[i].age);
1879 void InitializeStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo)
1882 /* index 0 is not used; nextIdx as 0 means end of list */
1883 memAllocInfo->nextFreeIdx = 1;
1885 for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
1887 memAllocInfo->allocations[i].listInfo.nextIdx = i + 1;
1888 memAllocInfo->allocations[i].ptr = 0;
1891 /* override the last one to point to 0 meaning end of list */
1892 memAllocInfo->allocations[MAX_MEM_ALLOCATIONS - 1].listInfo.nextIdx = 0;
1895 uint32_t GetNextFreeIdx(StaticMemAllocInfo * memAllocInfo)
1897 uint32_t toBeReturned = memAllocInfo->nextFreeIdx;
1899 uint32_t newNextFreeIdx = memAllocInfo->allocations[memAllocInfo->nextFreeIdx].listInfo.nextIdx;
1901 if(newNextFreeIdx == 0 || newNextFreeIdx >= MAX_MEM_ALLOCATIONS)
1903 printf("\nSomething wrong in GetNextFreeIdx newNextIdx = %ld\n",newNextFreeIdx);
1906 memAllocInfo->nextFreeIdx = newNextFreeIdx;
1908 return toBeReturned;
1911 #define CRASH_ENB {int *p = 0; *p = 100;}
1912 void FreeIdx(uint8_t* ptr, uint32_t idx, StaticMemAllocInfo* memAllocInfo,uint32_t size, char* file, uint32_t line)
1914 if(idx == 0 || idx >= MAX_MEM_ALLOCATIONS)
1916 printf("Something wrong in FreeIdx... idx = %ld called from %s:%ld\n",idx,file,line);
1919 /*printf("FreeIdx... idx = %d nexFree = %d\n",idx, memAllocInfo->nextFreeIdx);*/
1920 memAllocInfo->allocations[idx].listInfo.nextIdx = memAllocInfo->nextFreeIdx;
1921 if((ptr != memAllocInfo->allocations[idx].ptr) ||
1922 (size != memAllocInfo->allocations[idx].size))
1924 #ifdef XEON_SPECIFIC_CHANGES
1928 printf("\nFreeing wrong ptr stored = %p trying to free %p freeing size (%ld)"
1929 "allocated size(%ld) from %s:%ld\n",
1930 memAllocInfo->allocations[idx].ptr,
1933 memAllocInfo->allocations[idx].size,
1936 printf("\nAllocation was done from %s:%ld\n",memAllocInfo->allocations[idx].file, memAllocInfo->allocations[idx].lineNo);
1937 printf("\n***********************************************************\n");
1941 memAllocInfo->allocations[idx].ptr = 0;
1943 memAllocInfo->nextFreeIdx = idx;
1947 void LogForStaticMemLeak(StaticMemAllocInfo* memAllocInfo, char* file, uint32_t line, uint32_t size, void* ptr, uint32_t idx)
1950 memAllocInfo->allocations[idx].file = file;
1951 memAllocInfo->allocations[idx].lineNo = line;
1952 memAllocInfo->allocations[idx].size = size;
1953 memAllocInfo->allocations[idx].ptr = ptr;
1954 memAllocInfo->allocations[idx].age = StaticMemLeakAge;
1956 if(StaticMemLeakIntCount++ % 256 == 0)
1962 void InitializeForStaticMemLeak()
1966 StaticMemLeakFileArr[0] = fopen("region0.log","w");
1967 StaticMemLeakFileArr[1] = fopen("region1.log","w");
1968 StaticMemLeakFileArr[2] = fopen("region2.log","w");
1969 StaticMemLeakFileArr[3] = fopen("region3.log","w");
1971 if(StaticMemLeakFileArr[0] == NULL ||
1972 StaticMemLeakFileArr[1] == NULL ||
1973 StaticMemLeakFileArr[2] == NULL ||
1974 StaticMemLeakFileArr[3] == NULL)
1977 printf("\nCould not open files for Static Mem Leak detection logging :( crashing...\n");
1981 for(i = 0; i < 4; i++)
1983 InitializeStaticMemAllocInfo(&SMemLeakInfo[i]);
1987 void DumpStaticMemLeakFiles()
1991 for(i = 0; i < 4; i++)
1993 PrintStaticMemAllocInfo(&SMemLeakInfo[i], StaticMemLeakFileArr[i]);
1996 /* Static memory leak detection changes */
2001 * Fun: ssRegMainThread
2003 * Desc: This function is used to add the memory region
2004 * mapping for the main thread.
2006 * Ret: VOID (Always successful)
2013 S16 SReInitTmr(void)
2016 Txt prntBuf[PRNTSZE];
2018 sprintf(prntBuf, "\n SReInitTmr(): ReStarting the Tmr\n");
2019 SDisplay(1,prntBuf);
2020 ret = ssdReInitTmr();
2023 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
2024 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SReInitTmr(): Failed to Restart the Tmr\n");
2032 * Fun: SGetConfigPath
2034 * Desc: This function is used to Get config files path
2036 * Ret: S8* config file Path
2043 S8* SGetConfigPath(Void)
2045 return osCp.configFilePath;
2048 /**********************************************************************
2050 **********************************************************************/