3c8e706f79d432ba698d2d07518a35b296a4f437
[o-du/l2.git] / src / cm / cm_lte.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:     Common LTE
22   
23      Type:     C source file
24   
25      Desc:     C code for packing/unpacking of cm_lte data structures. 
26   
27      File:     cm_lte.c 
28   
29 **********************************************************************/
30
31 /* header include files (.h) */
32
33 #include "envopt.h"             /* environment options */  
34 #include "envdep.h"             /* environment dependent */
35 #include "envind.h"             /* environment independent */
36
37 /* header/extern include files (.x) */
38
39 #include "gen.h"           /* general layer */
40 #include "ssi.h"           /* system services */
41 #include "cm_lte.h"             /* common lte header file */
42 #include "cm5.h"           /* common timers */
43 #include "mt_ss.h"         /* MTSS specific */
44 #include "mt_err.h"        /* MTSS error defines */
45 #include "ss_queue.h"      /* queues */
46 #include "ss_task.h"       /* tasking */
47 #include "ss_msg.h"        /* messaging */
48 #include "ss_mem.h"        /* memory management interface */
49 #include "ss_gen.h"        /* general */
50 /* mt003.301 Additions - Task deregistration */
51 #include "ss_err.h"        /* error */
52
53
54 /* header/extern include files (.x) */
55
56 #include "gen.x"           /* general layer */
57 #include "ssi.x"           /* system services */
58 #include "cm_lte.x"             /* common lte header file */
59 #include "cm5.x"           /* common timers */
60 #include "mt_ss.x"         /* MTSS specific */
61 #include "ss_queue.x"      /* queues */
62 #include "ss_task.x"       /* tasking */
63 #include "ss_timer.x"      /* timers */
64 #include "ss_strm.h"
65 #include "ss_strm.x"       /* STREAMS */
66 #include "ss_msg.x"        /* messaging */
67 #include "ss_mem.x"        /* memory management interface */
68 #include "ss_drvr.x"       /* driver tasks */
69 #include "ss_gen.x"        /* general */
70
71
72 /* public variable declarations */
73 uint32_t cmLteTime;
74
75 \f
76 /***********************************************************
77 *
78 *     Func : cmPkLteRlcId
79 *
80 *
81 *     Desc : RLC Identifier
82 *
83 *
84 *     Ret  : S16
85 *
86 *     Notes:
87 *
88 *     File  : 
89 *
90 **********************************************************/
91 S16 cmPkLteRlcId(CmLteRlcId *param,Buffer *mBuf)
92 {
93
94
95    CMCHKPK(cmPkLteCellId, param->cellId, mBuf);
96    CMCHKPK(cmPkLteRnti, param->ueId, mBuf);
97    CMCHKPK(oduUnpackUInt8, param->rbType, mBuf);
98    CMCHKPK(cmPkLteRbId, param->rbId, mBuf);
99    return ROK;
100 }
101
102
103 \f
104 /***********************************************************
105 *
106 *     Func : cmUnpkLteRlcId
107 *
108 *
109 *     Desc : RLC Identifier
110 *
111 *
112 *     Ret  : S16
113 *
114 *     Notes:
115 *
116 *     File  : 
117 *
118 **********************************************************/
119 S16 cmUnpkLteRlcId(CmLteRlcId *param,Buffer *mBuf)
120 {
121
122
123    CMCHKUNPK(cmUnpkLteRbId, &param->rbId, mBuf);
124    CMCHKUNPK(oduPackUInt8, &param->rbType, mBuf);
125    CMCHKUNPK(cmUnpkLteRnti, &param->ueId, mBuf);
126    CMCHKUNPK(cmUnpkLteCellId, &param->cellId, mBuf);
127    return ROK;
128 }
129
130
131 \f
132 /***********************************************************
133 *
134 *     Func : cmPkLteTimingInfo
135 *
136 *
137 *     Desc : LTE Timing Info
138 *
139 *
140 *     Ret  : S16
141 *
142 *     Notes:
143 *
144 *     File  : 
145 *
146 **********************************************************/
147 S16 cmPkLteTimingInfo(CmLteTimingInfo *param,Buffer *mBuf)
148 {
149
150
151    CMCHKPK(oduUnpackUInt16, param->slot, mBuf);
152    CMCHKPK(oduUnpackUInt16, param->sfn, mBuf);
153    //CMCHKPK(oduUnpackUInt16, param->hSfn, mBuf);
154    return ROK;
155 }
156
157
158 \f
159 /***********************************************************
160 *
161 *     Func : cmUnpkLteTimingInfo
162 *
163 *
164 *     Desc : LTE Timing Info
165 *
166 *
167 *     Ret  : S16
168 *
169 *     Notes:
170 *
171 *     File  : 
172 *
173 **********************************************************/
174 S16 cmUnpkLteTimingInfo(CmLteTimingInfo *param,Buffer *mBuf)
175 {
176
177
178    //CMCHKUNPK(oduPackUInt16, &param->hSfn, mBuf);
179    CMCHKUNPK(oduPackUInt16, &param->sfn, mBuf);
180    CMCHKUNPK(oduPackUInt16,&param->slot, mBuf);
181    return ROK;
182 }
183
184
185 \f
186 /***********************************************************
187 *
188 *     Func : cmPkLtePdcpId
189 *
190 *
191 *     Desc : PDCP Id
192 *
193 *
194 *     Ret  : S16
195 *
196 *     Notes:
197 *
198 *     File  : 
199 *
200 **********************************************************/
201 S16 cmPkLtePdcpId(CmLtePdcpId *param,Buffer *mBuf)
202 {
203
204
205    CMCHKPK(oduUnpackUInt8, param->rbType, mBuf);
206    CMCHKPK(cmPkLteRbId, param->rbId, mBuf);
207    CMCHKPK(cmPkLteRnti, param->ueId, mBuf);
208    CMCHKPK(cmPkLteCellId, param->cellId, mBuf);
209    return ROK;
210 }
211
212
213 \f
214 /***********************************************************
215 *
216 *     Func : cmUnpkLtePdcpId
217 *
218 *
219 *     Desc : PDCP Id
220 *
221 *
222 *     Ret  : S16
223 *
224 *     Notes:
225 *
226 *     File  : 
227 *
228 **********************************************************/
229 S16 cmUnpkLtePdcpId(CmLtePdcpId *param,Buffer *mBuf)
230 {
231
232
233    CMCHKUNPK(cmUnpkLteCellId, &param->cellId, mBuf);
234    CMCHKUNPK(cmUnpkLteRnti, &param->ueId, mBuf);
235    CMCHKUNPK(cmUnpkLteRbId, &param->rbId, mBuf);
236    CMCHKUNPK(oduPackUInt8, &param->rbType, mBuf);
237    return ROK;
238 }
239 #ifdef LTE_L2_MEAS 
240 S16 cmUpdateSsiMemInfo(CmLteMemInfo *mInfo)
241 {
242    uint8_t   numReg = 0;
243    uint8_t   numPool = 0;
244    uint8_t   idxReg;
245    uint8_t   idxPool;
246    SsMemDbgInfo dbgInfo;
247
248    SGetRegPoolInfo(&numReg,&numPool); 
249    mInfo->numRegions = numReg;
250
251    for(idxReg=0; idxReg< numReg; idxReg++)
252    {
253       SGetRegInfo(idxReg, &dbgInfo);
254
255       if(mInfo->regInfo[idxReg].isGenMemInfoUpdated == TRUE)
256       {
257          for(idxPool=0; idxPool<numPool; idxPool++)
258          {
259             mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = dbgInfo.bktDbgTbl[idxPool].numAlloc;
260             if(mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed > mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed)
261                mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed = mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
262          }
263       }
264       else
265       {
266       mInfo->regInfo[idxReg].numPools = numPool;
267       mInfo->regInfo[idxReg].regionId = idxReg;
268       mInfo->regInfo[idxReg].regionType = 0;
269
270       for(idxPool=0; idxPool<numPool; idxPool++)
271       {
272          mInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = dbgInfo.bktDbgTbl[idxPool].numBlks;
273          mInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = dbgInfo.bktDbgTbl[idxPool].size;
274          mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = dbgInfo.bktDbgTbl[idxPool].numAlloc;
275          if(mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed > mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed)
276             mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed = mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
277       }
278          mInfo->regInfo[idxReg].isGenMemInfoUpdated = TRUE; 
279       }
280    }
281    return ROK;
282 }
283
284 S16 cmFillMemUtilizationMeas( CmLteMemInfo *memoryInfo,CmLteMemInfo *memInfo)
285 {
286    uint8_t idxReg = 0;
287    uint8_t idxPool = 0;
288    uint8_t numPool = 0;
289
290    memoryInfo->numRegions = memInfo->numRegions;
291    for(idxReg=0; idxReg < memInfo->numRegions; idxReg++)
292    {
293       memoryInfo->regInfo[idxReg].regionId = memInfo->regInfo[idxReg].regionId;
294       memoryInfo->regInfo[idxReg].numPools = memInfo->regInfo[idxReg].numPools;
295       memoryInfo->regInfo[idxReg].regionType = memInfo->regInfo[idxReg].regionType;
296       numPool = memoryInfo->regInfo[idxReg].numPools;
297
298       for(idxPool=0; idxPool < numPool; idxPool++)
299       {
300          memoryInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = memInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable;
301          memoryInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = memInfo->regInfo[idxReg].poolInfo[idxPool].poolSize;
302          memoryInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = memInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
303          memoryInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed  = memInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed;
304       }
305    }
306    return ROK;
307 }
308
309 S16 cmClearMemUtilizationCounter(CmLteMemInfo *memInfo)
310 {
311    uint8_t idxReg = 0;
312    uint8_t idxPool = 0;
313    uint8_t numPool = 0;
314    for(idxReg=0; idxReg < memInfo->numRegions; idxReg++)
315    {
316       memInfo->regInfo[idxReg].regionId = 0;
317       memInfo->regInfo[idxReg].numPools = 0;
318       memInfo->regInfo[idxReg].regionType = 0;
319       memInfo->regInfo[idxReg].isGenMemInfoUpdated = FALSE;
320       numPool = memInfo->regInfo[idxReg].numPools;
321
322       for(idxPool=0; idxPool<numPool; idxPool++)
323       {
324          memInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = 0;
325          memInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = 0;
326          memInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = 0;
327          memInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed  = 0;
328       }
329    }
330    return ROK;
331 }
332
333 S16 cmClearCpuUtilizationCounter(CmCpuStatsInfo *cpuInfo)
334 {
335    uint8_t idx= 0;
336    for(idx=0; idx < cpuInfo->numCores; idx++)
337    {
338       cpuInfo->cpuUtil[idx].maxCpuUtil = 0;
339       cpuInfo->cpuUtil[idx].totCpuUtil = 0;
340       cpuInfo->cpuUtil[idx].numSamples = 0;
341    }
342    cpuInfo->numCores = 0;
343    return ROK;
344 }
345
346 S16 cmFillCpuUtilizationMeas(CmLteCpuInfo *cpuMeasInfo,CmCpuStatsInfo *cpuInfo)
347 {
348    uint8_t idx= 0;
349    cpuMeasInfo->numCores = cpuInfo->numCores;
350    for(idx=0; idx < cpuInfo->numCores; idx++)
351    {
352       cpuMeasInfo->cpuUtil[idx].avgCpuUtil = cpuInfo->cpuUtil[idx].totCpuUtil/cpuInfo->cpuUtil[idx].numSamples;
353       cpuMeasInfo->cpuUtil[idx].maxCpuUtil = cpuInfo->cpuUtil[idx].maxCpuUtil;
354    }
355    return ROK;
356
357 }
358 #endif
359
360 #ifdef TENB_TTI_PERF
361 CmTtiProc ttiProc;
362 #define TTI_1MS 950
363
364 Void cmUpdateTtiCounters(uint32_t ttiProcessingTime)
365 {
366    ttiProc.numOfTti++;
367    ttiProc.totTtiProcessingTime += ttiProcessingTime;
368    if(ttiProcessingTime > ttiProc.maxTtiProcessingTime)  
369    {
370       ttiProc.maxTtiProcessingTime = ttiProcessingTime;
371    }
372    if(ttiProcessingTime > TTI_THRESHOLD_VALUE)
373    {
374       ttiProc.ttiThresholdExceedCount++;
375    }
376    if(ttiProcessingTime > TTI_1MS)
377    {
378       ttiProc.ttiStretchCount++;
379    }
380    return;    
381 }
382
383 Void cmResetTtiCounters(Void)
384 {
385         ttiProc.totTtiProcessingTime = 0;
386         ttiProc.numOfTti = 0;
387         ttiProc.maxTtiProcessingTime = 0;
388         ttiProc.ttiStretchCount = 0;
389         ttiProc.ttiThresholdExceedCount = 0;
390         ttiProc.phyReptTtiStretchCount = 0;
391         return;
392 }
393 #endif
394
395 /**********************************************************************
396          End of file
397 **********************************************************************/