From 75f42ac82955fa55d4925f3805495d676f6d34e5 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 12:40:07 +0100 Subject: [PATCH 1/8] add RLC AM destructor --- lib/include/srslte/upper/rlc_am.h | 1 + lib/src/upper/rlc_am.cc | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index 2311b23cb..7601baefa 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -71,6 +71,7 @@ class rlc_am { public: rlc_am(); + ~rlc_am(); void init(log *rlc_entity_log_, uint32_t lcid_, srsue::pdcp_interface_rlc *pdcp_, diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 413a02ac1..652970011 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -68,6 +68,20 @@ rlc_am::rlc_am() : tx_sdu_queue(16) do_status = false; } +rlc_am::~rlc_am() +{ + // reset RLC and dealloc SDUs + stop(); + + if(rx_sdu) { + pool->deallocate(rx_sdu); + } + + if(tx_sdu) { + pool->deallocate(tx_sdu); + } +} + void rlc_am::init(srslte::log *log_, uint32_t lcid_, srsue::pdcp_interface_rlc *pdcp_, From b5b1c0bf4b53aae7ebbb64c5ef0f6efe3ca16e4d Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 12:41:13 +0100 Subject: [PATCH 2/8] fix memory leaks RLC AM test --- lib/test/upper/rlc_am_test.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index 0b8c63668..184de3a00 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -59,6 +59,14 @@ public: n_sdus = 0; } + ~rlc_am_tester(){ + for (uint32_t i = 0; i < 10; i++) { + if (sdus[i] != NULL) { + byte_buffer_pool::get_instance()->deallocate(sdus[i]); + } + } + } + // PDCP interface void write_pdu(uint32_t lcid, byte_buffer_t *sdu) { @@ -1051,21 +1059,31 @@ void resegment_test_6() int main(int argc, char **argv) { basic_test(); byte_buffer_pool::get_instance()->cleanup(); + concat_test(); byte_buffer_pool::get_instance()->cleanup(); + segment_test(); byte_buffer_pool::get_instance()->cleanup(); + retx_test(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_1(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_2(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_3(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_4(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_5(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_6(); + byte_buffer_pool::get_instance()->cleanup(); } From c5ffdfe8c74bf3d06f393783c6e1847888bc791e Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 21:31:11 +0100 Subject: [PATCH 3/8] set byte_buffer ptr to null after deallocating from pool --- lib/include/srslte/common/buffer_pool.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index a4186a78b..e48144b6f 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -164,6 +164,7 @@ public: } b->reset(); pool->deallocate(b); + b = NULL; } private: buffer_pool *pool; From 1be93d4682baa5e2a166ebc940f894e68354ac16 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 21:32:21 +0100 Subject: [PATCH 4/8] add RLC UM destructor --- lib/include/srslte/upper/rlc_um.h | 1 + lib/src/upper/rlc_um.cc | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/include/srslte/upper/rlc_um.h b/lib/include/srslte/upper/rlc_um.h index 0a2469a7c..6d8eb6d08 100644 --- a/lib/include/srslte/upper/rlc_um.h +++ b/lib/include/srslte/upper/rlc_um.h @@ -50,6 +50,7 @@ class rlc_um { public: rlc_um(); + ~rlc_um(); void init(log *rlc_entity_log_, uint32_t lcid_, diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 213e8c840..a365a4501 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -59,6 +59,11 @@ rlc_um::rlc_um() : tx_sdu_queue(16) pdu_lost = false; } +rlc_um::~rlc_um() +{ + stop(); +} + void rlc_um::init(srslte::log *log_, uint32_t lcid_, srsue::pdcp_interface_rlc *pdcp_, @@ -114,12 +119,13 @@ void rlc_um::empty_queue() { void rlc_um::stop() { reset(); - mac_timers->timer_release_id(reordering_timer_id); + if (mac_timers) { + mac_timers->timer_release_id(reordering_timer_id); + } } void rlc_um::reset() { - // Empty tx_sdu_queue before locking the mutex empty_queue(); @@ -129,12 +135,17 @@ void rlc_um::reset() vr_ux = 0; vr_uh = 0; pdu_lost = false; - if(rx_sdu) - rx_sdu->reset(); - if(tx_sdu) - tx_sdu->reset(); - if(mac_timers) + if(rx_sdu) { + pool->deallocate(rx_sdu); + } + + if(tx_sdu) { + pool->deallocate(tx_sdu); + } + + if(mac_timers) { reordering_timer->stop(); + } // Drop all messages in RX window std::map::iterator it; From a6ccb05bb107bb91a2eeeb95b00c384d1d627968 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 21:32:53 +0100 Subject: [PATCH 5/8] fix mem leak in RLC UM test and RLC AM stress tester --- lib/test/upper/rlc_am_stress_test.cc | 1 + lib/test/upper/rlc_um_test.cc | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/test/upper/rlc_am_stress_test.cc b/lib/test/upper/rlc_am_stress_test.cc index 086a41bd8..137236b4a 100644 --- a/lib/test/upper/rlc_am_stress_test.cc +++ b/lib/test/upper/rlc_am_stress_test.cc @@ -85,6 +85,7 @@ private: usleep(100); } running = false; + byte_buffer_pool::get_instance()->deallocate(pdu); } rlc_interface_mac *rlc1; diff --git a/lib/test/upper/rlc_um_test.cc b/lib/test/upper/rlc_um_test.cc index 6ce39ef7f..3755c1174 100644 --- a/lib/test/upper/rlc_um_test.cc +++ b/lib/test/upper/rlc_um_test.cc @@ -62,6 +62,14 @@ public: n_sdus = 0; } + ~rlc_um_tester(){ + for (uint32_t i = 0; i < NBUFS; i++) { + if (sdus[i] != NULL) { + byte_buffer_pool::get_instance()->deallocate(sdus[i]); + } + } + } + // PDCP interface void write_pdu(uint32_t lcid, byte_buffer_t *sdu) { From d959608e10373c83fa4a6284448425cfccf71459 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 20 Feb 2018 11:44:46 +0100 Subject: [PATCH 6/8] fix mem dealloc in viterbi for 16bit AVX --- lib/src/phy/fec/viterbi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/phy/fec/viterbi.c b/lib/src/phy/fec/viterbi.c index 25d77ef36..4e5801b94 100644 --- a/lib/src/phy/fec/viterbi.c +++ b/lib/src/phy/fec/viterbi.c @@ -166,9 +166,15 @@ void free37_avx2_16bit(void *o) { if (q->symbols_uc) { free(q->symbols_uc); } + if (q->symbols_us) { + free(q->symbols_us); + } if (q->tmp) { free(q->tmp); } + if (q->tmp_s) { + free(q->tmp_s); + } delete_viterbi37_avx2_16bit(q->ptr); } From 94fe9d4a4710dc09a41bcb0e4844f59923d4fb35 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 20 Feb 2018 12:27:02 +0100 Subject: [PATCH 7/8] rlc: add basic RLC AM reset test --- lib/test/upper/rlc_am_test.cc | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index 184de3a00..67305c093 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -1056,6 +1056,60 @@ void resegment_test_6() } } +void reset_test() +{ + srslte::log_filter log1("RLC_AM_1"); + srslte::log_filter log2("RLC_AM_2"); + log1.set_level(srslte::LOG_LEVEL_DEBUG); + log2.set_level(srslte::LOG_LEVEL_DEBUG); + log1.set_hex_limit(-1); + log2.set_hex_limit(-1); + rlc_am_tester tester; + mac_dummy_timers timers; + + rlc_am rlc1; + int len; + + log1.set_level(srslte::LOG_LEVEL_DEBUG); + + rlc1.init(&log1, 1, &tester, &tester, &timers); + + LIBLTE_RRC_RLC_CONFIG_STRUCT cnfg; + cnfg.rlc_mode = LIBLTE_RRC_RLC_MODE_AM; + cnfg.dl_am_rlc.t_reordering = LIBLTE_RRC_T_REORDERING_MS5; + cnfg.dl_am_rlc.t_status_prohibit = LIBLTE_RRC_T_STATUS_PROHIBIT_MS5; + cnfg.ul_am_rlc.max_retx_thresh = LIBLTE_RRC_MAX_RETX_THRESHOLD_T4; + cnfg.ul_am_rlc.poll_byte = LIBLTE_RRC_POLL_BYTE_KB25; + cnfg.ul_am_rlc.poll_pdu = LIBLTE_RRC_POLL_PDU_P4; + cnfg.ul_am_rlc.t_poll_retx = LIBLTE_RRC_T_POLL_RETRANSMIT_MS5; + + rlc1.configure(&cnfg); + + // Push 1 SDU of size 10 into RLC1 + byte_buffer_t sdu_buf; + *sdu_buf.msg = 1; // Write the index into the buffer + sdu_buf.N_bytes = 100; + rlc1.write_sdu(&sdu_buf); + + // read 1 PDU from RLC1 and force segmentation + byte_buffer_t pdu_bufs; + len = rlc1.read_pdu(pdu_bufs.msg, 4); + pdu_bufs.N_bytes = len; + + // reset RLC1 + rlc1.reset(); + + // read another PDU segment from RLC1 + len = rlc1.read_pdu(pdu_bufs.msg, 4); + pdu_bufs.N_bytes = len; + + // now empty RLC buffer + len = rlc1.read_pdu(pdu_bufs.msg, 100); + pdu_bufs.N_bytes = len; + + assert(0 == rlc1.get_buffer_state()); +} + int main(int argc, char **argv) { basic_test(); byte_buffer_pool::get_instance()->cleanup(); @@ -1086,4 +1140,7 @@ int main(int argc, char **argv) { resegment_test_6(); byte_buffer_pool::get_instance()->cleanup(); + + reset_test(); + byte_buffer_pool::get_instance()->cleanup(); } From 8d852ddfe5e4f6eedb80e247d62b8628f9643c2f Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 20 Feb 2018 17:54:09 +0100 Subject: [PATCH 8/8] only reset SDU buffer in RLC AM/UM --- lib/src/upper/rlc_am.cc | 8 -------- lib/src/upper/rlc_um.cc | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 652970011..b34b0cb0b 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -72,14 +72,6 @@ rlc_am::~rlc_am() { // reset RLC and dealloc SDUs stop(); - - if(rx_sdu) { - pool->deallocate(rx_sdu); - } - - if(tx_sdu) { - pool->deallocate(tx_sdu); - } } void rlc_am::init(srslte::log *log_, diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index a365a4501..3fbcbaadf 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -136,11 +136,11 @@ void rlc_um::reset() vr_uh = 0; pdu_lost = false; if(rx_sdu) { - pool->deallocate(rx_sdu); + rx_sdu->reset(); } if(tx_sdu) { - pool->deallocate(tx_sdu); + tx_sdu->reset(); } if(mac_timers) {