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.
This commit is contained in:
Bartosz Podrygajlo
2024-11-05 13:50:55 +01:00
parent 220d851deb
commit 900fcd9762
4 changed files with 24 additions and 13 deletions
+13 -1
View File
@@ -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);
}
+1
View File
@@ -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;
/*@}*/
+1
View File
@@ -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)