Commit c093e4ed authored by francescomani's avatar francescomani

reworking configuration of LogicalChannelConfig at MAC UE

parent ff1cc7b3
......@@ -648,25 +648,16 @@ static void configure_ss_coreset(NR_BWP_PDCCH_t *pdcch, NR_PDCCH_Config_t *pdcch
}
}
static int lcid_cmp(const void *lc1, const void *lc2, void *mac_inst)
static int lcid_cmp(const void *a, const void *b)
{
uint8_t id1 = ((nr_lcordered_info_t *)lc1)->lcids_ordered;
uint8_t id2 = ((nr_lcordered_info_t *)lc2)->lcids_ordered;
NR_UE_MAC_INST_t *mac = (NR_UE_MAC_INST_t *)mac_inst;
NR_LogicalChannelConfig_t **lc_config = &mac->logicalChannelConfig[0];
AssertFatal(id1 > 0 && id2 > 0, "undefined logical channel identity\n");
AssertFatal(lc_config[id1 - 1] != NULL || lc_config[id2 - 1] != NULL, "logical channel configuration should be available\n");
return (lc_config[id1 - 1]->ul_SpecificParameters->priority - lc_config[id2 - 1]->ul_SpecificParameters->priority);
}
void nr_release_mac_config_logicalChannelBearer(NR_UE_MAC_INST_t *mac, long channel_identity)
{
if (mac->logicalChannelConfig[channel_identity - 1] != NULL) {
asn1cFreeStruc(asn_DEF_NR_LogicalChannelConfig, mac->logicalChannelConfig[channel_identity - 1]);
}
long pa, pb;
memcpy(&pa, &((nr_lcordered_info_t*)a)->logicalChannelConfig->ul_SpecificParameters->priority, sizeof(pa));
memcpy(&pb, &((nr_lcordered_info_t*)b)->logicalChannelConfig->ul_SpecificParameters->priority, sizeof(pb));
if (pa < pb)
return -1;
else if (pa > pb)
return 1;
return 0;
}
static int nr_get_ms_bucketsizeduration(long bucketsizeduration)
......@@ -695,14 +686,9 @@ static int nr_get_ms_bucketsizeduration(long bucketsizeduration)
}
}
void nr_configure_mac_config_logicalChannelBearer(module_id_t module_id,
long channel_identity,
NR_LogicalChannelConfig_t *lc_config)
void nr_configure_sched_info(NR_UE_MAC_INST_t *mac, long channel_identity, NR_LogicalChannelConfig_t *lc_config)
{
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
LOG_I(NR_MAC, "[MACLogicalChannelConfig]Applying RRC Logical Channel Config %d to lcid %li\n", module_id, channel_identity);
mac->logicalChannelConfig[channel_identity - 1] = lc_config;
LOG_D(NR_MAC, "Applying RRC Logical Channel Config to lcid %li\n", channel_identity);
// initialize the variable Bj for every LCID
mac->scheduling_info.lc_sched_info[channel_identity - 1].Bj = 0;
......@@ -729,59 +715,82 @@ static void configure_logicalChannelBearer(module_id_t module_id,
struct NR_CellGroupConfig__rlc_BearerToReleaseList *rlc_torelease_list)
{
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
if (rlc_torelease_list) {
for (int i = 0; i < rlc_torelease_list->list.count; i++) {
if (rlc_torelease_list->list.array[i]) {
int lc_identity = *rlc_torelease_list->list.array[i];
nr_release_mac_config_logicalChannelBearer(mac, lc_identity);
long id = *rlc_torelease_list->list.array[i];
int j;
for (j = 0; j < mac->lc_ordered_list.count; j++) {
if (id == mac->lc_ordered_list.array[j]->lcid)
break;
}
if (j < mac->lc_ordered_list.count) {
nr_lcordered_info_t *lc_info = mac->lc_ordered_list.array[j];
free(lc_info->logicalChannelConfig);
asn_sequence_del(&mac->lc_ordered_list, j, 0);
free(lc_info);
}
else
LOG_E(NR_MAC, "Element not present in the list, impossible to release\n");
}
}
if (rlc_toadd_list) {
for (int i = 0; i < rlc_toadd_list->list.count; i++) {
NR_RLC_BearerConfig_t *rlc_bearer = rlc_toadd_list->list.array[i];
int lc_identity = rlc_bearer->logicalChannelIdentity;
mac->lc_ordered_info[i].lcids_ordered = lc_identity;
NR_LogicalChannelConfig_t *mac_lc_config = NULL;
if (mac->logicalChannelConfig[lc_identity - 1] == NULL) {
NR_LogicalChannelConfig_t *mac_lc_config = rlc_bearer->mac_LogicalChannelConfig;
int j;
for (j = 0; j < mac->lc_ordered_list.count; j++) {
if (lc_identity == mac->lc_ordered_list.array[j]->lcid)
break;
}
if (j < mac->lc_ordered_list.count) {
LOG_D(NR_MAC, "Logical channel %d is already established, Reconfiguring now\n", lc_identity);
if (mac_lc_config != NULL) {
nr_configure_sched_info(mac, lc_identity, mac_lc_config);
UPDATE_MAC_IE(mac->lc_ordered_list.array[j]->logicalChannelConfig,
rlc_bearer->mac_LogicalChannelConfig,
NR_LogicalChannelConfig_t);
}
}
else {
/* setup of new LCID*/
nr_lcordered_info_t *lc_info = calloc(1, sizeof(*lc_info));
lc_info->lcid = lc_identity;
LOG_D(NR_MAC, "Establishing the logical channel %d\n", lc_identity);
AssertFatal(rlc_bearer->servedRadioBearer, "servedRadioBearer should be present for LCID establishment\n");
if (rlc_bearer->servedRadioBearer->present == NR_RLC_BearerConfig__servedRadioBearer_PR_srb_Identity) { /* SRB */
NR_SRB_Identity_t srb_id = rlc_bearer->servedRadioBearer->choice.srb_Identity;
if (rlc_bearer->mac_LogicalChannelConfig != NULL) {
UPDATE_MAC_IE(mac_lc_config, rlc_bearer->mac_LogicalChannelConfig, NR_LogicalChannelConfig_t);
if (mac_lc_config != NULL) {
UPDATE_MAC_IE(lc_info->logicalChannelConfig, rlc_bearer->mac_LogicalChannelConfig, NR_LogicalChannelConfig_t);
} else {
LOG_I(NR_RRC, "Applying the default logicalChannelConfig for SRB\n");
if (srb_id == 1)
mac_lc_config = (NR_LogicalChannelConfig_t *)&NR_SRB1_logicalChannelConfig_defaultValue;
else if (srb_id == 2)
mac_lc_config = (NR_LogicalChannelConfig_t *)&NR_SRB2_logicalChannelConfig_defaultValue;
else if (srb_id == 3)
mac_lc_config = (NR_LogicalChannelConfig_t *)&NR_SRB3_logicalChannelConfig_defaultValue;
else
AssertFatal(1 == 0, "The logical id %d is not a valid SRB id %li\n", lc_identity, srb_id);
}
} else { /* DRB */
AssertFatal(rlc_bearer->mac_LogicalChannelConfig,
"When establishing a DRB, LogicalChannelConfig should be mandatorily present\n");
UPDATE_MAC_IE(mac_lc_config, rlc_bearer->mac_LogicalChannelConfig, NR_LogicalChannelConfig_t);
LOG_D(NR_RRC, "Applying the default logicalChannelConfig for SRB\n");
switch (srb_id) {
case 1 :
lc_info->logicalChannelConfig = (NR_LogicalChannelConfig_t *)&NR_SRB1_logicalChannelConfig_defaultValue;
break;
case 2 :
lc_info->logicalChannelConfig = (NR_LogicalChannelConfig_t *)&NR_SRB2_logicalChannelConfig_defaultValue;
break;
case 3 :
lc_info->logicalChannelConfig = (NR_LogicalChannelConfig_t *)&NR_SRB3_logicalChannelConfig_defaultValue;
break;
default :
AssertFatal(false, "The logical id %d is not a valid SRB id %li\n", lc_identity, srb_id);
}
} else {
/* LC is already established, reconfiguring the LC */
LOG_D(NR_MAC, "Logical channel %d is already established, Reconfiguring now\n", lc_identity);
if (rlc_bearer->mac_LogicalChannelConfig != NULL) {
UPDATE_MAC_IE(mac_lc_config, rlc_bearer->mac_LogicalChannelConfig, NR_LogicalChannelConfig_t);
}
} else { /* DRB */
AssertFatal(mac_lc_config, "When establishing a DRB, LogicalChannelConfig should be mandatorily present\n");
UPDATE_MAC_IE(lc_info->logicalChannelConfig, rlc_bearer->mac_LogicalChannelConfig, NR_LogicalChannelConfig_t);
}
if (mac_lc_config) {
mac->lc_ordered_info[i].logicalChannelConfig_ordered = mac_lc_config;
nr_configure_mac_config_logicalChannelBearer(module_id, lc_identity, mac_lc_config);
nr_configure_sched_info(mac, lc_identity, lc_info->logicalChannelConfig);
ASN_SEQUENCE_ADD(&mac->lc_ordered_list, lc_info);
}
}
// reorder the logical channels as per its priority
qsort_r(mac->lc_ordered_info, rlc_toadd_list->list.count, sizeof(nr_lcordered_info_t), lcid_cmp, mac);
qsort(mac->lc_ordered_list.array, mac->lc_ordered_list.count, sizeof(nr_lcordered_info_t*), lcid_cmp);
}
}
......
......@@ -434,10 +434,9 @@ typedef struct ssb_list_info {
typedef struct nr_lcordered_info_s {
// logical channels ids ordered as per priority
int lcids_ordered;
NR_LogicalChannelIdentity_t lcid;
// logical channel configurations reordered as per priority
NR_LogicalChannelConfig_t *logicalChannelConfig_ordered;
NR_LogicalChannelConfig_t *logicalChannelConfig;
} nr_lcordered_info_t;
typedef struct {
......@@ -513,11 +512,9 @@ typedef struct NR_UE_MAC_INST_s {
/// BSR report flag management
uint8_t BSR_reporting_active;
// Pointers to LogicalChannelConfig indexed by LogicalChannelIdentity. Note NULL means LCHAN is inactive.
NR_LogicalChannelConfig_t *logicalChannelConfig[NR_MAX_NUM_LCID];
// order lc info
nr_lcordered_info_t lc_ordered_info[NR_MAX_NUM_LCID];
A_SEQUENCE_OF(nr_lcordered_info_t) lc_ordered_list;
NR_UE_SCHEDULING_INFO scheduling_info;
/// PHR
......
......@@ -221,9 +221,11 @@ void release_mac_configuration(NR_UE_MAC_INST_t *mac)
for (int i = 0; i < mac->ul_BWPs.count; i++)
release_ul_BWP(mac, i);
for (int i = 0; i < NR_MAX_NUM_LCID; i++) {
nr_release_mac_config_logicalChannelBearer(mac, i + 1);
memset(&mac->lc_ordered_info[i], 0, sizeof(nr_lcordered_info_t));
for (int i = 0; i < mac->lc_ordered_list.count; i++) {
nr_lcordered_info_t *lc_info = mac->lc_ordered_list.array[i];
free(lc_info->logicalChannelConfig);
asn_sequence_del(&mac->lc_ordered_list, i, 0);
free(lc_info);
}
memset(&mac->ssb_measurements, 0, sizeof(mac->ssb_measurements));
......
......@@ -1109,9 +1109,9 @@ void nr_ue_ul_scheduler(nr_uplink_indication_t *ul_info)
// update Bj for all active lcids before LCP procedure
LOG_D(NR_MAC, "====================[Frame %d][Slot %d]Logical Channel Prioritization===========\n", frame_tx, slot_tx);
for (nr_lcordered_info_t *lc_bearer = mac->lc_ordered_info; lc_bearer->logicalChannelConfig_ordered != NULL; lc_bearer++) {
int lcid = lc_bearer->lcids_ordered;
NR_LogicalChannelConfig_t *lcconfig = mac->logicalChannelConfig[lcid - 1];
for (int i = 0; i < mac->lc_ordered_list.count; i++) {
int lcid = mac->lc_ordered_list.array[i]->lcid;
NR_LogicalChannelConfig_t *lcconfig = mac->lc_ordered_list.array[i]->logicalChannelConfig;
NR_LC_SCHEDULING_INFO *sched_lc = &mac->scheduling_info.lc_sched_info[lcid - 1];
// max amount of data that can be buffered/accumulated in a logical channel buffer
int32_t bucketSize_max = sched_lc->bucket_size;
......@@ -1196,8 +1196,8 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t
}
//Get Buffer Occupancy and fill lcid_reordered_array
for (int lcid = 1; lcid <= NR_MAX_NUM_LCID; lcid++) {
if (mac->logicalChannelConfig[lcid - 1] != NULL) { // todo
for (int i = 0; i < mac->lc_ordered_list.count; i++) {
int lcid = mac->lc_ordered_list.array[i]->lcid;
int lcgid = mac->scheduling_info.lc_sched_info[lcid - 1].LCGID;
// Store already available data to transmit per Group
......@@ -1220,7 +1220,7 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t
if (rlc_status.bytes_in_buffer > 0) {
LOG_D(NR_MAC,"[UE %d] PDCCH Tick : LCID%d LCGID%d has data to transmit =%d bytes at frame %d slot %d\n",
module_idP, lcid,lcgid,rlc_status.bytes_in_buffer,frameP,slotP);
module_idP, lcid, lcgid, rlc_status.bytes_in_buffer, frameP, slotP);
mac->scheduling_info.lc_sched_info[lcid - 1].LCID_status = LCID_NOT_EMPTY;
//Update BSR_bytes and position in lcid_reordered_array only if Group is defined
......@@ -1248,7 +1248,6 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t
}
}
}
}
// Check whether a regular BSR can be triggered according to the first cases in 38.321
if (num_lcid_with_data) {
......@@ -2909,16 +2908,14 @@ void nr_ue_get_sdu_mac_ce_post(module_id_t module_idP,
}
}
uint32_t get_count_lcids_same_priority(NR_UE_MAC_INST_t *mac, uint8_t start, uint8_t total_active_lcids, int *lcid_ordered_array)
uint32_t get_count_lcids_same_priority(uint8_t start, uint8_t total_active_lcids, nr_lcordered_info_t *lcid_ordered_array)
{
// count number of logical channels with same priority as curr_lcid
uint8_t same_priority_count = 0;
uint8_t curr_lcid = lcid_ordered_array[start];
NR_LogicalChannelConfig_t *lc_config_curr = mac->logicalChannelConfig[curr_lcid - 1];
uint8_t curr_lcid = lcid_ordered_array[start].lcid;
for (uint8_t index = start; index < total_active_lcids; index++) {
uint8_t next_lcid = lcid_ordered_array[index];
NR_LogicalChannelConfig_t *lc_config_next = mac->logicalChannelConfig[next_lcid - 1];
if (lc_config_curr->ul_SpecificParameters->priority == lc_config_next->ul_SpecificParameters->priority) {
if (lcid_ordered_array[start].logicalChannelConfig->ul_SpecificParameters->priority ==
lcid_ordered_array[index].logicalChannelConfig->ul_SpecificParameters->priority) {
same_priority_count++;
}
}
......@@ -2936,7 +2933,14 @@ long get_num_bytes_to_reqlc(NR_UE_MAC_INST_t *mac,
long *target)
{
/* Calculates the number of bytes the logical channel should request from the correcponding RLC buffer*/
NR_LogicalChannelConfig_t *lc_config = mac->logicalChannelConfig[lc_num - 1];
NR_LogicalChannelConfig_t *lc_config = NULL;
for (int i = 0; i < mac->lc_ordered_list.count; i++) {
if (mac->lc_ordered_list.array[i]->lcid == lc_num) {
lc_config = mac->lc_ordered_list.array[i]->logicalChannelConfig;
break;
}
}
AssertFatal(lc_config, "Couldn't find LC config for ID %d\n", lc_num);
long pbr = nr_get_pbr(lc_config->ul_SpecificParameters->prioritisedBitRate);
int32_t lcid_remain_buffer = mac->scheduling_info.lc_sched_info[lc_num - 1].LCID_buffer_remain;
*target = (same_priority_count > 1) ? min(buflen_remain_ep, pbr) : pbr;
......@@ -2963,11 +2967,11 @@ long get_num_bytes_to_reqlc(NR_UE_MAC_INST_t *mac,
return num_bytes_requested;
}
bool get_dataavailability_buffers(uint8_t total_active_lcids, int *lcid_ordered_array, bool *data_status_lcbuffers)
bool get_dataavailability_buffers(uint8_t total_active_lcids, nr_lcordered_info_t *lcid_ordered_array, bool *data_status_lcbuffers)
{
// check whether there is any data in the rlc buffer corresponding to active lcs
for (uint8_t id = 0; id < total_active_lcids; id++) {
int lcid = lcid_ordered_array[id];
int lcid = lcid_ordered_array[id].lcid;
if (data_status_lcbuffers[lcid - 1]) {
return true;
}
......@@ -2975,21 +2979,22 @@ bool get_dataavailability_buffers(uint8_t total_active_lcids, int *lcid_ordered_
return false;
}
uint8_t select_logical_channels(NR_UE_MAC_INST_t *mac, uint8_t *num_active_lcids, int *active_lcids)
static void select_logical_channels(NR_UE_MAC_INST_t *mac, int *num_active_lcids, nr_lcordered_info_t *active_lcids)
{
// (TODO: selection of logical channels for logical channel prioritization procedure as per 5.4.3.1.2 Selection of logical
// channels, TS38.321)
// selection of logical channels with Bj > 0
for (nr_lcordered_info_t *lc_bearer = mac->lc_ordered_info; lc_bearer->logicalChannelConfig_ordered != NULL; lc_bearer++) {
uint8_t lcid = lc_bearer->lcids_ordered;
for (int i = 0; i < mac->lc_ordered_list.count; i++) {
int lcid = mac->lc_ordered_list.array[i]->lcid;
NR_LogicalChannelConfig_t *logicalChannelConfig = mac->lc_ordered_list.array[i]->logicalChannelConfig;
if (mac->scheduling_info.lc_sched_info[lcid - 1].Bj > 0) {
active_lcids[*num_active_lcids] = lcid;
active_lcids[*num_active_lcids].lcid = lcid;
active_lcids[*num_active_lcids].logicalChannelConfig = logicalChannelConfig;
(*num_active_lcids)++;
LOG_D(NR_MAC, "The available lcid is %d with total active channels count = %d\n", lcid, *num_active_lcids);
}
}
return 0;
}
static bool fill_mac_sdu(module_id_t module_idP,
......@@ -3188,10 +3193,6 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
// Pointer used to build the MAC PDU by placing the RLC SDUs in the ULSCH buffer
uint8_t *pdu = ulsch_buffer;
// variable used to build the lcids with positive Bj
int lcids_bj_pos[NR_MAX_NUM_LCID] = {0};
uint8_t avail_lcids_count = 0;
// variable used to store the lcid data status during lcp
bool lcids_data_status[NR_MAX_NUM_LCID] = {0};
memset(lcids_data_status, 1, NR_MAX_NUM_LCID);
......@@ -3209,6 +3210,9 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
LOG_D(NR_MAC, "In %s: [UE %d] [%d.%d] process UL transport block at with size TBS = %d bytes \n", __FUNCTION__, module_idP, frameP, subframe, buflen);
// selection of logical channels
int avail_lcids_count = 0;
// variable used to build the lcids with positive Bj
nr_lcordered_info_t lcids_bj_pos[mac->lc_ordered_list.count];
select_logical_channels(mac, &avail_lcids_count, lcids_bj_pos);
// multiplex in the order of highest priority
......@@ -3229,7 +3233,7 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
still space availble in the MAC PDU, then from the next run all the remaining data from the higher priority logical channel
is placed in the MAC PDU before going on to next high priority logical channel
*/
int lcid = lcids_bj_pos[id];
int lcid = lcids_bj_pos[id].lcid;
// skip the logical channel if no data in the buffer initially or the data in the buffer was zero because it was written in to
// MAC PDU
......@@ -3241,7 +3245,7 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
// count number of lc with same priority as lcid
if (!num_lcids_same_priority) {
num_lcids_same_priority = count_same_priority_lcids =
get_count_lcids_same_priority(mac, id, avail_lcids_count, lcids_bj_pos);
get_count_lcids_same_priority(id, avail_lcids_count, lcids_bj_pos);
}
buflen_remain = buflen - (mac_ce_p->total_mac_pdu_header_len + mac_ce_p->sdu_length_total + sh_size);
......
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