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