Commit 10eedd66 authored by Sagar Parsawar's avatar Sagar Parsawar

Fixed memory leak issue of nr_gold_prs buffer in gNB

parent 006421d7
...@@ -268,6 +268,9 @@ void init_nr_prs_ue_vars(PHY_VARS_NR_UE *ue) ...@@ -268,6 +268,9 @@ void init_nr_prs_ue_vars(PHY_VARS_NR_UE *ue)
for(int idx = 0; idx < NR_MAX_PRS_COMB_SIZE; idx++) for(int idx = 0; idx < NR_MAX_PRS_COMB_SIZE; idx++)
{ {
prs_vars[idx] = (NR_UE_PRS *)malloc16_clear(sizeof(NR_UE_PRS)); prs_vars[idx] = (NR_UE_PRS *)malloc16_clear(sizeof(NR_UE_PRS));
prs_vars[idx]->ch_tmp = (int16_t *)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t));
prs_vars[idx]->chF_interpol = (int16_t *)malloc16_clear(NR_PRS_IDFT_OVERSAMP_FACTOR*fp->ofdm_symbol_size*sizeof(int32_t));
prs_vars[idx]->chT_interpol = (int16_t *)malloc16_clear(NR_PRS_IDFT_OVERSAMP_FACTOR*fp->ofdm_symbol_size*sizeof(int32_t));
for(int k = 0; k < NR_MAX_PRS_RESOURCES_PER_SET; k++) for(int k = 0; k < NR_MAX_PRS_RESOURCES_PER_SET; k++)
{ {
// PRS channel estimates // PRS channel estimates
...@@ -277,12 +280,12 @@ void init_nr_prs_ue_vars(PHY_VARS_NR_UE *ue) ...@@ -277,12 +280,12 @@ void init_nr_prs_ue_vars(PHY_VARS_NR_UE *ue)
prs_vars[idx]->prs_resource[k].prs_meas = (prs_meas_t **)malloc16_clear( fp->nb_antennas_rx*sizeof(prs_meas_t *) ); prs_vars[idx]->prs_resource[k].prs_meas = (prs_meas_t **)malloc16_clear( fp->nb_antennas_rx*sizeof(prs_meas_t *) );
AssertFatal((prs_vars[idx]->prs_resource[k].prs_meas!=NULL), "NR UE init: PRS measurements malloc failed for gNB_id %d\n", idx); AssertFatal((prs_vars[idx]->prs_resource[k].prs_meas!=NULL), "NR UE init: PRS measurements malloc failed for gNB_id %d\n", idx);
for (int i=0; i<fp->nb_antennas_rx; i++) { for (int j=0; j<fp->nb_antennas_rx; j++) {
prs_vars[idx]->prs_resource[k].prs_ch_estimates[i] = (int32_t *)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t)); prs_vars[idx]->prs_resource[k].prs_ch_estimates[j] = (int32_t *)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t));
prs_vars[idx]->prs_resource[k].prs_ch_estimates_time[i] = (int32_t *)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t)); prs_vars[idx]->prs_resource[k].prs_ch_estimates_time[j] = (int32_t *)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t));
AssertFatal(((prs_vars[idx]->prs_resource[k].prs_ch_estimates[i]!=NULL) || (prs_vars[idx]->prs_resource[k].prs_ch_estimates_time[i]!=NULL)), "NR UE init: PRS channel estimates malloc failed for rx_ant %d\n", i); AssertFatal(((prs_vars[idx]->prs_resource[k].prs_ch_estimates[j]!=NULL) || (prs_vars[idx]->prs_resource[k].prs_ch_estimates_time[j]!=NULL)), "NR UE init: PRS channel estimates malloc failed for rx_ant %d\n", j);
prs_vars[idx]->prs_resource[k].prs_meas[i] = (prs_meas_t *)malloc16_clear(sizeof(prs_meas_t) ); prs_vars[idx]->prs_resource[k].prs_meas[j] = (prs_meas_t *)malloc16_clear(sizeof(prs_meas_t) );
AssertFatal((prs_vars[idx]->prs_resource[k].prs_meas[i]!=NULL), "NR UE init: PRS measurements malloc failed for rx_ant %d\n", i); AssertFatal((prs_vars[idx]->prs_resource[k].prs_meas[j]!=NULL), "NR UE init: PRS measurements malloc failed for rx_ant %d\n", j);
} }
} }
} }
......
...@@ -801,6 +801,17 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB) ...@@ -801,6 +801,17 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
free_and_zero(common_vars->beam_id[i]); free_and_zero(common_vars->beam_id[i]);
} }
for (int rsc=0; rsc < gNB->prs_vars.NumPRSResources; rsc++) {
for (int slot=0; slot<fp->slots_per_frame; slot++) {
for (int symb=0; symb<fp->symbols_per_slot; symb++) {
free_and_zero(gNB->nr_gold_prs[rsc][slot][symb]);
}
free_and_zero(gNB->nr_gold_prs[rsc][slot]);
}
free_and_zero(gNB->nr_gold_prs[rsc]);
}
free_and_zero(gNB->nr_gold_prs);
/* Do NOT free per-antenna txdataF/rxdataF: the gNB gets a pointer to the /* Do NOT free per-antenna txdataF/rxdataF: the gNB gets a pointer to the
* RU's txdataF/rxdataF, and the RU will free that */ * RU's txdataF/rxdataF, and the RU will free that */
free_and_zero(common_vars->txdataF); free_and_zero(common_vars->txdataF);
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
//#define DEBUG_CH //#define DEBUG_CH
//#define DEBUG_PRS_CHEST //#define DEBUG_PRS_CHEST
//#define DEBUG_PRS_PRINTS //#define DEBUG_PRS_PRINTS
#define IDFT_INTERPOL_FACTOR 1
extern short nr_qpsk_mod_table[8]; extern short nr_qpsk_mod_table[8];
static inline int abs32(int x) static inline int abs32(int x)
...@@ -58,6 +57,9 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -58,6 +57,9 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
prs_meas_t **prs_meas = ue->prs_vars[gNB_id]->prs_resource[rsc_id].prs_meas; prs_meas_t **prs_meas = ue->prs_vars[gNB_id]->prs_resource[rsc_id].prs_meas;
int32_t **prs_chestF = ue->prs_vars[gNB_id]->prs_resource[rsc_id].prs_ch_estimates; int32_t **prs_chestF = ue->prs_vars[gNB_id]->prs_resource[rsc_id].prs_ch_estimates;
int32_t **prs_chestT = ue->prs_vars[gNB_id]->prs_resource[rsc_id].prs_ch_estimates_time; int32_t **prs_chestT = ue->prs_vars[gNB_id]->prs_resource[rsc_id].prs_ch_estimates_time;
int16_t *ch_tmp = ue->prs_vars[gNB_id]->ch_tmp;
int16_t *chF_interpol = ue->prs_vars[gNB_id]->chF_interpol;
int16_t *chT_interpol = ue->prs_vars[gNB_id]->chT_interpol;
int slot_prs = (proc->nr_slot_rx - rep_num*prs_cfg->PRSResourceTimeGap + frame_params->slots_per_frame)%frame_params->slots_per_frame; int slot_prs = (proc->nr_slot_rx - rep_num*prs_cfg->PRSResourceTimeGap + frame_params->slots_per_frame)%frame_params->slots_per_frame;
uint32_t **nr_gold_prs = ue->nr_gold_prs[gNB_id][rsc_id][slot_prs]; uint32_t **nr_gold_prs = ue->nr_gold_prs[gNB_id][rsc_id][slot_prs];
...@@ -65,12 +67,6 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -65,12 +67,6 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
int16_t *rxF, *pil, *fl, *fm, *fmm, *fml, *fmr, *fr, mod_prs[NR_MAX_PRS_LENGTH<<1]; int16_t *rxF, *pil, *fl, *fm, *fmm, *fml, *fmr, *fr, mod_prs[NR_MAX_PRS_LENGTH<<1];
int16_t ch[2] = {0}, noiseFig[2] = {0}; int16_t ch[2] = {0}, noiseFig[2] = {0};
int16_t k_prime = 0, k = 0, re_offset = 0, first_half = 0, second_half = 0; int16_t k_prime = 0, k = 0, re_offset = 0, first_half = 0, second_half = 0;
int16_t *ch_tmp = (int16_t *)malloc16_clear(frame_params->ofdm_symbol_size*sizeof(int32_t));
AssertFatal((ch_tmp != NULL), "[%s] channel estimate buffer initialization failed!!", __FUNCTION__);
int16_t *chF_interpol = (int16_t *)malloc16_clear(IDFT_INTERPOL_FACTOR*frame_params->ofdm_symbol_size*sizeof(int32_t));
AssertFatal((chF_interpol != NULL), "[%s] channel estimate buffer initialization failed!!", __FUNCTION__);
int16_t *chT_interpol = (int16_t *)malloc16_clear(IDFT_INTERPOL_FACTOR*frame_params->ofdm_symbol_size*sizeof(int32_t));
AssertFatal((chT_interpol != NULL), "[%s] channel estimate buffer initialization failed!!", __FUNCTION__);
int32_t ch_pwr = 0, snr = 0; int32_t ch_pwr = 0, snr = 0;
#ifdef DEBUG_PRS_CHEST #ifdef DEBUG_PRS_CHEST
char filename[64] = {0}, varname[64] = {0}; char filename[64] = {0}, varname[64] = {0};
...@@ -78,7 +74,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -78,7 +74,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
int16_t *ch_init = ch_tmp; int16_t *ch_init = ch_tmp;
int16_t scale_factor = (1.0f/(float)(prs_cfg->NumPRSSymbols))*(1<<15); int16_t scale_factor = (1.0f/(float)(prs_cfg->NumPRSSymbols))*(1<<15);
int16_t num_pilots = (12/prs_cfg->CombSize)*prs_cfg->NumRB; int16_t num_pilots = (12/prs_cfg->CombSize)*prs_cfg->NumRB;
int16_t start_offset = (IDFT_INTERPOL_FACTOR-1)*frame_params->ofdm_symbol_size>>1; int16_t start_offset = (NR_PRS_IDFT_OVERSAMP_FACTOR-1)*frame_params->ofdm_symbol_size>>1;
int16_t k_prime_table[K_PRIME_TABLE_ROW_SIZE][K_PRIME_TABLE_COL_SIZE] = PRS_K_PRIME_TABLE; int16_t k_prime_table[K_PRIME_TABLE_ROW_SIZE][K_PRIME_TABLE_COL_SIZE] = PRS_K_PRIME_TABLE;
for(int l = prs_cfg->SymbolStart; l < prs_cfg->SymbolStart+prs_cfg->NumPRSSymbols; l++) for(int l = prs_cfg->SymbolStart; l < prs_cfg->SymbolStart+prs_cfg->NumPRSSymbols; l++)
...@@ -436,7 +432,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -436,7 +432,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
// Time domain IMPULSE response // Time domain IMPULSE response
idft_size_idx_t idftsizeidx; idft_size_idx_t idftsizeidx;
switch (IDFT_INTERPOL_FACTOR*frame_params->ofdm_symbol_size) { switch (NR_PRS_IDFT_OVERSAMP_FACTOR*frame_params->ofdm_symbol_size) {
case 128: case 128:
idftsizeidx = IDFT_128; idftsizeidx = IDFT_128;
break; break;
...@@ -472,7 +468,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -472,7 +468,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
case 4096: case 4096:
idftsizeidx = IDFT_4096; idftsizeidx = IDFT_4096;
break; break;
// 16x IDFT oversampling
case 8192: case 8192:
idftsizeidx = IDFT_8192; idftsizeidx = IDFT_8192;
break; break;
...@@ -511,7 +507,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -511,7 +507,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
(int16_t *)&chT_interpol[0],1); (int16_t *)&chT_interpol[0],1);
// rearrange impulse response // rearrange impulse response
memcpy((int16_t *)&prs_chestT[rxAnt][0], &chT_interpol[IDFT_INTERPOL_FACTOR*frame_params->ofdm_symbol_size], (frame_params->ofdm_symbol_size>>1)*sizeof(int32_t)); memcpy((int16_t *)&prs_chestT[rxAnt][0], &chT_interpol[NR_PRS_IDFT_OVERSAMP_FACTOR*frame_params->ofdm_symbol_size], (frame_params->ofdm_symbol_size>>1)*sizeof(int32_t));
memcpy((int16_t *)&prs_chestT[rxAnt][(frame_params->ofdm_symbol_size>>1)], &chT_interpol[start_offset], (frame_params->ofdm_symbol_size>>1)*sizeof(int32_t)); memcpy((int16_t *)&prs_chestT[rxAnt][(frame_params->ofdm_symbol_size>>1)], &chT_interpol[start_offset], (frame_params->ofdm_symbol_size>>1)*sizeof(int32_t));
// peak estimator // peak estimator
...@@ -521,7 +517,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -521,7 +517,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
&ch_pwr); &ch_pwr);
//prs measurements //prs measurements
prs_meas[rxAnt]->dl_toa -= (frame_params->ofdm_symbol_size>>1); prs_meas[rxAnt]->dl_toa -= (frame_params->ofdm_symbol_size>>1); // adjusting ToA wrt center
prs_meas[rxAnt]->gNB_id = gNB_id; prs_meas[rxAnt]->gNB_id = gNB_id;
prs_meas[rxAnt]->sfn = proc->frame_rx; prs_meas[rxAnt]->sfn = proc->frame_rx;
prs_meas[rxAnt]->slot = proc->nr_slot_rx; prs_meas[rxAnt]->slot = proc->nr_slot_rx;
...@@ -531,7 +527,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -531,7 +527,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
#ifdef DEBUG_PRS_CHEST #ifdef DEBUG_PRS_CHEST
sprintf(filename, "%s%i%s", "PRSpilot_", rxAnt, ".m"); sprintf(filename, "%s%i%s", "PRSpilot_", rxAnt, ".m");
LOG_M(filename, "prs_loc", &mod_prs[0], prs_cfg->NumRB*(12/prs_cfg->CombSize),1,1); LOG_M(filename, "prs_loc", &mod_prs[0], num_pilots,1,1);
sprintf(filename, "%s%i%s", "rxSigF_", rxAnt, ".m"); sprintf(filename, "%s%i%s", "rxSigF_", rxAnt, ".m");
sprintf(varname, "%s%i", "rxF_", rxAnt); sprintf(varname, "%s%i", "rxF_", rxAnt);
LOG_M(filename, varname, &rxdataF[rxAnt][0], prs_cfg->NumPRSSymbols*frame_params->ofdm_symbol_size,1,1); LOG_M(filename, varname, &rxdataF[rxAnt][0], prs_cfg->NumPRSSymbols*frame_params->ofdm_symbol_size,1,1);
...@@ -557,9 +553,6 @@ int nr_prs_channel_estimation(uint8_t gNB_id, ...@@ -557,9 +553,6 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
T_INT(rxAnt), T_BUFFER(&prs_chestT[rxAnt][0], frame_params->ofdm_symbol_size*sizeof(int32_t))); T_INT(rxAnt), T_BUFFER(&prs_chestT[rxAnt][0], frame_params->ofdm_symbol_size*sizeof(int32_t)));
} }
free(ch_tmp);
free(chF_interpol);
free(chT_interpol);
return(0); return(0);
} }
......
...@@ -346,6 +346,7 @@ typedef struct { ...@@ -346,6 +346,7 @@ typedef struct {
int32_t **ptrs_re_per_slot; int32_t **ptrs_re_per_slot;
} NR_UE_PDSCH; } NR_UE_PDSCH;
#define NR_PRS_IDFT_OVERSAMP_FACTOR 1 // IDFT oversampling factor for NR PRS channel estimates in time domain, ALLOWED value 16x, and 1x is default(ie. IDFT size is frame_params->ofdm_symbol_size)
typedef struct { typedef struct {
prs_data_t prs_cfg; prs_data_t prs_cfg;
int32_t **prs_ch_estimates; int32_t **prs_ch_estimates;
...@@ -357,6 +358,10 @@ typedef struct { ...@@ -357,6 +358,10 @@ typedef struct {
typedef struct { typedef struct {
uint8_t NumPRSResources; uint8_t NumPRSResources;
NR_PRS_RESOURCE_t prs_resource[NR_MAX_PRS_RESOURCES_PER_SET]; NR_PRS_RESOURCE_t prs_resource[NR_MAX_PRS_RESOURCES_PER_SET];
//temp buffers
int16_t *ch_tmp;
int16_t *chF_interpol;
int16_t *chT_interpol;
} NR_UE_PRS; } NR_UE_PRS;
#define NR_PDCCH_DEFS_NR_UE #define NR_PDCCH_DEFS_NR_UE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment