From fed06138b9891177ab1e24522d2af0a4efd2b45d Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 3 Mar 2020 16:25:04 +0000 Subject: [PATCH] moved rach_detected to stack thread. Created a more friendly interface to enqueue tasks in stack --- lib/include/srslte/common/multiqueue.h | 22 ++++- .../srslte/interfaces/enb_interfaces.h | 16 ++-- srsenb/hdr/stack/enb_stack_lte.h | 13 +-- srsenb/hdr/stack/mac/mac.h | 17 ++-- srsenb/src/stack/enb_stack_lte.cc | 9 ++- srsenb/src/stack/mac/mac.cc | 81 ++++++++++--------- srsenb/test/phy/enb_phy_test.cc | 3 +- srsue/hdr/stack/ue_stack_lte.h | 4 +- 8 files changed, 102 insertions(+), 63 deletions(-) diff --git a/lib/include/srslte/common/multiqueue.h b/lib/include/srslte/common/multiqueue.h index 2393678b5..5fd99e493 100644 --- a/lib/include/srslte/common/multiqueue.h +++ b/lib/include/srslte/common/multiqueue.h @@ -58,6 +58,24 @@ class multiqueue_handler }; public: + class queue_handler + { + public: + queue_handler() = default; + queue_handler(multiqueue_handler* parent_, int id) : parent(parent_), queue_id(id) {} + template + void push(FwdRef&& value) + { + parent->push(queue_id, std::forward(value)); + } + bool try_push(const myobj& value) { return parent->try_push(queue_id, value); } + std::pair try_push(myobj&& value) { return parent->try_push(queue_id, std::move(value)); } + + private: + multiqueue_handler* parent = nullptr; + int queue_id = -1; + }; + explicit multiqueue_handler(uint32_t capacity_ = std::numeric_limits::max()) : capacity(capacity_) {} ~multiqueue_handler() { reset(); } @@ -214,6 +232,8 @@ public: return is_queue_active_(qidx); } + queue_handler get_queue_handler() { return {this, add_queue()}; } + private: bool is_queue_active_(int qidx) const { return running and queues[qidx].active; } @@ -257,7 +277,7 @@ private: std::unique_ptr task_ptr; }; -using multiqueue_task_handler = multiqueue_handler; +using task_multiqueue = multiqueue_handler; } // namespace srslte diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index 49e2775d1..86bf9774b 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -26,6 +26,7 @@ #include "srslte/asn1/s1ap_asn1.h" #include "srslte/common/common.h" #include "srslte/common/interfaces_common.h" +#include "srslte/common/multiqueue.h" #include "srslte/common/security.h" #include "srslte/interfaces/rrc_interface_types.h" #include "srslte/interfaces/sched_interface.h" @@ -98,8 +99,8 @@ public: */ typedef std::vector ul_sched_list_t; - virtual int sr_detected(uint32_t tti, uint16_t rnti) = 0; - virtual int rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) = 0; + virtual int sr_detected(uint32_t tti, uint16_t rnti) = 0; + virtual void rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) = 0; /** * PHY callback for giving MAC the Rank Indicator information of a given RNTI for an eNb cell/carrier. @@ -476,6 +477,13 @@ typedef struct { int link_failure_nof_err; } mac_args_t; +class enb_task_interface_lte +{ +public: + virtual srslte::timer_handler::unique_timer get_unique_timer() = 0; + virtual srslte::task_multiqueue::queue_handler get_task_queue() = 0; +}; + class stack_interface_s1ap_lte { public: @@ -491,10 +499,8 @@ public: }; // STACK interface for MAC -class stack_interface_mac_lte +class stack_interface_mac_lte : public enb_task_interface_lte { -public: - virtual void process_pdus() = 0; }; } // namespace srsenb diff --git a/srsenb/hdr/stack/enb_stack_lte.h b/srsenb/hdr/stack/enb_stack_lte.h index 606c40c31..062bb445a 100644 --- a/srsenb/hdr/stack/enb_stack_lte.h +++ b/srsenb/hdr/stack/enb_stack_lte.h @@ -62,10 +62,10 @@ public: bool get_metrics(stack_metrics_t* metrics) final; /* PHY-MAC interface */ - int sr_detected(uint32_t tti, uint16_t rnti) final { return mac.sr_detected(tti, rnti); } - int rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) final + int sr_detected(uint32_t tti, uint16_t rnti) final { return mac.sr_detected(tti, rnti); } + void rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) final { - return mac.rach_detected(tti, primary_cc_idx, preamble_idx, time_adv); + mac.rach_detected(tti, primary_cc_idx, preamble_idx, time_adv); } int ri_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t ri_value) final { @@ -113,7 +113,8 @@ public: void add_gtpu_m1u_socket_handler(int fd) override; /* Stack-MAC interface */ - void process_pdus() override; + srslte::timer_handler::unique_timer get_unique_timer() final; + srslte::task_multiqueue::queue_handler get_task_queue() final; private: static const int STACK_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD @@ -158,8 +159,8 @@ private: phy_interface_stack_lte* phy = nullptr; // state - bool started = false; - srslte::multiqueue_task_handler pending_tasks; + bool started = false; + srslte::task_multiqueue pending_tasks; int enb_queue_id = -1, sync_queue_id = -1, mme_queue_id = -1, gtpu_queue_id = -1, mac_queue_id = -1; }; diff --git a/srsenb/hdr/stack/mac/mac.h b/srsenb/hdr/stack/mac/mac.h index ab19cb167..22eca1317 100644 --- a/srsenb/hdr/stack/mac/mac.h +++ b/srsenb/hdr/stack/mac/mac.h @@ -53,8 +53,8 @@ public: void start_pcap(srslte::mac_pcap* pcap_); /******** Interface from PHY (PHY -> MAC) ****************/ - int sr_detected(uint32_t tti, uint16_t rnti) final; - int rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) final; + int sr_detected(uint32_t tti, uint16_t rnti) final; + void rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) final; int ri_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t ri_value) override; int pmi_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t pmi_value) override; @@ -93,7 +93,7 @@ public: bool process_pdus(); - void get_metrics(mac_metrics_t metrics[ENB_METRICS_MAX_USERS]); + 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) override; @@ -116,6 +116,9 @@ private: srslte_cell_t cell = {}; mac_args_t args = {}; + // derived from args + srslte::task_multiqueue::queue_handler stack_task_queue; + bool started = false; /* Scheduler unit */ @@ -139,23 +142,23 @@ private: std::vector rar_pdu_msg; srslte::byte_buffer_t rar_payload[sched_interface::MAX_RAR_LIST]; - const static int NOF_BCCH_DLSCH_MSG = sched_interface::MAX_SIBS; + const static int NOF_BCCH_DLSCH_MSG = sched_interface::MAX_SIBS; uint8_t bcch_dlsch_payload[sched_interface::MAX_SIB_PAYLOAD_LEN] = {}; - const static int pcch_payload_buffer_len = 1024; + const static int pcch_payload_buffer_len = 1024; uint8_t pcch_payload_buffer[pcch_payload_buffer_len] = {}; srslte_softbuffer_tx_t bcch_softbuffer_tx[NOF_BCCH_DLSCH_MSG] = {}; srslte_softbuffer_tx_t pcch_softbuffer_tx = {}; srslte_softbuffer_tx_t rar_softbuffer_tx = {}; - const static int mcch_payload_len = 3000; // TODO FIND OUT MAX LENGTH + const static int mcch_payload_len = 3000; // TODO FIND OUT MAX LENGTH int current_mcch_length = 0; uint8_t mcch_payload_buffer[mcch_payload_len] = {}; asn1::rrc::mcch_msg_s mcch; asn1::rrc::sib_type2_s sib2; asn1::rrc::sib_type13_r9_s sib13; - const static int mtch_payload_len = 10000; + const static int mtch_payload_len = 10000; uint8_t mtch_payload_buffer[mtch_payload_len] = {}; // pointer to MAC PCAP object diff --git a/srsenb/src/stack/enb_stack_lte.cc b/srsenb/src/stack/enb_stack_lte.cc index 7bb03a9d8..46ffd0362 100644 --- a/srsenb/src/stack/enb_stack_lte.cc +++ b/srsenb/src/stack/enb_stack_lte.cc @@ -238,9 +238,14 @@ void enb_stack_lte::add_gtpu_m1u_socket_handler(int fd) rx_sockets->add_socket_pdu_handler(fd, gtpu_m1u_handler); } -void enb_stack_lte::process_pdus() +srslte::timer_handler::unique_timer enb_stack_lte::get_unique_timer() { - pending_tasks.push(mac_queue_id, [this]() { mac.process_pdus(); }); + return timers.get_unique_timer(); +} + +srslte::task_multiqueue::queue_handler enb_stack_lte::get_task_queue() +{ + return pending_tasks.get_queue_handler(); } } // namespace srsenb diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 94f38b0de..db86f6e50 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -70,6 +70,8 @@ bool mac::init(const mac_args_t& args_, args = args_; cell = *cell_; + stack_task_queue = stack->get_task_queue(); + scheduler.init(rrc); // Set default scheduler configuration @@ -323,7 +325,7 @@ int mac::crc_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t nof_byt if (crc) { Info("Pushing PDU rnti=%d, tti=%d, nof_bytes=%d\n", rnti, tti, nof_bytes); ue_db[rnti]->push_pdu(tti, nof_bytes); - stack->process_pdus(); + stack_task_queue.push([this]() { process_pdus(); }); } else { ue_db[rnti]->deallocate_pdu(tti); } @@ -410,7 +412,7 @@ int mac::sr_detected(uint32_t tti, uint16_t rnti) return ret; } -int mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, uint32_t time_adv) +void mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, uint32_t time_adv) { log_h->step(tti); uint16_t rnti; @@ -426,50 +428,53 @@ int mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, } // Set PCAP if available - if (pcap) { + if (pcap != nullptr) { ue_db[rnti]->start_pcap(pcap); } - } - // Generate RAR data - sched_interface::dl_sched_rar_info_t rar_info = {}; - rar_info.preamble_idx = preamble_idx; - rar_info.ta_cmd = time_adv; - rar_info.temp_crnti = rnti; - rar_info.msg3_size = 7; - rar_info.prach_tti = tti; - - // Add new user to the scheduler so that it can RX/TX SRB0 - sched_interface::ue_cfg_t ue_cfg = {}; - ue_cfg.supported_cc_list.emplace_back(); - ue_cfg.supported_cc_list.back().active = true; - ue_cfg.supported_cc_list.back().enb_cc_idx = enb_cc_idx; - ue_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; - ue_cfg.dl_cfg.tm = SRSLTE_TM1; - if (scheduler.ue_cfg(rnti, ue_cfg) != SRSLTE_SUCCESS) { - Error("Registering new user rnti=0x%x to SCHED\n", rnti); - return -1; + // Increase RNTI counter + last_rnti++; + if (last_rnti >= 60000) { + last_rnti = 70; + } } - // Register new user in RRC - rrc_h->add_user(rnti, ue_cfg); + stack_task_queue.push([this, rnti, tti, enb_cc_idx, preamble_idx, time_adv]() { + // Generate RAR data + sched_interface::dl_sched_rar_info_t rar_info = {}; + rar_info.preamble_idx = preamble_idx; + rar_info.ta_cmd = time_adv; + rar_info.temp_crnti = rnti; + rar_info.msg3_size = 7; + rar_info.prach_tti = tti; + + // Add new user to the scheduler so that it can RX/TX SRB0 + sched_interface::ue_cfg_t ue_cfg = {}; + ue_cfg.supported_cc_list.emplace_back(); + ue_cfg.supported_cc_list.back().active = true; + ue_cfg.supported_cc_list.back().enb_cc_idx = enb_cc_idx; + ue_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; + ue_cfg.dl_cfg.tm = SRSLTE_TM1; + if (scheduler.ue_cfg(rnti, ue_cfg) != SRSLTE_SUCCESS) { + Error("Registering new user rnti=0x%x to SCHED\n", rnti); + return; + } - // Add temporal rnti to the PHY - if (phy_h->add_rnti(rnti, enb_cc_idx, true)) { - Error("Registering temporal-rnti=0x%x to PHY\n", rnti); - } + // Register new user in RRC + rrc_h->add_user(rnti, ue_cfg); - // Trigger scheduler RACH - scheduler.dl_rach_info(enb_cc_idx, rar_info); + // Add temporal rnti to the PHY + if (phy_h->add_rnti(rnti, enb_cc_idx, true) != SRSLTE_SUCCESS) { + Error("Registering temporal-rnti=0x%x to PHY\n", rnti); + return; + } - log_h->info("RACH: tti=%d, preamble=%d, offset=%d, temp_crnti=0x%x\n", tti, preamble_idx, time_adv, rnti); - log_h->console("RACH: tti=%d, preamble=%d, offset=%d, temp_crnti=0x%x\n", tti, preamble_idx, time_adv, rnti); - // Increase RNTI counter - last_rnti++; - if (last_rnti >= 60000) { - last_rnti = 70; - } - return 0; + // Trigger scheduler RACH + scheduler.dl_rach_info(enb_cc_idx, rar_info); + + log_h->info("RACH: tti=%d, preamble=%d, offset=%d, temp_crnti=0x%x\n", tti, preamble_idx, time_adv, rnti); + log_h->console("RACH: tti=%d, preamble=%d, offset=%d, temp_crnti=0x%x\n", tti, preamble_idx, time_adv, rnti); + }); } int mac::get_dl_sched(uint32_t tti, dl_sched_list_t& dl_sched_res_list) diff --git a/srsenb/test/phy/enb_phy_test.cc b/srsenb/test/phy/enb_phy_test.cc index 8920783de..f9a7f13b9 100644 --- a/srsenb/test/phy/enb_phy_test.cc +++ b/srsenb/test/phy/enb_phy_test.cc @@ -372,10 +372,9 @@ public: return SRSLTE_SUCCESS; } - int rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) override + void rach_detected(uint32_t tti, uint32_t primary_cc_idx, uint32_t preamble_idx, uint32_t time_adv) override { notify_rach_detected(); - return 0; } int ri_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t ri_value) override { diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 4f293b6ab..7dbc4bcce 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -168,8 +168,8 @@ private: gw_interface_stack* gw = nullptr; // Thread - static const int STACK_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD - srslte::multiqueue_task_handler pending_tasks; + static const int STACK_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD + srslte::task_multiqueue pending_tasks; int sync_queue_id = -1, ue_queue_id = -1, gw_queue_id = -1, mac_queue_id = -1, background_queue_id = -1; srslte::task_thread_pool background_tasks; ///< Thread pool used for long, low-priority tasks };