From 581a99c616dde3833828bcd67874c8ee3c7b979d Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 15 Feb 2022 12:44:14 +0000 Subject: [PATCH] nr,gnb: use memory pool to allocate scheduler UEs --- .../srsran/adt/pool/circular_stack_pool.h | 16 ++++++++++++++++ srsgnb/hdr/stack/mac/sched_nr.h | 5 ++++- srsgnb/hdr/stack/mac/sched_nr_ue.h | 4 +++- srsgnb/src/stack/mac/sched_nr.cc | 10 ++++++++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/include/srsran/adt/pool/circular_stack_pool.h b/lib/include/srsran/adt/pool/circular_stack_pool.h index 2228e8d29..640ff6b13 100644 --- a/lib/include/srsran/adt/pool/circular_stack_pool.h +++ b/lib/include/srsran/adt/pool/circular_stack_pool.h @@ -107,6 +107,22 @@ private: srslog::basic_logger& logger; }; +template +unique_pool_ptr make_pool_obj_with_fallback(circular_stack_pool& pool, size_t key, Args&&... args) +{ + void* block = pool.allocate(key, sizeof(T), alignof(T)); + if (block == nullptr) { + // allocated with "new" as a fallback + return unique_pool_ptr(new T(std::forward(args)...), std::default_delete()); + } + // allocation using memory pool was successful + new (block) T(std::forward(args)...); + return unique_pool_ptr(static_cast(block), [key, &pool](T* ptr) { + ptr->~T(); + pool.deallocate(key, ptr); + }); +} + } // namespace srsran #endif // SRSRAN_CIRCULAR_MAP_STACK_POOL_H diff --git a/srsgnb/hdr/stack/mac/sched_nr.h b/srsgnb/hdr/stack/mac/sched_nr.h index 2041d09d4..144d9261d 100644 --- a/srsgnb/hdr/stack/mac/sched_nr.h +++ b/srsgnb/hdr/stack/mac/sched_nr.h @@ -17,6 +17,7 @@ #include "sched_nr_interface.h" #include "sched_nr_ue.h" #include "srsran/adt/pool/cached_alloc.h" +#include "srsran/adt/pool/circular_stack_pool.h" #include "srsran/common/slot_point.h" #include extern "C" { @@ -61,7 +62,7 @@ public: private: int ue_cfg_impl(uint16_t rnti, const ue_cfg_t& cfg); - int add_ue_impl(uint16_t rnti, std::unique_ptr u); + int add_ue_impl(uint16_t rnti, sched_nr_impl::unique_ue_ptr u); // args sched_nr_impl::sched_params_t cfg; @@ -74,6 +75,8 @@ private: using slot_cc_worker = sched_nr_impl::cc_worker; std::vector > cc_workers; + // UE Database + std::unique_ptr > ue_pool; using ue_map_t = sched_nr_impl::ue_map_t; ue_map_t ue_db; diff --git a/srsgnb/hdr/stack/mac/sched_nr_ue.h b/srsgnb/hdr/stack/mac/sched_nr_ue.h index b6cd93699..0fd4eb123 100644 --- a/srsgnb/hdr/stack/mac/sched_nr_ue.h +++ b/srsgnb/hdr/stack/mac/sched_nr_ue.h @@ -22,6 +22,7 @@ #include "srsran/adt/circular_map.h" #include "srsran/adt/move_callback.h" #include "srsran/adt/pool/cached_alloc.h" +#include "srsran/adt/pool/pool_interface.h" namespace srsenb { @@ -205,7 +206,8 @@ private: ue_carrier* ue = nullptr; }; -using ue_map_t = rnti_map_t >; +using unique_ue_ptr = srsran::unique_pool_ptr; +using ue_map_t = rnti_map_t; using slot_ue_map_t = rnti_map_t; } // namespace sched_nr_impl diff --git a/srsgnb/src/stack/mac/sched_nr.cc b/srsgnb/src/stack/mac/sched_nr.cc index 9176611a3..0c95a0739 100644 --- a/srsgnb/src/stack/mac/sched_nr.cc +++ b/srsgnb/src/stack/mac/sched_nr.cc @@ -295,6 +295,9 @@ int sched_nr::config(const sched_args_t& sched_cfg, srsran::const_span(8, sizeof(ue), 4)); + // Initiate Common Sched Configuration cfg.cells.reserve(cell_list.size()); for (uint32_t cc = 0; cc < cell_list.size(); ++cc) { @@ -333,7 +336,7 @@ void sched_nr::ue_rem(uint16_t rnti) }); } -int sched_nr::add_ue_impl(uint16_t rnti, std::unique_ptr u) +int sched_nr::add_ue_impl(uint16_t rnti, sched_nr_impl::unique_ue_ptr u) { logger->info("SCHED: New user rnti=0x%x, cc=%d", rnti, cfg.cells[0].cc); return ue_db.insert(rnti, std::move(u)).has_value() ? SRSRAN_SUCCESS : SRSRAN_ERROR; @@ -342,6 +345,8 @@ int sched_nr::add_ue_impl(uint16_t rnti, std::unique_ptr u) int sched_nr::ue_cfg_impl(uint16_t rnti, const ue_cfg_t& uecfg) { if (not ue_db.contains(rnti)) { + // create user object + unique_ue_ptr u = srsran::make_pool_obj_with_fallback(*ue_pool, rnti, rnti, uecfg, cfg); return add_ue_impl(rnti, std::make_unique(rnti, uecfg, cfg)); } ue_db[rnti]->set_cfg(uecfg); @@ -416,7 +421,8 @@ void sched_nr::get_metrics(mac_metrics_t& metrics) int sched_nr::dl_rach_info(const rar_info_t& rar_info) { // create user object outside of sched main thread - std::unique_ptr u = std::make_unique(rar_info.temp_crnti, rar_info.cc, cfg); + unique_ue_ptr u = + srsran::make_pool_obj_with_fallback(*ue_pool, rar_info.temp_crnti, rar_info.temp_crnti, rar_info.cc, cfg); // enqueue UE creation event + RACH handling auto add_ue = [this, rar_info, u = std::move(u)](event_manager::logger& ev_logger) mutable {