From e5df35304d4d6574df8136c0310ff059b1a52f94 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 19 Jan 2021 16:58:56 +0100 Subject: [PATCH] Fix issue with new way of managing ul buffers not working with CA --- .../srslte/interfaces/enb_interfaces.h | 4 +- srsenb/hdr/stack/enb_stack_lte.h | 4 +- srsenb/hdr/stack/mac/mac.h | 2 +- srsenb/hdr/stack/mac/ue.h | 8 +-- srsenb/src/phy/lte/cc_worker.cc | 2 +- srsenb/src/stack/mac/mac.cc | 16 ++++-- srsenb/src/stack/mac/ue.cc | 54 +++++++++++-------- srsenb/test/phy/enb_phy_test.cc | 2 +- 8 files changed, 54 insertions(+), 38 deletions(-) diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index b7945afb2..d93a84c9c 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -177,12 +177,12 @@ public: * * @param tti the given TTI * @param rnti the UE identifier in the eNb - * @param pdu_ptr pointer to the uplink buffer + * @param enb_cc_idx the eNb Cell/Carrier identifier * @param nof_bytes the number of grants carrierd by the PUSCH message * @param crc_res the CRC check, set to true if the message was decoded succesfully * @return SRSLTE_SUCCESS if no error occurs, SRSLTE_ERROR* if an error occurs */ - virtual int push_pdu(uint32_t tti_rx, uint16_t rnti, const uint8_t* pdu_ptr, uint32_t nof_bytes, bool crc_res) = 0; + virtual int push_pdu(uint32_t tti_rx, uint16_t rnti, uint32_t enb_cc_idx, uint32_t nof_bytes, bool crc_res) = 0; virtual int get_dl_sched(uint32_t tti, dl_sched_list_t& dl_sched_res) = 0; virtual int get_mch_sched(uint32_t tti, bool is_mcch, dl_sched_list_t& dl_sched_res) = 0; diff --git a/srsenb/hdr/stack/enb_stack_lte.h b/srsenb/hdr/stack/enb_stack_lte.h index 8929bbfc6..62d96cc68 100644 --- a/srsenb/hdr/stack/enb_stack_lte.h +++ b/srsenb/hdr/stack/enb_stack_lte.h @@ -80,9 +80,9 @@ public: { return mac.crc_info(tti, rnti, enb_cc_idx, nof_bytes, crc_res); } - int push_pdu(uint32_t tti, uint16_t rnti, const uint8_t* pdu_ptr, uint32_t nof_bytes, bool crc_res) final + int push_pdu(uint32_t tti, uint16_t rnti, uint32_t enb_cc_idx, uint32_t nof_bytes, bool crc_res) final { - return mac.push_pdu(tti, rnti, pdu_ptr, nof_bytes, crc_res); + return mac.push_pdu(tti, rnti, enb_cc_idx, nof_bytes, crc_res); } int get_dl_sched(uint32_t tti, dl_sched_list_t& dl_sched_res) final { return mac.get_dl_sched(tti, dl_sched_res); } int get_mch_sched(uint32_t tti, bool is_mcch, dl_sched_list_t& dl_sched_res) final diff --git a/srsenb/hdr/stack/mac/mac.h b/srsenb/hdr/stack/mac/mac.h index 6f6a72a08..0aa6c1832 100644 --- a/srsenb/hdr/stack/mac/mac.h +++ b/srsenb/hdr/stack/mac/mac.h @@ -56,7 +56,7 @@ public: int ta_info(uint32_t tti, uint16_t rnti, float ta_us) override; int ack_info(uint32_t tti, uint16_t rnti, uint32_t enb_cc_idx, uint32_t tb_idx, bool ack) override; int crc_info(uint32_t tti, uint16_t rnti, uint32_t enb_cc_idx, uint32_t nof_bytes, bool crc_res) override; - int push_pdu(uint32_t tti, uint16_t rnti, const uint8_t* pdu_ptr, uint32_t nof_bytes, bool crc_res) override; + int push_pdu(uint32_t tti, uint16_t rnti, uint32_t enb_cc_idx, uint32_t nof_bytes, bool crc_res) override; int get_dl_sched(uint32_t tti_tx_dl, dl_sched_list_t& dl_sched_res) override; int get_ul_sched(uint32_t tti_tx_ul, ul_sched_list_t& ul_sched_res) override; diff --git a/srsenb/hdr/stack/mac/ue.h b/srsenb/hdr/stack/mac/ue.h index 3dde41198..6eae19f1f 100644 --- a/srsenb/hdr/stack/mac/ue.h +++ b/srsenb/hdr/stack/mac/ue.h @@ -72,10 +72,10 @@ public: srslte_softbuffer_rx_t* get_rx_softbuffer(const uint32_t ue_cc_idx, const uint32_t tti); bool process_pdus(); - uint8_t* request_buffer(uint32_t tti, const uint32_t len); + uint8_t* request_buffer(uint32_t tti, uint32_t ue_cc_idx, const uint32_t len); void process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channel_t channel) override; - void push_pdu(uint32_t tti, const uint8_t* pdu_ptr, uint32_t len); - void deallocate_pdu(uint32_t tti, const uint8_t* pdu_ptr); + void push_pdu(uint32_t tti, uint32_t ue_cc_idx, uint32_t len); + void deallocate_pdu(uint32_t tti, uint32_t ue_cc_idx); void metrics_read(mac_ue_metrics_t* metrics_); void metrics_rx(bool crc, uint32_t tbs); @@ -124,7 +124,7 @@ private: tx_payload_buffer; // Save 2 buffers per HARQ process - srslte::circular_array rx_used_buffers; + std::vector > rx_used_buffers; srslte::block_queue pending_ta_commands; ta ta_fsm; diff --git a/srsenb/src/phy/lte/cc_worker.cc b/srsenb/src/phy/lte/cc_worker.cc index 0c568d39b..1d04fd282 100644 --- a/srsenb/src/phy/lte/cc_worker.cc +++ b/srsenb/src/phy/lte/cc_worker.cc @@ -374,7 +374,7 @@ void cc_worker::decode_pusch(stack_interface_phy_lte::ul_sched_grant_t* grants, // Inform MAC about the CRC result phy->stack->crc_info(tti_rx, rnti, cc_idx, ul_cfg.pusch.grant.tb.tbs / 8, pusch_res.crc); // Push PDU buffer - phy->stack->push_pdu(tti_rx, rnti, grants[i].data, ul_cfg.pusch.grant.tb.tbs / 8, pusch_res.crc); + phy->stack->push_pdu(tti_rx, rnti, cc_idx, ul_cfg.pusch.grant.tb.tbs / 8, pusch_res.crc); // Logging if (log_h->get_level() >= srslte::LOG_LEVEL_INFO) { char str[512]; diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 0d7cd86cb..953e3c116 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -323,7 +323,7 @@ int mac::crc_info(uint32_t tti_rx, uint16_t rnti, uint32_t enb_cc_idx, uint32_t return scheduler.ul_crc_info(tti_rx, rnti, enb_cc_idx, crc); } -int mac::push_pdu(uint32_t tti_rx, uint16_t rnti, const uint8_t* pdu_ptr, uint32_t nof_bytes, bool crc) +int mac::push_pdu(uint32_t tti_rx, uint16_t rnti, uint32_t enb_cc_idx, uint32_t nof_bytes, bool crc) { srslte::rwlock_read_guard lock(rwlock); @@ -331,14 +331,21 @@ int mac::push_pdu(uint32_t tti_rx, uint16_t rnti, const uint8_t* pdu_ptr, uint32 return SRSLTE_ERROR; } + std::array enb_ue_cc_map = scheduler.get_enb_ue_cc_map(rnti); + if (enb_ue_cc_map[enb_cc_idx] < 0) { + Error("User rnti=0x%x is not activated for carrier %d\n", rnti, enb_cc_idx); + return SRSLTE_ERROR; + } + uint32_t ue_cc_idx = enb_ue_cc_map[enb_cc_idx]; + // push the pdu through the queue if received correctly if (crc) { Info("Pushing PDU rnti=0x%x, tti_rx=%d, nof_bytes=%d\n", rnti, tti_rx, nof_bytes); - ue_db[rnti]->push_pdu(tti_rx, pdu_ptr, nof_bytes); + ue_db[rnti]->push_pdu(tti_rx, ue_cc_idx, nof_bytes); stack_task_queue.push([this]() { process_pdus(); }); } else { Debug("Discarting PDU rnti=0x%x, tti_rx=%d, nof_bytes=%d\n", rnti, tti_rx, nof_bytes); - ue_db[rnti]->deallocate_pdu(tti_rx, pdu_ptr); + ue_db[rnti]->deallocate_pdu(tti_rx, ue_cc_idx); } return SRSLTE_SUCCESS; } @@ -906,7 +913,8 @@ int mac::get_ul_sched(uint32_t tti_tx_ul, ul_sched_list_t& ul_sched_res_list) if (sched_result.pusch[n].current_tx_nb == 0) { srslte_softbuffer_rx_reset_tbs(phy_ul_sched_res->pusch[n].softbuffer_rx, sched_result.pusch[i].tbs * 8); } - phy_ul_sched_res->pusch[n].data = ue_db[rnti]->request_buffer(tti_tx_ul, sched_result.pusch[i].tbs); + phy_ul_sched_res->pusch[n].data = + ue_db[rnti]->request_buffer(tti_tx_ul, sched_result.pusch[i].dci.ue_cc_idx, sched_result.pusch[i].tbs); if (phy_ul_sched_res->pusch[n].data) { phy_ul_sched_res->nof_grants++; } else { diff --git a/srsenb/src/stack/mac/ue.cc b/srsenb/src/stack/mac/ue.cc index 41ccc9425..092a08c4a 100644 --- a/srsenb/src/stack/mac/ue.cc +++ b/srsenb/src/stack/mac/ue.cc @@ -44,6 +44,7 @@ ue::ue(uint16_t rnti_, pdus(128), nof_rx_harq_proc(nof_rx_harq_proc_), nof_tx_harq_proc(nof_tx_harq_proc_), + rx_used_buffers(nof_cells_), ta_fsm(this) { srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance(); @@ -94,6 +95,15 @@ void ue::reset() srslte_softbuffer_tx_reset(&buffer); } } + + for (auto& rx_buffers_cc : rx_used_buffers) { + for (auto& ptr : rx_buffers_cc) { + if (ptr) { + pdus.deallocate(ptr); + ptr = nullptr; + } + } + } } /** @@ -161,19 +171,19 @@ ue::get_tx_softbuffer(const uint32_t ue_cc_idx, const uint32_t harq_process, con return &softbuffer_tx.at(ue_cc_idx).at((harq_process * SRSLTE_MAX_TB + tb_idx) % nof_tx_harq_proc); } -uint8_t* ue::request_buffer(uint32_t tti, const uint32_t len) +uint8_t* ue::request_buffer(uint32_t tti, uint32_t cc_idx, const uint32_t len) { uint8_t* pdu = nullptr; if (len > 0) { pdu = pdus.request(len); if (pdu) { // Deallocate oldest buffer if we didn't deallocate it - if (rx_used_buffers[tti] != nullptr) { - pdus.deallocate(rx_used_buffers[tti]); - rx_used_buffers[tti] = nullptr; + if (rx_used_buffers.at(cc_idx)[tti] != nullptr) { + pdus.deallocate(rx_used_buffers.at(cc_idx)[tti]); + rx_used_buffers.at(cc_idx)[tti] = nullptr; log_h->warning("buffers: RX PDU of rnti=0x%x and pid=%d wasn't deallocated\n", rnti, tti % nof_rx_harq_proc); } - rx_used_buffers[tti] = pdu; + rx_used_buffers.at(cc_idx)[tti] = pdu; log_h->info("RX PDU saved for pid=%d\n", tti % nof_rx_harq_proc); } else { log_h->error("buffers: Requesting buffer from pool\n"); @@ -306,35 +316,33 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe Debug("MAC PDU processed\n"); } -void ue::deallocate_pdu(uint32_t tti, const uint8_t* pdu_ptr) +void ue::deallocate_pdu(uint32_t tti, uint32_t cc_idx) { - if (pdu_ptr) { - if (rx_used_buffers[tti] == pdu_ptr) { - rx_used_buffers[tti] = nullptr; - } else { - Warning("buffers: Unexpected RX PDU pointer in deallocate_pdu for rnti=0x%x pid=%d\n", rnti, tti % nof_rx_harq_proc); - } - pdus.deallocate(pdu_ptr); + if (rx_used_buffers.at(cc_idx)[tti] != nullptr) { + pdus.deallocate(rx_used_buffers.at(cc_idx)[tti]); + rx_used_buffers.at(cc_idx)[tti] = nullptr; } else { - Error("Error deallocating PDU: null ptr\n"); + Warning("buffers: Null RX PDU pointer in deallocate_pdu for rnti=0x%x pid=%d cc_idx=%d\n", + rnti, + tti % nof_rx_harq_proc, + cc_idx); } } -void ue::push_pdu(uint32_t tti, const uint8_t* pdu_ptr, uint32_t len) +void ue::push_pdu(uint32_t tti, uint32_t cc_idx, uint32_t len) { - if (pdu_ptr) { - if (rx_used_buffers[tti] == pdu_ptr) { - rx_used_buffers[tti] = nullptr; - } else { - Warning("buffers: Unexpected RX PDU pointer in push_pdu for rnti=0x%x pid=%d\n", rnti, tti % nof_rx_harq_proc); - } + if (rx_used_buffers.at(cc_idx)[tti] != nullptr) { if (len > 0) { - pdus.push(pdu_ptr, len); + pdus.push(rx_used_buffers.at(cc_idx)[tti], len); } else { Error("Error pushing PDU: null length\n"); } + rx_used_buffers.at(cc_idx)[tti] = nullptr; } else { - Error("Error pushing PDU: null pointer\n"); + Warning("buffers: Null RX PDU pointer in push_pdu for rnti=0x%x pid=%d cc_idx=%d\n", + rnti, + tti % nof_rx_harq_proc, + cc_idx); } } diff --git a/srsenb/test/phy/enb_phy_test.cc b/srsenb/test/phy/enb_phy_test.cc index eee341fe8..b6c449e6f 100644 --- a/srsenb/test/phy/enb_phy_test.cc +++ b/srsenb/test/phy/enb_phy_test.cc @@ -493,7 +493,7 @@ public: return 0; } - int push_pdu(uint32_t tti, uint16_t rnti, const uint8_t* pdu_ptr, uint32_t nof_bytes, bool crc_res) override + int push_pdu(uint32_t tti, uint16_t rnti, uint32_t cc_idx, uint32_t nof_bytes, bool crc_res) override { log_h.info("Received push_pdu tti=%d; rnti=0x%x; ack=%d;\n", tti, rnti, crc_res); notify_push_pdu();