Commit 900fcd97 authored by Bartosz Podrygajlo's avatar Bartosz Podrygajlo

Thread safety for MAC config

Move mac_IF_mutex to MAC instance and use it for ensuring thread safety when modifying
MAC structures from RRC.
parent 220d851d
......@@ -872,6 +872,8 @@ void nr_rrc_mac_config_req_mib(module_id_t module_id,
int sched_sib)
{
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
int ret = pthread_mutex_lock(&mac->if_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
AssertFatal(mib, "MIB should not be NULL\n");
if (!mac->mib)
mac->mib = calloc(1, sizeof(*mac->mib));
......@@ -883,6 +885,7 @@ void nr_rrc_mac_config_req_mib(module_id_t module_id,
else if (sched_sib == 2)
mac->get_otherSI = true;
nr_ue_decode_mib(mac, cc_idP);
pthread_mutex_unlock(&mac->if_mutex);
}
static void setup_puschpowercontrol(NR_UE_MAC_INST_t *mac, NR_PUSCH_PowerControl_t *source, NR_PUSCH_PowerControl_t *target)
......@@ -1611,6 +1614,8 @@ void nr_rrc_mac_config_req_reset(module_id_t module_id,
NR_UE_MAC_reset_cause_t cause)
{
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
int ret = pthread_mutex_lock(&mac->if_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
fapi_nr_synch_request_t sync_req = {.target_Nid_cell = -1, .ssb_bw_scan = true};
switch (cause) {
case GO_TO_IDLE:
......@@ -1649,6 +1654,7 @@ void nr_rrc_mac_config_req_reset(module_id_t module_id,
default:
AssertFatal(false, "Invalid MAC reset cause %d\n", cause);
}
pthread_mutex_unlock(&mac->if_mutex);
}
static int get_ta_offset(long *n_TimingAdvanceOffset)
......@@ -1676,6 +1682,8 @@ void nr_rrc_mac_config_req_sib1(module_id_t module_id,
NR_ServingCellConfigCommonSIB_t *scc)
{
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
int ret = pthread_mutex_lock(&mac->if_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
AssertFatal(scc, "SIB1 SCC should not be NULL\n");
UPDATE_IE(mac->tdd_UL_DL_ConfigurationCommon, scc->tdd_UL_DL_ConfigurationCommon, NR_TDD_UL_DL_ConfigCommon_t);
......@@ -1708,6 +1716,7 @@ void nr_rrc_mac_config_req_sib1(module_id_t module_id,
if (!get_softmodem_params()->emulate_l1)
mac->if_module->phy_config_request(&mac->phy_config);
pthread_mutex_unlock(&mac->if_mutex);
}
void nr_rrc_mac_config_req_sib19_r17(module_id_t module_id,
......@@ -2518,8 +2527,10 @@ void nr_rrc_mac_config_req_cg(module_id_t module_id,
NR_UE_NR_Capability_t *ue_Capability)
{
LOG_I(MAC,"[UE %d] Applying CellGroupConfig from gNodeB\n", module_id);
AssertFatal(cell_group_config, "CellGroupConfig should not be NULL\n");
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
int ret = pthread_mutex_lock(&mac->if_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
AssertFatal(cell_group_config, "CellGroupConfig should not be NULL\n");
if (cell_group_config->physicalCellGroupConfig)
configure_physicalcellgroup(mac, cell_group_config->physicalCellGroupConfig);
......@@ -2562,4 +2573,5 @@ void nr_rrc_mac_config_req_cg(module_id_t module_id,
if (!mac->dl_config_request || !mac->ul_config_request)
ue_init_config_request(mac, mac->current_DL_BWP->scs);
pthread_mutex_unlock(&mac->if_mutex);
}
......@@ -617,6 +617,7 @@ typedef struct NR_UE_MAC_INST_s {
int f_b_f_c;
bool pusch_power_control_initialized;
int delta_msg2;
pthread_mutex_t if_mutex;
} NR_UE_MAC_INST_t;
/*@}*/
......
......@@ -70,6 +70,7 @@ void nr_ue_init_mac(NR_UE_MAC_INST_t *mac)
mac->p_Max = INT_MIN;
mac->p_Max_alt = INT_MIN;
mac->n_ta_offset = -1;
pthread_mutex_init(&mac->if_mutex, NULL);
reset_mac_inst(mac);
// need to inizialize because might not been setup (optional timer)
......
......@@ -65,7 +65,6 @@ queue_t nr_dl_tti_req_queue;
queue_t nr_tx_req_queue;
queue_t nr_ul_dci_req_queue;
queue_t nr_ul_tti_req_queue;
pthread_mutex_t mac_IF_mutex;
static void save_pdsch_pdu_for_crnti(nfapi_nr_dl_tti_request_t *dl_tti_request);
void nrue_init_standalone_socket(int tx_port, int rx_port)
......@@ -1141,18 +1140,17 @@ void update_harq_status(NR_UE_MAC_INST_t *mac, uint8_t harq_pid, uint8_t ack_nac
int nr_ue_ul_indication(nr_uplink_indication_t *ul_info)
{
int ret = pthread_mutex_lock(&mac_IF_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
LOG_D(PHY, "Locked in ul, slot %d\n", ul_info->slot);
module_id_t module_id = ul_info->module_id;
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
int ret = pthread_mutex_lock(&mac->if_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
LOG_D(PHY, "Locked in ul, slot %d\n", ul_info->slot);
LOG_T(NR_MAC, "Not calling scheduler mac->ra.ra_state = %d\n", mac->ra.ra_state);
if (is_nr_UL_slot(mac->tdd_UL_DL_ConfigurationCommon, ul_info->slot, mac->frame_type))
nr_ue_ul_scheduler(mac, ul_info);
pthread_mutex_unlock(&mac_IF_mutex);
pthread_mutex_unlock(&mac->if_mutex);
return 0;
}
......@@ -1264,26 +1262,26 @@ static uint32_t nr_ue_dl_processing(nr_downlink_indication_t *dl_info)
int nr_ue_dl_indication(nr_downlink_indication_t *dl_info)
{
int ret = pthread_mutex_lock(&mac_IF_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
uint32_t ret2 = 0;
NR_UE_MAC_INST_t *mac = get_mac_inst(dl_info->module_id);
int ret = pthread_mutex_lock(&mac->if_mutex);
AssertFatal(!ret, "mutex failed %d\n", ret);
if (!dl_info->dci_ind && !dl_info->rx_ind)
// DL indication to process DCI reception
nr_ue_dl_scheduler(mac, dl_info);
else
// DL indication to process data channels
ret2 = nr_ue_dl_processing(dl_info);
pthread_mutex_unlock(&mac_IF_mutex);
pthread_mutex_unlock(&mac->if_mutex);
return ret2;
}
void nr_ue_slot_indication(uint8_t mod_id)
{
pthread_mutex_lock(&mac_IF_mutex);
NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
pthread_mutex_lock(&mac->if_mutex);
update_mac_timers(mac);
pthread_mutex_unlock(&mac_IF_mutex);
pthread_mutex_unlock(&mac->if_mutex);
}
nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id)
......@@ -1309,7 +1307,6 @@ nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id)
nr_ue_if_module_inst[module_id]->ul_indication = nr_ue_ul_indication;
nr_ue_if_module_inst[module_id]->slot_indication = nr_ue_slot_indication;
}
pthread_mutex_init(&mac_IF_mutex, NULL);
return nr_ue_if_module_inst[module_id];
}
......
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