nr,gnb: use memory pool to allocate scheduler UEs

master
Francisco 3 years ago committed by Andre Puschmann
parent a2174a5714
commit 581a99c616

@ -107,6 +107,22 @@ private:
srslog::basic_logger& logger; srslog::basic_logger& logger;
}; };
template <typename T, size_t N, typename... Args>
unique_pool_ptr<T> make_pool_obj_with_fallback(circular_stack_pool<N>& 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<T>(new T(std::forward<Args>(args)...), std::default_delete<T>());
}
// allocation using memory pool was successful
new (block) T(std::forward<Args>(args)...);
return unique_pool_ptr<T>(static_cast<T*>(block), [key, &pool](T* ptr) {
ptr->~T();
pool.deallocate(key, ptr);
});
}
} // namespace srsran } // namespace srsran
#endif // SRSRAN_CIRCULAR_MAP_STACK_POOL_H #endif // SRSRAN_CIRCULAR_MAP_STACK_POOL_H

@ -17,6 +17,7 @@
#include "sched_nr_interface.h" #include "sched_nr_interface.h"
#include "sched_nr_ue.h" #include "sched_nr_ue.h"
#include "srsran/adt/pool/cached_alloc.h" #include "srsran/adt/pool/cached_alloc.h"
#include "srsran/adt/pool/circular_stack_pool.h"
#include "srsran/common/slot_point.h" #include "srsran/common/slot_point.h"
#include <array> #include <array>
extern "C" { extern "C" {
@ -61,7 +62,7 @@ public:
private: private:
int ue_cfg_impl(uint16_t rnti, const ue_cfg_t& cfg); int ue_cfg_impl(uint16_t rnti, const ue_cfg_t& cfg);
int add_ue_impl(uint16_t rnti, std::unique_ptr<sched_nr_impl::ue> u); int add_ue_impl(uint16_t rnti, sched_nr_impl::unique_ue_ptr u);
// args // args
sched_nr_impl::sched_params_t cfg; sched_nr_impl::sched_params_t cfg;
@ -74,6 +75,8 @@ private:
using slot_cc_worker = sched_nr_impl::cc_worker; using slot_cc_worker = sched_nr_impl::cc_worker;
std::vector<std::unique_ptr<sched_nr_impl::cc_worker> > cc_workers; std::vector<std::unique_ptr<sched_nr_impl::cc_worker> > cc_workers;
// UE Database
std::unique_ptr<srsran::circular_stack_pool<SRSENB_MAX_UES> > ue_pool;
using ue_map_t = sched_nr_impl::ue_map_t; using ue_map_t = sched_nr_impl::ue_map_t;
ue_map_t ue_db; ue_map_t ue_db;

@ -22,6 +22,7 @@
#include "srsran/adt/circular_map.h" #include "srsran/adt/circular_map.h"
#include "srsran/adt/move_callback.h" #include "srsran/adt/move_callback.h"
#include "srsran/adt/pool/cached_alloc.h" #include "srsran/adt/pool/cached_alloc.h"
#include "srsran/adt/pool/pool_interface.h"
namespace srsenb { namespace srsenb {
@ -205,7 +206,8 @@ private:
ue_carrier* ue = nullptr; ue_carrier* ue = nullptr;
}; };
using ue_map_t = rnti_map_t<std::unique_ptr<ue> >; using unique_ue_ptr = srsran::unique_pool_ptr<ue>;
using ue_map_t = rnti_map_t<unique_ue_ptr>;
using slot_ue_map_t = rnti_map_t<slot_ue>; using slot_ue_map_t = rnti_map_t<slot_ue>;
} // namespace sched_nr_impl } // namespace sched_nr_impl

@ -295,6 +295,9 @@ int sched_nr::config(const sched_args_t& sched_cfg, srsran::const_span<sched_nr_
cfg = sched_params_t{sched_cfg}; cfg = sched_params_t{sched_cfg};
logger = &srslog::fetch_basic_logger(sched_cfg.logger_name); logger = &srslog::fetch_basic_logger(sched_cfg.logger_name);
// Initiate UE memory pool
ue_pool.reset(new srsran::circular_stack_pool<SRSENB_MAX_UES>(8, sizeof(ue), 4));
// Initiate Common Sched Configuration // Initiate Common Sched Configuration
cfg.cells.reserve(cell_list.size()); cfg.cells.reserve(cell_list.size());
for (uint32_t cc = 0; cc < cell_list.size(); ++cc) { 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<sched_nr_impl::ue> 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); 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; 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<sched_nr_impl::ue> u)
int sched_nr::ue_cfg_impl(uint16_t rnti, const ue_cfg_t& uecfg) int sched_nr::ue_cfg_impl(uint16_t rnti, const ue_cfg_t& uecfg)
{ {
if (not ue_db.contains(rnti)) { if (not ue_db.contains(rnti)) {
// create user object
unique_ue_ptr u = srsran::make_pool_obj_with_fallback<ue>(*ue_pool, rnti, rnti, uecfg, cfg);
return add_ue_impl(rnti, std::make_unique<ue>(rnti, uecfg, cfg)); return add_ue_impl(rnti, std::make_unique<ue>(rnti, uecfg, cfg));
} }
ue_db[rnti]->set_cfg(uecfg); 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) int sched_nr::dl_rach_info(const rar_info_t& rar_info)
{ {
// create user object outside of sched main thread // create user object outside of sched main thread
std::unique_ptr<ue> u = std::make_unique<ue>(rar_info.temp_crnti, rar_info.cc, cfg); unique_ue_ptr u =
srsran::make_pool_obj_with_fallback<ue>(*ue_pool, rar_info.temp_crnti, rar_info.temp_crnti, rar_info.cc, cfg);
// enqueue UE creation event + RACH handling // enqueue UE creation event + RACH handling
auto add_ue = [this, rar_info, u = std::move(u)](event_manager::logger& ev_logger) mutable { auto add_ue = [this, rar_info, u = std::move(u)](event_manager::logger& ev_logger) mutable {

Loading…
Cancel
Save