diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index 87d11f212..79d62e663 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -94,8 +94,6 @@ public: // Radio-Link status virtual void rl_failure(uint16_t rnti) = 0; virtual void rl_ok(uint16_t rnti) = 0; - - virtual void tti_clock() = 0; }; /* Interface MAC -> PHY */ @@ -313,6 +311,8 @@ public: // Combined interface for PHY to access stack (MAC and RRC) class stack_interface_phy_lte : public mac_interface_phy_lte { +public: + virtual void tti_clock() = 0; }; // Combined interface for stack (MAC and RRC) to access PHY @@ -351,6 +351,13 @@ public: virtual void add_gtpu_m1u_socket_handler(int fd) = 0; }; +// STACK interface for MAC +class stack_interface_mac_lte +{ +public: + virtual void process_pdus() = 0; +}; + } // namespace srsenb #endif // SRSLTE_ENB_INTERFACES_H diff --git a/srsenb/hdr/stack/enb_stack_lte.h b/srsenb/hdr/stack/enb_stack_lte.h index dba1b12cc..b2fa14cec 100644 --- a/srsenb/hdr/stack/enb_stack_lte.h +++ b/srsenb/hdr/stack/enb_stack_lte.h @@ -47,6 +47,7 @@ class enb_stack_lte final : public enb_stack_base, public stack_interface_phy_lte, public stack_interface_s1ap_lte, public stack_interface_gtpu_lte, + public stack_interface_mac_lte, public thread { public: @@ -99,6 +100,9 @@ public: void add_gtpu_s1u_socket_handler(int fd) override; void add_gtpu_m1u_socket_handler(int fd) override; + /* Stack-MAC interface */ + void process_pdus(); + private: static const int STACK_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD // thread loop @@ -157,7 +161,7 @@ private: void operator()() { func(this); } }; srslte::multiqueue_handler pending_tasks; - int enb_queue_id = -1, sync_queue_id = -1, mme_queue_id = -1, gtpu_queue_id = -1; + int enb_queue_id = -1, sync_queue_id = -1, mme_queue_id = -1, gtpu_queue_id = -1, mac_queue_id = -1; }; } // namespace srsenb diff --git a/srsenb/hdr/stack/mac/mac.h b/srsenb/hdr/stack/mac/mac.h index 7cfce8a1b..9bb41f867 100644 --- a/srsenb/hdr/stack/mac/mac.h +++ b/srsenb/hdr/stack/mac/mac.h @@ -22,29 +22,21 @@ #ifndef SRSENB_MAC_H #define SRSENB_MAC_H -#include +#include "scheduler.h" +#include "scheduler_metric.h" #include "srslte/common/log.h" -#include "srslte/common/timers.h" -#include "srslte/interfaces/enb_interfaces.h" -#include "srslte/interfaces/sched_interface.h" -#include "srslte/common/tti_sync_cv.h" +#include "srslte/common/mac_pcap.h" #include "srslte/common/threads.h" #include "srslte/common/tti_sync_cv.h" -#include "srslte/common/mac_pcap.h" -#include "scheduler.h" -#include "scheduler_metric.h" +#include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/enb_metrics_interface.h" +#include "srslte/interfaces/sched_interface.h" #include "ue.h" +#include namespace srsenb { - -class pdu_process_handler -{ -public: - virtual bool process_pdus() = 0; -}; -class mac : public mac_interface_phy_lte, public mac_interface_rlc, public mac_interface_rrc, public pdu_process_handler +class mac : public mac_interface_phy_lte, public mac_interface_rlc, public mac_interface_rrc { public: mac(); @@ -54,9 +46,10 @@ public: phy_interface_stack_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc, + stack_interface_mac_lte* stack_, srslte::log* log_h); void stop(); - + void start_pcap(srslte::mac_pcap* pcap_); /******** Interface from PHY (PHY -> MAC) ****************/ @@ -81,12 +74,11 @@ public: } void build_mch_sched(uint32_t tbs); void rl_failure(uint16_t rnti); - void rl_ok(uint16_t rnti); - void tti_clock(); - - /******** Interface from RRC (RRC -> MAC) ****************/ + void rl_ok(uint16_t rnti); + + /******** Interface from RRC (RRC -> MAC) ****************/ /* Provides cell configuration including SIB periodicity, etc. */ - int cell_cfg(sched_interface::cell_cfg_t *cell_cfg); + int cell_cfg(sched_interface::cell_cfg_t* cell_cfg); void reset(); /* Manages UE scheduling context */ @@ -122,9 +114,10 @@ private: 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; - srslte_cell_t cell; + srslte_cell_t cell; mac_args_t args; bool started; @@ -169,46 +162,8 @@ private: const static int mtch_payload_len = 10000; uint8_t mtch_payload_buffer[mtch_payload_len]; - /* Functions for MAC Timers */ - srslte::timer_handler timers_db; - void setup_timers(); - // pointer to MAC PCAP object srslte::mac_pcap* pcap; - - /* Class to run upper-layer timers with normal priority */ - class timer_thread : public thread - { - public: - timer_thread(mac* parent_, srslte::timer_handler* t) : ttisync(10240), timers(t), running(false), parent(parent_), thread("MAC_TIMER") { start(); } - void tti_clock(); - void stop(); - - private: - void run_thread(); - srslte::tti_sync_cv ttisync; - srslte::timer_handler *timers; - mac *parent; - bool running; - }; - timer_thread timers_thread; - - /* Class to process MAC PDUs from DEMUX unit */ - class pdu_process : public thread { - public: - pdu_process(pdu_process_handler *h); - void notify(); - void stop(); - private: - void run_thread(); - bool running; - bool have_data; - pthread_mutex_t mutex; - pthread_cond_t cvar; - pdu_process_handler *handler; - }; - pdu_process pdu_process_thread; - }; } // namespace srsenb diff --git a/srsenb/src/stack/enb_stack_lte.cc b/srsenb/src/stack/enb_stack_lte.cc index 6b97afe1b..f8916831c 100644 --- a/srsenb/src/stack/enb_stack_lte.cc +++ b/srsenb/src/stack/enb_stack_lte.cc @@ -35,6 +35,7 @@ enb_stack_lte::enb_stack_lte(srslte::logger* logger_) : logger(logger_), pdcp(&p sync_queue_id = pending_tasks.add_queue(); mme_queue_id = pending_tasks.add_queue(); gtpu_queue_id = pending_tasks.add_queue(); + mac_queue_id = pending_tasks.add_queue(); pool = byte_buffer_pool::get_instance(); } @@ -130,7 +131,7 @@ int enb_stack_lte::init(const stack_args_t& args_, const rrc_cfg_t& rrc_cfg_) rx_sockets.reset(new srslte::rx_multisocket_handler("ENBSOCKETS", &stack_log)); // Init all layers - mac.init(args.mac, &cell_cfg, phy, &rlc, &rrc, &mac_log); + mac.init(args.mac, &cell_cfg, phy, &rlc, &rrc, this, &mac_log); rlc.init(&pdcp, &rrc, &mac, &timers, &rlc_log); pdcp.init(&rlc, &rrc, >pu); rrc.init(&rrc_cfg, phy, &mac, &rlc, &pdcp, &s1ap, >pu, &timers, &rrc_log); @@ -158,7 +159,6 @@ void enb_stack_lte::tti_clock() void enb_stack_lte::tti_clock_impl() { timers.step_all(); - mac.tti_clock(); rrc.tti_clock(); } @@ -193,6 +193,7 @@ void enb_stack_lte::stop_impl() pending_tasks.erase_queue(enb_queue_id); pending_tasks.erase_queue(mme_queue_id); pending_tasks.erase_queue(gtpu_queue_id); + pending_tasks.erase_queue(mac_queue_id); started = false; } @@ -261,4 +262,9 @@ 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() +{ + pending_tasks.push(mac_queue_id, task_t{[this](task_t*) { mac.process_pdus(); }}); +} + } // namespace srsenb diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 9716a88ab..c82e71c13 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -38,12 +38,10 @@ using namespace asn1::rrc; namespace srsenb { -mac::mac() : timers_db(128), timers_thread(this, &timers_db), last_rnti(0), - rar_pdu_msg(sched_interface::MAX_RAR_LIST), rar_payload(), - pdu_process_thread(this) +mac::mac() : last_rnti(0), rar_pdu_msg(sched_interface::MAX_RAR_LIST), rar_payload() { - started = false; - pcap = NULL; + started = false; + pcap = NULL; phy_h = NULL; rlc_h = NULL; rrc_h = NULL; @@ -71,14 +69,16 @@ bool mac::init(const mac_args_t& args_, phy_interface_stack_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc, + stack_interface_mac_lte* stack_, srslte::log* log_h_) { started = false; if (cell_ && phy && rlc && log_h_) { phy_h = phy; - rlc_h = rlc; - rrc_h = rrc; + rlc_h = rlc; + rrc_h = rrc; + stack = stack_; log_h = log_h_; args = args_; @@ -122,8 +122,6 @@ void mac::stop() srslte_softbuffer_tx_free(&pcch_softbuffer_tx); srslte_softbuffer_tx_free(&rar_softbuffer_tx); started = false; - timers_thread.stop(); - pdu_process_thread.stop(); } pthread_rwlock_unlock(&rwlock); } @@ -133,8 +131,6 @@ void mac::reset() { Info("Resetting MAC\n"); - timers_db.stop_all(); - last_rnti = 70; /* Setup scheduler */ @@ -353,7 +349,7 @@ int mac::crc_info(uint32_t tti, uint16_t rnti, uint32_t nof_bytes, bool crc) 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); - pdu_process_thread.notify(); + stack->process_pdus(); } else { ue_db[rnti]->deallocate_pdu(tti); } @@ -836,95 +832,12 @@ int mac::get_ul_sched(uint32_t tti, ul_sched_t *ul_sched_res) return SRSLTE_SUCCESS; } -void mac::tti_clock() -{ - timers_thread.tti_clock(); -} - -/******************************************************** - * - * Class to run timers with normal priority - * - *******************************************************/ -void mac::timer_thread::run_thread() -{ - running = true; - ttisync.set_producer_cntr(0); - ttisync.resync(); - while(running) { - ttisync.wait(); - timers->step_all(); - } -} - -void mac::timer_thread::stop() -{ - running = false; - ttisync.increase(); - wait_thread_finish(); -} - -void mac::timer_thread::tti_clock() -{ - ttisync.increase(); -} - - - -/******************************************************** - * - * Class that runs a thread to process DL MAC PDUs from - * DEMUX unit - * - *******************************************************/ -mac::pdu_process::pdu_process(pdu_process_handler* h) : running(false), thread("MAC_PDU_PROCESS") -{ - handler = h; - pthread_mutex_init(&mutex, NULL); - pthread_cond_init(&cvar, NULL); - have_data = false; - start(MAC_PDU_THREAD_PRIO); -} - -void mac::pdu_process::stop() -{ - pthread_mutex_lock(&mutex); - running = false; - pthread_cond_signal(&cvar); - pthread_mutex_unlock(&mutex); - - wait_thread_finish(); -} - -void mac::pdu_process::notify() -{ - pthread_mutex_lock(&mutex); - have_data = true; - pthread_cond_signal(&cvar); - pthread_mutex_unlock(&mutex); -} - -void mac::pdu_process::run_thread() -{ - running = true; - while(running) { - have_data = handler->process_pdus(); - if (!have_data) { - pthread_mutex_lock(&mutex); - while(!have_data && running) { - pthread_cond_wait(&cvar, &mutex); - } - pthread_mutex_unlock(&mutex); - } - } -} - bool mac::process_pdus() { pthread_rwlock_rdlock(&rwlock); bool ret = false; for (auto& u : ue_db) { - ret = ret | u.second->process_pdus(); + ret |= u.second->process_pdus(); } pthread_rwlock_unlock(&rwlock); return ret;