diff --git a/lib/include/srsran/upper/bearer_mem_pool.h b/lib/include/srsran/upper/bearer_mem_pool.h new file mode 100644 index 000000000..f7953863a --- /dev/null +++ b/lib/include/srsran/upper/bearer_mem_pool.h @@ -0,0 +1,27 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2021 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#ifndef SRSRAN_BEARER_MEM_POOL_H +#define SRSRAN_BEARER_MEM_POOL_H + +#include + +namespace srsran { + +// Allocation of objects in rnti-dedicated memory pool +void reserve_rlc_memblocks(size_t nof_blocks); +void* allocate_rlc_bearer(std::size_t size); +void deallocate_rlc_bearer(void* p); + +} // namespace srsran + +#endif // SRSRAN_BEARER_MEM_POOL_H diff --git a/lib/include/srsran/upper/rlc_common.h b/lib/include/srsran/upper/rlc_common.h index ab76e4c5a..f48939dcc 100644 --- a/lib/include/srsran/upper/rlc_common.h +++ b/lib/include/srsran/upper/rlc_common.h @@ -15,6 +15,7 @@ #include "srsran/adt/circular_buffer.h" #include "srsran/interfaces/rlc_interface_types.h" +#include "srsran/upper/bearer_mem_pool.h" #include "srsran/upper/rlc_metrics.h" #include @@ -270,6 +271,9 @@ public: virtual void set_bsr_callback(bsr_callback_t callback) = 0; + void* operator new(size_t sz) { return allocate_rlc_bearer(sz); } + void operator delete(void* p) { return deallocate_rlc_bearer(p); } + private: bool suspended = false; diff --git a/lib/src/upper/CMakeLists.txt b/lib/src/upper/CMakeLists.txt index df43f663e..9d70b93ad 100644 --- a/lib/src/upper/CMakeLists.txt +++ b/lib/src/upper/CMakeLists.txt @@ -18,8 +18,9 @@ set(SOURCES gtpu.cc rlc_am_lte.cc pdcp_entity_nr.cc rlc_um_nr.cc - rlc_am_nr.cc) + rlc_am_nr.cc + bearer_mem_pool.cc) add_library(srsran_upper STATIC ${SOURCES}) target_link_libraries(srsran_upper srsran_common srsran_asn1) -INSTALL(TARGETS srsran_upper DESTINATION ${LIBRARY_DIR}) \ No newline at end of file +INSTALL(TARGETS srsran_upper DESTINATION ${LIBRARY_DIR}) diff --git a/lib/src/upper/bearer_mem_pool.cc b/lib/src/upper/bearer_mem_pool.cc new file mode 100644 index 000000000..764d8d122 --- /dev/null +++ b/lib/src/upper/bearer_mem_pool.cc @@ -0,0 +1,44 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2021 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#include "srsran/upper/bearer_mem_pool.h" +#include "srsran/adt/pool/batch_mem_pool.h" +#include "srsran/upper/rlc_am_lte.h" +#include "srsran/upper/rlc_um_lte.h" +#include "srsran/upper/rlc_um_nr.h" + +namespace srsran { + +srsran::background_mem_pool* get_bearer_pool() +{ + static background_mem_pool pool( + 4, std::max(std::max(sizeof(rlc_am_lte), sizeof(rlc_um_lte)), sizeof(rlc_um_nr)), 8, 8); + return &pool; +} + +void reserve_rlc_memblocks(size_t nof_blocks) +{ + srsran::background_mem_pool* pool = get_bearer_pool(); + while (pool->cache_size() < nof_blocks) { + pool->allocate_batch(); + } +} +void* allocate_rlc_bearer(std::size_t sz) +{ + return get_bearer_pool()->allocate_node(sz); +} +void deallocate_rlc_bearer(void* p) +{ + get_bearer_pool()->deallocate_node(p); +} + +} // namespace srsran diff --git a/srsenb/src/stack/enb_stack_lte.cc b/srsenb/src/stack/enb_stack_lte.cc index 97cb04db9..59d44c5c9 100644 --- a/srsenb/src/stack/enb_stack_lte.cc +++ b/srsenb/src/stack/enb_stack_lte.cc @@ -15,6 +15,7 @@ #include "srsenb/hdr/enb.h" #include "srsran/interfaces/enb_metrics_interface.h" #include "srsran/srslog/event_trace.h" +#include "srsran/upper/bearer_mem_pool.h" using namespace srsran; @@ -71,8 +72,10 @@ int enb_stack_lte::init(const stack_args_t& args_, const rrc_cfg_t& rrc_cfg_) args = args_; rrc_cfg = rrc_cfg_; - // Init RNTI memory pool + // Init RNTI and bearer memory pools reserve_rnti_memblocks(args.mac.max_nof_ues); + uint32_t min_nof_bearers_per_ue = 4; + reserve_rlc_memblocks(args.mac.max_nof_ues * min_nof_bearers_per_ue); // setup logging for each layer mac_logger.set_level(srslog::str_to_basic_level(args.log.mac_level));