Skip to content

Commit 770fae7

Browse files
committed
rlc: adding latency metric to RLC UM in the uplink
1 parent 1e62f08 commit 770fae7

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

include/srsran/rlc/rlc_rx_metrics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct rlc_rx_metrics {
3939
size_t num_pdu_bytes; ///< Number of PDU bytes
4040
uint32_t num_lost_pdus; ///< Number of dropped PDUs (reassembly timeout expiry or out of rx window)
4141
uint32_t num_malformed_pdus; ///< Number of malformed PDUs
42+
uint32_t sdu_latency_us; ///< total SDU latency (in us)>
4243

4344
/// RLC mode of the entity
4445
rlc_mode mode;

lib/rlc/rlc_rx_metrics_container.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ class rlc_rx_metrics_container
7272
metrics.num_malformed_pdus += num_pdus_;
7373
}
7474

75+
void metrics_add_sdu_latency(uint32_t sdu_latency_us_)
76+
{
77+
if (not enabled) {
78+
return;
79+
}
80+
std::lock_guard<std::mutex> lock(metrics_mutex);
81+
metrics.sdu_latency_us += sdu_latency_us_;
82+
}
83+
7584
/// RLC AM specific metrics
7685
void metrics_add_ctrl_pdus(uint32_t num_ctrl_, uint32_t num_ctrl_pdu_bytes_)
7786
{

lib/rlc/rlc_rx_um_entity.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ rlc_rx_um_entity::rlc_rx_um_entity(gnb_du_id_t gnb_du_id,
4747
void rlc_rx_um_entity::handle_pdu(byte_buffer_slice buf)
4848
{
4949
metrics.metrics_add_pdus(1, buf.length());
50-
50+
auto start = std::chrono::high_resolution_clock::now();
5151
pcap.push_pdu(pcap_context, buf);
5252

5353
rlc_um_pdu_header header = {};
@@ -81,6 +81,9 @@ void rlc_rx_um_entity::handle_pdu(byte_buffer_slice buf)
8181
// deliver to upper layer
8282
logger.log_info("RX SDU. sdu_len={}", sdu.value().length());
8383
metrics.metrics_add_sdus(1, sdu.value().length());
84+
auto latency =
85+
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - start);
86+
metrics.metrics_add_sdu_latency(latency.count() / 1000);
8487
upper_dn.on_new_sdu(std::move(sdu.value()));
8588
// Nothing else to do here ...
8689
return;
@@ -115,6 +118,9 @@ void rlc_rx_um_entity::handle_pdu(byte_buffer_slice buf)
115118
// Do not pass empty SDU to upper layers and continue as normal to maintain state
116119
} else {
117120
logger.log_info("RX SDU. sn={} sdu_len={}", header.sn, sdu.value().length());
121+
auto latency = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() -
122+
sdu_info.time_of_arrival);
123+
metrics.metrics_add_sdu_latency(latency.count() / 1000);
118124
metrics.metrics_add_sdus(1, sdu.value().length());
119125
upper_dn.on_new_sdu(std::move(sdu.value()));
120126
}
@@ -274,8 +280,11 @@ bool rlc_rx_um_entity::handle_segment_data_sdu(const rlc_um_pdu_header& header,
274280
logger.log_debug("RX SDU segment. payload_len={} {}", payload.length(), header);
275281

276282
// Add new SN to RX window if no segments have been received yet
277-
rlc_rx_um_sdu_info& rx_sdu = rx_window->has_sn(header.sn) ? (*rx_window)[header.sn] : rx_window->add_sn(header.sn);
278-
283+
rlc_rx_um_sdu_info& rx_sdu = rx_window->has_sn(header.sn) ? (*rx_window)[header.sn] : ([&]() -> rlc_rx_um_sdu_info& {
284+
rlc_rx_um_sdu_info& sdu = rx_window->add_sn(header.sn);
285+
sdu.time_of_arrival = std::chrono::high_resolution_clock::now();
286+
return sdu;
287+
})();
279288
// Create SDU segment, to be stored later
280289
rlc_rx_um_sdu_segment segment = {};
281290
segment.si = header.si;

lib/rlc/rlc_rx_um_entity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ struct rlc_rx_um_sdu_info {
4343
bool has_gap = false;
4444
/// Buffer for set of SDU segments.
4545
segment_set_t segments;
46+
/// Time of arrival of the first segment of the SDU.
47+
std::chrono::system_clock::time_point time_of_arrival;
4648
};
4749

4850
/// \brief Rx state variables

0 commit comments

Comments
 (0)