Memory handling fixes
[o-du/l2.git] / src / 5gnrrlc / rlc_stats.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
19 /**********************************************************************
20  
21     Name:  
22  
23     Type:   C include file
24  
25     Desc:   
26  
27     File:  rlc_stats.c
28  
29 **********************************************************************/
30
31 /* header (.h) include files */
32 #include "common_def.h"
33 #include "lkw.h"           /* LKW defines */
34 #include "ckw.h"           /* CKW defines */
35 #include "kwu.h"           /* KWU defines */
36 #include "rgu.h"           /* RGU defines */
37 #include "rlc_err.h"        /* RLC error options */
38 #include "rlc_env.h"        /* RLC environment options */
39
40 /* extern (.x) include files */
41 #include "lkw.x"           /* LKW */
42 #include "ckw.x"           /* CKW */
43 #include "kwu.x"           /* KWU */
44 #include "rgu.x"           /* RGU */
45
46 #ifdef TENB_STATS
47 #include "l2_tenb_stats.x"    /* Total EnodeB Stats declarations */
48 #endif
49
50 #include "rlc_utils.h"            /* RLC defines */
51 #include "rlc_ul.h"
52
53 #ifdef TENB_STATS
54 TSL2CellStatsCb* l2CellStats[L2_STATS_MAX_CELLS];
55 TSL2UeStatsCb*   l2UeStats[L2_STATS_MAX_UES];
56 CmLListCp        freeL2UeStatsLst; /*!< Free Pool of UE stats Blocks */
57 CmLListCp        inUseL2UeStatsLst;/*!< In Use Pool of UE stats Blocks */
58
59 /*
60 *
61 *       Fun:   TSL2AllocStatsMem
62 *
63 *       Desc:  Pre-Allocate Memory for L2 stats BLOCKs 
64 *
65 *       Ret:   
66 *
67 *       Notes: None
68 *
69 *
70 */
71 Void TSL2AllocStatsMem(Inst inst)
72 {
73    uint32_t cnt=0;
74    RlcCb *gCb;
75
76    gCb = RLC_GET_RLCCB(inst);
77    cmLListInit(&inUseL2UeStatsLst);     
78    cmLListInit(&freeL2UeStatsLst);      
79    for (cnt=0; cnt < L2_STATS_MAX_CELLS; cnt++)
80    {
81       if(NULL == l2CellStats[cnt])
82       {
83          RLC_ALLOC(gCb, l2CellStats[cnt], (Size)sizeof (TSL2CellStatsCb));
84          if(l2CellStats[cnt] == NULL)
85          {
86             DU_LOG("\nERROR  -->  RLC : STATS Unexpected MEM Alloc Failure\n");
87          }
88       }
89       memset(l2CellStats[cnt], 0x00, sizeof(TSL2CellStatsCb));
90    }
91
92    for (cnt=0; cnt < L2_STATS_MAX_UES; cnt++)
93    {
94       TSL2UeStatsCb *statsCb = l2UeStats[cnt];
95       if(NULL == statsCb)
96       {
97          RLC_ALLOC(gCb, statsCb, (Size)sizeof (TSL2UeStatsCb));
98          if(NULL == statsCb)        
99          {
100             DU_LOG("\nERROR  -->   RLC : STATS Unexpected MEM Alloc Failure at %d\n", (int)cnt);
101          }
102       }
103       memset(statsCb, 0x00, sizeof(TSL2UeStatsCb));
104       statsCb->lnk.node = (PTR)statsCb;
105       cmLListAdd2Tail(&freeL2UeStatsLst, &statsCb->lnk);
106       l2UeStats[cnt] = statsCb;
107    }
108
109    return;
110 }
111
112 /*
113  *
114  *       Fun:   TSL2AllocUeStatsBlk
115  *
116  *       Desc:  Assign Stats Block for this UE[RNTI] 
117  *
118  *       Ret:   
119  *
120  *       Notes: None
121  *
122  *
123  */
124 TSL2UeStatsCb* TSL2AllocUeStatsBlk (uint16_t rnti)
125 {
126    CmLList          *tmp = NULLP;
127    TSL2UeStatsCb  *statsCb = NULLP;
128
129    tmp = freeL2UeStatsLst.first;
130    if (tmp == NULLP)
131    {
132       DU_LOG("\nERROR  -->  RLC :  STATS Unexpected Mem BLK unavailable for UE %d\n", rnti);
133    }
134    cmLListDelFrm(&freeL2UeStatsLst, tmp);
135    statsCb = (TSL2UeStatsCb *)(tmp->node);
136    cmLListAdd2Tail(&inUseL2UeStatsLst, tmp);
137
138    statsCb->stats.rnti = (uint32_t)rnti;
139    statsCb->inUse = TRUE;
140
141    return (statsCb);
142 }
143
144 /*
145  *
146  *       Fun:   TSL2DeallocUeStatsBlk
147  *
148  *       Desc:  Deassign Stats Block for this UE[RNTI] 
149  *
150  *       Ret:   
151  *
152  *       Notes: None
153  *
154  *
155  */
156 Void TSL2DeallocUeStatsBlk(uint16_t rnti,TSL2UeStatsCb *statsCb)
157 {
158    statsCb->inUse = FALSE;
159    cmLListDelFrm(&inUseL2UeStatsLst, &statsCb->lnk);
160    freeL2UeStatsLst.crnt = freeL2UeStatsLst.first;
161    cmLListInsAfterCrnt(&freeL2UeStatsLst, &statsCb->lnk);
162
163    return;
164 }
165
166 /*
167  *
168  *       Fun:   TSL2AllocCellStatsBlk
169  *
170  *       Desc:  Assign Stats Block for this CELL[CELLID] 
171  *
172  *       Ret:   
173  *
174  *       Notes: None
175  *
176  *
177  */
178 TSL2CellStatsCb* TSL2AllocCellStatsBlk(uint32_t cellId)
179 {
180    if (cellId != 1)
181    {
182       DU_LOG("\nERROR  -->  RLC : STATS Unexpected CellID = %d\n", (int)cellId);
183    }
184
185    return (l2CellStats[cellId-1]);
186 }
187
188 /*
189  *
190  *       Fun:   TSL2DeallocCellStatsBlk
191  *
192  *       Desc:  Deassign Stats Block for this CELL[CELLID] 
193  *
194  *       Ret:   
195  *
196  *       Notes: None
197  *
198  *
199  */
200 Void TSL2DeallocCellStatsBlk(uint32_t cellId)
201 {
202
203    return;
204 }
205
206 /*
207  *
208  *       Fun:   TSL2SendStatsToApp
209  *
210  *       Desc:  Collates and Sends STATS to Application 
211  *              Send UE STATS first. 10 UEs are grouped in one message.
212  *              Followed by CELL Stats. All CELLS are grouped in one msg.
213  *              At Reception of CELL stats APP assumes STATS reception cycle is complete.
214  *
215  *       Ret:   
216  *
217  *       Notes: None
218  *
219  *
220  */
221 Void TSL2SendStatsToApp(Pst    *pst, SuId   suId)
222 {
223    uint32_t idx;
224
225    for (idx = 0; idx < L2_STATS_MAX_UES; idx++)
226    {
227       TSL2UeStatsCb *statsCb = l2UeStats[idx];
228       uint32_t rnti;
229       if (statsCb->inUse != TRUE)
230       {
231          continue;
232       }
233       if (pst->selector == 0)
234       {
235          /* Loose Coupling */
236          TSInfPkSndL2UeStats(pst, suId, &statsCb->stats);
237       }
238       else
239       {
240 #ifdef PX
241          /* Tight Coupling */
242          TSInfHdlL2UeStatsInd(pst, suId, &statsCb->stats);
243 #endif
244       }
245       rnti = statsCb->stats.rnti;
246       memset(&statsCb->stats.nonPersistent, 0x00, sizeof(statsCb->stats.nonPersistent));
247       /* memset(&statsCb->stats, 0x00, sizeof(TSInfL2UeStats)); */
248       statsCb->stats.rnti = rnti;
249    }
250
251    /* Allocate mBuf for CELLSTATS */
252    for (idx = 0; idx < L2_STATS_MAX_CELLS; idx++)
253    {
254       TSL2CellStatsCb *statsCellCb = l2CellStats[idx];
255       uint32_t cellId;
256       if (pst->selector == 0)
257       {
258          /* Loose Coupling */
259          TSInfPkSndL2CellStats(pst, suId, l2CellStats[idx]);
260       }
261       else
262       {
263 #ifdef PX
264          /* Tight Coupling */
265          TSInfHdlL2CellStatsInd(pst, suId, l2CellStats[idx]);
266 #endif
267       }
268       cellId = statsCellCb->cellId;
269       memset(l2CellStats[idx], 0x00, sizeof(TSInfL2CellStats));
270       statsCellCb->cellId = cellId;
271    }
272    return;
273 }
274 #endif /* TENB_STATS */
275 /**********************************************************************
276   End of file
277  **********************************************************************/