From 89df8f1582711b9805889178826e13cdb511967d Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 25 Jul 2018 16:08:07 +0200 Subject: [PATCH] unify RLC interface for writing SDUs w/ and w/o blocking --- lib/include/srslte/upper/rlc_am.h | 3 +-- lib/include/srslte/upper/rlc_common.h | 3 +-- lib/include/srslte/upper/rlc_tm.h | 3 +-- lib/include/srslte/upper/rlc_um.h | 3 +-- lib/src/upper/rlc.cc | 8 ++------ lib/src/upper/rlc_am.cc | 29 ++++++++++----------------- lib/src/upper/rlc_tm.cc | 29 +++++++++------------------ lib/src/upper/rlc_um.cc | 12 +++++------ 8 files changed, 33 insertions(+), 57 deletions(-) diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index f57a65b0b..ab2c6cd63 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -86,8 +86,7 @@ public: uint32_t get_bearer(); // PDCP interface - void write_sdu(byte_buffer_t *sdu); - void write_sdu_nb(byte_buffer_t *sdu); + void write_sdu(byte_buffer_t *sdu, bool blocking = true); // MAC interface uint32_t get_buffer_state(); diff --git a/lib/include/srslte/upper/rlc_common.h b/lib/include/srslte/upper/rlc_common.h index 540298217..71fe934df 100644 --- a/lib/include/srslte/upper/rlc_common.h +++ b/lib/include/srslte/upper/rlc_common.h @@ -166,8 +166,7 @@ public: virtual void reset_metrics() = 0; // PDCP interface - virtual void write_sdu(byte_buffer_t *sdu) = 0; - virtual void write_sdu_nb(byte_buffer_t *sdu) = 0; + virtual void write_sdu(byte_buffer_t *sdu, bool blocking) = 0; // MAC interface virtual uint32_t get_buffer_state() = 0; diff --git a/lib/include/srslte/upper/rlc_tm.h b/lib/include/srslte/upper/rlc_tm.h index 5db629231..b1fa03ac6 100644 --- a/lib/include/srslte/upper/rlc_tm.h +++ b/lib/include/srslte/upper/rlc_tm.h @@ -59,8 +59,7 @@ public: void reset_metrics(); // PDCP interface - void write_sdu(byte_buffer_t *sdu); - void write_sdu_nb(byte_buffer_t *sdu); + void write_sdu(byte_buffer_t *sdu, bool blocking); // MAC interface uint32_t get_buffer_state(); diff --git a/lib/include/srslte/upper/rlc_um.h b/lib/include/srslte/upper/rlc_um.h index a880b2238..f866417d2 100644 --- a/lib/include/srslte/upper/rlc_um.h +++ b/lib/include/srslte/upper/rlc_um.h @@ -65,8 +65,7 @@ public: uint32_t get_bearer(); // PDCP interface - void write_sdu(byte_buffer_t *sdu); - void write_sdu_nb(byte_buffer_t *sdu); + void write_sdu(byte_buffer_t *sdu, bool blocking = true); // MAC interface uint32_t get_buffer_state(); diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index b461a5740..31b740df4 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -202,11 +202,7 @@ void rlc::write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking) { pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { - if (blocking) { - rlc_array.at(lcid)->write_sdu(sdu); - } else { - rlc_array.at(lcid)->write_sdu_nb(sdu); - } + rlc_array.at(lcid)->write_sdu(sdu, blocking); } else { rlc_log->warning("RLC LCID %d doesn't exist. Deallocating SDU\n", lcid); byte_buffer_pool::get_instance()->deallocate(sdu); @@ -218,7 +214,7 @@ void rlc::write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu) { pthread_rwlock_rdlock(&rwlock); if (valid_lcid_mrb(lcid)) { - rlc_array_mrb.at(lcid)->write_sdu_nb(sdu); + rlc_array_mrb.at(lcid)->write_sdu(sdu, false); // write in non-blocking mode by default } else { rlc_log->warning("RLC LCID %d doesn't exist. Deallocating SDU\n", lcid); byte_buffer_pool::get_instance()->deallocate(sdu); diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index c2ce16dcc..92c32410d 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -199,32 +199,25 @@ uint32_t rlc_am::get_bearer() * PDCP interface ***************************************************************************/ -void rlc_am::write_sdu(byte_buffer_t *sdu) +void rlc_am::write_sdu(byte_buffer_t *sdu, bool blocking) { if (!tx_enabled) { byte_buffer_pool::get_instance()->deallocate(sdu); return; } if (sdu) { - tx_sdu_queue.write(sdu); - log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (%d B, tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); - } else { - log->warning("NULL SDU pointer in write_sdu()\n"); - } -} - -void rlc_am::write_sdu_nb(byte_buffer_t *sdu) -{ - if (!tx_enabled) { - byte_buffer_pool::get_instance()->deallocate(sdu); - return; - } - if (sdu) { - if (tx_sdu_queue.try_write(sdu)) { + if (blocking) { + // block on write to queue + tx_sdu_queue.write(sdu); log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (%d B, tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); } else { - log->debug_hex(sdu->msg, sdu->N_bytes, "[Dropped SDU] %s Tx SDU (%d B, tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); - pool->deallocate(sdu); + // non-blocking write + if (tx_sdu_queue.try_write(sdu)) { + log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (%d B, tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); + } else { + log->debug_hex(sdu->msg, sdu->N_bytes, "[Dropped SDU] %s Tx SDU (%d B, tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); + pool->deallocate(sdu); + } } } else { log->warning("NULL SDU pointer in write_sdu()\n"); diff --git a/lib/src/upper/rlc_tm.cc b/lib/src/upper/rlc_tm.cc index 9b132b39b..96e075cb6 100644 --- a/lib/src/upper/rlc_tm.cc +++ b/lib/src/upper/rlc_tm.cc @@ -96,35 +96,26 @@ uint32_t rlc_tm::get_bearer() } // PDCP interface -void rlc_tm::write_sdu(byte_buffer_t *sdu) +void rlc_tm::write_sdu(byte_buffer_t *sdu, bool blocking) { if (!tx_enabled) { byte_buffer_pool::get_instance()->deallocate(sdu); return; } if (sdu) { - ul_queue.write(sdu); - log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, queue size=%d, bytes=%d", - rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes()); - } else { - log->warning("NULL SDU pointer in write_sdu()\n"); - } -} - -void rlc_tm::write_sdu_nb(byte_buffer_t *sdu) -{ - if (!tx_enabled) { - byte_buffer_pool::get_instance()->deallocate(sdu); - return; - } - if (sdu) { - if (ul_queue.try_write(sdu)) { + if (blocking) { + ul_queue.write(sdu); log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, queue size=%d, bytes=%d", rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes()); } else { - log->debug_hex(sdu->msg, sdu->N_bytes, "[Dropped SDU] %s Tx SDU, queue size=%d, bytes=%d", + if (ul_queue.try_write(sdu)) { + log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, queue size=%d, bytes=%d", + rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes()); + } else { + log->debug_hex(sdu->msg, sdu->N_bytes, "[Dropped SDU] %s Tx SDU, queue size=%d, bytes=%d", rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes()); - pool->deallocate(sdu); + pool->deallocate(sdu); + } } } else { log->warning("NULL SDU pointer in write_sdu()\n"); diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index ac80e6940..9ea96f6ee 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -142,14 +142,14 @@ uint32_t rlc_um::get_bearer() /**************************************************************************** * PDCP interface ***************************************************************************/ -void rlc_um::write_sdu(byte_buffer_t *sdu) +void rlc_um::write_sdu(byte_buffer_t *sdu, bool blocking) { - tx.write_sdu(sdu); -} + if (blocking) { + tx.write_sdu(sdu); + } else { + tx.try_write_sdu(sdu); + } -void rlc_um::write_sdu_nb(byte_buffer_t *sdu) -{ - tx.try_write_sdu(sdu); } /****************************************************************************