Commit 5ceba4a2 authored by Robert Schmidt's avatar Robert Schmidt

FlexRAN: lock sc_update with mutex

Prevent sc_update from being changed by an incoming slice reconfiguration
change while writing data to the scheduler
parent 7b8c5cea
...@@ -61,6 +61,8 @@ int perform_slice_config_update_count = 1; ...@@ -61,6 +61,8 @@ int perform_slice_config_update_count = 1;
/* queue of incoming new UE<>slice association commands */ /* queue of incoming new UE<>slice association commands */
Protocol__FlexUeConfig *ue_slice_assoc_update[NUM_MAX_UE]; Protocol__FlexUeConfig *ue_slice_assoc_update[NUM_MAX_UE];
int n_ue_slice_assoc_updates = 0; int n_ue_slice_assoc_updates = 0;
/* mutex for sc_update: do not receive new config and write it at the same time */
pthread_mutex_t sc_update_mtx = PTHREAD_MUTEX_INITIALIZER;
int flexran_agent_mac_stats_reply(mid_t mod_id, int flexran_agent_mac_stats_reply(mid_t mod_id,
...@@ -1446,10 +1448,13 @@ void flexran_agent_slice_update(mid_t mod_id) ...@@ -1446,10 +1448,13 @@ void flexran_agent_slice_update(mid_t mod_id)
if (perform_slice_config_update_count <= 0) return; if (perform_slice_config_update_count <= 0) return;
perform_slice_config_update_count--; perform_slice_config_update_count--;
pthread_mutex_lock(&sc_update_mtx);
if (!slice_config[mod_id]) { if (!slice_config[mod_id]) {
/* if the configuration does not exist for agent, create from eNB structure /* if the configuration does not exist for agent, create from eNB structure
* and exit */ * and exit */
flexran_create_config_structures(mod_id); flexran_create_config_structures(mod_id);
pthread_mutex_unlock(&sc_update_mtx);
return; return;
} }
...@@ -1479,6 +1484,7 @@ void flexran_agent_slice_update(mid_t mod_id) ...@@ -1479,6 +1484,7 @@ void flexran_agent_slice_update(mid_t mod_id)
LOG_W(FLEXRAN_AGENT, "[%d] reverting to original number of %ld UL slices\n", LOG_W(FLEXRAN_AGENT, "[%d] reverting to original number of %ld UL slices\n",
mod_id, sc_update[mod_id]->n_ul); mod_id, sc_update[mod_id]->n_ul);
} }
pthread_mutex_unlock(&sc_update_mtx);
return; return;
} }
...@@ -1514,6 +1520,7 @@ void flexran_agent_slice_update(mid_t mod_id) ...@@ -1514,6 +1520,7 @@ void flexran_agent_slice_update(mid_t mod_id)
if (changes > 0) if (changes > 0)
LOG_I(FLEXRAN_AGENT, "[%d] slice configuration: applied %d changes\n", mod_id, changes); LOG_I(FLEXRAN_AGENT, "[%d] slice configuration: applied %d changes\n", mod_id, changes);
pthread_mutex_unlock(&sc_update_mtx);
} }
Protocol__FlexSliceConfig *flexran_agent_get_slice_config(mid_t mod_id) Protocol__FlexSliceConfig *flexran_agent_get_slice_config(mid_t mod_id)
......
...@@ -38,6 +38,7 @@ extern Protocol__FlexSliceConfig *sc_update[NUM_MAX_ENB]; ...@@ -38,6 +38,7 @@ extern Protocol__FlexSliceConfig *sc_update[NUM_MAX_ENB];
extern int perform_slice_config_update_count; extern int perform_slice_config_update_count;
extern Protocol__FlexUeConfig *ue_slice_assoc_update[NUM_MAX_UE]; extern Protocol__FlexUeConfig *ue_slice_assoc_update[NUM_MAX_UE];
extern int n_ue_slice_assoc_updates; extern int n_ue_slice_assoc_updates;
extern pthread_mutex_t sc_update_mtx;
Protocol__FlexranMessage * flexran_agent_generate_diff_mac_stats_report(Protocol__FlexranMessage *new_message, Protocol__FlexranMessage * flexran_agent_generate_diff_mac_stats_report(Protocol__FlexranMessage *new_message,
Protocol__FlexranMessage *old_message) { Protocol__FlexranMessage *old_message) {
...@@ -1228,6 +1229,9 @@ void prepare_update_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *slice) ...@@ -1228,6 +1229,9 @@ void prepare_update_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *slice)
LOG_E(FLEXRAN_AGENT, "Can not update slice policy (no existing slice profile)\n"); LOG_E(FLEXRAN_AGENT, "Can not update slice policy (no existing slice profile)\n");
return; return;
} }
pthread_mutex_lock(&sc_update_mtx);
if (slice->n_dl == 0) if (slice->n_dl == 0)
LOG_I(FLEXRAN_AGENT, "[%d] no DL slice configuration in flex_slice_config message\n", mod_id); LOG_I(FLEXRAN_AGENT, "[%d] no DL slice configuration in flex_slice_config message\n", mod_id);
for (int i = 0; i < slice->n_dl; i++) for (int i = 0; i < slice->n_dl; i++)
...@@ -1238,6 +1242,8 @@ void prepare_update_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *slice) ...@@ -1238,6 +1242,8 @@ void prepare_update_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *slice)
for (int i = 0; i < slice->n_ul; i++) for (int i = 0; i < slice->n_ul; i++)
prepare_update_slice_config_ul(mod_id, slice->ul[i]); prepare_update_slice_config_ul(mod_id, slice->ul[i]);
pthread_mutex_unlock(&sc_update_mtx);
/* perform the slice configuration reads a couple of times. If there are /* perform the slice configuration reads a couple of times. If there are
* inconsistencies (i.e. the MAC refuses a configuration), we will have a * inconsistencies (i.e. the MAC refuses a configuration), we will have a
* couple of warnings because the current configuration and the one in * couple of warnings because the current configuration and the one in
...@@ -1395,7 +1401,6 @@ int apply_ue_slice_assoc_update(mid_t mod_id) ...@@ -1395,7 +1401,6 @@ int apply_ue_slice_assoc_update(mid_t mod_id)
{ {
int i; int i;
int changes = 0; int changes = 0;
/* TODO should lock structure */
for (i = 0; i < n_ue_slice_assoc_updates; i++) { for (i = 0; i < n_ue_slice_assoc_updates; i++) {
int ue_id = find_UE_id(mod_id, ue_slice_assoc_update[i]->rnti); int ue_id = find_UE_id(mod_id, ue_slice_assoc_update[i]->rnti);
if (ue_slice_assoc_update[i]->has_dl_slice_id) { if (ue_slice_assoc_update[i]->has_dl_slice_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