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 */
124 extern Cntr cfgNumRegs;
125 extern SsRegCfg cfgRegInfo[SS_MAX_REGS];
128 /* ss029.103: modification: multiple procId related changes */
129 #ifdef SS_MULTIPLE_PROCS
130 /* static functions */
131 static S16 SInsProcId ARGS((ProcId proc));
132 static S16 SRemProcId ARGS((ProcId proc));
133 static S16 SLockOsCp ARGS((Void));
134 static S16 SULockOsCp ARGS((Void));
135 #endif /* SS_MULTIPLE_PROCS */
137 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
138 static void InitializeForStaticMemLeak ARGS((void));
139 static void InitializeStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo));
140 uint32_t GetNextFreeIdx ARGS((StaticMemAllocInfo * memAllocInfo));
141 void FreeIdx ARGS((uint8_t* ptr, uint32_t idx, StaticMemAllocInfo* memAllocInfo,uint32_t size, char*
142 file, uint32_t line));
143 void LogForStaticMemLeak ARGS((StaticMemAllocInfo* memAllocInfo, char* file,
144 uint32_t line, uint32_t size, void* ptr, uint32_t idx));
145 static void PrintStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo, FILE
148 /* ss001.301: additions */
150 void DumpSSIDemandQDebugInformation()
153 RTLIN_DUMP_DEBUG("Demand Q Information\n");
154 RTLIN_DUMP_DEBUG("====================\n");
155 for(i = 0; i < osCp.numSTsks; i++)
157 SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
159 for(j = 0; j < SS_MAX_NUM_DQ; j++)
162 RTLIN_DUMP_DEBUG("Task[%lu] Q[%lu] QSize = %lu region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
164 RTLIN_DUMP_DEBUG("Task[%u] Q[%u] QSize = %u region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
170 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
171 pthread_mutex_t dumpingLock = PTHREAD_MUTEX_INITIALIZER;
173 Void mtSigSegvHndlr()
177 printf("\nBacktrace for thread Id (%lu) total threads = %d\n", (unsigned long) pthread_self(), osCp.numSTsks);
179 for(i = 0; i < osCp.numSTsks; i++)
181 SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
182 if((tskEntry->dep.tId != pthread_self()) && (tskEntry->dep.tId != 0))
184 pthread_kill(tskEntry->dep.tId, SIGUSR2);
191 Void mtSigUsr2Hndlr()
193 printf("\nBacktrace for thread Id (%lu) cause:SIGUSR2(%d)\n",(unsigned long) pthread_self(),SIGUSR2);
195 pthread_mutex_lock(&dumpingLock);
197 pthread_mutex_unlock(&dumpingLock);
209 * Fun: System Services initialization function
211 * Desc: This is the general initialization function for
212 * all System Services implementations. It initializes
213 * all the common global data structures and calls the
214 * implementation-specific initialization and start
234 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
235 Txt prntBufLoc[1000];
236 #ifdef SS_DRVR_SUPPORT
237 SsDrvrTskEntry *drvrTsk;
239 /* ss002.301 : Modications */
241 osCp.configFilePath = "/mnt/tmp/configFile";
243 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
245 /* ss019.103 - Modified for correct initialization of OS control point */
246 /* start initializing OS control point */
247 /* ss029.103: modification: multiple procId related changes */
248 #ifndef SS_MULTIPLE_PROCS
249 /* ss004.301: Cavium changes */
250 #ifdef SS_SEUM_CAVIUM
251 osCp.procId = cvmx_get_core_num();
253 osCp.procId = SS_PROC_ID;
254 #endif /* SS_SEUM_CAVIUM */
255 #else /* SS_MULTIPLE_PROCS */
256 for (i = 0; i < SS_MAX_PROCS; i++)
257 osCp.procLst.procId[i] = PROCNC;
259 osCp.procLst.free = SS_MAX_PROCS;
260 #endif /* SS_MULTIPLE_PROCS */
262 #ifdef SS_THR_REG_MAP
263 memset(osCp.threadMemoryRegionMap, SS_INVALID_THREAD_REG_MAP,
264 (sizeof(Region) * SS_MAX_THREAD_REGION_MAP));
268 /* implementation specific general initialization */
272 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
273 sprintf(prntBufLoc,"\n SInit(): ssdInitGen failed to initialize\
274 implementation specific general information \n");
275 SDisplay(1,prntBufLoc);
279 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
280 InitializeForStaticMemLeak();
282 /* initialize memory information */
285 for (i = 0; i < SS_MAX_REGS; i++)
287 reg = &osCp.regionTbl[i];
298 /* ss007.301 initializing the per region mBufRefLock */
299 SInitLock(®->mBufRefLock, SS_LOCK_MUTEX);
301 /* zero the pool information */
303 for (j = 0; j < SS_MAX_POOLS_PER_REG; j++)
304 reg->poolTbl[j].type = SS_POOL_UND;
306 /* find this region ID in the region configuration structure */
307 for (j = 0; j < cfgNumRegs; j++)
308 if (cfgRegInfo[j].region == i)
311 /* this region is not configured */
315 /* Load the configuration information into the region table.
316 * Note, the region still has to be registered, for it to
319 for (k = 0; k < cfgRegInfo[j].numPools; k++)
321 reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
322 if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
323 reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
327 /* Initialization of dynamic regions */
328 for (i = 0; i < SS_MAX_REGS; i++)
330 reg = &osCp.dynRegionTbl[i];
341 /* ss007.301 initializing the per region mBufRefLock */
342 SInitLock(®->mBufRefLock, SS_LOCK_MUTEX);
344 /* zero the pool information */
346 for (j = 0; j < SS_MAX_POOLS_PER_REG; j++)
347 reg->poolTbl[j].type = SS_POOL_UND;
349 /* find this region ID in the region configuration structure */
350 for (j = 0; j < cfgNumRegs; j++)
351 if (cfgRegInfo[j].region == i)
354 /* this region is not configured */
358 /* Load the configuration information into the region table.
359 * Note, the region still has to be registered, for it to
362 for (k = 0; k < cfgRegInfo[j].numPools; k++)
364 reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
365 if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
366 reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
370 ret = ssInitSema(&osCp.regionTblSem, SS_MAX_STSKS);
373 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
374 sprintf(prntBufLoc,"\n SInit(): Could not initialize the region Table Semaphore \n");
375 SDisplay(1,prntBufLoc);
379 /* implementation specific memory initialization */
383 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
384 sprintf(prntBufLoc,"\n SInit(): Memory initialization failed \n");
385 SDisplay(1,prntBufLoc);
390 /* initialize TAPA and system task information */
391 /* ss029.103: modification: multiple procId related changes */
392 #ifndef SS_MULTIPLE_PROCS
393 for (i = 0; i < SS_MAX_ENT; i++)
394 for (j = 0; j < SS_MAX_INST; j++)
395 osCp.tTskIds[i][j] = SS_TSKNC;
396 #else /* SS_MULTIPLE_PROCS */
397 for (i = 0; i < SS_MAX_PROCS; i++)
398 for (j = 0; j < SS_MAX_ENT; j++)
399 for (k = 0; k < SS_MAX_INST; k++)
400 osCp.tTskIds[i][j][k] = SS_TSKNC;
401 #endif /* SS_MULTIPLE_PROCS */
403 for (i = 0; i < SS_MAX_TTSKS; i++)
405 tTsk = &osCp.tTskTbl[i];
410 tTsk->tskType = TTUND;
412 tTsk->initTsk = NULLP;
413 tTsk->actvTsk = NULLP;
415 /* ss029.103: addition: TAPA task control block added */
416 #ifdef SS_MULTIPLE_PROCS
418 #endif /* SS_MULTIPLE_PROCS */
424 osCp.nxtTTskEntry = 0;
426 ret = ssInitSema(&osCp.tTskTblSem, SS_MAX_STSKS);
429 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
430 sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
431 SDisplay(1,prntBufLoc);
435 #ifdef SS_MULTICORE_SUPPORT
436 /* check whether number of system tasks is
437 * equal to number of (regions-1).
438 * The last region is meant for timer task
439 * which under the current feature has as entry
440 * in system task table.
442 if(SS_MAX_STSKS > SS_MAX_REGS)
444 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
449 /* initialize system task information */
450 for (i = 0; i < SS_MAX_STSKS; i++)
452 sTsk = &osCp.sTskTbl[i];
455 sTsk->termPend = FALSE;
457 for (j = 0; j < SS_MAX_TTSKS; j++)
458 sTsk->tTsks[j] = SS_INVALID_IDX;
462 /* ss002.301 : Modifications */
463 #ifdef SS_MULTICORE_SUPPORT
466 sTsk->region = (SS_MAX_REGS - 1);
476 osCp.nxtSTskEntry = 0;
478 ret = SInitLock(&osCp.sTskTblLock, SS_STSKTBL_LOCK);
481 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
482 sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
483 SDisplay(1,prntBufLoc);
487 /* ss028.103 - Addition of lock for mBuf reference count */
488 /* ss007.301 moving the mBufRefLock from common to per region */
489 /* SInitLock(&osCp.mBufRefLock, SS_LOCK_MUTEX);*/
491 /* implementation specific task initialization */
495 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
496 sprintf(prntBufLoc,"\n SInit(): implementation specific task initialization Failed \n");
497 SDisplay(1,prntBufLoc);
501 #ifdef SS_DRVR_SUPPORT
502 /* initialize driver task information */
503 for (i = 0; i < SS_MAX_DRVRTSKS; i++)
505 drvrTsk = &osCp.drvrTskTbl[i];
507 drvrTsk->used = FALSE;
509 drvrTsk->channel = 0;
510 drvrTsk->actvTsk = NULLP;
511 drvrTsk->isTsk = NULLP;
516 osCp.numDrvrTsks = 0;
518 /* implementation specific driver initialization */
522 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
523 sprintf(prntBufLoc,"\n SInit(): ssdInitDrvr failed \n");
524 SDisplay(1,prntBufLoc);
529 /*ss004.301: Cavium Changes */
530 #ifdef SS_SEUM_CAVIUM
531 ret = ssInitRcvWork();
534 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
537 #endif /* SS_SEUM_CAVIUM */
540 /* initialize the demand queue lookup table */
541 osCp.dmndQLookupTbl[0] = 255;
542 osCp.dmndQLookupTbl[1] = 0;
543 osCp.dmndQLookupTbl[2] = 1;
544 osCp.dmndQLookupTbl[3] = 1;
545 for (i = 4; i < 256; i++)
547 if (i >= 128 && i <= 255)
548 osCp.dmndQLookupTbl[i] = 7;
549 if (i >= 64 && i <= 127)
550 osCp.dmndQLookupTbl[i] = 6;
551 if (i >= 32 && i <= 63)
552 osCp.dmndQLookupTbl[i] = 5;
553 if (i >= 16 && i <= 31)
554 osCp.dmndQLookupTbl[i] = 4;
555 if (i >= 8 && i <= 15)
556 osCp.dmndQLookupTbl[i] = 3;
557 if (i >= 4 && i <= 7)
558 osCp.dmndQLookupTbl[i] = 2;
562 /* initialize timer information */
563 for (i = 0; i < SS_MAX_TMRS; i++)
565 tmr = &osCp.tmrTbl[i];
569 tmr->ownerEnt = ENTNC;
570 tmr->ownerInst = INSTNC;
573 * ss015.301 - Modifed in initialization as timer activation
574 * functions enclosed in a union. Also initialized the mtFlag
577 tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
578 #ifndef SS_MULTIPLE_PROCS
580 tmr->ssTmrActvFn.mtFlag = FALSE;
581 tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
588 osCp.nxtTmrEntry = 0;
590 ret = SInitLock(&osCp.tmrTblLock, SS_TMRTBL_LOCK);
593 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
597 /* implementation specific timer initialization */
601 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
602 sprintf(prntBufLoc,"\n SInit(): Could not initialize the timer \n");
603 SDisplay(1,prntBufLoc);
607 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
608 /* ss005.201: Initialize logging streams */
609 /* implementation specific logging initialization */
613 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
614 sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logging streams \n");
615 SDisplay(1,prntBufLoc);
619 #ifdef SS_LOGGER_SUPPORT /* ss001.301: additions */
620 /* Initialize the lock, return on failure */
621 if( SInitLock(&(osCp.logger.bufLock),SS_LOCK_MUTEX) != ROK)
623 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
624 sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logger Buffer Lock \n");
625 SDisplay(1,prntBufLoc);
629 /* Initialize the logger configuration flag */
630 osCp.logger.configured = FALSE;
631 /* Ss002.301 : Initialised */
632 osCp.logger.started = FALSE;
633 #endif /* SS_LOGGER_SUPPORT */
634 /* ss001.301: additions */
636 #ifdef SS_HISTOGRAM_SUPPORT
637 /* Here we are filling all the tapa entity Ids, which will be
638 * helpful to get the entity Id using file name. */
640 #endif /* SS_HISTOGRAM_SUPPORT */
643 #ifdef SS_FBSED_TSK_REG
644 /* Configure task registration based on the configuration */
645 /*ss013.301 : Fixed warnings for 32/64 bit compilation*/
646 cmCfgrTskReg((uint8_t *)"task_info.t");
647 #endif /* SS_FBSED_TSK_REG */
649 /*ss011.301 : RMIOS release related changes*/
654 /* call tst() function */
658 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
663 /* call implementation-specific starter function */
671 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
673 #ifdef SS_LOGGER_SUPPORT
674 /* ss005.301: Deinitialize the logging at the end */
675 SDestroyLock(&(osCp.logger.bufLock));
676 /*ss013.301 : Fix for compile time warning*/
678 #endif /* SS_LOGGER_SUPPORT */
683 SDestroyLock(&osCp.tmrTblLock);
686 #ifdef SS_DRVR_SUPPORT
692 SDestroyLock(&osCp.sTskTblLock);
694 if ( (ssDestroySema(&osCp.tTskTblSem)) != ROK)
696 #if (ERRCLASS & ERRCLS_DEBUG)
697 SSLOGERROR(ERRCLS_DEBUG, ESS012, ERRZERO,
698 "Could not destroy the Semaphore");
699 /* ss005.301: Changes, clean the threads and exit */
706 /* ss007.301 destroying the per region mBufRefLock */
707 for (i= 0;i<SS_MAX_REGS;i++)
709 SDestroyLock(&osCp.regionTbl[i].mBufRefLock);
711 /* ss006.13: addition */
712 if ( (ssDestroySema(&osCp.regionTblSem)) != ROK)
714 #if (ERRCLASS & ERRCLS_DEBUG)
715 SSLOGERROR(ERRCLS_DEBUG, ESS013, ERRZERO,
716 "Could not destroy the Semaphore");
717 /* ss005.301: Changes, clean the threads and exit */
728 /* ss033.103: Added SDeInit API to free all the resources */
731 * Fun: System Services de-initialization function
733 * Desc: This is the de-initialization function for System
734 * Services implementations. It releases all the common
735 * global data structures.
751 SDestroyLock(&osCp.tmrTblLock);
753 #ifdef SS_DRVR_SUPPORT
758 SDestroyLock(&osCp.sTskTblLock);
760 if ((ssDestroySema(&osCp.tTskTblSem)) != ROK)
762 #if (ERRCLASS & ERRCLS_DEBUG)
763 SSLOGERROR(ERRCLS_DEBUG, ESS014, ERRZERO,
764 "Could not destroy the Semaphore");
772 if ((ssDestroySema(&osCp.regionTblSem)) != ROK)
774 #if (ERRCLASS & ERRCLS_DEBUG)
775 SSLOGERROR(ERRCLS_DEBUG, ESS015, ERRZERO,
776 "Could not destroy the Semaphore");
783 /* ss007.301 destroying the per region mBufRefLock */
784 for (regCnt = 0; regCnt < SS_MAX_REGS; regCnt++)
786 SDestroyLock(&osCp.regionTbl[regCnt].mBufRefLock);
789 /* ss005.301: Deinitialize the logging at the end */
790 #ifdef SS_LOGGER_SUPPORT
791 SDestroyLock(&(osCp.logger.bufLock));
792 #endif /* SS_LOGGER_SUPPORT */
797 /* ss001.301: additions */
798 #ifdef SS_LOGGER_SUPPORT
801 Txt *buf /* buffer */
805 /* buffer synchronisation*/
806 bufSz = cmStrlen((uint8_t *)buf);
807 SLock(&osCp.logger.bufLock);
808 if(osCp.logger.started == FALSE)
810 (Void)SUnlock(&(osCp.logger.bufLock));
814 * Append the buffer to the global buffer
815 * and increment the current buffer size of the global buffer
817 if(((osCp.logger.curBufSiz) + bufSz) >= osCp.logger.maxBufSiz)
819 SFlushBufToLog(osCp.logger.buffer);
820 osCp.logger.curBufSiz = 0;
821 memset(osCp.logger.buffer, '\0', osCp.logger.maxBufSiz);
822 sprintf(osCp.logger.buffer, "%s", buf);
823 osCp.logger.curBufSiz += bufSz;
827 strcat(osCp.logger.buffer,buf);
828 osCp.logger.curBufSiz += bufSz;
830 (Void)SUnlock(&(osCp.logger.bufLock));
833 #endif /* SS_LOGGER_SUPPORT */
838 * Desc: Print a string.
840 * This function should be used for debugging only.
844 * Notes: Text buffer should be null terminated.
846 * SDisplay will replace SPrint.
848 * Typical usage consists of a call to sprintf to
849 * format the string into a buffer followed by a
857 Txt *buf /* buffer */
861 /* ss001.301: additions */
863 #ifdef SS_LOGGER_SUPPORT
865 #endif /* SS_LOGGER_SUPPORT */
869 } /* end of SPrint */
876 * Desc: Invoked by layer when an unrecoverable
877 * software error is detected. This function should
889 Seq seq, /* sequence */
890 Reason reason /* reason */
898 sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
899 (int)dt.month,(int)dt.day,(int)dt.year + 1900,
900 (int)dt.hour,(int)dt.min,(int)dt.sec);
904 ret = ssdError(seq, reason);
915 * Desc: Invoked by layer to log an error.
926 Ent ent, /* Calling layer's entity id */
927 Inst inst, /* Calling layer's instance id */
928 ProcId procId, /* Calling layer's processor id */
929 Txt *file, /* file name where error occured */
930 S32 line, /* line in file where error occured */
931 ErrCls errCls, /* error class */
932 ErrCode errCode, /* layer unique error code */
933 ErrVal errVal, /* error value */
934 Txt *errDesc /* description of error */
941 /*ss014.301: SSI-4GMX related changes*/
942 #ifndef SS_4GMX_LCORE
944 sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
945 (int)dt.month,(int)dt.day,(int)dt.year + 1900,
946 (int)dt.hour,(int)dt.min,(int)dt.sec);
950 /* ss001.301: additions */
951 #ifdef SS_LOGGER_SUPPORT
953 #endif /* SS_LOGGER_SUPPORT */
955 ssdLogError(ent, inst, procId, file, line,
956 errCls, errCode, errVal, errDesc);
962 /* ss029.103: modification:
963 SFndProcId function is not supported with multiple procIds */
964 #ifndef SS_MULTIPLE_PROCS
970 * Desc: This function finds the local processor ID.
972 * Ret: local processor id
979 ProcId SFndProcId(void)
982 return (osCp.procId);
983 } /* end of SFndProcId */
990 * Desc: This function stores the local processor ID.
999 Void SSetProcId(ProcId procId)
1002 osCp.procId = procId;
1007 #endif /* SS_MULTIPLE_PROCS */
1009 /* ss029.103: addition: New SSI functions with multiple proc support */
1010 #ifdef SS_MULTIPLE_PROCS
1014 * Fun: SGetProcIdIdx
1016 * Desc: This function finds index of procId in the process id table
1025 uint16_t SGetProcIdIdx(ProcId proc)
1030 idx = SS_HASH_IDX(proc);
1032 for (i = idx; i < SS_MAX_PROCS; i++)
1033 if (osCp.procLst.procId[i] == proc)
1036 /* search upto idx */
1037 for (i = 0; i < idx; i++)
1038 if (osCp.procLst.procId[i] == proc)
1041 return (SS_INV_PROCID_IDX);
1042 } /* SGetProcIdIdx */
1049 * Desc: This function inserts procId in the process id table
1058 static S16 SInsProcId(ProcId proc)
1064 idx = SS_HASH_IDX(proc);
1066 for (i = idx; i < SS_MAX_PROCS; i++)
1067 if (osCp.procLst.procId[i] == SS_INV_PROCID)
1069 osCp.procLst.procId[i] = proc;
1070 osCp.procLst.free--;
1074 /* search for free entry upto idx */
1075 for (i = 0; i < idx; i++)
1076 if (osCp.procLst.procId[i] == SS_INV_PROCID)
1078 osCp.procLst.procId[i] = proc;
1079 osCp.procLst.free--;
1091 * Desc: This function inserts procId in the process id table
1100 static S16 SRemProcId(ProcId proc)
1106 idx = SS_HASH_IDX(proc);
1108 for (i = idx; i < SS_MAX_PROCS; i++)
1109 if (osCp.procLst.procId[i] == proc)
1111 osCp.procLst.procId[i] = SS_INV_PROCID;
1112 osCp.procLst.free++;
1116 /* search upto idx */
1117 for (i = 0; i < idx; i++)
1118 if (osCp.procLst.procId[i] == proc)
1120 osCp.procLst.procId[i] = SS_INV_PROCID;
1121 osCp.procLst.free++;
1133 * Desc: This function locks OsCp
1142 static S16 SLockOsCp(void)
1147 ret = SLock(&osCp.sTskTblLock);
1150 SSLOGERROR(ERRCLS_DEBUG, ESS016, ERRZERO,
1151 "Could not lock system task table");
1155 SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
1159 #if (ERRCLASS & ERRCLS_DEBUG)
1160 SSLOGERROR(ERRCLS_DEBUG, ESS017, ERRZERO,
1161 "Could not lock TAPA task table");
1164 if ( SUnlock(&osCp.sTskTblLock) != ROK)
1166 #if (ERRCLASS & ERRCLS_DEBUG)
1167 SSLOGERROR(ERRCLS_DEBUG, ESS018, ERRZERO,
1168 "Could not give the Semaphore");
1185 * Desc: This function locks OsCp
1194 static S16 SULockOsCp(Void)
1197 /* unlock the table */
1198 SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1200 if ( SUnlock(&osCp.sTskTblLock) != ROK)
1202 #if (ERRCLASS & ERRCLS_DEBUG)
1203 SSLOGERROR(ERRCLS_DEBUG, ESS019, ERRZERO,
1204 "Could not give the Semaphore");
1217 * Fun: SAddProcIdLst
1219 * Desc: This function adds given proc ids to the list
1228 S16 SAddProcIdLst(uint16_t numPIds,ProcId *pIdLst)
1234 #if (ERRCLASS & ERRCLS_INT_PAR)
1236 if (numPIds > SS_MAX_PROCS)
1238 SSLOGERROR(ERRCLS_INT_PAR, ESS020, ERRZERO, "number of proc Ids exceeds\
1243 /* find if the entry exist in the table */
1244 for (i = 0; i < numPIds; i++)
1246 if (pIdLst[i] == SS_INV_PROCID)
1248 SSLOGERROR(ERRCLS_INT_PAR, ESS021, ERRZERO, "Invalid proc Ids");
1255 if (SLockOsCp() != ROK)
1258 #if (ERRCLASS & ERRCLS_INT_PAR)
1259 for (i = 0; i < numPIds; i++)
1260 if (SGetProcIdIdx(pIdLst[i]) != SS_INV_PROCID_IDX)
1262 SSLOGERROR(ERRCLS_INT_PAR, ESS022, ERRZERO, "Duplicate proc id");
1263 (Void) SULockOsCp();
1267 if (numPIds > osCp.procLst.free)
1269 SSLOGERROR(ERRCLS_INT_PAR, ESS023, ERRZERO, "Total number of proc id \
1271 (Void) SULockOsCp();
1276 /* insert the entries in the table */
1279 for (i = 0; i < numPIds; i++)
1281 if (SInsProcId(pIdLst[i]) == RFAILED)
1283 #if (ERRCLASS & ERRCLS_DEBUG)
1284 SSLOGERROR(ERRCLS_DEBUG, ESS024, ERRZERO,
1285 "Could not insert the proc id");
1287 (Void) SULockOsCp();
1292 /* unlock the table */
1293 if (SULockOsCp() != ROK)
1297 } /* SAddProcIdLst */
1302 * Fun: SRemProcIdLst
1304 * Desc: This function adds given proc ids to the list
1313 S16 SRemProcIdLst(uint16_t numPIds,ProcId *pIdLst)
1318 #if (ERRCLASS & ERRCLS_INT_PAR)
1320 if (numPIds > SS_MAX_PROCS)
1324 if (SLockOsCp() != ROK)
1327 if (numPIds > (SS_MAX_PROCS - osCp.procLst.free))
1329 (Void) SULockOsCp();
1333 /* find if the entry exist in the table */
1334 for (i = 0; i < numPIds; i++)
1336 if (SGetProcIdIdx(pIdLst[i]) == SS_INV_PROCID_IDX)
1338 (Void) SULockOsCp();
1343 /* insert the entries in the table */
1344 for (i = 0; i < numPIds; i++)
1345 SRemProcId(pIdLst[i]);
1347 if (SULockOsCp() != ROK)
1351 } /* SRemProcIdLst */
1356 * Fun: SGetProcIdLst
1358 * Desc: This function retrieves proc Id list
1367 S16 SGetProcIdLst(uint16_t *numPIds,ProcId *pIdLst)
1373 #if (ERRCLASS & ERRCLS_INT_PAR)
1374 if ((numPIds == NULLP) || (pIdLst == NULLP))
1376 SSLOGERROR(ERRCLS_INT_PAR, ESS025, ERRZERO, "Invalid numPIds/pIdLst");
1381 if (SLockOsCp() != ROK)
1384 for (i = 0; i < SS_MAX_PROCS; i++)
1386 if (osCp.procLst.procId[i] != PROCNC)
1387 pIdLst[count++] = osCp.procLst.procId[i];
1392 if (SULockOsCp() != ROK)
1399 } /* SGetProcIdLst */
1406 * Desc: This function retrieves protocol layer control block for given proc,
1428 #if (ERRCLASS & ERRCLS_INT_PAR)
1429 if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) || (inst >= SS_MAX_INST))
1431 SSLOGERROR(ERRCLS_INT_PAR, ESS026, ERRZERO, "Invalid proc/entity/instance");
1437 * ss030.103: delete: locking/unlocking removed as it causes
1438 * deadlock/blockage in some cases
1441 procIdIdx = SGetProcIdIdx(proc);
1443 if (procIdIdx == SS_INV_PROCID_IDX)
1445 #if (ERRCLASS & ERRCLS_INT_PAR)
1446 SSLOGERROR(ERRCLS_INT_PAR, ESS027, ERRZERO, "Could not get proc table idx");
1451 idx = osCp.tTskIds[procIdIdx][ent][inst];
1452 if (idx == SS_TSKNC)
1458 *xxCb = osCp.tTskTbl[idx].xxCb;
1459 /*ss032.103 added a check for NULLP */
1466 #endif /* SS_MULTIPLE_PROCS */
1468 /* ss001.301: additions */
1469 #ifdef SS_HISTOGRAM_SUPPORT
1474 * Desc: It is static data base contains all entity Ids of tapa task.
1475 * This Data base is used to find the entity id using two letter
1476 * prifix product code.
1485 S16 SFillEntIds(Void)
1488 uint8_t entInfo[26][26] = {
1489 /* A B C D E F G H I J K *
1490 L M N O P Q R S T U V *
1492 {ENTAA, ENTAB, ENTAC, ENTNC, ENTAE, ENTAF, ENTNC, ENTAH, ENTNC, ENTNC, ENTNC,
1493 /* A */ ENTAL, ENTAM, ENTNC, ENTNC, ENTAP, ENTAQ, ENTAR, ENTAS, ENTNC, ENTAU, ENTNC,
1494 ENTAW, ENTNC, ENTNC, ENTNC},
1496 /* A B C D E F G H I J K *
1497 L M N O P Q R S T U V *
1499 {ENTNC, ENTNC, ENTNC, ENTBD, ENTNC, ENTNC, ENTNC, ENTNC, ENTBI, ENTNC, ENTNC,
1500 /* B */ ENTNC, ENTBM, ENTNC, ENTNC, ENTNC, ENTNC, ENTBR, ENTBS, ENTNC, ENTNC, ENTBV,
1501 ENTBW, ENTNC, ENTNC, ENTNC},
1502 /* A B C D E F G H I J K *
1503 L M N O P Q R S T U V *
1505 {ENTNC, ENTNC, ENTCC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCH, ENTNC, ENTNC, ENTNC,
1506 /* C */ ENTCL, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCS, ENTNC, ENTCU, ENTCV,
1507 ENTNC, ENTNC, ENTNC, ENTNC},
1508 /* A B C D E F G H I J K *
1509 L M N O P Q R S T U V *
1511 {ENTNC, ENTDB, ENTNC, ENTNC, ENTNC, ENTNC, ENTDG, ENTNC, ENTDI, ENTNC, ENTDK,
1512 /* D */ ENTNC, ENTDM, ENTDN, ENTNC, ENTDP, ENTNC, ENTNC, ENTNC, ENTDT, ENTDU, ENTDV,
1513 ENTNC, ENTNC, ENTNC, ENTNC},
1514 /* A B C D E F G H I J K *
1515 L M N O P Q R S T U V *
1517 {ENTNC, ENTNC, ENTNC, ENTNC, ENTEC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1518 /* E */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTER, ENTES, ENTNC, ENTNC, ENTEV,
1519 ENTNC, ENTNC, ENTNC, ENTNC},
1520 /* A B C D E F G H I J K *
1521 L M N O P Q R S T U V *
1523 {ENTFA, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1524 /* F */ ENTNC, ENTFM, ENTFN, ENTNC, ENTFP, ENTNC, ENTFR, ENTNC, ENTNC, ENTFU, ENTNC,
1525 ENTFW, ENTNC, ENTNC, ENTNC},
1526 /* A B C D E F G H I J K *
1527 L M N O P Q R S T U V *
1529 {ENTGA, ENTGB, ENTGC, ENTGD, ENTGE, ENTGF, ENTGG, ENTGH, ENTGI, ENTNC, ENTNC,
1530 /* G */ ENTGL, ENTGM, ENTGN, ENTGO, ENTGP, ENTNC, ENTGR, ENTGS, ENTGT, ENTGU, ENTNC,
1531 ENTGW, ENTGX, ENTGY, ENTGZ},
1532 /* A B C D E F G H I J K *
1533 L M N O P Q R S T U V *
1535 {ENTNC, ENTNC, ENTHC, ENTNC, ENTHE, ENTNC, ENTHG, ENTNC, ENTHI, ENTNC, ENTNC,
1536 /* H */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTHR, ENTHS, ENTNC, ENTHU, ENTNC,
1537 ENTNC, ENTNC, ENTNC, ENTNC},
1538 /* A B C D E F G H I J K *
1539 L M N O P Q R S T U V *
1541 {ENTIA, ENTIB, ENTNC, ENTID, ENTIE, ENTNC, ENTNC, ENTNC, ENTII, ENTNC, ENTNC,
1542 /* I */ ENTNC, ENTIM, ENTIN, ENTNC, ENTNC, ENTIQ, ENTNC, ENTIS, ENTIT, ENTIU, ENTNC,
1543 ENTIW, ENTIX, ENTNC, ENTNC},
1544 /* A B C D E F G H I J K *
1545 L M N O P Q R S T U V *
1547 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1548 /* J */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1549 ENTNC, ENTNC, ENTNC, ENTNC},
1550 /* A B C D E F G H I J K *
1551 L M N O P Q R S T U V *
1553 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1554 /* K */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1555 ENTRLC, ENTNC, ENTNC, ENTNC},
1556 /* A B C D E F G H I J K *
1557 L M N O P Q R S T U V *
1559 {ENTLA, ENTLB, ENTLC, ENTLD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTLK,
1560 /* L */ ENTNC, ENTLM, ENTLN, ENTNC, ENTNC, ENTNC, ENTLR, ENTNC, ENTLT, ENTLU, ENTLV,
1561 ENTNC, ENTLX, ENTNC, ENTNC},
1562 /* A B C D E F G H I J K *
1563 L M N O P Q R S T U V *
1565 {ENTMA, ENTNC, ENTMC, ENTMD, ENTME, ENTNC, ENTMG, ENTNC, ENTNC, ENTNC, ENTMK,
1566 /* M */ ENTML, ENTMM, ENTNC, ENTNC, ENTNC, ENTNC, ENTMR, ENTMS, ENTMT, ENTMU, ENTMV,
1567 ENTMW, ENTMX, ENTNC, ENTMZ},
1568 /* A B C D E F G H I J K *
1569 L M N O P Q R S T U V *
1571 {ENTNC, ENTNC, ENTNC, ENTND, ENTNC, ENTNF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1572 /* N */ ENTNC, ENTNM, ENTNC, ENTNC, ENTNP, ENTNC, ENTNC, ENTNS, ENTNC, ENTNC, ENTNV,
1573 ENTNW, ENTNC, ENTNC, ENTNC},
1574 /* A B C D E F G H I J K *
1575 L M N O P Q R S T U V *
1577 {ENTNC, ENTNC, ENTNC, ENTOD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1578 /* O */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1579 ENTNC, ENTNC, ENTNC, ENTNC},
1580 /* A B C D E F G H I J K *
1581 L M N O P Q R S T U V *
1583 {ENTPA, ENTNC, ENTNC, ENTPD, ENTNC, ENTNC, ENTNC, ENTPH, ENTNC, ENTNC, ENTNC,
1584 /* P */ ENTPL, ENTNC, ENTPN, ENTNC, ENTPN, ENTPQ, ENTPR, ENTNC, ENTNC, ENTPU, ENTPV,
1585 ENTNC, ENTNC, ENTNC, ENTNC},
1586 /* A B C D E F G H I J K *
1587 L M N O P Q R S T U V *
1589 {ENTNC, ENTNC, ENTQC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTQI, ENTNC, ENTNC,
1590 /* Q */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1591 ENTQW, ENTNC, ENTNC, ENTNC},
1592 /* A B C D E F G H I J K *
1593 L M N O P Q R S T U V *
1595 {ENTRA, ENTNC, ENTNC, ENTRD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1596 /* R */ ENTRL, ENTRM, ENTRN, ENTNC, ENTRP, ENTNC, ENTRR, ENTNC, ENTRT, ENTRU, ENTNC,
1597 ENTNC, ENTRX, ENTRY, ENTNC},
1598 /* A B C D E F G H I J K *
1599 L M N O P Q R S T U V *
1601 {ENTSA, ENTSB, ENTSC, ENTSD, ENTSE, ENTSF, ENTSG, ENTSH, ENTSI, ENTNC, ENTNC,
1602 /* S */ ENTNC, ENTSM, ENTSN, ENTSO, ENTSP, ENTNC, ENTSR, ENTSS, ENTST, ENTSU, ENTSV,
1603 ENTNC, ENTNC, ENTNC, ENTSZ},
1604 /* A B C D E F G H I J K *
1605 L M N O P Q R S T U V *
1607 {ENTNC, ENTNC, ENTTC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1608 /* T */ ENTNC, ENTTM, ENTNC, ENTNC, ENTTP, ENTNC, ENTNC, ENTTS, ENTTT, ENTTU, ENTNC,
1609 ENTNC, ENTNC, ENTNC, ENTNC},
1610 /* A B C D E F G H I J K *
1611 L M N O P Q R S T U V *
1613 {ENTNC, ENTNC, ENTNC, ENTUD, ENTNC, ENTNC, ENTNC, ENTUH, ENTNC, ENTNC, ENTNC,
1614 /* U */ ENTUL, ENTUM, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTUS, ENTNC, ENTNC, ENTNC,
1615 ENTNC, ENTNC, ENTNC, ENTUZ},
1616 /* A B C D E F G H I J K *
1617 L M N O P Q R S T U V *
1619 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1620 /* V */ ENTNC, ENTVM, ENTNC, ENTVO, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVU, ENTNC,
1621 ENTNC, ENTNC, ENTNC, ENTNC},
1622 /* A B C D E F G H I J K *
1623 L M N O P Q R S T U V *
1625 {ENTNC, ENTNC, ENTWC, ENTWD, ENTNC, ENTNC, ENTNC, ENTNC, ENTWI, ENTNC, ENTNC,
1626 /* W */ ENTNC, ENTNC, ENTWN, ENTNC, ENTNC, ENTNC, ENTNC, ENTWS, ENTNC, ENTWU, ENTNC,
1627 ENTNC, ENTNC, ENTNC, ENTNC},
1628 /* A B C D E F G H I J K *
1629 L M N O P Q R S T U V *
1631 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXG, ENTNC, ENTXI, ENTNC, ENTNC,
1632 /* X */ ENTNC, ENTXM, ENTXN, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXU, ENTNC,
1633 ENTNC, ENTXX, ENTXY, ENTNC},
1634 /* A B C D E F G H I J K *
1635 L M N O P Q R S T U V *
1637 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1638 /* Y */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1639 ENTNC, ENTNC, ENTNC, ENTNC},
1640 /* A B C D E F G H I J K *
1641 L M N O P Q R S T U V *
1643 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1644 /* Z */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1645 ENTNC, ENTNC, ENTNC, ENTNC}
1648 /*ss013.301 :Adding TRC MACRO*/
1649 memcpy(osCp.entId, entInfo, sizeof(entInfo));
1659 * Desc: This function gives the entity Id depending in the
1660 * file name. This function uses the first two letter
1661 * of file name to find the entity id.
1666 * RFAILED Region not registered
1670 S16 SGetEntInd(Ent *entId,uint8_t *fileName)
1674 uint8_t *letter = NULLP;
1675 /* ss002.301 Additions */
1676 S8 *strippedName = NULLP;
1678 uint8_t tempIdx = 0;
1679 uint8_t firstIdx = 0;
1680 uint8_t secondIdx = 0;
1683 /* ss002.301 Additions */
1684 if ((strippedName = strrchr((const char *)fileName, '/')))
1686 fileName = (uint8_t *)strippedName + 1;
1689 if(fileName[0] =='l' && fileName[3] == '.')
1691 /* Usally layer manager interface files starts
1692 * with l. so leave the first letter and take
1694 * Eg. Layer manger inteface file name for TUCL is lhi.c.
1695 * so here we leave l and we take hi to get the entity Id. */
1696 letter = ++fileName;
1701 /* Handle exceptional file names */
1705 if (letter[1] == 'g' && letter[2] == 'u')
1717 /* here first two charactes of file name should be alphabets.
1718 * if any one of the letter is non alphabet then we return ENTNC
1719 * as an entity Id */
1720 /* Eg. In fileName l4_ptui.c, second letter is numeral. so we consider
1721 * this file belogs to entity Id ENTNC. */
1722 for(count = 0; count < 2; count++)
1724 /* ss002.301 - Optimizations */
1725 if(letter[count] < 'a' || letter[count] > 'z')
1732 tempIdx = letter[count] - 'a';
1740 secondIdx = tempIdx;
1743 /* First two letter of file name are alphabets the get the
1744 * entity id from the static data base which is loaded in sFillEntIds() */
1745 *entId = osCp.entId[firstIdx][secondIdx];
1749 #endif /* SS_HISTOGRAM_SUPPORT */
1750 #ifdef SS_LOCK_SUPPORT
1751 /* ss002.301 Readwrite lock additions */
1756 * Desc: This function is used to aquire the read write lock
1765 S16 SLockNew(SLockInfo *lockId,uint8_t lockType)
1770 if((retVal = ssdLockNew(lockId, lockType)) != ROK)
1772 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SLockNew(): Failed to aquire the lock\n");
1782 * Desc: This function is used to aquire the read write lock
1791 S16 SInitLockNew(SLockInfo *lockId,uint8_t lockType)
1796 if((retVal = ssdInitLockNew(lockId, lockType)) != ROK)
1798 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SInitLockNew(): Initialization of lock Failed\n");
1808 * Desc: This function is used to Unlock the read write lock
1817 S16 SUnlockNew(SLockInfo *lockId,uint8_t lockType)
1822 if((retVal = ssdUnlockNew(lockId, lockType)) != ROK)
1824 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SUnlockNew(): Failed to release the lock\n");
1832 * Fun: SDestroyLockNew
1834 * Desc: This function is used to destroy the read write lock
1843 S16 SDestroyLockNew(SLockInfo *lockId,uint8_t lockType)
1848 if((retVal = ssdDestroyLockNew(lockId, lockType)) != ROK)
1850 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SDestroyLockNew(): Failed to destroy the lock\n");
1855 #endif /* SS_LOCK_SUPPORT */
1857 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1858 /* Static memory leak detection changes */
1859 static uint32_t StaticMemLeakAge;
1860 static uint32_t StaticMemLeakIntCount = 1;
1862 void PrintStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo, FILE *opFile)
1866 fprintf(opFile, "Current Time = %ld\n",StaticMemLeakAge);
1868 for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
1870 if(memAllocInfo->allocations[i].ptr)
1872 fprintf(opFile, "p = %p f = %s l = %ld s = %ld a = %ld\n",
1873 memAllocInfo->allocations[i].ptr,
1874 memAllocInfo->allocations[i].file,
1875 memAllocInfo->allocations[i].lineNo,
1876 memAllocInfo->allocations[i].size,
1877 memAllocInfo->allocations[i].age);
1884 void InitializeStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo)
1887 /* index 0 is not used; nextIdx as 0 means end of list */
1888 memAllocInfo->nextFreeIdx = 1;
1890 for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
1892 memAllocInfo->allocations[i].listInfo.nextIdx = i + 1;
1893 memAllocInfo->allocations[i].ptr = 0;
1896 /* override the last one to point to 0 meaning end of list */
1897 memAllocInfo->allocations[MAX_MEM_ALLOCATIONS - 1].listInfo.nextIdx = 0;
1900 uint32_t GetNextFreeIdx(StaticMemAllocInfo * memAllocInfo)
1902 uint32_t toBeReturned = memAllocInfo->nextFreeIdx;
1904 uint32_t newNextFreeIdx = memAllocInfo->allocations[memAllocInfo->nextFreeIdx].listInfo.nextIdx;
1906 if(newNextFreeIdx == 0 || newNextFreeIdx >= MAX_MEM_ALLOCATIONS)
1908 printf("\nSomething wrong in GetNextFreeIdx newNextIdx = %ld\n",newNextFreeIdx);
1911 memAllocInfo->nextFreeIdx = newNextFreeIdx;
1913 return toBeReturned;
1916 #define CRASH_ENB {int *p = 0; *p = 100;}
1917 void FreeIdx(uint8_t* ptr, uint32_t idx, StaticMemAllocInfo* memAllocInfo,uint32_t size, char* file, uint32_t line)
1919 if(idx == 0 || idx >= MAX_MEM_ALLOCATIONS)
1921 printf("Something wrong in FreeIdx... idx = %ld called from %s:%ld\n",idx,file,line);
1924 /*printf("FreeIdx... idx = %d nexFree = %d\n",idx, memAllocInfo->nextFreeIdx);*/
1925 memAllocInfo->allocations[idx].listInfo.nextIdx = memAllocInfo->nextFreeIdx;
1926 if((ptr != memAllocInfo->allocations[idx].ptr) ||
1927 (size != memAllocInfo->allocations[idx].size))
1929 #ifdef XEON_SPECIFIC_CHANGES
1933 printf("\nFreeing wrong ptr stored = %p trying to free %p freeing size (%ld)"
1934 "allocated size(%ld) from %s:%ld\n",
1935 memAllocInfo->allocations[idx].ptr,
1938 memAllocInfo->allocations[idx].size,
1941 printf("\nAllocation was done from %s:%ld\n",memAllocInfo->allocations[idx].file, memAllocInfo->allocations[idx].lineNo);
1942 printf("\n***********************************************************\n");
1946 memAllocInfo->allocations[idx].ptr = 0;
1948 memAllocInfo->nextFreeIdx = idx;
1952 void LogForStaticMemLeak(StaticMemAllocInfo* memAllocInfo, char* file, uint32_t line, uint32_t size, void* ptr, uint32_t idx)
1955 memAllocInfo->allocations[idx].file = file;
1956 memAllocInfo->allocations[idx].lineNo = line;
1957 memAllocInfo->allocations[idx].size = size;
1958 memAllocInfo->allocations[idx].ptr = ptr;
1959 memAllocInfo->allocations[idx].age = StaticMemLeakAge;
1961 if(StaticMemLeakIntCount++ % 256 == 0)
1967 void InitializeForStaticMemLeak()
1971 StaticMemLeakFileArr[0] = fopen("region0.log","w");
1972 StaticMemLeakFileArr[1] = fopen("region1.log","w");
1973 StaticMemLeakFileArr[2] = fopen("region2.log","w");
1974 StaticMemLeakFileArr[3] = fopen("region3.log","w");
1976 if(StaticMemLeakFileArr[0] == NULL ||
1977 StaticMemLeakFileArr[1] == NULL ||
1978 StaticMemLeakFileArr[2] == NULL ||
1979 StaticMemLeakFileArr[3] == NULL)
1982 printf("\nCould not open files for Static Mem Leak detection logging :( crashing...\n");
1986 for(i = 0; i < 4; i++)
1988 InitializeStaticMemAllocInfo(&SMemLeakInfo[i]);
1992 void DumpStaticMemLeakFiles()
1996 for(i = 0; i < 4; i++)
1998 PrintStaticMemAllocInfo(&SMemLeakInfo[i], StaticMemLeakFileArr[i]);
2001 /* Static memory leak detection changes */
2006 * Fun: ssRegMainThread
2008 * Desc: This function is used to add the memory region
2009 * mapping for the main thread.
2011 * Ret: VOID (Always successful)
2018 S16 SReInitTmr(void)
2021 Txt prntBuf[PRNTSZE];
2023 sprintf(prntBuf, "\n SReInitTmr(): ReStarting the Tmr\n");
2024 SDisplay(1,prntBuf);
2025 ret = ssdReInitTmr();
2028 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
2029 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SReInitTmr(): Failed to Restart the Tmr\n");
2037 * Fun: SGetConfigPath
2039 * Desc: This function is used to Get config files path
2041 * Ret: S8* config file Path
2048 S8* SGetConfigPath(Void)
2050 return osCp.configFilePath;
2053 /**********************************************************************
2055 **********************************************************************/