Commit 5ca436db authored by Xu Bo's avatar Xu Bo

move pre_scd thread creation to init_RU_proc function and delete log and vars...

move pre_scd thread creation to init_RU_proc function and delete log and vars setting in pre_scd_nb_rbs_required function
parent b446c472
......@@ -436,6 +436,14 @@ typedef struct RU_proc_t_s {
/// timestamp to send to "slave rru"
openair0_timestamp timestamp_phy_tx;
#endif
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
pthread_t pthread_pre_scd;
/// condition variable for time processing thread
pthread_cond_t cond_pre_scd;
/// mutex for time thread
pthread_mutex_t mutex_pre_scd;
int instance_pre_scd;
#endif
} RU_proc_t;
/// Context data structure for eNB subframe processing
......@@ -570,14 +578,6 @@ typedef struct eNB_proc_t_s {
te_params tep;
/// set of scheduling variables RXn-TXnp4 threads
eNB_rxtx_proc_t proc_rxtx[2];
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
pthread_t pthread_pre_scd;
/// condition variable for time processing thread
pthread_cond_t cond_pre_scd;
/// mutex for time thread
pthread_mutex_t mutex_pre_scd;
int instance_pre_scd;
#endif
} eNB_proc_t;
......
......@@ -548,20 +548,33 @@ void sort_UEs(module_id_t Mod_idP, int frameP, sub_frame_t subframeP)
}
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
inline uint16_t search_rbs_required(uint16_t mcs, uint16_t TBS,uint16_t NB_RB, uint16_t step_size){
uint16_t nb_rb,i_TBS,tmp_TBS;
i_TBS=get_I_TBS(mcs);
for(nb_rb=step_size;nb_rb<NB_RB;nb_rb+=step_size){
tmp_TBS = TBStable[i_TBS][nb_rb-1];
if(TBS<tmp_TBS)return(nb_rb);
}
return NB_RB;
}
void pre_scd_nb_rbs_required( module_id_t module_idP,
frame_t frameP,
sub_frame_t subframeP,
int min_rb_unit[MAX_NUM_CCs],
uint16_t nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX])
{
int CC_id,UE_id, lc_id,i, j, tmp, N_RB_DL;;
int CC_id=0,UE_id, lc_id, N_RB_DL;
UE_TEMPLATE UE_template;
eNB_UE_STATS *eNB_UE_stats, *eNB_UE_stats_i, *eNB_UE_stats_j;
eNB_UE_STATS *eNB_UE_stats;
rnti_t rnti;
mac_rlc_status_resp_t rlc_status;
uint16_t TBS = 0;
uint16_t step_size=2;
N_RB_DL = to_prb(RC.mac[module_idP]->common_channels[CC_id].mib->message.dl_Bandwidth);
if(N_RB_DL==50) step_size=3;
if(N_RB_DL==100) step_size=4;
memset(nb_rbs_required, 0, sizeof(uint16_t)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
for (UE_id = 0; UE_id <NUMBER_OF_UE_MAX; UE_id++) {
if (pre_scd_activeUE[UE_id] != TRUE)
......@@ -571,132 +584,27 @@ void pre_scd_nb_rbs_required( module_id_t module_idP,
// clear logical channel interface variables
UE_template.dl_buffer_total = 0;
UE_template.dl_pdus_total = 0;
rnti = UE_RNTI(module_idP, UE_id);
for (lc_id = DCCH; lc_id <= DTCH; lc_id++) {
UE_template.dl_buffer_info[lc_id] = 0;
UE_template.dl_pdus_in_buffer[lc_id] = 0;
UE_template.dl_buffer_head_sdu_creation_time[lc_id] = 0;
UE_template.dl_buffer_head_sdu_remaining_size_to_send[lc_id] = 0;
rlc_status =
mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP,
ENB_FLAG_YES, MBMS_FLAG_NO, lc_id, 0);
UE_template.dl_buffer_info[lc_id] = rlc_status.bytes_in_buffer; //storing the dlsch buffer for each logical channel
UE_template.dl_pdus_in_buffer[lc_id] = rlc_status.pdus_in_buffer;
UE_template.dl_buffer_head_sdu_creation_time[lc_id] = rlc_status.head_sdu_creation_time;
UE_template.dl_buffer_head_sdu_creation_time_max =
cmax(UE_template.dl_buffer_head_sdu_creation_time_max,
rlc_status.head_sdu_creation_time);
UE_template.dl_buffer_head_sdu_remaining_size_to_send[lc_id] =
rlc_status.head_sdu_remaining_size_to_send;
UE_template.dl_buffer_head_sdu_is_segmented[lc_id] = rlc_status.head_sdu_is_segmented;
UE_template.dl_buffer_total += UE_template.dl_buffer_info[lc_id]; //storing the total dlsch buffer
UE_template.dl_pdus_total += UE_template.dl_pdus_in_buffer[lc_id];
#ifdef DEBUG_eNB_SCHEDULER
/* note for dl_buffer_head_sdu_remaining_size_to_send[i] :
* 0 if head SDU has not been segmented (yet), else remaining size not already segmented and sent
*/
if (UE_template.dl_buffer_info[lc_id] > 0)
LOG_D(MAC,
"[eNB %d] Frame %d Subframe %d : RLC status for UE %d %x in LCID%d: total of %d pdus and size %d, head sdu queuing time %d, remaining size %d, is segmeneted %d \n",
module_idP, frameP, subframeP, UE_id, rnti,
lc_id, UE_template.dl_pdus_in_buffer[lc_id],
UE_template.dl_buffer_info[lc_id],
UE_template.dl_buffer_head_sdu_creation_time[lc_id],
UE_template.
dl_buffer_head_sdu_remaining_size_to_send[lc_id],
UE_template.dl_buffer_head_sdu_is_segmented[lc_id]);
#endif
UE_template.dl_buffer_total += rlc_status.bytes_in_buffer; //storing the total dlsch buffer
}
if (UE_template.dl_buffer_total > 0)
LOG_D(MAC,
"[eNB %d] Frame %d Subframe %d : RLC status for UE %d %x: total DL buffer size %d and total number of pdu %d \n",
module_idP, frameP, subframeP, UE_id,rnti,
UE_template.dl_buffer_total,
UE_template.dl_pdus_total);
// end of store dlsch buffer
// assgin rbs required
// Calculate the number of RBs required by each UE on the basis of logical channel's buffer
//update CQI information across component carriers
for (i = 0; i < pre_scd_numactiveCCs[UE_id]; i++) {
CC_id = pre_scd_ordered_CCids[i][UE_id];
eNB_UE_stats = &pre_scd_eNB_UE_stats[CC_id][UE_id];
eNB_UE_stats = &pre_scd_eNB_UE_stats[CC_id][UE_id];
eNB_UE_stats->dlsch_mcs1 = 28;
}
eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]];
// provide the list of CCs sorted according to MCS
for (i = 0; i < pre_scd_numactiveCCs[UE_id]; i++) {
eNB_UE_stats_i =
&pre_scd_eNB_UE_stats[pre_scd_ordered_CCids[i][UE_id]][UE_id];
for (j = i + 1; j < pre_scd_numactiveCCs[UE_id]; j++) {
DevAssert(j < MAX_NUM_CCs);
eNB_UE_stats_j =
&pre_scd_eNB_UE_stats[pre_scd_ordered_CCids[j][UE_id]][UE_id];
if (eNB_UE_stats_j->dlsch_mcs1
> eNB_UE_stats_i->dlsch_mcs1) {
tmp = pre_scd_ordered_CCids[i][UE_id];
pre_scd_ordered_CCids[i][UE_id] =
pre_scd_ordered_CCids[j][UE_id];
pre_scd_ordered_CCids[j][UE_id] = tmp;
}
}
}
if (UE_template.dl_buffer_total > 0) {
LOG_D(MAC, "[preprocessor] assign RB for UE %d\n", UE_id);
for (i = 0; i < pre_scd_numactiveCCs[UE_id]; i++) {
CC_id = pre_scd_ordered_CCids[i][UE_id];
eNB_UE_stats = &pre_scd_eNB_UE_stats[CC_id][UE_id];
if (eNB_UE_stats->dlsch_mcs1 == 0) {
nb_rbs_required[CC_id][UE_id] = 4; // don't let the TBS get too small
} else {
nb_rbs_required[CC_id][UE_id] =
min_rb_unit[CC_id];
}
TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,
nb_rbs_required[CC_id][UE_id]);
LOG_D(MAC,
"[preprocessor] start RB assignement for UE %d CC_id %d dl buffer %d (RB unit %d, MCS %d, TBS %d) \n",
UE_id, CC_id,
UE_template.dl_buffer_total,
nb_rbs_required[CC_id][UE_id],
eNB_UE_stats->dlsch_mcs1, TBS);
N_RB_DL =
to_prb(
RC.mac[module_idP]->common_channels[CC_id].mib->message.dl_Bandwidth);
/* calculating required number of RBs for each UE */
while (TBS
< UE_template.dl_buffer_total) {
nb_rbs_required[CC_id][UE_id] +=
min_rb_unit[CC_id];
if (nb_rbs_required[CC_id][UE_id] > N_RB_DL) {
TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, N_RB_DL);
nb_rbs_required[CC_id][UE_id] = N_RB_DL;
break;
}
TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,
nb_rbs_required[CC_id][UE_id]);
} // end of while
LOG_D(MAC,
"[eNB %d] Frame %d Subframe %d: UE %d on CC %d: RB unit %d, nb_required RB %d (TBS %d, mcs %d)\n",
module_idP, frameP, subframeP, UE_id, CC_id,
min_rb_unit[CC_id],
nb_rbs_required[CC_id][UE_id], TBS,
eNB_UE_stats->dlsch_mcs1);
}
nb_rbs_required[CC_id][UE_id] = search_rbs_required(eNB_UE_stats->dlsch_mcs1, UE_template.dl_buffer_total, N_RB_DL, step_size);
}
}
}
......
......@@ -95,10 +95,6 @@ unsigned short config_frames[4] = {2,9,11,13};
#include "T.h"
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
#include "pdcp.h"
#endif
//#define DEBUG_THREADS 1
//#define USRP_DEBUG 1
......@@ -500,61 +496,7 @@ void wakeup_prach_eNB_br(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe) {
}
#endif
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
void* pre_scd_thread( void* param ){
static int eNB_pre_scd_status;
protocol_ctxt_t ctxt;
int frame;
int subframe;
int min_rb_unit[MAX_NUM_CCs];
int CC_id;
int Mod_id;
PHY_VARS_eNB *eNB= (PHY_VARS_eNB *)param;
eNB_proc_t *proc = &eNB->proc;
Mod_id = eNB->Mod_id;
frame = 0;
subframe = 4;
thread_top_init("pre_scd_thread",0,870000,1000000,1000000);
while (!oai_exit) {
if(oai_exit){
break;
}
pthread_mutex_lock(&proc->mutex_pre_scd );
if (proc->instance_pre_scd < 0) {
pthread_cond_wait(&proc->cond_pre_scd, &proc->mutex_pre_scd);
}
pthread_mutex_unlock(&proc->mutex_pre_scd);
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, Mod_id, ENB_FLAG_YES,
NOT_A_RNTI, frame, subframe,
eNB->Mod_id);
pdcp_run(&ctxt);
for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
rrc_rx_tx(&ctxt, 0, // eNB index, unused in eNB
CC_id);
min_rb_unit[CC_id] = get_min_rb_unit(Mod_id, CC_id);
}
pre_scd_nb_rbs_required(Mod_id, frame, subframe,min_rb_unit,pre_nb_rbs_required[new_dlsch_ue_select_tbl_in_use]);
if (subframe==9) {
subframe=0;
frame++;
frame&=1023;
} else {
subframe++;
}
pthread_mutex_lock(&proc->mutex_pre_scd );
proc->instance_pre_scd--;
pthread_mutex_unlock(&proc->mutex_pre_scd);
}
eNB_pre_scd_status = 0;
return &eNB_pre_scd_status;
}
#endif
/*!
* \brief The prach receive thread of eNB.
......@@ -712,14 +654,6 @@ void init_eNB_proc(int inst) {
// attr_te = &proc->attr_te;
#endif
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
proc->instance_pre_scd = -1;
pthread_mutex_init( &proc->mutex_pre_scd, NULL);
pthread_cond_init( &proc->cond_pre_scd, NULL);
pthread_create(&proc->pthread_pre_scd, NULL, pre_scd_thread, eNB);
pthread_setname_np(proc->pthread_pre_scd, "pre_scd_thread");
#endif
if (eNB->single_thread_flag==0) {
pthread_create( &proc_rxtx[0].pthread_rxtx, attr0, eNB_thread_rxtx, &proc_rxtx[0] );
pthread_create( &proc_rxtx[1].pthread_rxtx, attr1, eNB_thread_rxtx, &proc_rxtx[1] );
......@@ -806,13 +740,6 @@ void kill_eNB_proc(int inst) {
pthread_mutex_destroy( &proc->mutex_prach_br );
pthread_cond_destroy( &proc->cond_prach_br );
#endif
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
proc->instance_pre_scd = 0;
pthread_cond_signal( &proc->cond_pre_scd );
pthread_join( proc->pthread_pre_scd, (void**)&status );
pthread_mutex_destroy( &proc->mutex_pre_scd );
pthread_cond_destroy( &proc->cond_pre_scd );
#endif
LOG_I(PHY, "Destroying UL_INFO mutex\n");
pthread_mutex_destroy(&eNB->UL_INFO_mutex);
int i;
......
......@@ -110,6 +110,10 @@ unsigned short config_frames[4] = {2,9,11,13};
#include "T.h"
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
#include "pdcp.h"
#endif
extern volatile int oai_exit;
......@@ -1553,25 +1557,25 @@ static void* ru_thread( void* param ) {
memcpy(&pre_scd_activeUE, &RC.mac[ru->eNB_list[0]->Mod_id]->UE_list.active, sizeof(boolean_t)*NUMBER_OF_UE_MAX);
memcpy(&pre_scd_ordered_CCids, &RC.mac[ru->eNB_list[0]->Mod_id]->UE_list.ordered_CCids, sizeof(int)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
memcpy(&pre_scd_numactiveCCs, &RC.mac[ru->eNB_list[0]->Mod_id]->UE_list.numactiveCCs, sizeof(int)*NUMBER_OF_UE_MAX);
if (pthread_mutex_lock(&ru->eNB_list[0]->proc.mutex_pre_scd)!= 0) {
LOG_E( MAC, "[eNB] error locking MAC proc mutex for eNB pre scd\n");
if (pthread_mutex_lock(&ru->proc.mutex_pre_scd)!= 0) {
LOG_E( PHY, "[eNB] error locking proc mutex for eNB pre scd\n");
exit_fun("error locking mutex_time");
}
ru->eNB_list[0]->proc.instance_pre_scd++;
ru->proc.instance_pre_scd++;
if (ru->eNB_list[0]->proc.instance_pre_scd == 0) {
if (pthread_cond_signal(&ru->eNB_list[0]->proc.cond_pre_scd) != 0) {
LOG_E( MAC, "[eNB] ERROR pthread_cond_signal for eNB time sync\n" );
if (ru->proc.instance_pre_scd == 0) {
if (pthread_cond_signal(&ru->proc.cond_pre_scd) != 0) {
LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB time sync\n" );
exit_fun( "ERROR pthread_cond_signal cond_pre_scd" );
}
}else{
LOG_E( MAC, "[eNB] frame %d subframe %d rxtx busy instance_pre_scd %d\n",
frame,subframe,ru->eNB_list[0]->proc.instance_pre_scd );
LOG_E( PHY, "[eNB] frame %d subframe %d rxtx busy instance_pre_scd %d\n",
frame,subframe,ru->proc.instance_pre_scd );
}
if (pthread_mutex_unlock(&ru->eNB_list[0]->proc.mutex_pre_scd)!= 0) {
LOG_E( MAC, "[eNB] error unlocking mutex_pre_scd mutex for eNB pre scd\n");
if (pthread_mutex_unlock(&ru->proc.mutex_pre_scd)!= 0) {
LOG_E( PHY, "[eNB] error unlocking mutex_pre_scd mutex for eNB pre scd\n");
exit_fun("error unlocking mutex_pre_scd");
}
#endif
......@@ -1690,6 +1694,60 @@ void *ru_thread_synch(void *arg) {
}
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
void* pre_scd_thread( void* param ){
static int eNB_pre_scd_status;
protocol_ctxt_t ctxt;
int frame;
int subframe;
int min_rb_unit[MAX_NUM_CCs];
int CC_id;
int Mod_id;
RU_t *ru = (RU_t*)param;
Mod_id = ru->eNB_list[0]->Mod_id;
frame = 0;
subframe = 4;
thread_top_init("pre_scd_thread",0,870000,1000000,1000000);
while (!oai_exit) {
if(oai_exit){
break;
}
pthread_mutex_lock(&ru->proc.mutex_pre_scd );
if (ru->proc.instance_pre_scd < 0) {
pthread_cond_wait(&ru->proc.cond_pre_scd, &ru->proc.mutex_pre_scd);
}
pthread_mutex_unlock(&ru->proc.mutex_pre_scd);
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, Mod_id, ENB_FLAG_YES,
NOT_A_RNTI, frame, subframe,Mod_id);
pdcp_run(&ctxt);
for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
rrc_rx_tx(&ctxt, 0, // eNB index, unused in eNB
CC_id);
min_rb_unit[CC_id] = get_min_rb_unit(Mod_id, CC_id);
}
pre_scd_nb_rbs_required(Mod_id, frame, subframe,min_rb_unit,pre_nb_rbs_required[new_dlsch_ue_select_tbl_in_use]);
if (subframe==9) {
subframe=0;
frame++;
frame&=1023;
} else {
subframe++;
}
pthread_mutex_lock(&ru->proc.mutex_pre_scd );
ru->proc.instance_pre_scd--;
pthread_mutex_unlock(&ru->proc.mutex_pre_scd);
}
eNB_pre_scd_status = 0;
return &eNB_pre_scd_status;
}
#endif
#ifdef UE_EXPANSION
/*!
* \brief The phy tx thread of eNB.
......@@ -1838,6 +1896,13 @@ void init_RU_proc(RU_t *ru) {
#endif
pthread_create( &proc->pthread_FH, attr_FH, ru_thread, (void*)ru );
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
proc->instance_pre_scd = -1;
pthread_mutex_init( &proc->mutex_pre_scd, NULL);
pthread_cond_init( &proc->cond_pre_scd, NULL);
pthread_create(&proc->pthread_pre_scd, NULL, pre_scd_thread, (void*)ru);
pthread_setname_np(proc->pthread_pre_scd, "pre_scd_thread");
#endif
#ifdef UE_EXPANSION
pthread_create( &proc->pthread_phy_tx, NULL, eNB_thread_phy_tx, (void*)ru );
......@@ -2263,6 +2328,15 @@ void stop_ru(RU_t *ru) {
int *status;
#endif
printf("Stopping RU %p processing threads\n",(void*)ru);
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
if(ru){
ru->proc.instance_pre_scd = 0;
pthread_cond_signal( &ru->proc.cond_pre_scd );
pthread_join(ru->proc.pthread_pre_scd, (void**)&status );
pthread_mutex_destroy(&ru->proc.mutex_pre_scd );
pthread_cond_destroy(&ru->proc.cond_pre_scd );
}
#endif
#ifdef UE_EXPANSION
if(ru){
ru->proc.instance_cnt_phy_tx = 0;
......
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