moved rach_detected to stack thread. Created a more friendly interface to enqueue tasks in stack

master
Francisco Paisana 5 years ago
parent d10e950650
commit fed06138b9

@ -58,6 +58,24 @@ class multiqueue_handler
}; };
public: public:
class queue_handler
{
public:
queue_handler() = default;
queue_handler(multiqueue_handler<myobj>* parent_, int id) : parent(parent_), queue_id(id) {}
template <typename FwdRef>
void push(FwdRef&& value)
{
parent->push(queue_id, std::forward<FwdRef>(value));
}
bool try_push(const myobj& value) { return parent->try_push(queue_id, value); }
std::pair<bool, myobj> try_push(myobj&& value) { return parent->try_push(queue_id, std::move(value)); }
private:
multiqueue_handler<myobj>* parent = nullptr;
int queue_id = -1;
};
explicit multiqueue_handler(uint32_t capacity_ = std::numeric_limits<uint32_t>::max()) : capacity(capacity_) {} explicit multiqueue_handler(uint32_t capacity_ = std::numeric_limits<uint32_t>::max()) : capacity(capacity_) {}
~multiqueue_handler() { reset(); } ~multiqueue_handler() { reset(); }
@ -214,6 +232,8 @@ public:
return is_queue_active_(qidx); return is_queue_active_(qidx);
} }
queue_handler get_queue_handler() { return {this, add_queue()}; }
private: private:
bool is_queue_active_(int qidx) const { return running and queues[qidx].active; } bool is_queue_active_(int qidx) const { return running and queues[qidx].active; }
@ -257,7 +277,7 @@ private:
std::unique_ptr<base_task> task_ptr; std::unique_ptr<base_task> task_ptr;
}; };
using multiqueue_task_handler = multiqueue_handler<move_task_t>; using task_multiqueue = multiqueue_handler<move_task_t>;
} // namespace srslte } // namespace srslte

@ -26,6 +26,7 @@
#include "srslte/asn1/s1ap_asn1.h" #include "srslte/asn1/s1ap_asn1.h"
#include "srslte/common/common.h" #include "srslte/common/common.h"
#include "srslte/common/interfaces_common.h" #include "srslte/common/interfaces_common.h"
#include "srslte/common/multiqueue.h"
#include "srslte/common/security.h" #include "srslte/common/security.h"
#include "srslte/interfaces/rrc_interface_types.h" #include "srslte/interfaces/rrc_interface_types.h"
#include "srslte/interfaces/sched_interface.h" #include "srslte/interfaces/sched_interface.h"
@ -98,8 +99,8 @@ public:
*/ */
typedef std::vector<ul_sched_t> ul_sched_list_t; typedef std::vector<ul_sched_t> ul_sched_list_t;
virtual int sr_detected(uint32_t tti, uint16_t rnti) = 0; 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 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. * 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; int link_failure_nof_err;
} mac_args_t; } 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 class stack_interface_s1ap_lte
{ {
public: public:
@ -491,10 +499,8 @@ public:
}; };
// STACK interface for MAC // 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 } // namespace srsenb

@ -62,10 +62,10 @@ public:
bool get_metrics(stack_metrics_t* metrics) final; bool get_metrics(stack_metrics_t* metrics) final;
/* PHY-MAC interface */ /* PHY-MAC interface */
int sr_detected(uint32_t tti, uint16_t rnti) final { return mac.sr_detected(tti, rnti); } 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 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 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; void add_gtpu_m1u_socket_handler(int fd) override;
/* Stack-MAC interface */ /* 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: private:
static const int STACK_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD 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; phy_interface_stack_lte* phy = nullptr;
// state // state
bool started = false; bool started = false;
srslte::multiqueue_task_handler pending_tasks; 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; int enb_queue_id = -1, sync_queue_id = -1, mme_queue_id = -1, gtpu_queue_id = -1, mac_queue_id = -1;
}; };

@ -53,8 +53,8 @@ public:
void start_pcap(srslte::mac_pcap* pcap_); void start_pcap(srslte::mac_pcap* pcap_);
/******** Interface from PHY (PHY -> MAC) ****************/ /******** Interface from PHY (PHY -> MAC) ****************/
int sr_detected(uint32_t tti, uint16_t rnti) final; 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; 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 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; 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(); 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 void
write_mcch(asn1::rrc::sib_type2_s* sib2, asn1::rrc::sib_type13_r9_s* sib13, asn1::rrc::mcch_msg_s* mcch) override; 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 = {}; srslte_cell_t cell = {};
mac_args_t args = {}; mac_args_t args = {};
// derived from args
srslte::task_multiqueue::queue_handler stack_task_queue;
bool started = false; bool started = false;
/* Scheduler unit */ /* Scheduler unit */
@ -139,23 +142,23 @@ private:
std::vector<srslte::rar_pdu> rar_pdu_msg; std::vector<srslte::rar_pdu> rar_pdu_msg;
srslte::byte_buffer_t rar_payload[sched_interface::MAX_RAR_LIST]; 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] = {}; 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] = {}; uint8_t pcch_payload_buffer[pcch_payload_buffer_len] = {};
srslte_softbuffer_tx_t bcch_softbuffer_tx[NOF_BCCH_DLSCH_MSG] = {}; srslte_softbuffer_tx_t bcch_softbuffer_tx[NOF_BCCH_DLSCH_MSG] = {};
srslte_softbuffer_tx_t pcch_softbuffer_tx = {}; srslte_softbuffer_tx_t pcch_softbuffer_tx = {};
srslte_softbuffer_tx_t rar_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; int current_mcch_length = 0;
uint8_t mcch_payload_buffer[mcch_payload_len] = {}; uint8_t mcch_payload_buffer[mcch_payload_len] = {};
asn1::rrc::mcch_msg_s mcch; asn1::rrc::mcch_msg_s mcch;
asn1::rrc::sib_type2_s sib2; asn1::rrc::sib_type2_s sib2;
asn1::rrc::sib_type13_r9_s sib13; 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] = {}; uint8_t mtch_payload_buffer[mtch_payload_len] = {};
// pointer to MAC PCAP object // pointer to MAC PCAP object

@ -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); 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 } // namespace srsenb

@ -70,6 +70,8 @@ bool mac::init(const mac_args_t& args_,
args = args_; args = args_;
cell = *cell_; cell = *cell_;
stack_task_queue = stack->get_task_queue();
scheduler.init(rrc); scheduler.init(rrc);
// Set default scheduler configuration // 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) { if (crc) {
Info("Pushing PDU rnti=%d, tti=%d, nof_bytes=%d\n", rnti, tti, nof_bytes); Info("Pushing PDU rnti=%d, tti=%d, nof_bytes=%d\n", rnti, tti, nof_bytes);
ue_db[rnti]->push_pdu(tti, nof_bytes); ue_db[rnti]->push_pdu(tti, nof_bytes);
stack->process_pdus(); stack_task_queue.push([this]() { process_pdus(); });
} else { } else {
ue_db[rnti]->deallocate_pdu(tti); ue_db[rnti]->deallocate_pdu(tti);
} }
@ -410,7 +412,7 @@ int mac::sr_detected(uint32_t tti, uint16_t rnti)
return ret; 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); log_h->step(tti);
uint16_t rnti; 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 // Set PCAP if available
if (pcap) { if (pcap != nullptr) {
ue_db[rnti]->start_pcap(pcap); ue_db[rnti]->start_pcap(pcap);
} }
}
// Generate RAR data // Increase RNTI counter
sched_interface::dl_sched_rar_info_t rar_info = {}; last_rnti++;
rar_info.preamble_idx = preamble_idx; if (last_rnti >= 60000) {
rar_info.ta_cmd = time_adv; last_rnti = 70;
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;
} }
// Register new user in RRC stack_task_queue.push([this, rnti, tti, enb_cc_idx, preamble_idx, time_adv]() {
rrc_h->add_user(rnti, ue_cfg); // 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 // Register new user in RRC
if (phy_h->add_rnti(rnti, enb_cc_idx, true)) { rrc_h->add_user(rnti, ue_cfg);
Error("Registering temporal-rnti=0x%x to PHY\n", rnti);
}
// Trigger scheduler RACH // Add temporal rnti to the PHY
scheduler.dl_rach_info(enb_cc_idx, rar_info); 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); // Trigger scheduler RACH
log_h->console("RACH: tti=%d, preamble=%d, offset=%d, temp_crnti=0x%x\n", tti, preamble_idx, time_adv, rnti); scheduler.dl_rach_info(enb_cc_idx, rar_info);
// Increase RNTI counter
last_rnti++; log_h->info("RACH: tti=%d, preamble=%d, offset=%d, temp_crnti=0x%x\n", tti, preamble_idx, time_adv, rnti);
if (last_rnti >= 60000) { log_h->console("RACH: tti=%d, preamble=%d, offset=%d, temp_crnti=0x%x\n", tti, preamble_idx, time_adv, rnti);
last_rnti = 70; });
}
return 0;
} }
int mac::get_dl_sched(uint32_t tti, dl_sched_list_t& dl_sched_res_list) int mac::get_dl_sched(uint32_t tti, dl_sched_list_t& dl_sched_res_list)

@ -372,10 +372,9 @@ public:
return SRSLTE_SUCCESS; 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(); notify_rach_detected();
return 0;
} }
int ri_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t ri_value) override int ri_info(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t ri_value) override
{ {

@ -168,8 +168,8 @@ private:
gw_interface_stack* gw = nullptr; gw_interface_stack* gw = nullptr;
// Thread // Thread
static const int STACK_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD static const int STACK_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD
srslte::multiqueue_task_handler pending_tasks; 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; 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 srslte::task_thread_pool background_tasks; ///< Thread pool used for long, low-priority tasks
}; };

Loading…
Cancel
Save