diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index 81420ad93..3aebdc78d 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -53,7 +53,9 @@ public: dl_sched_grant_t pdsch[MAX_GRANTS]; uint32_t nof_grants; uint32_t cfi; - } dl_sched_t; + } dl_sched_t; // per carrier + + typedef std::vector dl_sched_list_t; typedef struct { uint16_t rnti; diff --git a/lib/include/srslte/interfaces/sched_interface.h b/lib/include/srslte/interfaces/sched_interface.h index ee811ae36..b8d4a3b03 100644 --- a/lib/include/srslte/interfaces/sched_interface.h +++ b/lib/include/srslte/interfaces/sched_interface.h @@ -239,8 +239,8 @@ public: virtual int ul_cqi_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t cqi, uint32_t ul_ch_code) = 0; /* Run Scheduler for this tti */ - virtual int dl_sched(uint32_t tti, dl_sched_res_t* sched_result) = 0; - virtual int ul_sched(uint32_t tti, ul_sched_res_t* sched_result) = 0; + virtual int dl_sched(uint32_t tti, uint32_t cc_idx, dl_sched_res_t& sched_result) = 0; + virtual int ul_sched(uint32_t tti, uint32_t cc_idx, ul_sched_res_t& sched_result) = 0; /* Custom */ virtual void set_dl_tti_mask(uint8_t* tti_mask, uint32_t nof_sfs) = 0; diff --git a/srsenb/hdr/stack/mac/mac.h b/srsenb/hdr/stack/mac/mac.h index 9bb41f867..ea7717c24 100644 --- a/srsenb/hdr/stack/mac/mac.h +++ b/srsenb/hdr/stack/mac/mac.h @@ -60,13 +60,13 @@ public: int ri_info(uint32_t tti, uint16_t rnti, uint32_t ri_value); int pmi_info(uint32_t tti, uint16_t rnti, uint32_t pmi_value); - int cqi_info(uint32_t tti, uint16_t rnti, uint32_t cqi_value); - int snr_info(uint32_t tti, uint16_t rnti, float snr); + int cqi_info(uint32_t tti, uint16_t rnti, uint32_t cqi_value); + int snr_info(uint32_t tti, uint16_t rnti, float snr); int ack_info(uint32_t tti, uint16_t rnti, uint32_t tb_idx, bool ack); - int crc_info(uint32_t tti, uint16_t rnti, uint32_t nof_bytes, bool crc_res); - - int get_dl_sched(uint32_t tti, dl_sched_t *dl_sched_res); - int get_ul_sched(uint32_t tti, ul_sched_t *ul_sched_res); + int crc_info(uint32_t tti, uint16_t rnti, uint32_t nof_bytes, bool crc_res); + + int get_dl_sched(uint32_t tti, dl_sched_t* dl_sched_res); + int get_ul_sched(uint32_t tti, ul_sched_t* ul_sched_res); int get_mch_sched(uint32_t tti, bool is_mcch, dl_sched_t* dl_sched_res); void set_sched_dl_tti_mask(uint8_t* tti_mask, uint32_t nof_sfs) final { @@ -99,31 +99,31 @@ public: void get_metrics(mac_metrics_t metrics[ENB_METRICS_MAX_USERS]); void write_mcch(asn1::rrc::sib_type2_s* sib2, asn1::rrc::sib_type13_r9_s* sib13, asn1::rrc::mcch_msg_s* mcch); -private: +private: + static const int MAX_LOCATIONS = 20; + static const uint32_t cfi = 3; + srslte_dci_location_t locations[MAX_LOCATIONS] = {}; - static const int MAX_LOCATIONS = 20; - static const uint32_t cfi = 3; - srslte_dci_location_t locations[MAX_LOCATIONS]; - - static const int MAC_PDU_THREAD_PRIO = 60; + static const int MAC_PDU_THREAD_PRIO = 60; - // We use a rwlock in MAC to allow multiple workers to access MAC simultaneously. No conflicts will happen since access for different TTIs - pthread_rwlock_t rwlock; + // We use a rwlock in MAC to allow multiple workers to access MAC simultaneously. No conflicts will happen since + // access for different TTIs + pthread_rwlock_t rwlock = {}; // Interaction with PHY - phy_interface_stack_lte* phy_h; - rlc_interface_mac* rlc_h; - rrc_interface_mac* rrc_h; - stack_interface_mac_lte* stack; - srslte::log* log_h; + phy_interface_stack_lte* phy_h = nullptr; + rlc_interface_mac* rlc_h = nullptr; + rrc_interface_mac* rrc_h = nullptr; + stack_interface_mac_lte* stack = nullptr; + srslte::log* log_h = nullptr; srslte_cell_t cell; - mac_args_t args; - - bool started; + mac_args_t args = {}; + + bool started = false; /* Scheduler unit */ - sched scheduler; + sched scheduler; dl_metric_rr sched_metric_dl_rr; ul_metric_rr sched_metric_ul_rr; sched_interface::cell_cfg_t cell_config; @@ -163,7 +163,7 @@ private: uint8_t mtch_payload_buffer[mtch_payload_len]; // pointer to MAC PCAP object - srslte::mac_pcap* pcap; + srslte::mac_pcap* pcap = nullptr; }; } // namespace srsenb diff --git a/srsenb/hdr/stack/mac/scheduler.h b/srsenb/hdr/stack/mac/scheduler.h index 643bc158a..d9fd62c98 100644 --- a/srsenb/hdr/stack/mac/scheduler.h +++ b/srsenb/hdr/stack/mac/scheduler.h @@ -145,8 +145,8 @@ public: int ul_phr(uint16_t rnti, int phr) final; int ul_cqi_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t cqi, uint32_t ul_ch_code) final; - int dl_sched(uint32_t tti, dl_sched_res_t* sched_result) final; - int ul_sched(uint32_t tti, ul_sched_res_t* sched_result) final; + int dl_sched(uint32_t tti, uint32_t cc_idx, dl_sched_res_t& sched_result) final; + int ul_sched(uint32_t tti, uint32_t cc_idx, ul_sched_res_t& sched_result) final; /* Custom functions */ diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 9091ad190..ec58e0acc 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -40,22 +40,13 @@ namespace srsenb { mac::mac() : last_rnti(0), rar_pdu_msg(sched_interface::MAX_RAR_LIST), rar_payload() { - started = false; - pcap = NULL; - phy_h = NULL; - rlc_h = NULL; - rrc_h = NULL; - log_h = NULL; - - bzero(&locations, sizeof(locations)); bzero(&cell, sizeof(cell)); - bzero(&args, sizeof(args)); bzero(&bcch_dlsch_payload, sizeof(bcch_dlsch_payload)); bzero(&pcch_payload_buffer, sizeof(pcch_payload_buffer)); bzero(&bcch_softbuffer_tx, sizeof(bcch_softbuffer_tx)); bzero(&pcch_softbuffer_tx, sizeof(pcch_softbuffer_tx)); bzero(&rar_softbuffer_tx, sizeof(rar_softbuffer_tx)); - pthread_rwlock_init(&rwlock, NULL); + pthread_rwlock_init(&rwlock, nullptr); } mac::~mac() @@ -540,9 +531,8 @@ int mac::get_dl_sched(uint32_t tti, dl_sched_t *dl_sched_res) } // Run scheduler with current info - sched_interface::dl_sched_res_t sched_result; - bzero(&sched_result, sizeof(sched_interface::dl_sched_res_t)); - if (scheduler.dl_sched(tti, &sched_result) < 0) { + sched_interface::dl_sched_res_t sched_result = {}; + if (scheduler.dl_sched(tti, 0, sched_result) < 0) { Error("Running scheduler\n"); return SRSLTE_ERROR; } @@ -790,9 +780,8 @@ int mac::get_ul_sched(uint32_t tti, ul_sched_t *ul_sched_res) } // Run scheduler with current info - sched_interface::ul_sched_res_t sched_result; - bzero(&sched_result, sizeof(sched_interface::ul_sched_res_t)); - if (scheduler.ul_sched(tti, &sched_result)<0) { + sched_interface::ul_sched_res_t sched_result = {}; + if (scheduler.ul_sched(tti, 0, sched_result) < 0) { Error("Running scheduler\n"); return SRSLTE_ERROR; } diff --git a/srsenb/src/stack/mac/scheduler.cc b/srsenb/src/stack/mac/scheduler.cc index e8051173d..04b022712 100644 --- a/srsenb/src/stack/mac/scheduler.cc +++ b/srsenb/src/stack/mac/scheduler.cc @@ -384,7 +384,7 @@ void sched::tpc_dec(uint16_t rnti) *******************************************************/ // Downlink Scheduler API -int sched::dl_sched(uint32_t tti, sched_interface::dl_sched_res_t* sched_result) +int sched::dl_sched(uint32_t tti, uint32_t cc_idx, sched_interface::dl_sched_res_t& sched_result) { if (!configured) { return 0; @@ -393,19 +393,21 @@ int sched::dl_sched(uint32_t tti, sched_interface::dl_sched_res_t* sched_result) uint32_t tti_rx = sched_utils::tti_subtract(tti, TX_DELAY); current_tti = sched_utils::max_tti(current_tti, tti_rx); - // Compute scheduling Result for tti_rx - pthread_rwlock_rdlock(&rwlock); - tti_sched_result_t* tti_sched = carrier_schedulers[0]->generate_tti_result(tti_rx); - pthread_rwlock_unlock(&rwlock); + if (cc_idx < carrier_schedulers.size()) { + // Compute scheduling Result for tti_rx + pthread_rwlock_rdlock(&rwlock); + tti_sched_result_t* tti_sched = carrier_schedulers[cc_idx]->generate_tti_result(tti_rx); + pthread_rwlock_unlock(&rwlock); - // Copy result - *sched_result = tti_sched->dl_sched_result; + // copy result + sched_result = tti_sched->dl_sched_result; + } return 0; } // Uplink Scheduler API -int sched::ul_sched(uint32_t tti, srsenb::sched_interface::ul_sched_res_t* sched_result) +int sched::ul_sched(uint32_t tti, uint32_t cc_idx, srsenb::sched_interface::ul_sched_res_t& sched_result) { if (!configured) { return 0; @@ -413,12 +415,15 @@ int sched::ul_sched(uint32_t tti, srsenb::sched_interface::ul_sched_res_t* sched // Compute scheduling Result for tti_rx uint32_t tti_rx = sched_utils::tti_subtract(tti, 2 * FDD_HARQ_DELAY_MS); - pthread_rwlock_rdlock(&rwlock); - tti_sched_result_t* tti_sched = carrier_schedulers[0]->generate_tti_result(tti_rx); - pthread_rwlock_unlock(&rwlock); - // Copy result - *sched_result = tti_sched->ul_sched_result; + if (cc_idx < carrier_schedulers.size()) { + pthread_rwlock_rdlock(&rwlock); + tti_sched_result_t* tti_sched = carrier_schedulers[cc_idx]->generate_tti_result(tti_rx); + pthread_rwlock_unlock(&rwlock); + + // copy result + sched_result = tti_sched->ul_sched_result; + } return SRSLTE_SUCCESS; } diff --git a/srsenb/test/mac/scheduler_test.cc b/srsenb/test/mac/scheduler_test.cc index c6c144a34..bdfa189b6 100644 --- a/srsenb/test/mac/scheduler_test.cc +++ b/srsenb/test/mac/scheduler_test.cc @@ -139,10 +139,10 @@ int main(int argc, char *argv[]) while(running) { log_out.step(tti); if (tti > 50) { - running = false; + running = false; } - my_sched.dl_sched(tti, &sched_result_dl); - my_sched.ul_sched(tti, &sched_result_ul); + my_sched.dl_sched(tti, 0, sched_result_dl); + my_sched.ul_sched(tti, 0, sched_result_ul); tti = (tti + 1) % 10240; if (tti >= 4) { my_sched.ul_crc_info(tti, rnti, 0, tti % 2); diff --git a/srsenb/test/mac/scheduler_test_rand.cc b/srsenb/test/mac/scheduler_test_rand.cc index 0a90330a4..4d58f54c7 100644 --- a/srsenb/test/mac/scheduler_test_rand.cc +++ b/srsenb/test/mac/scheduler_test_rand.cc @@ -410,8 +410,8 @@ void sched_tester::run_tti(uint32_t tti_rx) ack_txs(); before_sched(); - dl_sched(tti_data.tti_tx_dl, &tti_data.sched_result_dl); - ul_sched(tti_data.tti_tx_ul, &tti_data.sched_result_ul); + dl_sched(tti_data.tti_tx_dl, CARRIER_IDX, tti_data.sched_result_dl); + ul_sched(tti_data.tti_tx_ul, CARRIER_IDX, tti_data.sched_result_ul); process_results(); }