pre_processor.c 94.2 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22

/*! \file pre_processor.c
23
 * \brief eNB scheduler preprocessing fuction prior to scheduling
24
 * \author Navid Nikaein and Ankit Bhamri
25
 * \date 2013 - 2014
26
 * \email navid.nikaein@eurecom.fr
27
 * \version 1.0
28 29 30 31
 * @ingroup _mac

 */

32 33 34
#define _GNU_SOURCE
#include <stdlib.h>

35
#include "assertions.h"
36 37 38 39 40 41 42
#include "PHY/defs.h"
#include "PHY/extern.h"

#include "SCHED/defs.h"
#include "SCHED/extern.h"

#include "LAYER2/MAC/defs.h"
43
#include "LAYER2/MAC/proto.h"
44 45
#include "LAYER2/MAC/extern.h"
#include "UTIL/LOG/log.h"
46
#include "UTIL/LOG/vcd_signal_dumper.h"
47 48 49 50 51
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
52
#include "rlc.h"
53 54


55

56 57 58 59 60 61
#define DEBUG_eNB_SCHEDULER 1
#define DEBUG_HEADER_PARSING 1
//#define DEBUG_PACKET_TRACE 1

//#define ICIC 0

62
/* this function checks that get_eNB_UE_stats returns
Cedric Roux's avatar
Cedric Roux committed
63
 * a non-NULL pointer for all the active CCs of an UE
64
 */
65
/*
66
int phy_stats_exist(module_id_t Mod_id, int rnti)
67 68
{
  int CC_id;
Cedric Roux's avatar
Cedric Roux committed
69 70
  int i;
  int UE_id          = find_UE_id(Mod_id, rnti);
71
  UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
Cedric Roux's avatar
Cedric Roux committed
72 73 74 75 76 77 78 79 80 81 82 83
  if (UE_id == -1) {
    LOG_W(MAC, "[eNB %d] UE %x not found, should be there (in phy_stats_exist)\n",
	  Mod_id, rnti);
    return 0;
  }
  if (UE_list->numactiveCCs[UE_id] == 0) {
    LOG_W(MAC, "[eNB %d] UE %x has no active CC (in phy_stats_exist)\n",
	  Mod_id, rnti);
    return 0;
  }
  for (i = 0; i < UE_list->numactiveCCs[UE_id]; i++) {
    CC_id = UE_list->ordered_CCids[i][UE_id];
84 85
    if (mac_xface->get_eNB_UE_stats(Mod_id, CC_id, rnti) == NULL)
      return 0;
86
  }
87 88
  return 1;
}
89
*/
90

91
// This function stores the downlink buffer for all the logical channels
92 93 94
void
store_dlsch_buffer(module_id_t Mod_id, frame_t frameP,
		   sub_frame_t subframeP)
95
{
Cedric Roux's avatar
Cedric Roux committed
96

97 98 99 100 101
    int UE_id, i;
    rnti_t rnti;
    mac_rlc_status_resp_t rlc_status;
    UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
    UE_TEMPLATE *UE_template;
Raymond Knopp's avatar
 
Raymond Knopp committed
102

103 104 105
    for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
	if (UE_list->active[UE_id] != TRUE)
	    continue;
106

107 108
	UE_template =
	    &UE_list->UE_template[UE_PCCID(Mod_id, UE_id)][UE_id];
109

110 111 112
	// clear logical channel interface variables
	UE_template->dl_buffer_total = 0;
	UE_template->dl_pdus_total = 0;
113

114 115
	rnti = UE_RNTI(Mod_id, UE_id);

116 117 118 119 120
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
	for (i = DCCH; i <=DTCH; i++) {	// loop over DCCH, DCCH1 and DTCH
#else
    for (i = 0; i < MAX_NUM_LCID; i++) {    // loop over all the logical channels
#endif
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

	    rlc_status =
		mac_rlc_status_ind(Mod_id, rnti, Mod_id, frameP, subframeP,
				   ENB_FLAG_YES, MBMS_FLAG_NO, i, 0);
	    UE_template->dl_buffer_info[i] = rlc_status.bytes_in_buffer;	//storing the dlsch buffer for each logical channel
	    UE_template->dl_pdus_in_buffer[i] = rlc_status.pdus_in_buffer;
	    UE_template->dl_buffer_head_sdu_creation_time[i] =
		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[i] =
		rlc_status.head_sdu_remaining_size_to_send;
	    UE_template->dl_buffer_head_sdu_is_segmented[i] =
		rlc_status.head_sdu_is_segmented;
	    UE_template->dl_buffer_total += UE_template->dl_buffer_info[i];	//storing the total dlsch buffer
	    UE_template->dl_pdus_total +=
		UE_template->dl_pdus_in_buffer[i];
139

Cedric Roux's avatar
Cedric Roux committed
140
#ifdef DEBUG_eNB_SCHEDULER
141

142 143 144 145 146 147 148 149 150 151 152 153 154
	    /* 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[i] > 0)
		LOG_D(MAC,
		      "[eNB %d] Frame %d Subframe %d : RLC status for UE %d in LCID%d: total of %d pdus and size %d, head sdu queuing time %d, remaining size %d, is segmeneted %d \n",
		      Mod_id, frameP, subframeP, UE_id,
		      i, UE_template->dl_pdus_in_buffer[i],
		      UE_template->dl_buffer_info[i],
		      UE_template->dl_buffer_head_sdu_creation_time[i],
		      UE_template->
		      dl_buffer_head_sdu_remaining_size_to_send[i],
		      UE_template->dl_buffer_head_sdu_is_segmented[i]);
155

Cedric Roux's avatar
Cedric Roux committed
156
#endif
157

158
	}
159

160 161 162 163 164 165 166
	//#ifdef DEBUG_eNB_SCHEDULER
	if (UE_template->dl_buffer_total > 0)
	    LOG_D(MAC,
		  "[eNB %d] Frame %d Subframe %d : RLC status for UE %d : total DL buffer size %d and total number of pdu %d \n",
		  Mod_id, frameP, subframeP, UE_id,
		  UE_template->dl_buffer_total,
		  UE_template->dl_pdus_total);
167

168 169
	//#endif
    }
170 171
}

172

173
// This function returns the estimated number of RBs required by each UE for downlink scheduling
174 175 176 177 178 179 180
void
assign_rbs_required(module_id_t Mod_id,
		    frame_t frameP,
		    sub_frame_t subframe,
		    uint16_t
		    nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX],
		    int min_rb_unit[MAX_NUM_CCs])
181
{
182

183
    uint16_t TBS = 0;
184

185 186 187 188
    int UE_id, n, i, j, CC_id, pCCid, tmp;
    UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
    eNB_UE_STATS *eNB_UE_stats, *eNB_UE_stats_i, *eNB_UE_stats_j;
    int N_RB_DL;
189

190 191 192 193
    // clear rb allocations across all CC_id
    for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
	if (UE_list->active[UE_id] != TRUE)
	    continue;
194

195
	pCCid = UE_PCCID(Mod_id, UE_id);
196

197 198
	//update CQI information across component carriers
	for (n = 0; n < UE_list->numactiveCCs[UE_id]; n++) {
199

200 201
	    CC_id = UE_list->ordered_CCids[n][UE_id];
	    eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
202

203 204
	    eNB_UE_stats->dlsch_mcs1 =
		cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]];
205

206
	}
207

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
	// provide the list of CCs sorted according to MCS
	for (i = 0; i < UE_list->numactiveCCs[UE_id]; i++) {
	    eNB_UE_stats_i =
		&UE_list->eNB_UE_stats[UE_list->
				       ordered_CCids[i][UE_id]][UE_id];
	    for (j = i + 1; j < UE_list->numactiveCCs[UE_id]; j++) {
		DevAssert(j < MAX_NUM_CCs);
		eNB_UE_stats_j =
		    &UE_list->
		    eNB_UE_stats[UE_list->ordered_CCids[j][UE_id]][UE_id];
		if (eNB_UE_stats_j->dlsch_mcs1 >
		    eNB_UE_stats_i->dlsch_mcs1) {
		    tmp = UE_list->ordered_CCids[i][UE_id];
		    UE_list->ordered_CCids[i][UE_id] =
			UE_list->ordered_CCids[j][UE_id];
		    UE_list->ordered_CCids[j][UE_id] = tmp;
		}
	    }
	}
227

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
	if (UE_list->UE_template[pCCid][UE_id].dl_buffer_total > 0) {
	    LOG_D(MAC, "[preprocessor] assign RB for UE %d\n", UE_id);

	    for (i = 0; i < UE_list->numactiveCCs[UE_id]; i++) {
		CC_id = UE_list->ordered_CCids[i][UE_id];
		eNB_UE_stats = &UE_list->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_list->UE_template[pCCid][UE_id].dl_buffer_total,
		      nb_rbs_required[CC_id][UE_id],
		      eNB_UE_stats->dlsch_mcs1, TBS);

		N_RB_DL =
		    to_prb(RC.mac[Mod_id]->common_channels[CC_id].
			   mib->message.dl_Bandwidth);

		/* calculating required number of RBs for each UE */
		while (TBS <
		       UE_list->UE_template[pCCid][UE_id].
		       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: UE %d on CC %d: RB unit %d,  nb_required RB %d (TBS %d, mcs %d)\n",
		      Mod_id, frameP, UE_id, CC_id, min_rb_unit[CC_id],
		      nb_rbs_required[CC_id][UE_id], TBS,
		      eNB_UE_stats->dlsch_mcs1);
	    }
	}
Raymond Knopp's avatar
 
Raymond Knopp committed
281 282
    }
}
283 284


Raymond Knopp's avatar
 
Raymond Knopp committed
285
// This function scans all CC_ids for a particular UE to find the maximum round index of its HARQ processes
286

287 288 289
int
maxround(module_id_t Mod_id, uint16_t rnti, int frame,
	 sub_frame_t subframe, uint8_t ul_flag)
290
{
291

292 293 294 295
    uint8_t round, round_max = 0, UE_id;
    int CC_id, harq_pid;
    UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
    COMMON_channels_t *cc;
296

297
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
298

299
	cc = &RC.mac[Mod_id]->common_channels[CC_id];
300

301 302
	UE_id = find_UE_id(Mod_id, rnti);
	if (cc->tdd_Config)
303
	    harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame ,subframe);
304 305
	else
	    harq_pid = ((frame * 10) + subframe) & 7;
306

307 308 309 310
	round = UE_list->UE_sched_ctrl[UE_id].round[CC_id][harq_pid];
	if (round > round_max) {
	    round_max = round;
	}
311
    }
312

313
    return round_max;
Raymond Knopp's avatar
 
Raymond Knopp committed
314
}
315

Raymond Knopp's avatar
 
Raymond Knopp committed
316
// This function scans all CC_ids for a particular UE to find the maximum DL CQI
317
// it returns -1 if the UE is not found in PHY layer (get_eNB_UE_stats gives NULL)
318
int maxcqi(module_id_t Mod_id, int32_t UE_id)
319
{
320 321 322
    UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
    int CC_id, n;
    int CQI = 0;
323

324 325
    for (n = 0; n < UE_list->numactiveCCs[UE_id]; n++) {
	CC_id = UE_list->ordered_CCids[n][UE_id];
326

327 328 329
	if (UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id] > CQI) {
	    CQI = UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id];
	}
330
    }
331

332
    return CQI;
Raymond Knopp's avatar
 
Raymond Knopp committed
333
}
334

335
struct sort_ue_dl_params {
336 337 338
    int Mod_idP;
    int frameP;
    int subframeP;
339
};
340

341 342
static int ue_dl_compare(const void *_a, const void *_b, void *_params)
{
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
    struct sort_ue_dl_params *params = _params;
    UE_list_t *UE_list = &RC.mac[params->Mod_idP]->UE_list;

    int UE_id1 = *(const int *) _a;
    int UE_id2 = *(const int *) _b;

    int rnti1 = UE_RNTI(params->Mod_idP, UE_id1);
    int pCC_id1 = UE_PCCID(params->Mod_idP, UE_id1);
    int round1 =
	maxround(params->Mod_idP, rnti1, params->frameP, params->subframeP,
		 1);

    int rnti2 = UE_RNTI(params->Mod_idP, UE_id2);
    int pCC_id2 = UE_PCCID(params->Mod_idP, UE_id2);
    int round2 =
	maxround(params->Mod_idP, rnti2, params->frameP, params->subframeP,
		 1);

    int cqi1 = maxcqi(params->Mod_idP, UE_id1);
    int cqi2 = maxcqi(params->Mod_idP, UE_id2);

    if (round1 > round2)
	return -1;
    if (round1 < round2)
	return 1;

    if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[1] +
	UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2] >
	UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] +
	UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2])
	return -1;
    if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[1] +
	UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2] <
	UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] +
	UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2])
	return 1;

    if (UE_list->
	UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max >
	UE_list->
	UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max)
	return -1;
    if (UE_list->
	UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max <
	UE_list->
	UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max)
	return 1;

    if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total >
	UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total)
	return -1;
    if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total <
	UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total)
	return 1;

    if (cqi1 > cqi2)
	return -1;
    if (cqi1 < cqi2)
	return 1;

    return 0;
404
#if 0
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    /* The above order derives from the following.  */
    if (round2 > round1) {	// Check first if one of the UEs has an active HARQ process which needs service and swap order
	swap_UEs(UE_list, UE_id1, UE_id2, 0);
    } else if (round2 == round1) {
	// RK->NN : I guess this is for fairness in the scheduling. This doesn't make sense unless all UEs have the same configuration of logical channels.  This should be done on the sum of all information that has to be sent.  And still it wouldn't ensure fairness.  It should be based on throughput seen by each UE or maybe using the head_sdu_creation_time, i.e. swap UEs if one is waiting longer for service.
	//  for(j=0;j<MAX_NUM_LCID;j++){
	//    if (eNB_mac_inst[Mod_id][pCC_id1].UE_template[UE_id1].dl_buffer_info[j] <
	//      eNB_mac_inst[Mod_id][pCC_id2].UE_template[UE_id2].dl_buffer_info[j]){

	// first check the buffer status for SRB1 and SRB2

	if ((UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[1] +
	     UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2]) <
	    (UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] +
	     UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2])) {
	    swap_UEs(UE_list, UE_id1, UE_id2, 0);
	} else if (UE_list->UE_template[pCC_id1]
		   [UE_id1].dl_buffer_head_sdu_creation_time_max <
		   UE_list->UE_template[pCC_id2]
		   [UE_id2].dl_buffer_head_sdu_creation_time_max) {
	    swap_UEs(UE_list, UE_id1, UE_id2, 0);
	} else if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total <
		   UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total) {
	    swap_UEs(UE_list, UE_id1, UE_id2, 0);
	} else if (cqi1 < cqi2) {
	    swap_UEs(UE_list, UE_id1, UE_id2, 0);
	}
    }
433 434
#endif
}
435

Raymond Knopp's avatar
 
Raymond Knopp committed
436
// This fuction sorts the UE in order their dlsch buffer and CQI
437
void sort_UEs(module_id_t Mod_idP, int frameP, sub_frame_t subframeP)
438
{
439 440 441 442 443
    int i;
    int list[NUMBER_OF_UE_MAX];
    int list_size = 0;
    int rnti;
    struct sort_ue_dl_params params = { Mod_idP, frameP, subframeP };
444

445
    UE_list_t *UE_list = &RC.mac[Mod_idP]->UE_list;
446

447
    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
448

449 450 451 452
	if (UE_list->active[i] == FALSE)
	    continue;
	if ((rnti = UE_RNTI(Mod_idP, i)) == NOT_A_RNTI)
	    continue;
453
#if 0
454 455
	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
	    continue;
456
#endif
457 458 459
	list[list_size] = i;
	list_size++;
    }
460

461
    qsort_r(list, list_size, sizeof(int), ue_dl_compare, &params);
462

463 464 465 466 467 468 469 470
    if (list_size) {
	for (i = 0; i < list_size - 1; i++)
	    UE_list->next[list[i]] = list[i + 1];
	UE_list->next[list[list_size - 1]] = -1;
	UE_list->head = list[0];
    } else {
	UE_list->head = -1;
    }
471 472

#if 0
473 474


475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
    int UE_id1, UE_id2;
    int pCC_id1, pCC_id2;
    int cqi1, cqi2, round1, round2;
    int i = 0, ii = 0;		//,j=0;
    rnti_t rnti1, rnti2;

    UE_list_t *UE_list = &RC.mac[Mod_idP]->UE_list;

    for (i = UE_list->head; i >= 0; i = UE_list->next[i]) {

	for (ii = UE_list->next[i]; ii >= 0; ii = UE_list->next[ii]) {

	    UE_id1 = i;
	    rnti1 = UE_RNTI(Mod_idP, UE_id1);
	    if (rnti1 == NOT_A_RNTI)
		continue;
	    if (UE_list->UE_sched_ctrl[UE_id1].ul_out_of_sync == 1)
		continue;
	    pCC_id1 = UE_PCCID(Mod_idP, UE_id1);
	    cqi1 = maxcqi(Mod_idP, UE_id1);	//
	    round1 = maxround(Mod_idP, rnti1, frameP, subframeP, 0);

	    UE_id2 = ii;
	    rnti2 = UE_RNTI(Mod_idP, UE_id2);
	    if (rnti2 == NOT_A_RNTI)
		continue;
	    if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1)
		continue;
	    cqi2 = maxcqi(Mod_idP, UE_id2);
	    round2 = maxround(Mod_idP, rnti2, frameP, subframeP, 0);	//mac_xface->get_ue_active_harq_pid(Mod_id,rnti2,subframe,&harq_pid2,&round2,0);
	    pCC_id2 = UE_PCCID(Mod_idP, UE_id2);

	    if (round2 > round1) {	// Check first if one of the UEs has an active HARQ process which needs service and swap order
		swap_UEs(UE_list, UE_id1, UE_id2, 0);
	    } else if (round2 == round1) {
		// RK->NN : I guess this is for fairness in the scheduling. This doesn't make sense unless all UEs have the same configuration of logical channels.  This should be done on the sum of all information that has to be sent.  And still it wouldn't ensure fairness.  It should be based on throughput seen by each UE or maybe using the head_sdu_creation_time, i.e. swap UEs if one is waiting longer for service.
		//  for(j=0;j<MAX_NUM_LCID;j++){
		//    if (eNB_mac_inst[Mod_id][pCC_id1].UE_template[UE_id1].dl_buffer_info[j] <
		//      eNB_mac_inst[Mod_id][pCC_id2].UE_template[UE_id2].dl_buffer_info[j]){

		// first check the buffer status for SRB1 and SRB2

		if ((UE_list->UE_template[pCC_id1][UE_id1].
		     dl_buffer_info[1] +
		     UE_list->UE_template[pCC_id1][UE_id1].
		     dl_buffer_info[2]) <
		    (UE_list->UE_template[pCC_id2][UE_id2].
		     dl_buffer_info[1] +
		     UE_list->UE_template[pCC_id2][UE_id2].
		     dl_buffer_info[2])) {
		    swap_UEs(UE_list, UE_id1, UE_id2, 0);
		} else if (UE_list->UE_template[pCC_id1]
			   [UE_id1].dl_buffer_head_sdu_creation_time_max <
			   UE_list->UE_template[pCC_id2]
			   [UE_id2].dl_buffer_head_sdu_creation_time_max) {
		    swap_UEs(UE_list, UE_id1, UE_id2, 0);
		} else if (UE_list->UE_template[pCC_id1][UE_id1].
			   dl_buffer_total <
			   UE_list->UE_template[pCC_id2][UE_id2].
			   dl_buffer_total) {
		    swap_UEs(UE_list, UE_id1, UE_id2, 0);
		} else if (cqi1 < cqi2) {
		    swap_UEs(UE_list, UE_id1, UE_id2, 0);
		}
	    }
	}
Raymond Knopp's avatar
 
Raymond Knopp committed
541
    }
542
#endif
543 544
}

Xu Bo's avatar
Xu Bo committed
545
#if defined(UE_EXPANSION) || defined(UE_EXPANSION_SIM2)
546 547 548 549 550 551 552 553 554
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]>>3;
    if(TBS<tmp_TBS)return(nb_rb);
  }
  return NB_RB;
}
Xu Bo's avatar
Xu Bo committed
555 556 557 558 559 560
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])
{
561
    int                          CC_id=0,UE_id, lc_id, N_RB_DL;
Xu Bo's avatar
Xu Bo committed
562
    UE_TEMPLATE                  UE_template;
563
    eNB_UE_STATS                 *eNB_UE_stats;
Xu Bo's avatar
Xu Bo committed
564 565
    rnti_t                       rnti;
    mac_rlc_status_resp_t        rlc_status;
566 567 568 569 570
    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;
Xu Bo's avatar
Xu Bo committed
571
    memset(nb_rbs_required, 0, sizeof(uint16_t)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
572
    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
Xu Bo's avatar
Xu Bo committed
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588

    for (UE_id = 0; UE_id <NUMBER_OF_UE_MAX; UE_id++) {
        if (pre_scd_activeUE[UE_id] != TRUE)
            continue;

        // store dlsch buffer

        // clear logical channel interface variables
        UE_template.dl_buffer_total = 0;

        rnti = UE_RNTI(module_idP, UE_id);

        for (lc_id = DCCH; lc_id <= DTCH; lc_id++) {
            rlc_status =
                    mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP,
                            ENB_FLAG_YES, MBMS_FLAG_NO, lc_id, 0);
589
            UE_template.dl_buffer_total += rlc_status.bytes_in_buffer; //storing the total dlsch buffer
Xu Bo's avatar
Xu Bo committed
590 591 592 593 594 595
        }
         // 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
596
        eNB_UE_stats = &pre_scd_eNB_UE_stats[CC_id][UE_id];
Xu Bo's avatar
Xu Bo committed
597

598
        eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]];
Xu Bo's avatar
Xu Bo committed
599 600 601


        if (UE_template.dl_buffer_total > 0) {
602
          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);
Xu Bo's avatar
Xu Bo committed
603 604 605 606 607
        }
    }
}
#endif

Xu Bo's avatar
Xu Bo committed
608
#ifdef UE_EXPANSION
609 610 611 612 613 614 615 616 617 618 619 620
int cc_id_end(uint8_t *cc_id_flag )
{
  int end_flag = 1;
  for (int CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
    if (cc_id_flag[CC_id]==0) {
      end_flag = 0;
      break;
    }
  }
  return end_flag;
}

Xu Bo's avatar
Xu Bo committed
621 622 623 624 625 626 627 628 629 630 631 632
void dlsch_scheduler_pre_ue_select(
    module_id_t     module_idP,
    frame_t         frameP,
    sub_frame_t     subframeP,
    int*            mbsfn_flag,
    uint16_t        nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX],
    DLSCH_UE_SELECT dlsch_ue_select[MAX_NUM_CCs])
{
  eNB_MAC_INST                   *eNB      = RC.mac[module_idP];
  COMMON_channels_t              *cc       = eNB->common_channels;
  UE_list_t                      *UE_list  = &eNB->UE_list;
  UE_sched_ctrl                  *ue_sched_ctl;
633 634 635 636
  uint8_t                        CC_id;
  int                            UE_id;
  unsigned char                  round             = 0;
  unsigned char                  harq_pid          = 0;
Xu Bo's avatar
Xu Bo committed
637
  rnti_t                         rnti;
638
  uint16_t                       i;
Xu Bo's avatar
Xu Bo committed
639 640 641 642
  unsigned char                  aggregation;
  int                            format_flag;
  nfapi_dl_config_request_body_t *DL_req;
  nfapi_dl_config_request_pdu_t  *dl_config_pdu;
643
  uint16_t                       dlsch_ue_max_num[MAX_NUM_CCs] = {0};
Xu Bo's avatar
Xu Bo committed
644
  uint16_t                       saved_dlsch_dci[MAX_NUM_CCs] = {0};
645 646
  uint8_t                        end_flag[MAX_NUM_CCs] = {0};

Xu Bo's avatar
Xu Bo committed
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
  // Initialization
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    dlsch_ue_max_num[CC_id] = (uint16_t)RC.rrc[module_idP]->configuration.ue_multiple_max[CC_id];

    // save origin DL PDU number
    DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
    saved_dlsch_dci[CC_id] = DL_req->number_pdu;
  }

  // Insert DLSCH(retransmission) UE into selected UE list
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    if (mbsfn_flag[CC_id]>0) {
      continue;
    }

    DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
663
    for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
Xu Bo's avatar
Xu Bo committed
664 665 666 667 668 669 670 671 672 673
      if (UE_list->active[UE_id] == FALSE) {
        continue;
      }

      rnti = UE_RNTI(module_idP, UE_id);
      if (rnti == NOT_A_RNTI) {
        continue;
      }

      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
674
#if 0
Xu Bo's avatar
Xu Bo committed
675 676 677
      if (ue_sched_ctl->ul_out_of_sync == 1) {
        continue;
      }
678
#endif
Xu Bo's avatar
Xu Bo committed
679 680 681 682 683
      if (cc[CC_id].tdd_Config) harq_pid = ((frameP*10)+subframeP)%10;
      else harq_pid = ((frameP*10)+subframeP)&7;

      round = ue_sched_ctl->round[CC_id][harq_pid];
      if (round != 8) {  // retransmission
684 685 686
        if(UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] == 0){
          continue;
        }
Xu Bo's avatar
Xu Bo committed
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
        switch (get_tmode(module_idP, CC_id, UE_id)) {
          case 1:
          case 2:
          case 7:
            aggregation = get_aggregation(get_bw_index(module_idP, CC_id),
                  ue_sched_ctl->dl_cqi[CC_id],
                  format1);
            break;
          case 3:
            aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
                  ue_sched_ctl->dl_cqi[CC_id],
                  format2A);
            break;
          default:
            LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
            aggregation = 2;
Xu Bo's avatar
Xu Bo committed
703
            break;
Xu Bo's avatar
Xu Bo committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
        }
        format_flag = 1;
        if (!CCE_allocation_infeasible(module_idP,
                                      CC_id,
                                      format_flag,
                                      subframeP,
                                      aggregation,
                                      rnti)) {
          dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
          dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
          DL_req->number_pdu++;

          nb_rbs_required[CC_id][UE_id] = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
          // Insert DLSCH(retransmission) UE into selected UE list
          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].ue_priority = SCH_DL_RETRANS;
          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
          dlsch_ue_select[CC_id].ue_num++;
          if (dlsch_ue_select[CC_id].ue_num == dlsch_ue_max_num[CC_id]) {
727
            end_flag[CC_id] = 1;
Xu Bo's avatar
Xu Bo committed
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
            break;
          }
        } else {
          if (cc[CC_id].tdd_Config != NULL) { //TDD
            set_ue_dai (subframeP,
                         UE_id,
                         CC_id,
            cc[CC_id].tdd_Config->subframeAssignment,
                         UE_list);
            // update UL DAI after DLSCH scheduling
            set_ul_DAI(module_idP,UE_id,CC_id,frameP,subframeP);
          }

          add_ue_dlsch_info(module_idP,
                            CC_id,
                            UE_id,
                            subframeP,
                            S_DL_NONE);
746 747
          end_flag[CC_id] = 1;
          break;
Xu Bo's avatar
Xu Bo committed
748 749 750 751
        }
      }
    }
  }
752 753 754 755 756 757 758
  if(cc_id_end(end_flag) == 1){
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
      DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
      DL_req->number_pdu = saved_dlsch_dci[CC_id];
    }
    return;
  }
Xu Bo's avatar
Xu Bo committed
759 760 761

  // Insert DLSCH(first transmission) UE into selected UE list (UE_id > last_dlsch_ue_id[CC_id])
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
762 763 764
      if (mbsfn_flag[CC_id]>0) {
        continue;
      }
Xu Bo's avatar
Xu Bo committed
765 766

      DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
767 768
      for (UE_id = (last_dlsch_ue_id[CC_id]+1); UE_id <NUMBER_OF_UE_MAX; UE_id++) {
        if(end_flag[CC_id] == 1){
Xu Bo's avatar
Xu Bo committed
769 770 771 772 773 774 775 776 777 778 779 780
          break;
        }

        if (UE_list->active[UE_id] == FALSE) {
          continue;
        }

        rnti = UE_RNTI(module_idP,UE_id);
        if (rnti == NOT_A_RNTI)
          continue;

        ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
781
#if 0
Xu Bo's avatar
Xu Bo committed
782 783 784
        if (ue_sched_ctl->ul_out_of_sync == 1) {
          continue;
        }
785
#endif
786 787 788 789 790 791 792
       for(i = 0;i<dlsch_ue_select[CC_id].ue_num;i++){
          if(dlsch_ue_select[CC_id].list[i].UE_id == UE_id){
           break;
          }
        }
        if(i < dlsch_ue_select[CC_id].ue_num)
          continue;
Xu Bo's avatar
Xu Bo committed
793

794 795 796 797 798 799 800 801
        if (cc[CC_id].tdd_Config) harq_pid = ((frameP*10)+subframeP)%10;
        else harq_pid = ((frameP*10)+subframeP)&7;

        round = ue_sched_ctl->round[CC_id][harq_pid];
        if (round == 8) {
            if (nb_rbs_required[CC_id][UE_id] == 0) {
              continue;
            }
Xu Bo's avatar
Xu Bo committed
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
            switch (get_tmode(module_idP, CC_id, UE_id)) {
              case 1:
              case 2:
              case 7:
                aggregation = get_aggregation(get_bw_index(module_idP, CC_id),
                      ue_sched_ctl->dl_cqi[CC_id],
                      format1);
                break;
              case 3:
                aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
                      ue_sched_ctl->dl_cqi[CC_id],
                      format2A);
                break;
              default:
                LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
                aggregation = 2;
818
                break;
Xu Bo's avatar
Xu Bo committed
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
            }
            format_flag = 1;
            if (!CCE_allocation_infeasible(module_idP,
                                           CC_id,
                                           format_flag,
                                           subframeP,
                                           aggregation,
                                           rnti)) {
              dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
              dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
              DL_req->number_pdu++;

              // Insert DLSCH(first transmission) UE into selected selected UE list
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].ue_priority = SCH_DL_FIRST;
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
              dlsch_ue_select[CC_id].ue_num++;

841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
          if (dlsch_ue_select[CC_id].ue_num == dlsch_ue_max_num[CC_id]) {
                  end_flag[CC_id] = 1;
                  break;
              }
          }else {
            if (cc[CC_id].tdd_Config != NULL) { //TDD
              set_ue_dai (subframeP,
                           UE_id,
                           CC_id,
              cc[CC_id].tdd_Config->subframeAssignment,
                           UE_list);
              // update UL DAI after DLSCH scheduling
              set_ul_DAI(module_idP,UE_id,CC_id,frameP,subframeP);
            }
           add_ue_dlsch_info(module_idP,
Xu Bo's avatar
Xu Bo committed
856 857 858 859
                            CC_id,
                            UE_id,
                            subframeP,
                            S_DL_NONE);
860 861 862
            end_flag[CC_id] = 1;
            break;
          }
Xu Bo's avatar
Xu Bo committed
863 864 865
      }
    }
  }
866 867 868 869 870 871 872
  if(cc_id_end(end_flag) == 1){
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
      DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
      DL_req->number_pdu = saved_dlsch_dci[CC_id];
    }
    return;
  }
Xu Bo's avatar
Xu Bo committed
873 874 875

  // Insert DLSCH(first transmission) UE into selected UE list (UE_id <= last_dlsch_ue_id[CC_id])
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
876 877 878
      if (mbsfn_flag[CC_id]>0) {
        continue;
      }
Xu Bo's avatar
Xu Bo committed
879 880

      DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
881 882
      for (UE_id = 0; UE_id <= last_dlsch_ue_id[CC_id]; UE_id++) {
        if(end_flag[CC_id] == 1){
Xu Bo's avatar
Xu Bo committed
883 884 885 886 887 888 889 890 891 892 893 894
          break;
        }

        if (UE_list->active[UE_id] == FALSE) {
          continue;
        }

        rnti = UE_RNTI(module_idP,UE_id);
        if (rnti == NOT_A_RNTI)
          continue;

        ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
895
#if 0
Xu Bo's avatar
Xu Bo committed
896 897 898
        if (ue_sched_ctl->ul_out_of_sync == 1) {
          continue;
        }
899
#endif
900 901 902 903 904 905 906
        for(i = 0;i<dlsch_ue_select[CC_id].ue_num;i++){
          if(dlsch_ue_select[CC_id].list[i].UE_id == UE_id){
           break;
          }
        }
        if(i < dlsch_ue_select[CC_id].ue_num)
          continue;
Xu Bo's avatar
Xu Bo committed
907

908 909 910 911 912 913 914 915
        if (cc[CC_id].tdd_Config) harq_pid = ((frameP*10)+subframeP)%10;
        else harq_pid = ((frameP*10)+subframeP)&7;

        round = ue_sched_ctl->round[CC_id][harq_pid];
        if (round == 8) {
            if (nb_rbs_required[CC_id][UE_id] == 0) {
                continue;
             }
Xu Bo's avatar
Xu Bo committed
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
            switch (get_tmode(module_idP, CC_id, UE_id)) {
              case 1:
              case 2:
              case 7:
                aggregation = get_aggregation(get_bw_index(module_idP, CC_id),
                      ue_sched_ctl->dl_cqi[CC_id],
                      format1);
                break;
              case 3:
                aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
                      ue_sched_ctl->dl_cqi[CC_id],
                      format2A);
                break;
              default:
                LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
                aggregation = 2;
932
                break;
Xu Bo's avatar
Xu Bo committed
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
            }
            format_flag = 1;
            if (!CCE_allocation_infeasible(module_idP,
                                           CC_id,
                                           format_flag,
                                           subframeP,
                                           aggregation,
                                           rnti)) {
              dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
              dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
              DL_req->number_pdu++;

              // Insert DLSCH(first transmission) UE into selected selected UE list
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].ue_priority = SCH_DL_FIRST;
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
              dlsch_ue_select[CC_id].ue_num++;

955 956 957 958 959 960 961 962 963 964 965 966 967 968
              if (dlsch_ue_select[CC_id].ue_num == dlsch_ue_max_num[CC_id]) {
                end_flag[CC_id] = 1;
                break;
              }
            } else {
              if (cc[CC_id].tdd_Config != NULL) { //TDD
                set_ue_dai (subframeP,
                            UE_id,
                            CC_id,
                            cc[CC_id].tdd_Config->subframeAssignment,
                            UE_list);
              // update UL DAI after DLSCH scheduling
                set_ul_DAI(module_idP,UE_id,CC_id,frameP,subframeP);
              }
Xu Bo's avatar
Xu Bo committed
969 970 971 972 973
          add_ue_dlsch_info(module_idP,
                            CC_id,
                            UE_id,
                            subframeP,
                            S_DL_NONE);
974 975 976
              end_flag[CC_id] = 1;
              break;
            }
Xu Bo's avatar
Xu Bo committed
977 978 979 980 981 982 983 984
      }
    }
  }

  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
    DL_req->number_pdu = saved_dlsch_dci[CC_id];
  }
985
  return;
Xu Bo's avatar
Xu Bo committed
986 987 988 989 990
}



#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
991 992


993
// This function assigns pre-available RBS to each UE in specified sub-bands before scheduling is done
Raymond Knopp's avatar
 
Raymond Knopp committed
994
void dlsch_scheduler_pre_processor (module_id_t   Mod_id,
995 996 997
                                    frame_t       frameP,
                                    sub_frame_t   subframeP,
                                    int           N_RBG[MAX_NUM_CCs],
998
                                    int           *mbsfn_flag)
999
{
Raymond Knopp's avatar
 
Raymond Knopp committed
1000

Xu Bo's avatar
Xu Bo committed
1001
#ifndef UE_EXPANSION
1002
  unsigned char rballoc_sub[MAX_NUM_CCs][N_RBG_MAX],harq_pid=0,round=0,total_ue_count;
Xu Bo's avatar
Xu Bo committed
1003 1004 1005 1006 1007 1008
  uint16_t ii;
  uint16_t                nb_rbs_required_remaining_1[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
  uint16_t r1=0;
//  int rrc_status           = RRC_IDLE;
#else
  unsigned char rballoc_sub[MAX_NUM_CCs][N_RBG_MAX],harq_pid=0,Round=0;
1009 1010
  uint16_t                temp_total_rbs_count;
  unsigned char           temp_total_ue_count;
Xu Bo's avatar
Xu Bo committed
1011
#endif 
Raymond Knopp's avatar
 
Raymond Knopp committed
1012
  unsigned char MIMO_mode_indicator[MAX_NUM_CCs][N_RBG_MAX];
1013
  int                     UE_id, i; 
Xu Bo's avatar
Xu Bo committed
1014
  uint16_t                j;
Raymond Knopp's avatar
 
Raymond Knopp committed
1015 1016
  uint16_t                nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
  uint16_t                nb_rbs_required_remaining[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
Xu Bo's avatar
Xu Bo committed
1017
//  uint16_t                nb_rbs_required_remaining_1[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
1018
  uint16_t                average_rbs_per_user[MAX_NUM_CCs] = {0};
1019
  rnti_t             rnti;
Raymond Knopp's avatar
 
Raymond Knopp committed
1020
  int                min_rb_unit[MAX_NUM_CCs];
Xu Bo's avatar
Xu Bo committed
1021
//  uint16_t r1=0;
1022
  uint8_t CC_id;
1023
  UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
1024

1025
  int N_RB_DL;
1026
  int transmission_mode = 0;
1027 1028
  UE_sched_ctrl *ue_sched_ctl;
  //  int rrc_status           = RRC_IDLE;
1029
  COMMON_channels_t *cc;
1030 1031

#ifdef TM5
1032 1033 1034 1035 1036 1037 1038 1039
    int harq_pid1 = 0;
    int round1 = 0, round2 = 0;
    int UE_id2;
    uint16_t i1, i2, i3;
    rnti_t rnti1, rnti2;
    LTE_eNB_UE_stats *eNB_UE_stats1 = NULL;
    LTE_eNB_UE_stats *eNB_UE_stats2 = NULL;
    UE_sched_ctrl *ue_sched_ctl1, *ue_sched_ctl2;
1040
#endif
1041 1042

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1043

1044 1045
	if (mbsfn_flag[CC_id] > 0)	// If this CC is allocated for MBSFN skip it here
	    continue;
1046 1047


Raymond Knopp's avatar
 
Raymond Knopp committed
1048

1049
	min_rb_unit[CC_id] = get_min_rb_unit(Mod_id, CC_id);
1050

1051 1052 1053
	for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
	    if (UE_list->active[i] != TRUE)
		continue;
1054

1055 1056
	    UE_id = i;
	    // Initialize scheduling information for all active UEs
1057

1058 1059


1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
	    dlsch_scheduler_pre_processor_reset(Mod_id,
						UE_id,
						CC_id,
						frameP,
						subframeP,
						N_RBG[CC_id],
						nb_rbs_required,
						nb_rbs_required_remaining,
						rballoc_sub,
						MIMO_mode_indicator);
Raymond Knopp's avatar
 
Raymond Knopp committed
1070

1071 1072
	}
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
1073

Xu Bo's avatar
Xu Bo committed
1074
#if (!defined(UE_EXPANSION_SIM2)) &&(!defined(UE_EXPANSION))
1075 1076
    // Store the DLSCH buffer for each logical channel
    store_dlsch_buffer(Mod_id, frameP, subframeP);
Raymond Knopp's avatar
 
Raymond Knopp committed
1077 1078


1079

1080 1081 1082
    // Calculate the number of RBs required by each UE on the basis of logical channel's buffer
    assign_rbs_required(Mod_id, frameP, subframeP, nb_rbs_required,
			min_rb_unit);
Xu Bo's avatar
Xu Bo committed
1083 1084 1085
#else
    memcpy(nb_rbs_required, pre_nb_rbs_required[dlsch_ue_select_tbl_in_use] , sizeof(uint16_t)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1086

Xu Bo's avatar
Xu Bo committed
1087 1088 1089
#ifdef UE_EXPANSION
  dlsch_scheduler_pre_ue_select(Mod_id,frameP,subframeP, mbsfn_flag,nb_rbs_required,dlsch_ue_select);
#else
1090
  // Sorts the user on the basis of dlsch logical channel buffer and CQI
Raymond Knopp's avatar
 
Raymond Knopp committed
1091 1092
  sort_UEs (Mod_id,frameP,subframeP);

1093
  total_ue_count =0;
Xu Bo's avatar
Xu Bo committed
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
#endif


 //total_ue_count =0;

#ifdef UE_EXPANSION
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    average_rbs_per_user[CC_id] = 0;
    cc = &RC.mac[Mod_id]->common_channels[CC_id];
    // Get total available RBS count and total UE count
    N_RB_DL = to_prb(cc->mib->message.dl_Bandwidth);
    temp_total_rbs_count = RC.mac[Mod_id]->eNB_stats[CC_id].available_prbs;
    temp_total_ue_count = dlsch_ue_select[CC_id].ue_num;

    for (i = 0; i < dlsch_ue_select[CC_id].ue_num; i++) {
1109 1110 1111 1112 1113 1114 1115 1116
      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2){
          temp_total_ue_count--;
          continue;
      }
      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4){
          temp_total_ue_count--;
          continue;
      }
Xu Bo's avatar
Xu Bo committed
1117 1118 1119
      UE_id = dlsch_ue_select[CC_id].list[i].UE_id;
      nb_rbs_required[CC_id][UE_id] = dlsch_ue_select[CC_id].list[i].nb_rb;

1120 1121 1122 1123 1124 1125
      average_rbs_per_user[CC_id] = (uint16_t)round((double)temp_total_rbs_count/(double)temp_total_ue_count);
      if( average_rbs_per_user[CC_id] < min_rb_unit[CC_id] ){
        temp_total_ue_count--;
        dlsch_ue_select[CC_id].ue_num--;
        i--;
        continue;
Xu Bo's avatar
Xu Bo committed
1126 1127 1128 1129 1130
      }

      rnti = dlsch_ue_select[CC_id].list[i].rnti;

      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
1131
      if (cc->tdd_Config) harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
Xu Bo's avatar
Xu Bo committed
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
      else harq_pid = ((frameP*10)+subframeP)&7;
      Round    = ue_sched_ctl->round[CC_id][harq_pid];

      //if (mac_eNB_get_rrc_status(Mod_id, rnti) < RRC_RECONFIGURED || round > 0) {
      if (mac_eNB_get_rrc_status(Mod_id, rnti) < RRC_RECONFIGURED || Round != 8) {  // FIXME
        nb_rbs_required_remaining[CC_id][UE_id] = dlsch_ue_select[CC_id].list[i].nb_rb;
      } else {
        nb_rbs_required_remaining[CC_id][UE_id] = cmin(average_rbs_per_user[CC_id], dlsch_ue_select[CC_id].list[i].nb_rb);
      }

      transmission_mode = get_tmode(Mod_id,CC_id,UE_id);

      LOG_T(MAC,"calling dlsch_scheduler_pre_processor_allocate .. \n ");
      dlsch_scheduler_pre_processor_allocate (Mod_id,
                                              UE_id,
                                              CC_id,
                                              N_RBG[CC_id],
                                              transmission_mode,
                                              min_rb_unit[CC_id],
                                              N_RB_DL,
                                              nb_rbs_required,
                                              nb_rbs_required_remaining,
                                              rballoc_sub,
                                              MIMO_mode_indicator);
1156 1157 1158
      temp_total_rbs_count -= ue_sched_ctl->pre_nb_available_rbs[CC_id];
      temp_total_ue_count--;

Xu Bo's avatar
Xu Bo committed
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
      if (ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) {
        dlsch_ue_select[CC_id].ue_num = i;
        break;
      }

      if (temp_total_rbs_count == 0) {
        dlsch_ue_select[CC_id].ue_num = i+1;
        break;
      }
#ifdef TM5
      // TODO: data channel TM5: to be re-visited
#endif
    }
  }

#else
1175 1176 1177
    // loop over all active UEs
    for (i = UE_list->head; i >= 0; i = UE_list->next[i]) {
	rnti = UE_RNTI(Mod_id, i);
1178

1179 1180
	if (rnti == NOT_A_RNTI)
	    continue;
1181
#if 0
1182 1183
	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
	    continue;
1184
#endif
1185
	UE_id = i;
1186

1187 1188 1189 1190 1191 1192 1193 1194 1195
	for (ii = 0; ii < UE_num_active_CC(UE_list, UE_id); ii++) {
	    CC_id = UE_list->ordered_CCids[ii][UE_id];
	    ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
	    cc = &RC.mac[Mod_id]->common_channels[ii];
	    if (cc->tdd_Config)
		harq_pid = ((frameP * 10) + subframeP) % 10;
	    else
		harq_pid = ((frameP * 10) + subframeP) & 7;
	    round = ue_sched_ctl->round[CC_id][harq_pid];
1196

1197
	    average_rbs_per_user[CC_id] = 0;
1198

1199

1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
	    if (round != 8) {
		nb_rbs_required[CC_id][UE_id] =
		    UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
	    }
	    //nb_rbs_required_remaining[UE_id] = nb_rbs_required[UE_id];
	    if (nb_rbs_required[CC_id][UE_id] > 0) {
		total_ue_count = total_ue_count + 1;
	    }
	    // hypothetical assignment
	    /*
	     * If schedule is enabled and if the priority of the UEs is modified
	     * The average rbs per logical channel per user will depend on the level of
	     * priority. Concerning the hypothetical assignement, we should assign more
	     * rbs to prioritized users. Maybe, we can do a mapping between the
	     * average rbs per user and the level of priority or multiply the average rbs
	     * per user by a coefficient which represents the degree of priority.
	     */

	    N_RB_DL =
		to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->
		       message.dl_Bandwidth);

	    if (total_ue_count == 0) {
		average_rbs_per_user[CC_id] = 0;
	    } else if ((min_rb_unit[CC_id] * total_ue_count) <= (N_RB_DL)) {
		average_rbs_per_user[CC_id] =
		    (uint16_t) floor(N_RB_DL / total_ue_count);
	    } else {
		average_rbs_per_user[CC_id] = min_rb_unit[CC_id];	// consider the total number of use that can be scheduled UE
	    }
	}
Raymond Knopp's avatar
 
Raymond Knopp committed
1231
    }
1232

1233 1234 1235 1236
    // note: nb_rbs_required is assigned according to total_buffer_dl
    // extend nb_rbs_required to capture per LCID RB required
    for (i = UE_list->head; i >= 0; i = UE_list->next[i]) {
	rnti = UE_RNTI(Mod_id, i);
1237

1238 1239
	if (rnti == NOT_A_RNTI)
	    continue;
1240
#if 0
1241 1242
	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
	    continue;
1243
#endif
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
	for (ii = 0; ii < UE_num_active_CC(UE_list, i); ii++) {
	    CC_id = UE_list->ordered_CCids[ii][i];
	    ue_sched_ctl = &UE_list->UE_sched_ctrl[i];
	    round = ue_sched_ctl->round[CC_id][harq_pid];

	    // control channel or retransmission
	    /* TODO: do we have to check for retransmission? */
	    if (mac_eNB_get_rrc_status(Mod_id, rnti) < RRC_RECONFIGURED
		|| round > 0) {
		nb_rbs_required_remaining_1[CC_id][i] =
		    nb_rbs_required[CC_id][i];
	    } else {
		nb_rbs_required_remaining_1[CC_id][i] =
		    cmin(average_rbs_per_user[CC_id],
			 nb_rbs_required[CC_id][i]);
1259

1260 1261
	    }
	}
Raymond Knopp's avatar
 
Raymond Knopp committed
1262
    }
1263

1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
    //Allocation to UEs is done in 2 rounds,
    // 1st stage: average number of RBs allocated to each UE
    // 2nd stage: remaining RBs are allocated to high priority UEs
    for (r1 = 0; r1 < 2; r1++) {

	for (i = UE_list->head; i >= 0; i = UE_list->next[i]) {
	    for (ii = 0; ii < UE_num_active_CC(UE_list, i); ii++) {
		CC_id = UE_list->ordered_CCids[ii][i];

		if (r1 == 0) {
		    nb_rbs_required_remaining[CC_id][i] =
			nb_rbs_required_remaining_1[CC_id][i];
		} else {	// rb required based only on the buffer - rb allloctaed in the 1st round + extra reaming rb form the 1st round
		    nb_rbs_required_remaining[CC_id][i] =
			nb_rbs_required[CC_id][i] -
			nb_rbs_required_remaining_1[CC_id][i] +
			nb_rbs_required_remaining[CC_id][i];
		    if (nb_rbs_required_remaining[CC_id][i] < 0)
			abort();
		}

		if (nb_rbs_required[CC_id][i] > 0)
		    LOG_D(MAC,
			  "round %d : nb_rbs_required_remaining[%d][%d]= %d (remaining_1 %d, required %d,  pre_nb_available_rbs %d, N_RBG %d, rb_unit %d)\n",
			  r1, CC_id, i,
			  nb_rbs_required_remaining[CC_id][i],
			  nb_rbs_required_remaining_1[CC_id][i],
			  nb_rbs_required[CC_id][i],
			  UE_list->UE_sched_ctrl[i].
			  pre_nb_available_rbs[CC_id], N_RBG[CC_id],
			  min_rb_unit[CC_id]);
1295

1296 1297
	    }
	}
1298

1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312
	if (total_ue_count > 0) {
	    for (i = UE_list->head; i >= 0; i = UE_list->next[i]) {
		UE_id = i;

		for (ii = 0; ii < UE_num_active_CC(UE_list, UE_id); ii++) {
		    CC_id = UE_list->ordered_CCids[ii][UE_id];
		    ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
		    round = ue_sched_ctl->round[CC_id][harq_pid];

		    rnti = UE_RNTI(Mod_id, UE_id);

		    // LOG_D(MAC,"UE %d rnti 0x\n", UE_id, rnti );
		    if (rnti == NOT_A_RNTI)
			continue;
1313
#if 0
1314 1315
		    if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1)
			continue;
1316
#endif
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
		    transmission_mode = get_tmode(Mod_id, CC_id, UE_id);
		    //          mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti,frameP,subframeP,&harq_pid,&round,0);
		    //rrc_status = mac_eNB_get_rrc_status(Mod_id,rnti);
		    /* 1st allocate for the retx */

		    // retransmission in data channels
		    // control channel in the 1st transmission
		    // data channel for all TM
		    LOG_T(MAC,
			  "calling dlsch_scheduler_pre_processor_allocate .. \n ");
		    dlsch_scheduler_pre_processor_allocate(Mod_id, UE_id,
							   CC_id,
							   N_RBG[CC_id],
							   transmission_mode,
							   min_rb_unit
							   [CC_id],
							   to_prb(RC.mac
								  [Mod_id]->common_channels
								  [CC_id].mib->message.dl_Bandwidth),
							   nb_rbs_required,
							   nb_rbs_required_remaining,
							   rballoc_sub,
							   MIMO_mode_indicator);
1340

1341
#ifdef TM5
1342

1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
		    // data chanel TM5: to be revisted
		    if ((round == 0) &&
			(transmission_mode == 5) &&
			(ue_sched_ctl->dl_pow_off[CC_id] != 1)) {

			for (j = 0; j < N_RBG[CC_id]; j += 2) {

			    if ((((j == (N_RBG[CC_id] - 1))
				  && (rballoc_sub[CC_id][j] == 0)
				  && (ue_sched_ctl->
				      rballoc_sub_UE[CC_id][j] == 0))
				 || ((j < (N_RBG[CC_id] - 1))
				     && (rballoc_sub[CC_id][j + 1] == 0)
				     &&
				     (ue_sched_ctl->rballoc_sub_UE
				      [CC_id][j + 1] == 0)))
				&& (nb_rbs_required_remaining[CC_id][UE_id]
				    > 0)) {

				for (ii = UE_list->next[i + 1]; ii >= 0;
				     ii = UE_list->next[ii]) {

				    UE_id2 = ii;
				    rnti2 = UE_RNTI(Mod_id, UE_id2);
				    ue_sched_ctl2 =
					&UE_list->UE_sched_ctrl[UE_id2];
				    round2 = ue_sched_ctl2->round[CC_id];
				    if (rnti2 == NOT_A_RNTI)
					continue;
1372
#if 0				    if (UE_list->
1373 1374 1375
					UE_sched_ctrl
					[UE_id2].ul_out_of_sync == 1)
					continue;
1376
#endif
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
				    eNB_UE_stats2 =
					UE_list->
					eNB_UE_stats[CC_id][UE_id2];
				    //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0);

				    if ((mac_eNB_get_rrc_status
					 (Mod_id,
					  rnti2) >= RRC_RECONFIGURED)
					&& (round2 == 0)
					&&
					(get_tmode(Mod_id, CC_id, UE_id2)
					 == 5)
					&& (ue_sched_ctl->
					    dl_pow_off[CC_id] != 1)) {

					if ((((j == (N_RBG[CC_id] - 1))
					      &&
					      (ue_sched_ctl->rballoc_sub_UE
					       [CC_id][j] == 0))
					     || ((j < (N_RBG[CC_id] - 1))
						 &&
						 (ue_sched_ctl->
						  rballoc_sub_UE[CC_id][j +
									1]
						  == 0)))
					    &&
					    (nb_rbs_required_remaining
					     [CC_id]
					     [UE_id2] > 0)) {

					    if ((((eNB_UE_stats2->
						   DL_pmi_single ^
						   eNB_UE_stats1->
						   DL_pmi_single)
						  << (14 - j)) & 0xc000) == 0x4000) {	//MU-MIMO only for 25 RBs configuration

						rballoc_sub[CC_id][j] = 1;
						ue_sched_ctl->
						    rballoc_sub_UE[CC_id]
						    [j] = 1;
						ue_sched_ctl2->
						    rballoc_sub_UE[CC_id]
						    [j] = 1;
						MIMO_mode_indicator[CC_id]
						    [j] = 0;

						if (j < N_RBG[CC_id] - 1) {
						    rballoc_sub[CC_id][j +
								       1] =
							1;
						    ue_sched_ctl->
							rballoc_sub_UE
							[CC_id][j + 1] = 1;
						    ue_sched_ctl2->rballoc_sub_UE
							[CC_id][j + 1] = 1;
						    MIMO_mode_indicator
							[CC_id][j + 1]
							= 0;
						}

						ue_sched_ctl->
						    dl_pow_off[CC_id]
						    = 0;
						ue_sched_ctl2->
						    dl_pow_off[CC_id]
						    = 0;


						if ((j == N_RBG[CC_id] - 1)
						    && ((N_RB_DL == 25)
							|| (N_RB_DL ==
							    50))) {

						    nb_rbs_required_remaining
							[CC_id][UE_id] =
							nb_rbs_required_remaining
							[CC_id][UE_id] -
							min_rb_unit[CC_id]
							+ 1;
						    ue_sched_ctl->pre_nb_available_rbs
							[CC_id] =
							ue_sched_ctl->pre_nb_available_rbs
							[CC_id] +
							min_rb_unit[CC_id]
							- 1;
						    nb_rbs_required_remaining
							[CC_id][UE_id2] =
							nb_rbs_required_remaining
							[CC_id][UE_id2] -
							min_rb_unit[CC_id]
							+ 1;
						    ue_sched_ctl2->pre_nb_available_rbs
							[CC_id] =
							ue_sched_ctl2->pre_nb_available_rbs
							[CC_id] +
							min_rb_unit[CC_id]
							- 1;
						} else {

						    nb_rbs_required_remaining
							[CC_id][UE_id] =
							nb_rbs_required_remaining
							[CC_id][UE_id] - 4;
						    ue_sched_ctl->pre_nb_available_rbs
							[CC_id] =
							ue_sched_ctl->pre_nb_available_rbs
							[CC_id] + 4;
						    nb_rbs_required_remaining
							[CC_id][UE_id2] =
							nb_rbs_required_remaining
							[CC_id][UE_id2] -
							4;
						    ue_sched_ctl2->pre_nb_available_rbs
							[CC_id] =
							ue_sched_ctl2->pre_nb_available_rbs
							[CC_id] + 4;
						}

						break;
					    }
					}
				    }
				}
			    }
			}
		    }
1503
#endif
1504 1505 1506 1507
		}
	    }
	}			// total_ue_count
    }				// end of for for r1 and r2
Xu Bo's avatar
Xu Bo committed
1508
#endif  // end of #ifndef UE_EXPANSION
1509 1510
#ifdef TM5

1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
    // This has to be revisited!!!!
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
	i1 = 0;
	i2 = 0;
	i3 = 0;

	for (j = 0; j < N_RBG[CC_id]; j++) {
	    if (MIMO_mode_indicator[CC_id][j] == 2) {
		i1 = i1 + 1;
	    } else if (MIMO_mode_indicator[CC_id][j] == 1) {
		i2 = i2 + 1;
	    } else if (MIMO_mode_indicator[CC_id][j] == 0) {
		i3 = i3 + 1;
	    }
	}
1526

1527 1528 1529 1530 1531
	if ((i1 < N_RBG[CC_id]) && (i2 > 0) && (i3 == 0)) {
	    PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions =
		PHY_vars_eNB_g[Mod_id][CC_id]->
		check_for_SUMIMO_transmissions + 1;
	}
1532

1533 1534 1535 1536 1537
	if (i3 == N_RBG[CC_id] && i1 == 0 && i2 == 0) {
	    PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions =
		PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions +
		1;
	}
1538

Xu Bo's avatar
Xu Bo committed
1539
        if((i1 < N_RBG[CC_id]) && (i3 > 0)) {
1540 1541 1542
		PHY_vars_eNB_g[Mod_id][CC_id]->
		check_for_MUMIMO_transmissions + 1;
	}
1543

1544 1545 1546
	PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions =
	    PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions +
	    1;
1547

Raymond Knopp's avatar
 
Raymond Knopp committed
1548
    }
1549

1550 1551
#endif

Xu Bo's avatar
Xu Bo committed
1552 1553 1554
#ifdef UE_EXPANSION
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
      for (i = 0; i < dlsch_ue_select[CC_id].ue_num; i++) {
1555 1556 1557 1558 1559 1560
        if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2){
            continue;
        }
        if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4){
            continue;
        }
Xu Bo's avatar
Xu Bo committed
1561 1562 1563
        UE_id = dlsch_ue_select[CC_id].list[i].UE_id;
        ue_sched_ctl = &RC.mac[Mod_id]->UE_list.UE_sched_ctrl[UE_id];
#else
1564
  for(i=UE_list->head; i>=0; i=UE_list->next[i]) {
1565
    UE_id = i;
1566
    ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
1567 1568

    for (ii=0; ii<UE_num_active_CC(UE_list,UE_id); ii++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1569
      CC_id = UE_list->ordered_CCids[ii][UE_id];
Xu Bo's avatar
Xu Bo committed
1570
#endif
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
	    //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].dl_pow_off = dl_pow_off[UE_id];

	    if (ue_sched_ctl->pre_nb_available_rbs[CC_id] > 0) {
		LOG_D(MAC,
		      "******************DL Scheduling Information for UE%d ************************\n",
		      UE_id);
		LOG_D(MAC, "dl power offset UE%d = %d \n", UE_id,
		      ue_sched_ctl->dl_pow_off[CC_id]);
		LOG_D(MAC,
		      "***********RB Alloc for every subband for UE%d ***********\n",
		      UE_id);

		for (j = 0; j < N_RBG[CC_id]; j++) {
		    //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].rballoc_sub[i] = rballoc_sub_UE[CC_id][UE_id][i];
		    LOG_D(MAC, "RB Alloc for UE%d and Subband%d = %d\n",
			  UE_id, j,
			  ue_sched_ctl->rballoc_sub_UE[CC_id][j]);
		}

		//PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].pre_nb_available_rbs = pre_nb_available_rbs[CC_id][UE_id];
		LOG_D(MAC, "Total RBs allocated for UE%d = %d\n", UE_id,
		      ue_sched_ctl->pre_nb_available_rbs[CC_id]);
	    }
	}
Raymond Knopp's avatar
 
Raymond Knopp committed
1595
    }
1596 1597
}

Cedric Roux's avatar
Cedric Roux committed
1598
#define SF0_LIMIT 1
1599

1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
void
dlsch_scheduler_pre_processor_reset(int module_idP,
				    int UE_id,
				    uint8_t CC_id,
				    int frameP,
				    int subframeP,
				    int N_RBG,
				    uint16_t nb_rbs_required[MAX_NUM_CCs]
				    [NUMBER_OF_UE_MAX],
				    uint16_t
				    nb_rbs_required_remaining
				    [MAX_NUM_CCs][NUMBER_OF_UE_MAX],
				    unsigned char
				    rballoc_sub[MAX_NUM_CCs]
				    [N_RBG_MAX], unsigned char
				    MIMO_mode_indicator[MAX_NUM_CCs]
				    [N_RBG_MAX])
1617
{
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
    int i, j;
    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
    UE_sched_ctrl *ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
    rnti_t rnti = UE_RNTI(module_idP, UE_id);

    uint8_t *vrb_map = RC.mac[module_idP]->common_channels[CC_id].vrb_map;
    int N_RB_DL =
	to_prb(RC.mac[module_idP]->common_channels[CC_id].mib->
	       message.dl_Bandwidth);
    int RBGsize = N_RB_DL / N_RBG, RBGsize_last;
Cedric Roux's avatar
Cedric Roux committed
1628
#ifdef SF0_LIMIT
1629
    int sf0_upper = -1, sf0_lower = -1;
1630
#endif
1631

Xu Bo's avatar
Xu Bo committed
1632
    LOG_D(MAC,"Running preprocessor for UE %d (%x)\n",UE_id,rnti);
1633
    // initialize harq_pid and round
1634

1635 1636
    if (ue_sched_ctl->ta_timer)
	ue_sched_ctl->ta_timer--;
1637

1638 1639
    /*
       eNB_UE_stats *eNB_UE_stats;
1640

1641 1642
       if (eNB_UE_stats == NULL)
       return;
1643 1644


1645 1646 1647 1648 1649
       mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,
       frameP,subframeP,
       &ue_sched_ctl->harq_pid[CC_id],
       &ue_sched_ctl->round[CC_id],
       openair_harq_DL);
1650

1651

1652
       if (ue_sched_ctl->ta_timer == 0) {
1653

1654
       // WE SHOULD PROTECT the eNB_UE_stats with a mutex here ...
1655

1656 1657 1658 1659 1660
       ue_sched_ctl->ta_timer = 20;  // wait 20 subframes before taking TA measurement from PHY
       switch (N_RB_DL) {
       case 6:
       ue_sched_ctl->ta_update = eNB_UE_stats->timing_advance_update;
       break;
1661

1662 1663 1664
       case 15:
       ue_sched_ctl->ta_update = eNB_UE_stats->timing_advance_update/2;
       break;
Cedric Roux's avatar
Cedric Roux committed
1665

1666 1667 1668
       case 25:
       ue_sched_ctl->ta_update = eNB_UE_stats->timing_advance_update/4;
       break;
1669

1670 1671 1672
       case 50:
       ue_sched_ctl->ta_update = eNB_UE_stats->timing_advance_update/8;
       break;
1673

1674 1675 1676
       case 75:
       ue_sched_ctl->ta_update = eNB_UE_stats->timing_advance_update/12;
       break;
1677

1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
       case 100:
       ue_sched_ctl->ta_update = eNB_UE_stats->timing_advance_update/16;
       break;
       }
       // clear the update in case PHY does not have a new measurement after timer expiry
       eNB_UE_stats->timing_advance_update =  0;
       }
       else {
       ue_sched_ctl->ta_timer--;
       ue_sched_ctl->ta_update =0; // don't trigger a timing advance command
       }
1689

1690

1691 1692 1693 1694
       if (UE_id==0) {
       VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_TIMING_ADVANCE,ue_sched_ctl->ta_update);
       }
     */
1695

1696 1697 1698 1699
    nb_rbs_required[CC_id][UE_id] = 0;
    ue_sched_ctl->pre_nb_available_rbs[CC_id] = 0;
    ue_sched_ctl->dl_pow_off[CC_id] = 2;
    nb_rbs_required_remaining[CC_id][UE_id] = 0;
1700

1701
    switch (N_RB_DL) {
1702
    case 6:
1703 1704 1705
	RBGsize = 1;
	RBGsize_last = 1;
	break;
1706
    case 15:
1707 1708 1709
	RBGsize = 2;
	RBGsize_last = 1;
	break;
1710
    case 25:
1711 1712 1713
	RBGsize = 2;
	RBGsize_last = 1;
	break;
1714
    case 50:
1715 1716 1717
	RBGsize = 3;
	RBGsize_last = 2;
	break;
1718
    case 75:
1719 1720 1721
	RBGsize = 4;
	RBGsize_last = 3;
	break;
1722
    case 100:
1723 1724 1725 1726 1727
	RBGsize = 4;
	RBGsize_last = 4;
	break;
    default:
	AssertFatal(1 == 0, "unsupported RBs (%d)\n", N_RB_DL);
1728
    }
1729

Cedric Roux's avatar
Cedric Roux committed
1730
#ifdef SF0_LIMIT
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
    switch (N_RBG) {
    case 6:
	sf0_lower = 0;
	sf0_upper = 5;
	break;
    case 8:
	sf0_lower = 2;
	sf0_upper = 5;
	break;
    case 13:
	sf0_lower = 4;
	sf0_upper = 7;
	break;
    case 17:
	sf0_lower = 7;
	sf0_upper = 9;
	break;
    case 25:
	sf0_lower = 11;
	sf0_upper = 13;
	break;
    default:
	AssertFatal(1 == 0, "unsupported RBs (%d)\n", N_RB_DL);
    }
1755
#endif
1756 1757 1758
    // Initialize Subbands according to VRB map
    for (i = 0; i < N_RBG; i++) {
	int rb_size = i == N_RBG - 1 ? RBGsize_last : RBGsize;
Cedric Roux's avatar
Cedric Roux committed
1759

1760 1761
	ue_sched_ctl->rballoc_sub_UE[CC_id][i] = 0;
	rballoc_sub[CC_id][i] = 0;
Cedric Roux's avatar
Cedric Roux committed
1762
#ifdef SF0_LIMIT
1763 1764 1765 1766 1767 1768 1769
	// for avoiding 6+ PRBs around DC in subframe 0 (avoid excessive errors)
	/* TODO: make it proper - allocate those RBs, do not "protect" them, but
	 * compute number of available REs and limit MCS according to the
	 * TBS table 36.213 7.1.7.2.1-1 (can be done after pre-processor)
	 */
	if (subframeP == 0 && i >= sf0_lower && i <= sf0_upper)
	    rballoc_sub[CC_id][i] = 1;
1770
#endif
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
	// for SI-RNTI,RA-RNTI and P-RNTI allocations
	for (j = 0; j < rb_size; j++) {
	    if (vrb_map[j + (i * RBGsize)] != 0) {
		rballoc_sub[CC_id][i] = 1;
		LOG_D(MAC, "Frame %d, subframe %d : vrb %d allocated\n",
		      frameP, subframeP, j + (i * RBGsize));
		break;
	    }
	}
	LOG_D(MAC, "Frame %d Subframe %d CC_id %d RBG %i : rb_alloc %d\n",
	      frameP, subframeP, CC_id, i, rballoc_sub[CC_id][i]);
	MIMO_mode_indicator[CC_id][i] = 2;
1783
    }
1784 1785 1786
}


1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
void
dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id,
				       int UE_id,
				       uint8_t CC_id,
				       int N_RBG,
				       int transmission_mode,
				       int min_rb_unit,
				       uint8_t N_RB_DL,
				       uint16_t
				       nb_rbs_required[MAX_NUM_CCs]
				       [NUMBER_OF_UE_MAX],
				       uint16_t
				       nb_rbs_required_remaining
				       [MAX_NUM_CCs]
				       [NUMBER_OF_UE_MAX], unsigned char
				       rballoc_sub[MAX_NUM_CCs]
				       [N_RBG_MAX], unsigned char
				       MIMO_mode_indicator
				       [MAX_NUM_CCs][N_RBG_MAX])
1806 1807
{

1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857
    int i;
    UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
    UE_sched_ctrl *ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];

    for (i = 0; i < N_RBG; i++) {

	if ((rballoc_sub[CC_id][i] == 0) &&
	    (ue_sched_ctl->rballoc_sub_UE[CC_id][i] == 0) &&
	    (nb_rbs_required_remaining[CC_id][UE_id] > 0) &&
	    (ue_sched_ctl->pre_nb_available_rbs[CC_id] <
	     nb_rbs_required[CC_id][UE_id])) {

	    // if this UE is not scheduled for TM5
	    if (ue_sched_ctl->dl_pow_off[CC_id] != 0) {

		if ((i == N_RBG - 1)
		    && ((N_RB_DL == 25) || (N_RB_DL == 50))) {
		    if (nb_rbs_required_remaining[CC_id][UE_id] >=
			min_rb_unit - 1) {
			rballoc_sub[CC_id][i] = 1;
			ue_sched_ctl->rballoc_sub_UE[CC_id][i] = 1;
			MIMO_mode_indicator[CC_id][i] = 1;
			if (transmission_mode == 5) {
			    ue_sched_ctl->dl_pow_off[CC_id] = 1;
			}
			nb_rbs_required_remaining[CC_id][UE_id] =
			    nb_rbs_required_remaining[CC_id][UE_id] -
			    min_rb_unit + 1;
			ue_sched_ctl->pre_nb_available_rbs[CC_id] =
			    ue_sched_ctl->pre_nb_available_rbs[CC_id] +
			    min_rb_unit - 1;
		    }
		} else {
		    if (nb_rbs_required_remaining[CC_id][UE_id] >=
			min_rb_unit) {
			rballoc_sub[CC_id][i] = 1;
			ue_sched_ctl->rballoc_sub_UE[CC_id][i] = 1;
			MIMO_mode_indicator[CC_id][i] = 1;
			if (transmission_mode == 5) {
			    ue_sched_ctl->dl_pow_off[CC_id] = 1;
			}
			nb_rbs_required_remaining[CC_id][UE_id] =
			    nb_rbs_required_remaining[CC_id][UE_id] -
			    min_rb_unit;
			ue_sched_ctl->pre_nb_available_rbs[CC_id] =
			    ue_sched_ctl->pre_nb_available_rbs[CC_id] +
			    min_rb_unit;
		    }
		}
	    }			// dl_pow_off[CC_id][UE_id] ! = 0
1858
	}
1859 1860 1861 1862
    }
}


1863
/// ULSCH PRE_PROCESSOR
1864

Xu Bo's avatar
Xu Bo committed
1865
#ifndef UE_EXPANSION
1866
void ulsch_scheduler_pre_processor(module_id_t module_idP,
1867 1868
                                   int frameP,
                                   sub_frame_t subframeP,
1869
                                   unsigned char sched_subframeP,
1870
                                   uint16_t *first_rb)
1871
{
1872

1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
    int16_t i;
    uint16_t UE_id, n, r;
    uint8_t CC_id, harq_pid;
    uint16_t nb_allocated_rbs[MAX_NUM_CCs][NUMBER_OF_UE_MAX],
	total_allocated_rbs[MAX_NUM_CCs],
	average_rbs_per_user[MAX_NUM_CCs];
    int16_t total_remaining_rbs[MAX_NUM_CCs];
    uint16_t max_num_ue_to_be_scheduled = 0;
    uint16_t total_ue_count = 0;
    rnti_t rnti = -1;
    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
    UE_TEMPLATE *UE_template = 0;
    int N_RB_DL;
    int N_RB_UL;
    LOG_D(MAC, "In ulsch_preprocessor: assign max mcs min rb\n");
    // maximize MCS and then allocate required RB according to the buffer occupancy with the limit of max available UL RB
    assign_max_mcs_min_rb(module_idP, frameP, subframeP, first_rb);

    LOG_D(MAC, "In ulsch_preprocessor: sort ue \n");
    // sort ues
    sort_ue_ul(module_idP, frameP, subframeP);


    // we need to distribute RBs among UEs
    // step1:  reset the vars
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
	N_RB_DL =
	    to_prb(RC.mac[module_idP]->common_channels[CC_id].mib->
		   message.dl_Bandwidth);
	N_RB_UL =
	    to_prb(RC.mac[module_idP]->common_channels[CC_id].
		   ul_Bandwidth);
	total_allocated_rbs[CC_id] = 0;
	total_remaining_rbs[CC_id] = 0;
	average_rbs_per_user[CC_id] = 0;

	for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
	    nb_allocated_rbs[CC_id][i] = 0;
	}
1912 1913
    }

1914 1915 1916 1917
    LOG_D(MAC, "In ulsch_preprocessor: step2 \n");
    // step 2: calculate the average rb per UE
    total_ue_count = 0;
    max_num_ue_to_be_scheduled = 0;
1918

1919
    for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
1920

1921
	rnti = UE_RNTI(module_idP, i);
1922

1923 1924
	if (rnti == NOT_A_RNTI)
	    continue;
1925

1926 1927
	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
	    continue;
kaltenbe's avatar
kaltenbe committed
1928

1929

1930
	UE_id = i;
1931

1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
	LOG_D(MAC, "In ulsch_preprocessor: handling UE %d/%x\n", UE_id,
	      rnti);
	for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) {
	    // This is the actual CC_id in the list
	    CC_id = UE_list->ordered_ULCCids[n][UE_id];
	    LOG_D(MAC,
		  "In ulsch_preprocessor: handling UE %d/%x CCid %d\n",
		  UE_id, rnti, CC_id);
	    UE_template = &UE_list->UE_template[CC_id][UE_id];
	    average_rbs_per_user[CC_id] = 0;
1942

1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
	    if (UE_template->pre_allocated_nb_rb_ul > 0) {
		total_ue_count += 1;
	    }
	    /*
	       if((mac_xface->get_nCCE_max(module_idP,CC_id,3,subframeP) - nCCE_to_be_used[CC_id])  > (1<<aggregation)) {
	       nCCE_to_be_used[CC_id] = nCCE_to_be_used[CC_id] + (1<<aggregation);
	       max_num_ue_to_be_scheduled+=1;
	       } */

	    max_num_ue_to_be_scheduled += 1;

	    if (total_ue_count == 0) {
		average_rbs_per_user[CC_id] = 0;
	    } else if (total_ue_count == 1) {	// increase the available RBs, special case,
		average_rbs_per_user[CC_id] =
		    N_RB_UL - first_rb[CC_id] + 1;
	    } else if ((total_ue_count <= (N_RB_DL - first_rb[CC_id]))
		       && (total_ue_count <= max_num_ue_to_be_scheduled)) {
		average_rbs_per_user[CC_id] =
		    (uint16_t) floor((N_RB_UL - first_rb[CC_id]) /
				     total_ue_count);
	    } else if (max_num_ue_to_be_scheduled > 0) {
		average_rbs_per_user[CC_id] =
		    (uint16_t) floor((N_RB_UL - first_rb[CC_id]) /
				     max_num_ue_to_be_scheduled);
	    } else {
		average_rbs_per_user[CC_id] = 1;
		LOG_W(MAC,
		      "[eNB %d] frame %d subframe %d: UE %d CC %d: can't get average rb per user (should not be here)\n",
		      module_idP, frameP, subframeP, UE_id, CC_id);
	    }
	}
1975
    }
1976 1977 1978 1979 1980
    if (total_ue_count > 0)
	LOG_D(MAC,
	      "[eNB %d] Frame %d subframe %d: total ue to be scheduled %d/%d\n",
	      module_idP, frameP, subframeP, total_ue_count,
	      max_num_ue_to_be_scheduled);
1981

1982
    //LOG_D(MAC,"step3\n");
Raymond Knopp's avatar
 
Raymond Knopp committed
1983

1984 1985 1986
    // step 3: assigne RBS
    for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
	rnti = UE_RNTI(module_idP, i);
1987

1988 1989 1990 1991
	if (rnti == NOT_A_RNTI)
	    continue;
	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
	    continue;
1992

1993
	UE_id = i;
1994

1995 1996 1997 1998 1999 2000
	for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) {
	    // This is the actual CC_id in the list
	    CC_id = UE_list->ordered_ULCCids[n][UE_id];
	    harq_pid =
		subframe2harqpid(&RC.mac[module_idP]->
				 common_channels[CC_id], frameP,
2001
				 sched_subframeP);
2002

2003

2004
	    //      mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL);
2005

2006 2007 2008 2009 2010 2011 2012 2013 2014
	    if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id] > 0) {
		nb_allocated_rbs[CC_id][UE_id] =
		    UE_list->UE_template[CC_id][UE_id].nb_rb_ul[harq_pid];
	    } else {
		nb_allocated_rbs[CC_id][UE_id] =
		    cmin(UE_list->
			 UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul,
			 average_rbs_per_user[CC_id]);
	    }
2015

2016 2017 2018 2019 2020 2021
	    total_allocated_rbs[CC_id] += nb_allocated_rbs[CC_id][UE_id];
	    LOG_D(MAC,
		  "In ulsch_preprocessor: assigning %d RBs for UE %d/%x CCid %d, harq_pid %d\n",
		  nb_allocated_rbs[CC_id][UE_id], UE_id, rnti, CC_id,
		  harq_pid);
	}
2022
    }
2023

2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
    // step 4: assigne the remaining RBs and set the pre_allocated rbs accordingly
    for (r = 0; r < 2; r++) {

	for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
	    rnti = UE_RNTI(module_idP, i);

	    if (rnti == NOT_A_RNTI)
		continue;
	    if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
		continue;
	    UE_id = i;

	    for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) {
		// This is the actual CC_id in the list
		CC_id = UE_list->ordered_ULCCids[n][UE_id];
		UE_template = &UE_list->UE_template[CC_id][UE_id];
		total_remaining_rbs[CC_id] =
		    N_RB_UL - first_rb[CC_id] - total_allocated_rbs[CC_id];

		if (total_ue_count == 1) {
		    total_remaining_rbs[CC_id] += 1;
		}

		if (r == 0) {
		    while ((UE_template->pre_allocated_nb_rb_ul > 0) &&
			   (nb_allocated_rbs[CC_id][UE_id] <
			    UE_template->pre_allocated_nb_rb_ul)
			   && (total_remaining_rbs[CC_id] > 0)) {
			nb_allocated_rbs[CC_id][UE_id] =
			    cmin(nb_allocated_rbs[CC_id][UE_id] + 1,
				 UE_template->pre_allocated_nb_rb_ul);
			total_remaining_rbs[CC_id]--;
			total_allocated_rbs[CC_id]++;
		    }
		} else {
		    UE_template->pre_allocated_nb_rb_ul =
			nb_allocated_rbs[CC_id][UE_id];
		    LOG_D(MAC,
			  "******************UL Scheduling Information for UE%d CC_id %d ************************\n",
			  UE_id, CC_id);
		    LOG_D(MAC,
			  "[eNB %d] total RB allocated for UE%d CC_id %d  = %d\n",
			  module_idP, UE_id, CC_id,
			  UE_template->pre_allocated_nb_rb_ul);
		}
	    }
	}
2071
    }
2072

2073
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
2074

2075 2076 2077 2078 2079
	if (total_allocated_rbs[CC_id] > 0) {
	    LOG_D(MAC, "[eNB %d] total RB allocated for all UEs = %d/%d\n",
		  module_idP, total_allocated_rbs[CC_id],
		  N_RB_UL - first_rb[CC_id]);
	}
2080
    }
2081
}
Xu Bo's avatar
Xu Bo committed
2082
#endif
2083

2084 2085 2086
void
assign_max_mcs_min_rb(module_id_t module_idP, int frameP,
		      sub_frame_t subframeP, uint16_t * first_rb)
2087 2088
{

2089 2090 2091 2092 2093 2094 2095 2096
    int i;
    uint16_t n, UE_id;
    uint8_t CC_id;
    rnti_t rnti = -1;
    int mcs;
    int rb_table_index = 0, tbs, tx_power;
    eNB_MAC_INST *eNB = RC.mac[module_idP];
    UE_list_t *UE_list = &eNB->UE_list;
2097

2098 2099 2100
    UE_TEMPLATE *UE_template;
    int Ncp;
    int N_RB_UL;
2101

2102 2103 2104
    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
	if (UE_list->active[i] != TRUE)
	    continue;
2105

2106
	rnti = UE_RNTI(module_idP, i);
2107

2108 2109 2110 2111
	if (rnti == NOT_A_RNTI)
	    continue;
	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
	    continue;
2112

2113 2114 2115 2116
	if (UE_list->UE_sched_ctrl[i].phr_received == 1)
	    mcs = 20;		// if we've received the power headroom information the UE, we can go to maximum mcs
	else
	    mcs = 10;		// otherwise, limit to QPSK PUSCH
2117

2118
	UE_id = i;
2119

2120 2121 2122
	for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) {
	    // This is the actual CC_id in the list
	    CC_id = UE_list->ordered_ULCCids[n][UE_id];
2123

2124 2125 2126 2127 2128 2129
	    if (CC_id >= MAX_NUM_CCs) {
		LOG_E(MAC,
		      "CC_id %u should be < %u, loop n=%u < numactiveULCCs[%u]=%u",
		      CC_id, MAX_NUM_CCs, n, UE_id,
		      UE_list->numactiveULCCs[UE_id]);
	    }
2130

2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213
	    AssertFatal(CC_id < MAX_NUM_CCs,
			"CC_id %u should be < %u, loop n=%u < numactiveULCCs[%u]=%u",
			CC_id, MAX_NUM_CCs, n, UE_id,
			UE_list->numactiveULCCs[UE_id]);

	    UE_template = &UE_list->UE_template[CC_id][UE_id];

	    Ncp = RC.mac[module_idP]->common_channels[CC_id].Ncp;
	    N_RB_UL =
		to_prb(RC.mac[module_idP]->common_channels[CC_id].
		       ul_Bandwidth);
	    // if this UE has UL traffic
	    if (UE_template->ul_total_buffer > 0) {


		tbs = get_TBS_UL(mcs, 3) << 3;	// 1 or 2 PRB with cqi enabled does not work well!
		rb_table_index = 2;

		// fixme: set use_srs flag
		tx_power =
		    estimate_ue_tx_power(tbs, rb_table[rb_table_index], 0,
					 Ncp, 0);

		while ((((UE_template->phr_info - tx_power) < 0)
			|| (tbs > UE_template->ul_total_buffer))
		       && (mcs > 3)) {
		    // LOG_I(MAC,"UE_template->phr_info %d tx_power %d mcs %d\n", UE_template->phr_info,tx_power, mcs);
		    mcs--;
		    tbs = get_TBS_UL(mcs, rb_table[rb_table_index]) << 3;
		    tx_power = estimate_ue_tx_power(tbs, rb_table[rb_table_index], 0, Ncp, 0);	// fixme: set use_srs
		}

		while ((tbs < UE_template->ul_total_buffer) &&
		       (rb_table[rb_table_index] <
			(N_RB_UL - first_rb[CC_id]))
		       && ((UE_template->phr_info - tx_power) > 0)
		       && (rb_table_index < 32)) {

		    rb_table_index++;
		    tbs = get_TBS_UL(mcs, rb_table[rb_table_index]) << 3;
		    tx_power =
			estimate_ue_tx_power(tbs, rb_table[rb_table_index],
					     0, Ncp, 0);
		}

		UE_template->ue_tx_power = tx_power;

		if (rb_table[rb_table_index] >
		    (N_RB_UL - first_rb[CC_id] - 1)) {
		    rb_table_index--;
		}
		// 1 or 2 PRB with cqi enabled does not work well
		if (rb_table[rb_table_index] < 3) {
		    rb_table_index = 2;	//3PRB
		}

		UE_template->pre_assigned_mcs_ul = mcs;
		UE_template->pre_allocated_rb_table_index_ul =
		    rb_table_index;
		UE_template->pre_allocated_nb_rb_ul =
		    rb_table[rb_table_index];
		LOG_D(MAC,
		      "[eNB %d] frame %d subframe %d: for UE %d CC %d: pre-assigned mcs %d, pre-allocated rb_table[%d]=%d RBs (phr %d, tx power %d)\n",
		      module_idP, frameP, subframeP, UE_id, CC_id,
		      UE_template->pre_assigned_mcs_ul,
		      UE_template->pre_allocated_rb_table_index_ul,
		      UE_template->pre_allocated_nb_rb_ul,
		      UE_template->phr_info, tx_power);
	    } else {
		/* if UE has pending scheduling request then pre-allocate 3 RBs */
		//if (UE_template->ul_active == 1 && UE_template->ul_SR == 1) {
		if (UE_is_to_be_scheduled(module_idP, CC_id, i)) {
		    /* use QPSK mcs */
		    UE_template->pre_assigned_mcs_ul = 10;
		    UE_template->pre_allocated_rb_table_index_ul = 2;
		    UE_template->pre_allocated_nb_rb_ul = 3;
		} else {
		    UE_template->pre_assigned_mcs_ul = 0;
		    UE_template->pre_allocated_rb_table_index_ul = -1;
		    UE_template->pre_allocated_nb_rb_ul = 0;
		}
	    }
	}
2214 2215 2216
    }
}

2217
struct sort_ue_ul_params {
2218 2219 2220
    int module_idP;
    int frameP;
    int subframeP;
2221 2222 2223 2224
};

static int ue_ul_compare(const void *_a, const void *_b, void *_params)
{
2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265
    struct sort_ue_ul_params *params = _params;
    UE_list_t *UE_list = &RC.mac[params->module_idP]->UE_list;

    int UE_id1 = *(const int *) _a;
    int UE_id2 = *(const int *) _b;

    int rnti1 = UE_RNTI(params->module_idP, UE_id1);
    int pCCid1 = UE_PCCID(params->module_idP, UE_id1);
    int round1 = maxround(params->module_idP, rnti1, params->frameP,
			  params->subframeP, 1);

    int rnti2 = UE_RNTI(params->module_idP, UE_id2);
    int pCCid2 = UE_PCCID(params->module_idP, UE_id2);
    int round2 = maxround(params->module_idP, rnti2, params->frameP,
			  params->subframeP, 1);

    if (round1 > round2)
	return -1;
    if (round1 < round2)
	return 1;

    if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] >
	UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0])
	return -1;
    if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] <
	UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0])
	return 1;

    if (UE_list->UE_template[pCCid1][UE_id1].ul_total_buffer >
	UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer)
	return -1;
    if (UE_list->UE_template[pCCid1][UE_id1].ul_total_buffer <
	UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer)
	return 1;

    if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul >
	UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul)
	return -1;
    if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul <
	UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul)
	return 1;
2266

2267
    return 0;
2268 2269

#if 0
2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291
    /* The above order derives from the following.
     * The last case is not handled: "if (UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer > 0 )"
     * I don't think it makes a big difference.
     */
    if (round2 > round1) {
	swap_UEs(UE_list, UE_id1, UE_id2, 1);
    } else if (round2 == round1) {
	if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] <
	    UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) {
	    swap_UEs(UE_list, UE_id1, UE_id2, 1);
	} else if (UE_list->UE_template[pCCid1][UE_id1].ul_total_buffer <
		   UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer) {
	    swap_UEs(UE_list, UE_id1, UE_id2, 1);
	} else if (UE_list->UE_template[pCCid1][UE_id1].
		   pre_assigned_mcs_ul <
		   UE_list->UE_template[pCCid2][UE_id2].
		   pre_assigned_mcs_ul) {
	    if (UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer > 0) {
		swap_UEs(UE_list, UE_id1, UE_id2, 1);
	    }
	}
    }
2292 2293
#endif
}
2294

2295
void sort_ue_ul(module_id_t module_idP, int frameP, sub_frame_t subframeP)
2296
{
2297 2298 2299 2300 2301
    int i;
    int list[NUMBER_OF_UE_MAX];
    int list_size = 0;
    int rnti;
    struct sort_ue_ul_params params = { module_idP, frameP, subframeP };
2302

2303
    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
2304

2305 2306 2307 2308 2309 2310 2311
    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
	if (UE_list->active[i] == FALSE)
	    continue;
	if ((rnti = UE_RNTI(module_idP, i)) == NOT_A_RNTI)
	    continue;
	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
	    continue;
2312

2313 2314 2315
	list[list_size] = i;
	list_size++;
    }
2316

2317
    qsort_r(list, list_size, sizeof(int), ue_ul_compare, &params);
2318

2319 2320 2321 2322 2323 2324 2325 2326
    if (list_size) {
	for (i = 0; i < list_size - 1; i++)
	    UE_list->next_ul[list[i]] = list[i + 1];
	UE_list->next_ul[list[list_size - 1]] = -1;
	UE_list->head_ul = list[0];
    } else {
	UE_list->head_ul = -1;
    }
2327 2328

#if 0
2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391
    int UE_id1, UE_id2;
    int pCCid1, pCCid2;
    int round1, round2;
    int i = 0, ii = 0;
    rnti_t rnti1, rnti2;

    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;

    for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {

	//LOG_I(MAC,"sort ue ul i %d\n",i);
	for (ii = UE_list->next_ul[i]; ii >= 0; ii = UE_list->next_ul[ii]) {
	    //LOG_I(MAC,"sort ul ue 2 ii %d\n",ii);

	    UE_id1 = i;
	    rnti1 = UE_RNTI(module_idP, UE_id1);

	    if (rnti1 == NOT_A_RNTI)
		continue;
	    if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
		continue;


	    pCCid1 = UE_PCCID(module_idP, UE_id1);
	    round1 = maxround(module_idP, rnti1, frameP, subframeP, 1);

	    UE_id2 = ii;
	    rnti2 = UE_RNTI(module_idP, UE_id2);

	    if (rnti2 == NOT_A_RNTI)
		continue;
	    if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1)
		continue;

	    pCCid2 = UE_PCCID(module_idP, UE_id2);
	    round2 = maxround(module_idP, rnti2, frameP, subframeP, 1);

	    if (round2 > round1) {
		swap_UEs(UE_list, UE_id1, UE_id2, 1);
	    } else if (round2 == round1) {
		if (UE_list->
		    UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] <
		    UE_list->UE_template[pCCid2][UE_id2].
		    ul_buffer_info[LCGID0]) {
		    swap_UEs(UE_list, UE_id1, UE_id2, 1);
		} else if (UE_list->UE_template[pCCid1][UE_id1].
			   ul_total_buffer <
			   UE_list->UE_template[pCCid2][UE_id2].
			   ul_total_buffer) {
		    swap_UEs(UE_list, UE_id1, UE_id2, 1);
		} else if (UE_list->
			   UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul
			   <
			   UE_list->
			   UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul)
		{
		    if (UE_list->UE_template[pCCid2][UE_id2].
			ul_total_buffer > 0) {
			swap_UEs(UE_list, UE_id1, UE_id2, 1);
		    }
		}
	    }
	}
2392
    }
2393
#endif
2394
}
Xu Bo's avatar
Xu Bo committed
2395 2396 2397 2398 2399
#ifdef UE_EXPANSION
void ulsch_scheduler_pre_ue_select(
    module_id_t       module_idP,
    frame_t           frameP,
    sub_frame_t       subframeP,
2400
    sub_frame_t       sched_subframeP,
Xu Bo's avatar
Xu Bo committed
2401 2402 2403 2404 2405 2406
    ULSCH_UE_SELECT   ulsch_ue_select[MAX_NUM_CCs])
{
  eNB_MAC_INST *eNB=RC.mac[module_idP];
  COMMON_channels_t *cc;
  int CC_id,UE_id;
  int ret;
2407
  uint16_t i;
Xu Bo's avatar
Xu Bo committed
2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422
  uint8_t ue_first_num[MAX_NUM_CCs];
  uint8_t first_ue_total[MAX_NUM_CCs][20];
  uint8_t first_ue_id[MAX_NUM_CCs][20];
  uint8_t ul_inactivity_num[MAX_NUM_CCs];
  uint8_t ul_inactivity_id[MAX_NUM_CCs][20];
//  LTE_DL_FRAME_PARMS *frame_parms;
  uint8_t ulsch_ue_max_num[MAX_NUM_CCs];
  uint16_t saved_ulsch_dci[MAX_NUM_CCs];
  rnti_t rnti;
  UE_sched_ctrl *UE_sched_ctl = NULL;
  uint8_t cc_id_flag[MAX_NUM_CCs];
  uint8_t harq_pid = 0,round = 0;
  UE_list_t *UE_list= &eNB->UE_list;


Xu Bo's avatar
Xu Bo committed
2423
  uint8_t                        aggregation = 2;
Xu Bo's avatar
Xu Bo committed
2424 2425 2426 2427 2428 2429 2430
  int                            format_flag;
  nfapi_hi_dci0_request_body_t   *HI_DCI0_req;
  nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu;


  for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
      //save ulsch dci number
2431
      saved_ulsch_dci[CC_id] = eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body.number_of_dci;
Xu Bo's avatar
Xu Bo committed
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441
      // maximum multiplicity number
      ulsch_ue_max_num[CC_id] =RC.rrc[module_idP]->configuration.ue_multiple_max[CC_id];

      cc_id_flag[CC_id] = 0;
      ue_first_num[CC_id] = 0;
      ul_inactivity_num[CC_id] = 0;

  }
  // UE round >0
  for ( UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++ ) {
Xu Bo's avatar
Xu Bo committed
2442 2443 2444
      if (UE_list->active[UE_id] == FALSE)
          continue;

Xu Bo's avatar
Xu Bo committed
2445 2446 2447 2448
      rnti = UE_RNTI(module_idP,UE_id);
      if (rnti ==NOT_A_RNTI)
        continue;

Xu Bo's avatar
Xu Bo committed
2449
      CC_id = UE_PCCID(module_idP,UE_id);
Xu Bo's avatar
Xu Bo committed
2450 2451 2452 2453 2454 2455 2456
      if (UE_list->UE_template[CC_id][UE_id].configured == FALSE)
        continue;

      if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1)
        continue;

      // UL DCI
2457
      HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
Xu Bo's avatar
Xu Bo committed
2458 2459 2460
      if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
        cc_id_flag[CC_id] = 1;
        HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
2461
        ret = cc_id_end(cc_id_flag);
Xu Bo's avatar
Xu Bo committed
2462 2463 2464 2465 2466 2467 2468 2469 2470 2471
        if ( ret == 0 ) {
            continue;
        }
        if ( ret == 1 ) {
            return;
        }
      }

      cc = &eNB->common_channels[CC_id];
      //harq_pid
2472
      harq_pid = subframe2harqpid(cc,(frameP+(sched_subframeP<subframeP ? 1 : 0)),sched_subframeP);
Xu Bo's avatar
Xu Bo committed
2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511
      //round
      round = UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id][harq_pid];

      if ( round > 0 ) {
          hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
          format_flag = 2;
          if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
              cc_id_flag[CC_id] = 1;
              continue;
          } else {
              hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
              HI_DCI0_req->number_of_dci++;

              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_RETRANS;
              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = eNB->UE_list.UE_template[CC_id][UE_id].first_rb_ul[harq_pid];
              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].nb_rb = eNB->UE_list.UE_template[CC_id][UE_id].nb_rb_ul[harq_pid];
              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = UE_id;
              ulsch_ue_select[CC_id].ue_num++;
              continue;
          }
      }
      //
      if ( UE_id > last_ulsch_ue_id[CC_id] && ((ulsch_ue_select[CC_id].ue_num+ue_first_num[CC_id]) < ulsch_ue_max_num[CC_id]) ) {
        if ( UE_list->UE_template[CC_id][UE_id].ul_total_buffer > 0 ) {
          first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
          first_ue_total[CC_id][ue_first_num[CC_id]] = UE_list->UE_template[CC_id][UE_id].ul_total_buffer;
          ue_first_num[CC_id]++;
          continue;
        }
        if ( UE_list->UE_template[CC_id][UE_id].ul_SR > 0 ) {
          first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
          first_ue_total[CC_id] [ue_first_num[CC_id]] = 0;
          ue_first_num[CC_id]++;
          continue;
        }
        if ( (ulsch_ue_select[CC_id].ue_num+ul_inactivity_num[CC_id] ) < ulsch_ue_max_num[CC_id] ) {
            UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
2512 2513 2514 2515 2516 2517 2518
            uint8_t ul_period = 0;
            if (cc->tdd_Config) {
              ul_period = 50;
            } else {
              ul_period = 20;
            }
            if ( ((UE_sched_ctl->ul_inactivity_timer>ul_period)&&(UE_sched_ctl->ul_scheduled==0))  ||
Xu Bo's avatar
Xu Bo committed
2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529
              ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED))) {
            ul_inactivity_id[CC_id][ul_inactivity_num[CC_id]]= UE_id;
            ul_inactivity_num[CC_id] ++;
            continue;
          }
        }
      }

  }

  for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
2530
    HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
Xu Bo's avatar
Xu Bo committed
2531 2532 2533 2534 2535 2536 2537 2538 2539
    for ( int temp = 0; temp < ue_first_num[CC_id]; temp++ ) {
      if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
        cc_id_flag[CC_id] = 1;
        HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
        break;
      }

      hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
      format_flag = 2;
Xu Bo's avatar
Xu Bo committed
2540
      rnti = UE_RNTI(module_idP,first_ue_id[CC_id][temp]);
Xu Bo's avatar
Xu Bo committed
2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558
      if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
    	  cc_id_flag[CC_id] = 1;
          break;
      } else {
          hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
          HI_DCI0_req->number_of_dci++;

          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_FIRST;
          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = first_ue_total[CC_id][temp];
          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = first_ue_id[CC_id][temp];
          ulsch_ue_select[CC_id].ue_num++;
      }
    }
  }

  for ( UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++ ) {
Xu Bo's avatar
Xu Bo committed
2559 2560 2561
    if (UE_list->active[UE_id] == FALSE)
        continue;

Xu Bo's avatar
Xu Bo committed
2562 2563 2564 2565
    rnti = UE_RNTI(module_idP,UE_id);
    if (rnti ==NOT_A_RNTI)
        continue;

Xu Bo's avatar
Xu Bo committed
2566 2567 2568 2569 2570
    CC_id = UE_PCCID(module_idP,UE_id);

    if (UE_id > last_ulsch_ue_id[CC_id])
        continue;

Xu Bo's avatar
Xu Bo committed
2571 2572 2573 2574 2575 2576 2577 2578 2579
    if (UE_list->UE_template[CC_id][UE_id].configured == FALSE)
        continue;

    if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1)
        continue;

    if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
        cc_id_flag[CC_id] = 1;
        HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
2580
        ret = cc_id_end(cc_id_flag);
Xu Bo's avatar
Xu Bo committed
2581 2582 2583 2584 2585 2586 2587 2588
        if ( ret == 0 ) {
            continue;
        }
        if ( ret == 1 ) {
            return;
        }
    }

2589 2590 2591 2592 2593 2594 2595 2596
    for(i = 0;i<ulsch_ue_select[CC_id].ue_num;i++){
      if(ulsch_ue_select[CC_id].list[i].UE_id == UE_id){
       break;
      }
    }
    if(i < ulsch_ue_select[CC_id].ue_num)
      continue;

2597
    HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
Xu Bo's avatar
Xu Bo committed
2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623
    //SR BSR
    if ( (UE_list->UE_template[CC_id][UE_id].ul_total_buffer > 0) || (UE_list->UE_template[CC_id][UE_id].ul_SR > 0) ) {
        hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
        format_flag = 2;
        if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
            cc_id_flag[CC_id] = 1;
            continue;
        } else {
              hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
              HI_DCI0_req->number_of_dci++;

              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_FIRST;
              if(UE_list->UE_template[CC_id][UE_id].ul_total_buffer > 0)
                  ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = UE_list->UE_template[CC_id][UE_id].ul_total_buffer;
              else if(UE_list->UE_template[CC_id][UE_id].ul_SR > 0)
                  ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = 0;
              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = UE_id;
              ulsch_ue_select[CC_id].ue_num++;
              continue;
          }
    }
    //inactivity UE
    if ( (ulsch_ue_select[CC_id].ue_num+ul_inactivity_num[CC_id]) < ulsch_ue_max_num[CC_id] ) {
        UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
2624 2625 2626 2627 2628 2629 2630
        uint8_t ul_period = 0;
        if (cc->tdd_Config) {
          ul_period = 50;
        } else {
          ul_period = 20;
        }
        if ( ((UE_sched_ctl->ul_inactivity_timer>ul_period)&&(UE_sched_ctl->ul_scheduled==0))  ||
Xu Bo's avatar
Xu Bo committed
2631 2632 2633 2634 2635 2636 2637 2638 2639
            ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED))) {
          ul_inactivity_id[CC_id][ul_inactivity_num[CC_id]]= UE_id;
          ul_inactivity_num[CC_id]++;
          continue;
        }
    }
  }

  for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
2640
    HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
Xu Bo's avatar
Xu Bo committed
2641
    for ( int temp = 0; temp < ul_inactivity_num[CC_id]; temp++ ) {
Xu Bo's avatar
Xu Bo committed
2642
      if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
2643
        HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
Xu Bo's avatar
Xu Bo committed
2644 2645 2646 2647 2648 2649
        cc_id_flag[CC_id] = 1;
        break;
      }

      hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
      format_flag = 2;
Xu Bo's avatar
Xu Bo committed
2650
      rnti = UE_RNTI(module_idP,ul_inactivity_id[CC_id][temp]);
Xu Bo's avatar
Xu Bo committed
2651 2652
      if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
          cc_id_flag[CC_id] = 1;
Xu Bo's avatar
Xu Bo committed
2653
          continue;
Xu Bo's avatar
Xu Bo committed
2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684
      } else {
          hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
          HI_DCI0_req->number_of_dci++;

          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_INACTIVE;
          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = 0;
          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = ul_inactivity_id[CC_id][temp];
          ulsch_ue_select[CC_id].ue_num++;
      }
    }
    HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
  }
  return;
}

uint8_t find_rb_table_index(uint8_t average_rbs)
{
  int i;
  for ( i = 0; i < 34; i++ ) {
    if ( rb_table[i] > average_rbs ) {
      return (i-1);
    }
  }
  return i;
}

void ulsch_scheduler_pre_processor(module_id_t module_idP,
                                   frame_t frameP,
                                   sub_frame_t subframeP,
2685
                                   sub_frame_t sched_subframeP,
Xu Bo's avatar
Xu Bo committed
2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704
                                   ULSCH_UE_SELECT ulsch_ue_select[MAX_NUM_CCs])
{
  int                CC_id,ulsch_ue_num;
  eNB_MAC_INST       *eNB = RC.mac[module_idP];
  UE_list_t          *UE_list= &eNB->UE_list;
  UE_TEMPLATE        *UE_template = NULL;
  LTE_DL_FRAME_PARMS *frame_parms = NULL;
  uint8_t            ue_num_temp;
  uint8_t            total_rbs=0;
  uint8_t            average_rbs;
  uint16_t           first_rb[MAX_NUM_CCs];
  uint8_t            mcs;
  uint8_t            rb_table_index;
  uint32_t           tbs;
  int16_t            tx_power;
  int                UE_id;
  rnti_t             rnti;
  LOG_D(MAC,"In ulsch_preprocessor: ulsch ue select\n");
  //ue select
2705
  ulsch_scheduler_pre_ue_select(module_idP,frameP,subframeP,sched_subframeP,ulsch_ue_select);
Xu Bo's avatar
Xu Bo committed
2706 2707 2708 2709

  // MCS and RB assgin
  for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
    frame_parms = &(RC.eNB[module_idP][CC_id]->frame_parms);
2710 2711 2712 2713 2714
    if(frame_parms->N_RB_UL == 25){
      first_rb[CC_id] = 1;
    }else{
      first_rb[CC_id] = 2;
    } 
Xu Bo's avatar
Xu Bo committed
2715 2716 2717 2718
    ue_num_temp       = ulsch_ue_select[CC_id].ue_num;
    for ( ulsch_ue_num = 0; ulsch_ue_num < ulsch_ue_select[CC_id].ue_num; ulsch_ue_num++ ) {

      UE_id = ulsch_ue_select[CC_id].list[ulsch_ue_num].UE_id;
Xu Bo's avatar
Xu Bo committed
2719

Xu Bo's avatar
Xu Bo committed
2720 2721 2722 2723 2724
      if (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_MSG3) {
        first_rb[CC_id] ++;
        ue_num_temp--;
        continue;
      }
Xu Bo's avatar
Xu Bo committed
2725

Xu Bo's avatar
Xu Bo committed
2726 2727 2728 2729 2730 2731
      if (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_PRACH) {
        first_rb[CC_id] = ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb+ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
        ue_num_temp--;
        continue;
      }

Xu Bo's avatar
Xu Bo committed
2732
      rnti = UE_RNTI(CC_id,UE_id);
2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748
      if(frame_parms->N_RB_UL == 25){
        if ( first_rb[CC_id] >= frame_parms->N_RB_UL-1 ){
            LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
                   module_idP,frameP,subframeP,UE_id,rnti,CC_id);
          break;
        }
        // calculate the average rb ( remain UE)
        total_rbs = frame_parms->N_RB_UL-1-first_rb[CC_id];
      }else{
        if ( first_rb[CC_id] >= frame_parms->N_RB_UL-2 ){
            LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
                   module_idP,frameP,subframeP,UE_id,rnti,CC_id);
          break;
        }
        // calculate the average rb ( remain UE)
        total_rbs = frame_parms->N_RB_UL-2-first_rb[CC_id];
Xu Bo's avatar
Xu Bo committed
2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770
      }
      average_rbs = (int)round((double)total_rbs/(double)ue_num_temp);
      if ( average_rbs < 3 ) {
        ue_num_temp--;
        ulsch_ue_num--;
        ulsch_ue_select[CC_id].ue_num--;
        continue;
      }
      if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_RETRANS ) {
        if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb <= average_rbs ) {
            // assigne RBS(nb_rb)
            ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
            first_rb[CC_id] = first_rb[CC_id] + ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
        }
        if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb > average_rbs ) {
          if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb <= total_rbs ) {
              // assigne RBS(average_rbs)
              ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
              first_rb[CC_id] = first_rb[CC_id] + ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
          } else {
              // assigne RBS(remain rbs)
              ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
2771 2772 2773 2774 2775 2776
              rb_table_index = 2;
              while(rb_table[rb_table_index] <= total_rbs){
                rb_table_index++;
              }
              ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb = rb_table[rb_table_index-1];
              first_rb[CC_id] = first_rb[CC_id] + rb_table[rb_table_index-1];
Xu Bo's avatar
Xu Bo committed
2777 2778 2779
          }
        }
      }else{
Xu Bo's avatar
Xu Bo committed
2780 2781
        UE_template = &UE_list->UE_template[CC_id][UE_id];
        if ( UE_list->UE_sched_ctrl[UE_id].phr_received == 1 ) {
Xu Bo's avatar
Xu Bo committed
2782 2783 2784 2785 2786 2787 2788 2789 2790
          mcs = 20;
        } else {
          mcs = 10;
        }
        if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority  == SCH_UL_FIRST ) {
          if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ul_total_buffer > 0 ) {
            rb_table_index = 2;
            tbs = get_TBS_UL(mcs,rb_table[rb_table_index])<<3;
            tx_power= estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,frame_parms->Ncp,0);
2791

Xu Bo's avatar
Xu Bo committed
2792 2793 2794 2795 2796
            while ( (((UE_template->phr_info - tx_power) < 0 ) || (tbs > UE_template->ul_total_buffer)) && (mcs > 3) ) {
              mcs--;
              tbs = get_TBS_UL(mcs,rb_table[rb_table_index])<<3;
              tx_power= estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,frame_parms->Ncp,0);
            }
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811

            if(frame_parms->N_RB_UL == 25){
              while ( (tbs < UE_template->ul_total_buffer) && (rb_table[rb_table_index]<(frame_parms->N_RB_UL-1-first_rb[CC_id])) &&
                     ((UE_template->phr_info - tx_power) > 0) && (rb_table_index < 32 )) {
                rb_table_index++;
                tbs = get_TBS_UL(mcs,rb_table[rb_table_index])<<3;
                tx_power= estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,frame_parms->Ncp,0);
              }
            }else{
                while ( (tbs < UE_template->ul_total_buffer) && (rb_table[rb_table_index]<(frame_parms->N_RB_UL-2-first_rb[CC_id])) &&
                       ((UE_template->phr_info - tx_power) > 0) && (rb_table_index < 32 )) {
                  rb_table_index++;
                  tbs = get_TBS_UL(mcs,rb_table[rb_table_index])<<3;
                  tx_power= estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,frame_parms->Ncp,0);
                }
Xu Bo's avatar
Xu Bo committed
2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840
            }
            if ( rb_table[rb_table_index]<3 ) {
              rb_table_index=2;
            }
            if ( rb_table[rb_table_index] <= average_rbs ) {
              // assigne RBS( nb_rb)
              first_rb[CC_id] = first_rb[CC_id] + rb_table[rb_table_index];
              UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul = rb_table[rb_table_index];
              UE_list->UE_template[CC_id][UE_id].pre_allocated_rb_table_index_ul = rb_table_index;
              UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = mcs;
            }
            if ( rb_table[rb_table_index] > average_rbs ) {
              // assigne RBS(average_rbs)
              rb_table_index = find_rb_table_index(average_rbs);
              if (rb_table_index>=34){
                  LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: average RBs %d > 100\n",
                         module_idP,frameP,subframeP,UE_id,rnti,CC_id,average_rbs);
                  break;
              }
              first_rb[CC_id] = first_rb[CC_id] + rb_table[rb_table_index];
              UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul = rb_table[rb_table_index];
              UE_list->UE_template[CC_id][UE_id].pre_allocated_rb_table_index_ul = rb_table_index;
              UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = mcs;
            }
          }else {
            // assigne RBS( 3 RBs)
            first_rb[CC_id] = first_rb[CC_id] + 3;
            UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul = 3;
            UE_list->UE_template[CC_id][UE_id].pre_allocated_rb_table_index_ul = 2;
Xu Bo's avatar
Xu Bo committed
2841
            UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = 10;
Xu Bo's avatar
Xu Bo committed
2842 2843 2844 2845 2846 2847
          }
        }else if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority  == SCH_UL_INACTIVE ) {
          // assigne RBS( 3 RBs)
          first_rb[CC_id] = first_rb[CC_id] + 3;
          UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul = 3;
          UE_list->UE_template[CC_id][UE_id].pre_allocated_rb_table_index_ul = 2;
Xu Bo's avatar
Xu Bo committed
2848
          UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = 10;
Xu Bo's avatar
Xu Bo committed
2849 2850 2851 2852 2853 2854 2855
        }
      }
      ue_num_temp--;
    }
  }
}
#endif