Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[o-du/l2.git] / src / mt / ss_mem.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18 \f
19 /********************************************************************20**
20
21      Name:     System Services -- Memory management interface
22
23      Type:     C source file
24
25      Desc:     Implementation of the memory management interface.
26
27      File:     ss_mem.c
28
29 *********************************************************************21*/
30
31 \f
32 /* header include files (.h) */
33
34 #include "envopt.h"        /* environment options */
35 #include "envdep.h"        /* environment dependent */
36 #include "envind.h"        /* environment independent */
37   
38 #include "gen.h"           /* general layer */
39 #include "ssi.h"           /* system services */
40
41 #include "ss_err.h"        /* errors */
42 #include "ss_dep.h"        /* implementation-specific */
43 #include "ss_queue.h"      /* queues */
44 #include "ss_msg.h"        /* messaging */
45 #include "ss_mem.h"        /* memory management interface */
46 /*ss011.301 : RMI SSI specific includes*/
47 #ifdef SS_RMIOS
48 #include "uc_gen.h"        /* general */
49 #else
50 #include "ss_gen.h"        /* general */
51 #endif
52
53
54 #include "cm_mem.h"        /* common memory manager */
55 #include "cm_llist.h"
56 #include "cm_hash.h"
57
58 /* header/extern include files (.x) */
59
60 #include "gen.x"           /* general layer */
61 #include "ssi.x"           /* system services */
62
63 #include "ss_dep.x"        /* implementation-specific */
64 #include "ss_queue.x"      /* queues */
65 /*ss011.301 : RMI SSI specific includes*/
66 #ifdef SS_RMIOS
67 #include "uc_task.x"       /* tasking */
68 #include "uc_timer.x"      /* timers */
69 #else
70 #include "ss_task.x"       /* tasking */
71 #include "ss_timer.x"      /* timers */
72 #endif
73 #include "ss_strm.x"       /* STREAMS */
74 #include "ss_msg.x"        /* messaging */
75 #include "ss_mem.x"        /* memory management interface */
76 #include "ss_drvr.x"       /* driver tasks */
77 /*ss011.301 : RMI SSI specific includes*/
78 #ifdef SS_LOCKLESS_MEMORY
79 #include "cm_llist.x"
80 #include "cm_hash.x"
81 #include "cm_mem_wl.x"        /* common memory manager */
82 #else
83 #include "cm_mem.x"        /* common memory manager */
84 #endif /* SS_LOCKLESS_MEMORY */
85 #ifdef SS_RMIOS
86 #include "uc_gen.x"        /* general */
87 #else
88 #include "ss_gen.x"        /* general */
89 #endif
90 #include "cm_llist.x"
91 #include "cm_hash.x"
92
93
94 \f
95 /*
96 *     Interface functions
97 */
98  
99
100 /*
101 *
102 *       Fun:   SRegDynRegion
103 *
104 *       Desc:  Registers a memory region.
105 *
106 *       Ret:   ROK      - ok
107 *              RFAILED  - failed, general (optional)
108 *
109 *       Notes:
110 *
111 *       File:  ss_mem.c
112 *
113 */
114 #ifdef ANSI
115 PUBLIC S16 SRegDynRegion
116 (
117 Region region,                  /* region ID */
118 SRegInfo *regInfo               /* information about the region */
119 )
120 #else
121 PUBLIC S16 SRegDynRegion(region, regInfo)
122 Region region;                  /* region ID */
123 SRegInfo *regInfo;              /* information about the region */
124 #endif
125 {
126    S16 ret;
127
128
129    TRC1(SRegDynRegion);
130
131
132 #if (ERRCLASS & ERRCLS_INT_PAR)
133    /* validate region ID */
134    if (region >= SS_MAX_REGS)
135    {
136       SSLOGERROR(ERRCLS_INT_PAR, ESS028, region, "Invalid region");
137       RETVALUE(RFAILED);
138    }
139
140    /* validate region info pointer */
141    if (regInfo == NULLP)
142    {
143       SSLOGERROR(ERRCLS_INT_PAR, ESS029, ERRZERO, "Null pointer");
144       RETVALUE(RFAILED);
145    }
146 #endif
147
148
149    /* lock the region table */
150    SS_ACQUIRE_ALL_SEMA(&osCp.regionTblSem, ret);
151    if (ret != ROK)
152    {
153
154 #if (ERRCLASS & ERRCLS_DEBUG)
155       SSLOGERROR(ERRCLS_DEBUG, ESS030, (ErrVal) ret,
156                   "Could not lock region table");
157 #endif
158
159       RETVALUE(RFAILED);
160    }
161
162
163 #if (ERRCLASS & ERRCLS_INT_PAR)
164    /* verify that this region is not registered */
165    if (osCp.dynRegionTbl[region].used == TRUE)
166    {
167       SS_RELEASE_ALL_SEMA(&osCp.regionTblSem);
168
169       SSLOGERROR(ERRCLS_INT_PAR, ESS031, ERRZERO, "Region ID used");
170       RETVALUE(RFAILED);
171    }
172 #endif
173
174
175    /* fill in the region information */
176    osCp.dynRegionTbl[region].used = TRUE;
177    osCp.dynRegionTbl[region].regCb = regInfo->regCb;
178    osCp.dynRegionTbl[region].flags = regInfo->flags;
179    osCp.dynRegionTbl[region].start = regInfo->start;
180    osCp.dynRegionTbl[region].size = regInfo->size;
181    osCp.dynRegionTbl[region].alloc = regInfo->alloc;
182    osCp.dynRegionTbl[region].free = regInfo->free;
183    osCp.dynRegionTbl[region].ctl = regInfo->ctl;
184
185    osCp.numDynRegions++;
186
187
188    /* unlock the region table */
189    SS_RELEASE_ALL_SEMA(&osCp.regionTblSem);
190
191
192    RETVALUE(ROK);
193 }
194
195
196
197 \f
198 /*
199 *
200 *       Fun:   SRegRegion
201 *
202 *       Desc:  Registers a memory region.
203 *
204 *       Ret:   ROK      - ok
205 *              RFAILED  - failed, general (optional)
206 *
207 *       Notes:
208 *
209 *       File:  ss_mem.c
210 *
211 */
212 #ifdef ANSI
213 PUBLIC S16 SRegRegion
214 (
215 Region region,                  /* region ID */
216 SRegInfo *regInfo               /* information about the region */
217 )
218 #else
219 PUBLIC S16 SRegRegion(region, regInfo)
220 Region region;                  /* region ID */
221 SRegInfo *regInfo;              /* information about the region */
222 #endif
223 {
224    S16 ret;
225
226
227    TRC1(SRegRegion);
228
229
230 #if (ERRCLASS & ERRCLS_INT_PAR)
231    /* validate region ID */
232    if (region >= SS_MAX_REGS)
233    {
234       SSLOGERROR(ERRCLS_INT_PAR, ESS028, region, "Invalid region");
235       RETVALUE(RFAILED);
236    }
237
238    /* validate region info pointer */
239    if (regInfo == NULLP)
240    {
241       SSLOGERROR(ERRCLS_INT_PAR, ESS029, ERRZERO, "Null pointer");
242       RETVALUE(RFAILED);
243    }
244 #endif
245
246
247    /* lock the region table */
248    SS_ACQUIRE_ALL_SEMA(&osCp.regionTblSem, ret);
249    if (ret != ROK)
250    {
251
252 #if (ERRCLASS & ERRCLS_DEBUG)
253       SSLOGERROR(ERRCLS_DEBUG, ESS030, (ErrVal) ret,
254                   "Could not lock region table");
255 #endif
256
257       RETVALUE(RFAILED);
258    }
259
260
261 #if (ERRCLASS & ERRCLS_INT_PAR)
262    /* verify that this region is not registered */
263    if (osCp.regionTbl[region].used == TRUE)
264    {
265       SS_RELEASE_ALL_SEMA(&osCp.regionTblSem);
266
267       SSLOGERROR(ERRCLS_INT_PAR, ESS031, ERRZERO, "Region ID used");
268       RETVALUE(RFAILED);
269    }
270 #endif
271
272
273    /* fill in the region information */
274    osCp.regionTbl[region].used = TRUE;
275    osCp.regionTbl[region].regCb = regInfo->regCb;
276    osCp.regionTbl[region].flags = regInfo->flags;
277    osCp.regionTbl[region].start = regInfo->start;
278    osCp.regionTbl[region].size = regInfo->size;
279    osCp.regionTbl[region].alloc = regInfo->alloc;
280    osCp.regionTbl[region].free = regInfo->free;
281    osCp.regionTbl[region].ctl = regInfo->ctl;
282
283    osCp.numRegions++;
284
285
286    /* unlock the region table */
287    SS_RELEASE_ALL_SEMA(&osCp.regionTblSem);
288
289
290    RETVALUE(ROK);
291 }
292
293 \f
294 /*
295 *
296 *       Fun:   SDeregRegion
297 *
298 *       Desc:  Deregisters a memory region.
299 *
300 *       Ret:   ROK      - ok
301 *              RFAILED  - failed, general (optional)
302 *
303 *       Notes:
304 *
305 *       File:  ss_mem.c
306 *
307 */
308 #ifdef ANSI
309 PUBLIC S16 SDeregRegion
310 (
311 Region region                   /* region ID */
312 )
313 #else
314 PUBLIC S16 SDeregRegion(region)
315 Region region;                  /* region ID */
316 #endif
317 {
318    S16 ret;
319
320
321    TRC1(SDeregRegion);
322
323
324 #if (ERRCLASS & ERRCLS_INT_PAR)
325    /* validate region ID */
326    if (region >= SS_MAX_REGS)
327    {
328       SSLOGERROR(ERRCLS_INT_PAR, ESS032, region, "Invalid region");
329       RETVALUE(RFAILED);
330    }
331 #endif
332
333
334    /* lock the region table */
335    SS_ACQUIRE_ALL_SEMA(&osCp.regionTblSem, ret);
336    if (ret != ROK)
337    {
338
339 #if (ERRCLASS & ERRCLS_DEBUG)
340       SSLOGERROR(ERRCLS_DEBUG, ESS033, (ErrVal) ret,
341                   "Could not lock region table");
342 #endif
343
344       RETVALUE(RFAILED);
345    }
346
347
348 #if (ERRCLASS & ERRCLS_INT_PAR)
349    /* check if this region is registered */
350    if (osCp.regionTbl[region].used == FALSE)
351    {
352       SS_RELEASE_ALL_SEMA(&osCp.regionTblSem);
353       SSLOGERROR(ERRCLS_INT_PAR, ESS034, region, "Region not registered");
354       RETVALUE(RFAILED);
355    }
356 #endif
357
358
359    /* empty the information about the region */
360    osCp.regionTbl[region].used = FALSE;
361    osCp.regionTbl[region].start = NULLP;
362    osCp.regionTbl[region].size = 0;
363    osCp.regionTbl[region].regCb = NULLP;
364    osCp.regionTbl[region].flags = 0;
365    osCp.regionTbl[region].alloc = NULLP;
366    osCp.regionTbl[region].free = NULLP;
367    osCp.regionTbl[region].ctl = NULLP;
368
369    osCp.numRegions--;
370
371
372    /* unlock the region table */
373    SS_RELEASE_ALL_SEMA(&osCp.regionTblSem);
374
375
376    RETVALUE(ROK);
377 }
378
379 \f
380 /*
381 *
382 *       Fun:   SAlloc
383 *
384 *       Desc:  Allocates a block of memory of at least the specified
385 *              size.
386 *
387 *       Ret:   ROK      - ok
388 *              RFAILED  - failed, general (optional)
389 *
390 *       Notes:
391 *
392 *       File:  ss_mem.c
393 *
394 */
395 /*ss003.301-gaurded under flag SS_FAP*/
396 #ifndef SS_FAP
397 /* ss001.301: Additions */
398 #ifdef SS_HISTOGRAM_SUPPORT 
399 #ifdef ANSI
400 PUBLIC S16 SAlloc
401 (
402 Region region,                  /* region ID */
403 Size *size,                     /* size of block required/allocated */
404 U32 flags,                      /* allocation flags */
405 Data **ptr,                      /* filled with pointer to block */
406 U32   line,
407 U8    *fileName,
408 U8    entId
409 )
410 #else
411 PUBLIC S16 SAlloc(region, size, flags, ptr, line, fileName, entId)
412 Region region;                  /* region ID */
413 Size *size;                     /* size of block required/allocated */
414 U32 flags;                      /* allocation flags */
415 Data **ptr;                     /* filled with pointer to block */
416 U32   line;
417 U8   *fileName;
418 U8    entId;
419 #endif
420 #else
421 #ifdef T2K_MEM_LEAK_DBG
422 PUBLIC S16 SAllocNew
423 (
424 Region region,                  /* region ID */
425 Size *size,                     /* size of block required/allocated */
426 U32 flags,                      /* allocation flags */
427 Data **ptr,                      /* filled with pointer to block */
428 char* file,
429 U32 line
430 )
431 #else
432 #ifdef ANSI
433 PUBLIC S16 SAlloc
434 (
435 Region region,                  /* region ID */
436 Size *size,                     /* size of block required/allocated */
437 U32 flags,                      /* allocation flags */
438 Data **ptr                      /* filled with pointer to block */
439 )
440 #else
441 PUBLIC S16 SAlloc(region, size, flags, ptr)
442 Region region;                  /* region ID */
443 Size *size;                     /* size of block required/allocated */
444 U32 flags;                      /* allocation flags */
445 Data **ptr;                     /* filled with pointer to block */
446 #endif
447 #endif
448 #endif
449 {
450    S16 ret;
451 /* ss001.301: Additions */
452 #ifdef SS_HISTOGRAM_SUPPORT 
453    Bool hstReg = FALSE;
454 #endif /* SS_HISTOGRAM_SUPPORT */
455
456
457    TRC1(SAlloc);
458
459
460 #if (ERRCLASS & ERRCLS_INT_PAR)
461    /* validate region ID */
462    if (region >= SS_MAX_REGS)
463    {
464       SSLOGERROR(ERRCLS_INT_PAR, ESS035, region, "Invalid region");
465       RETVALUE(RFAILED);
466    }
467 #endif
468 #ifndef XEON_SPECIFIC_CHANGES
469    /* Get the region which is assgined with this thread. The region was 
470     * stored in the osCp and is taken with respect to thread ID. This macro
471     * is used only when SS_LOCKLESS_MEMORY flag is used and it overwrites 
472     * the region passed.
473     */
474    region = SS_GET_THREAD_MEM_REGION();
475 #endif
476 /* ss037.103 Removed the semaphore acquisition for performance enhancement */
477 #ifndef SS_PERF
478    /* acquire one semaphore, to protect against deregistration */
479    SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
480    if (ret != ROK)
481    {
482
483 #if (ERRCLASS & ERRCLS_DEBUG)
484       SSLOGERROR(ERRCLS_DEBUG, ESS036, (ErrVal) ret,
485                   "Could not lock region table");
486 #endif
487
488       RETVALUE(RFAILED);
489    }
490
491 #endif
492 #if (ERRCLASS & ERRCLS_INT_PAR)
493    /* verify that this region is present */
494    if (osCp.regionTbl[region].used == FALSE)
495    {
496 /* ss037.103 Removed the semaphore operation for performance enhancement */
497 #ifndef SS_PERF
498 /* ss006.13: addition */
499       if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
500       {
501 #if (ERRCLASS & ERRCLS_DEBUG)
502       SSLOGERROR(ERRCLS_DEBUG, ESS037, ERRZERO, 
503                   "Could not release the semaphore");
504       RETVALUE(RFAILED);
505 #endif
506       }
507 #endif
508       SSLOGERROR(ERRCLS_INT_PAR, ESS038, region, "Region not registered");
509       RETVALUE(RFAILED);
510    }
511 #endif
512 /* ss001.301: Additions */
513 #ifdef SS_HISTOGRAM_SUPPORT 
514    SGetHstGrmInfo(&entId, &hstReg);
515    /* call the memory manager, to allocate this memory */
516    /* ss036.103 - addition for passing memType as dynamic */
517 #ifdef SSI_DEBUG_LEVEL1
518    ret = (osCp.regionTbl[region].alloc)
519                (osCp.regionTbl[region].regCb, size, flags, ptr, 
520                 SS_DYNAMIC_MEM_FLAG, line, fileName, entId, hstReg);
521 #else
522    ret = (osCp.regionTbl[region].alloc)
523                (osCp.regionTbl[region].regCb, size, flags, ptr, line, 
524                 fileName, entId, hstReg);
525 #endif /* SSI_DEBUG_LEVEL1 */
526
527 #else
528
529    /* call the memory manager, to allocate this memory */
530 /* ss036.103 - addition for passing memType as dynamic */
531 #ifdef SSI_DEBUG_LEVEL1
532    ret = (osCp.regionTbl[region].alloc)
533                (osCp.regionTbl[region].regCb, size, flags, ptr, SS_DYNAMIC_MEM_FLAG);
534 #else
535 #ifdef SS_LOCKLESS_MEMORY
536 #ifdef T2K_MEM_LEAK_DBG
537    ret = (osCp.dynRegionTbl[region].alloc)
538                (osCp.dynRegionTbl[region].regCb, size, flags, ptr,file,line);
539 #else
540    ret = (osCp.dynRegionTbl[region].alloc)
541                (osCp.dynRegionTbl[region].regCb, size, flags, ptr);
542 #endif
543 #else
544 #ifdef T2K_MEM_LEAK_DBG
545    ret = (osCp.regionTbl[region].alloc)
546                (osCp.regionTbl[region].regCb, size, flags, ptr,file,line);
547 #else
548    ret = (osCp.regionTbl[region].alloc)
549                (osCp.regionTbl[region].regCb, size, flags, ptr);
550 #endif
551 #endif /* SS_LOCKLESS_MEMORY */
552 #endif /* SSI_DEBUG_LEVEL1 */
553
554 #endif /* SS_HISTOGRAM_SUPPORT */
555
556 /* ss037.103 Removed the semaphore operation for performance enhancement */
557
558 #ifndef SS_PERF
559    /* release the semaphore we took */
560 /* ss006.13: addition */
561    if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
562    {
563 #if (ERRCLASS & ERRCLS_DEBUG)
564      SSLOGERROR(ERRCLS_DEBUG, ESS039, ERRZERO, 
565                   "Could not release the semaphore");
566      RETVALUE(RFAILED);
567 #endif
568    }
569 #endif
570 /* ss036.103 - Addition to handle the memory trampling return value
571 * This in turn can call SRegMemErrHdlr 
572 */
573 #ifdef SSI_DEBUG_LEVEL1
574     if (ret == RTRAMPLINGNOK)
575     {
576         SRegMemErrHdlr( region,  *ptr,  ret);
577     }
578 #endif /* SSI_DEBUG_LEVEL1 */
579
580    RETVALUE(ret);
581 }
582
583 \f
584 /*
585 *
586 *       Fun:   SFree
587 *
588 *       Desc:  Frees a block of memory previously allocated by SAlloc().
589 *
590 *       Ret:   ROK      - ok
591 *              RFAILED  - failed, general (optional)
592 *
593 *       Notes:
594 *
595 *       File:  ss_mem.c
596 *
597 */
598 /* ss001.301: Additions */
599 #ifdef SS_HISTOGRAM_SUPPORT 
600 #ifdef ANSI
601 PUBLIC S16 SFree
602 (
603 Region region,                  /* region ID */
604 Data *ptr,                      /* pointer to the allocated block */
605 Size size,                      /* size of block */
606 U32  line,
607 U8   *fileName,
608 U8   entId
609 )
610 #else
611 PUBLIC S16 SFree(region, ptr, size, line, fileName, entId)
612 Region region;                  /* region ID */
613 Data *ptr;                      /* pointer to the allocated block */
614 Size size;                      /* size of block */
615 U32  line;
616 U8   *fileName;
617 U8   entId;
618 #endif
619 #else
620 #ifdef ANSI
621 #ifdef T2K_MEM_LEAK_DBG
622 PUBLIC S16 SFreeNew
623 (
624 Region region,                  /* region ID */
625 Data *ptr,                      /* pointer to the allocated block */
626 Size size,                       /* size of block */
627 char* file,
628 U32 line
629 )
630 #else
631 PUBLIC S16 SFree
632 (
633 Region region,                  /* region ID */
634 Data *ptr,                      /* pointer to the allocated block */
635 Size size                       /* size of block */
636 )
637 #endif
638 #else
639 PUBLIC S16 SFree(region, ptr, size)
640 Region region;                  /* region ID */
641 Data *ptr;                      /* pointer to the allocated block */
642 Size size;                      /* size of block */
643 #endif
644 #endif
645 {
646    S16 ret;
647
648 /* ss001.301: Additions */
649 #ifdef SS_HISTOGRAM_SUPPORT 
650    Bool hstReg = FALSE;
651 #endif /* SS_HISTOGRAM_SUPPORT */
652
653
654    TRC1(SFree);
655
656    /* Get the region which is assgined with this thread. The region was 
657     * stored in the osCp and is taken with respect to thread ID. This macro
658     * is used only when SS_LOCKLESS_MEMORY flag is used and it overwrites 
659     * the region passed.
660     */
661 #ifdef XEON_SPECIFIC_CHANGES
662    region = 0;
663 #else   
664    region = SS_GET_THREAD_MEM_REGION();
665 #endif   
666
667 #if (ERRCLASS & ERRCLS_INT_PAR)
668    /* validate region ID */
669    if (region >= SS_MAX_REGS)
670    {
671       SSLOGERROR(ERRCLS_INT_PAR, ESS040, region, "Invalid region");
672       RETVALUE(RFAILED);
673    }
674
675 /* ss021.103 - Addition to validate size and ptr */
676    if (size <= NULLD)
677    {
678       SSLOGERROR(ERRCLS_INT_PAR, ESS041, region, "Invalid size");
679       RETVALUE(RFAILED);
680    }
681
682    /* validate ptr */
683    if (ptr == (Data *)NULLP)
684    {
685       SSLOGERROR(ERRCLS_INT_PAR, ESS042, region, "Invalid ptr");
686       RETVALUE(RFAILED);
687    }
688
689 #endif
690 /* ss037.103 Removed the semaphore operation for performance enhancement */
691
692 #ifndef SS_PERF
693    /* acquire one semaphore, to protect against deregistration */
694    SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
695    if (ret != ROK)
696    {
697
698 #if (ERRCLASS & ERRCLS_DEBUG)
699       SSLOGERROR(ERRCLS_DEBUG, ESS043, (ErrVal) ret,
700                   "Could not lock region table");
701 #endif
702
703       RETVALUE(RFAILED);
704    }
705 #endif
706 #if (ERRCLASS & ERRCLS_INT_PAR)
707    /* verify that this region is around */
708    if (osCp.regionTbl[region].used == FALSE)
709    {
710 #ifndef SS_PERF
711 /* ss006.13: addition */
712       if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
713       {
714 #if (ERRCLASS & ERRCLS_DEBUG)
715          SSLOGERROR(ERRCLS_DEBUG, ESS044, ERRZERO, 
716                   "Could not release the semaphore");
717          RETVALUE(RFAILED);
718 #endif
719        }
720 #endif
721       SSLOGERROR(ERRCLS_INT_PAR, ESS045, region, "Region not registered");
722       RETVALUE(RFAILED);
723    }
724 #endif
725
726 /* ss001.301: Additions */
727 #ifdef SS_HISTOGRAM_SUPPORT 
728    SGetHstGrmInfo(&entId, &hstReg);
729
730    /* call the memory manager to free this memory */
731    ret = (osCp.regionTbl[region].free)
732            (osCp.regionTbl[region].regCb, ptr, size, line, fileName, 
733             entId, hstReg);
734
735 #else
736
737    /* call the memory manager to free this memory */
738 #ifdef SS_LOCKLESS_MEMORY
739 #ifdef T2K_MEM_LEAK_DBG
740    ret = (osCp.dynRegionTbl[region].free)(osCp.dynRegionTbl[region].regCb, ptr, size,file,line);
741 #else
742    ret = (osCp.dynRegionTbl[region].free)(osCp.dynRegionTbl[region].regCb, ptr, size);
743 #endif
744 #else
745 #ifdef T2K_MEM_LEAK_DBG
746    ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,file,line);
747 #else
748    ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
749 #endif
750 #endif /* SS_LOCKLESS_MEMORY */
751
752 #endif /* SS_HISTOGRAM_SUPPORT */
753
754 /* ss037.103 Removed the semaphore operation for performance enhancement */
755
756 #ifndef SS_PERF
757    /* release the semaphore we took */
758 /* ss006.13: addition */
759    if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
760    {
761 #if (ERRCLASS & ERRCLS_DEBUG)
762       SSLOGERROR(ERRCLS_DEBUG, ESS046, ERRZERO, 
763                   "Could not release the semaphore");
764       RETVALUE(RFAILED);
765 #endif
766     }
767 #endif
768 /* ss036.103 - changes to handle double free and trmapling return values
769 * This in turn may invoke SRegMemErrHdlr 
770 */
771 #ifdef SSI_DEBUG_LEVEL1
772     /* handle the double free error here by calling the OS specific error handling function */
773     if ((ret == RDBLFREE) || (ret == RTRAMPLINGNOK))
774     {
775         SRegMemErrHdlr( region,  ptr,  ret);
776     }
777 #endif /* SSI_DEBUG_LEVEL1 */
778
779    RETVALUE(ret);
780 }
781 #endif /* SS_FAP */
782
783 #ifndef SS_FAP
784 /* ss001.301: Additions */
785 #ifdef SS_HISTOGRAM_SUPPORT 
786
787 /*
788 *
789 *       Fun:  SHstGrmInfoShow 
790 *
791 *       Desc:  This function displays the memory usage information
792 *              per Tapa task, which are registerd during initialization.
793 *
794 *
795 *       Ret:   
796 *              
797 *
798 *       Notes: A Sample Output from the function 
799 *       Memory Histogram for the Tapa task = (Entity Id)117
800 *       ------Region Id = 0-------
801 *       -----------Bucket Id = 0-----------
802 *
803 *      File Name|   Line  | Bucket Alloc | Bytes Allocated | Bytes Wasted | Buckets Freed|Bytes Freed|
804 *      lhi.c    |    413  |            4 |             512 |          224 |            0 |         0 |
805 *      hi_acc1.c|    333  |            0 |               0 |            0 |            2 |       256 |
806 *      hi_acc1.c|    209  |           13 |            1664 |          728 |            0 |         0 |
807 *
808 *       File:  mt_ss.c
809 *
810 */
811 #ifdef ANSI
812 PUBLIC S16 SHstGrmInfoShow 
813 (
814 Ent      *entId
815 )
816 #else
817 PUBLIC S16 SHstGrmInfoShow(entId)
818 Ent      *entId;
819 #endif
820 {
821     /*ss012.301 : Increased Buffer size to fix segmentation fault*/
822     Txt                                         prntBuf[511];  /* Buffer to print on the console */
823         U16                                     ret = ROK;     /* return value */
824         Ent                                     tapaTsk[SS_MAX_TTSKS]; /* List of tapa task */
825         U32                                     tskCnt = 0;   /* Tapa task Count */
826         U32                                     regCnt = 0;   /* Region count */
827         U32                                     bktCnt = 0;   /* Bucket count in each region */
828         CmHstGrmHashListCp      *hashListCp = NULLP; /* Hash List ponter of bucket */
829         U32                  binCnt = 0;   
830         U32                  entCnt = 0;
831         CmMemEntries        *entry = NULLP;
832         U32                  blkSize = 0;
833    
834    TRC1(SRegInfoShow);
835
836    memset(tapaTsk, ENTNC, sizeof(tapaTsk));
837
838    if(entId == NULLP)
839         {
840             /* If user is not asking for specific entity id then,
841                   * Take Tapa task entity id from the osCp structure and 
842                   * print the histogram for all tapa task */
843         ret = SGetTapaTskEntIds(tapaTsk);
844         }/* End of if */
845         else
846         {
847            /* If user asked for specific tapa task then print histogram 
848                  * for those tapa task */
849                 for(tskCnt = 0; entId[tskCnt]; tskCnt++) 
850                 { 
851                         tapaTsk[tskCnt] = entId[tskCnt];
852                 }/* end of for */
853         }
854    for (tskCnt = 0; tapaTsk[tskCnt] != ENTNC; tskCnt++)
855         {
856         sprintf(prntBuf, "\n\nMemory Histogram for the Tapa task = (Entity Id)%d\n", tapaTsk[tskCnt]);
857         SPrint(prntBuf);
858                 for (regCnt = 0; regCnt < osCp.numRegions; regCnt++)
859                 {
860                    
861                         CmMmRegCb* regCb = (CmMmRegCb*)osCp.regionTbl[regCnt].regCb;
862
863                 sprintf(prntBuf, "------Region Id = %d-------\n", regCb->region);
864                 SPrint(prntBuf);
865          for (bktCnt = 0; bktCnt < regCb->numBkts; bktCnt++)
866                         {
867                                                  /* ss002.301 - Compilation fixes */
868             /*ss013.301 Fix for compilation warnings  32/64 bit */                
869 #ifdef ALIGN_64BIT
870                         sprintf(prntBuf, "-----------Bucket Id = %u-----------\n\n", bktCnt);
871 #else
872                         sprintf(prntBuf, "-----------Bucket Id = %lu-----------\n\n", bktCnt);
873 #endif
874                         SPrint(prntBuf);
875                         sprintf(prntBuf, "File Name         |   Line  | Bucket Alloc | Bytes Allocated | Bytes Wasted | Buckets Freed|Bytes Freed|\n");
876                         SPrint(prntBuf);
877                            hashListCp = &(regCb->bktTbl[bktCnt].hstGrmHashListCp);
878                            blkSize = regCb->bktTbl[bktCnt].size;
879                            for(binCnt = 0; binCnt < CMM_HIST_MAX_MEM_BIN; binCnt++)
880                                 {
881                                         for (entCnt = 0; entCnt < hashListCp->hashList[binCnt].numOfEntries; entCnt++)
882                                         {
883                                             entry = &(hashListCp->hashList[binCnt].entries[entCnt]);   
884                                                  if(entry->entId == tapaTsk[tskCnt])
885                                                  {
886                                                  /* ss002.301 - Compilation fixes */
887                          /*ss013.301 Fix for compilation warnings  32/64 bit */                
888 #ifdef ALIGN_64BIT
889                                                         sprintf(prntBuf, 
890                                                            "%-18s|%7u  |%13u |%16u |%13u |%13u |%10u |\n", 
891                         entry->fileName, entry->line, entry->bucketAllocReq, 
892                                                                 (blkSize*entry->bucketAllocReq), entry->wastedBytes, 
893                                                                 entry->bucketFreeReq, (blkSize*entry->bucketFreeReq));
894 #else
895                                                         sprintf(prntBuf, 
896                                                            "%-18s|%7lu  |%13lu |%16lu |%13lu |%13lu |%10lu |\n", 
897                         entry->fileName, entry->line, entry->bucketAllocReq, 
898                                                                 (blkSize*entry->bucketAllocReq), entry->wastedBytes, 
899                                                                 entry->bucketFreeReq, (blkSize*entry->bucketFreeReq));
900 #endif
901                      SPrint(prntBuf);
902                                                  }/* End of If */
903                                         }/* end of for. Entry count */
904                                 } /* End of for. Hash bin count */ 
905                          }
906
907                         sprintf(prntBuf, "\n\n----------- Heap blocks -----------\n\n");
908                         SPrint(prntBuf);
909                         sprintf(prntBuf, "File Name         |   Line  | Heap Allocs  | Bytes Allocated | Bytes Wasted |  Heap Frees  |Bytes Freed|\n");
910                         SPrint(prntBuf);
911                            hashListCp = &(regCb->heapCb.heapHstGrmHashListCp);
912                            for(binCnt = 0; binCnt < CMM_HIST_MAX_MEM_BIN; binCnt++)
913                                 {
914                                         for (entCnt = 0; entCnt < hashListCp->hashList[binCnt].numOfEntries; entCnt++)
915                                         {
916                                             entry = &(hashListCp->hashList[binCnt].entries[entCnt]);   
917                                                  if(entry->entId == tapaTsk[tskCnt])
918                                                  {
919                                                  /* ss002.301 - Compilation fixes */
920                          /*ss013.301 Fix for compilation warnings  32/64 bit */                
921 #ifdef ALIGN_64BIT
922                                                         sprintf(prntBuf, 
923                                                             "%-18s|%7u  |%13u |%16u |%13u |%13u |%10u |\n", 
924                      entry->fileName, entry->line, entry->bucketAllocReq, 
925                                                         entry->allocBytes, entry->wastedBytes, 
926                                                         entry->bucketFreeReq, entry->freedBytes);
927 #else
928                                                         sprintf(prntBuf, 
929                                                             "%-18s|%7lu  |%13lu |%16lu |%13lu |%13lu |%10lu |\n", 
930                      entry->fileName, entry->line, entry->bucketAllocReq, 
931                                                         entry->allocBytes, entry->wastedBytes, 
932                                                         entry->bucketFreeReq, entry->freedBytes);
933 #endif
934                      SPrint(prntBuf);
935                                                  }/* End of If */
936                                         }/* end of for. Entry count */
937                                 } /* End of for. Hash bin count */ 
938                  }/* End of for. Region Count */
939         } /* End of for (Tapa task)*/
940
941
942    /* Print the memory information used at common, sample and ssi files. 
943          we considerd common Sample file as invalid entity id. */
944         sprintf(prntBuf, "\n\nMemory Histogram for the Tapa task = (Entity Id = ENTNC)%d\n", ENTNC);
945         SPrint(prntBuf);
946         for (regCnt = 0; regCnt < osCp.numRegions; regCnt++)
947         {
948                 CmMmRegCb* regCb = (CmMmRegCb*)osCp.regionTbl[regCnt].regCb;
949
950                 sprintf(prntBuf, "------Region Id = %d-------\n", regCb->region);
951                 SPrint(prntBuf);
952       for (bktCnt = 0; bktCnt < regCb->numBkts; bktCnt++)
953                 {
954                                                  /* ss002.301 - Compilation fixes */
955             /*ss013.301 Fix for compilation warnings  32/64 bit */                
956 #ifdef ALIGN_64BIT
957                         sprintf(prntBuf, "-----------Bucket Id = %u-----------\n\n", bktCnt);
958 #else
959                         sprintf(prntBuf, "-----------Bucket Id = %lu-----------\n\n", bktCnt);
960 #endif
961                         SPrint(prntBuf);
962                         sprintf(prntBuf, "File Name         |   Line  | Bucket Alloc | Bytes Allocated | Bytes Wasted | Buckets Freed|Bytes Freed|\n");
963                         SPrint(prntBuf);
964                    hashListCp = &(regCb->bktTbl[bktCnt].hstGrmHashListCp);
965                    blkSize = regCb->bktTbl[bktCnt].size;
966                    for(binCnt = 0; binCnt < CMM_HIST_MAX_MEM_BIN; binCnt++)
967                         {
968                                 for (entCnt = 0; entCnt < hashListCp->hashList[binCnt].numOfEntries; entCnt++)
969                                 {
970                                     entry = &(hashListCp->hashList[binCnt].entries[entCnt]);   
971                                          if(entry->entId == tapaTsk[tskCnt])
972                                          {
973                                                  /* ss002.301 - Compilation fixes */
974             /*ss013.301 Fix for compilation warnings  32/64 bit */                
975 #ifdef ALIGN_64BIT
976                                                 sprintf(prntBuf, "%-18s|%7u  |%13u |%16u |%13u |%13u |%10u |\n", 
977                   entry->fileName, entry->line, entry->bucketAllocReq, (blkSize*entry->bucketAllocReq),
978                                                 entry->wastedBytes, entry->bucketFreeReq, (blkSize*entry->bucketFreeReq));
979 #else
980                                                 sprintf(prntBuf, "%-18s|%7lu  |%13lu |%16lu |%13lu |%13lu |%10lu |\n", 
981                   entry->fileName, entry->line, entry->bucketAllocReq, (blkSize*entry->bucketAllocReq),
982                                                 entry->wastedBytes, entry->bucketFreeReq, (blkSize*entry->bucketFreeReq));
983 #endif
984                   SPrint(prntBuf);
985                                          }/* End of If */
986                                 }/* end of for. Entry count */
987                         } /* End of for. Hash bin count */ 
988
989                  }/* End of for. Bucket Count */
990
991                 sprintf(prntBuf, "\n\n----------- Heap blocks -----------\n\n");
992                 SPrint(prntBuf);
993                 sprintf(prntBuf, "File Name         |   Line  | Heap Allocs  | Bytes Allocated | Bytes Wasted |  Heap Frees  |Bytes Freed|\n");
994                 SPrint(prntBuf);
995                         hashListCp = &(regCb->heapCb.heapHstGrmHashListCp);
996                         for(binCnt = 0; binCnt < CMM_HIST_MAX_MEM_BIN; binCnt++)
997                         {
998                                         for (entCnt = 0; entCnt < hashListCp->hashList[binCnt].numOfEntries; entCnt++)
999                                         {
1000                                             entry = &(hashListCp->hashList[binCnt].entries[entCnt]);   
1001                                                  if(entry->entId == tapaTsk[tskCnt])
1002                                                  {
1003                                                  /* ss002.301 - Compilation fixes */
1004                          /*ss013.301 Fix for compilation warnings  32/64 bit */                
1005 #ifdef ALIGN_64BIT
1006                                                         sprintf(prntBuf, 
1007                                                             "%-18s|%7u  |%13u |%16u |%13u |%13u |%10u |\n", 
1008                      entry->fileName, entry->line, entry->bucketAllocReq, 
1009                                                         entry->allocBytes, entry->wastedBytes, 
1010                                                         entry->bucketFreeReq, entry->freedBytes);
1011 #else
1012                                                         sprintf(prntBuf, 
1013                                                             "%-18s|%7lu  |%13lu |%16lu |%13lu |%13lu |%10lu |\n", 
1014                      entry->fileName, entry->line, entry->bucketAllocReq, 
1015                                                         entry->allocBytes, entry->wastedBytes, 
1016                                                         entry->bucketFreeReq, entry->freedBytes);
1017 #endif
1018                      SPrint(prntBuf);
1019                                                  }/* End of If */
1020                                         }/* end of for. Entry count */
1021                         } /* End of for. Hash bin count */ 
1022
1023          }/* End of for. Region Count */
1024
1025    RETVALUE(ROK);
1026 }   
1027
1028 #endif /* SS_HISTOGRAM_SUPPORT */
1029 #endif /* SS_FAP */
1030
1031 /**********************************************************************
1032          End of file
1033  **********************************************************************/