diff --git a/srsue/hdr/stack/mac_nr/mac_nr.h b/srsue/hdr/stack/mac_nr/mac_nr.h index f7cc798da..59550711a 100644 --- a/srsue/hdr/stack/mac_nr/mac_nr.h +++ b/srsue/hdr/stack/mac_nr/mac_nr.h @@ -137,7 +137,7 @@ private: srsran::block_queue pdu_queue; ///< currently only DCH PDUs supported (add BCH, PCH, etc) - mac_metrics_t metrics[SRSRAN_MAX_CARRIERS] = {}; + std::array metrics = {}; /// Rx buffer srsran::mac_sch_pdu_nr rx_pdu; diff --git a/srsue/hdr/stack/ue_stack_nr.h b/srsue/hdr/stack/ue_stack_nr.h index 84e10467c..674c06469 100644 --- a/srsue/hdr/stack/ue_stack_nr.h +++ b/srsue/hdr/stack/ue_stack_nr.h @@ -70,7 +70,7 @@ public: // RRC interface for PHY void in_sync() final; void out_of_sync() final; - void run_tti(uint32_t tti) final; + void run_tti(const uint32_t tti) final; // MAC interface for PHY sched_rnti_t get_dl_sched_rnti_nr(const uint32_t tti) final { return mac->get_dl_sched_rnti_nr(tti); } diff --git a/srsue/src/stack/mac_nr/mac_nr.cc b/srsue/src/stack/mac_nr/mac_nr.cc index 981f1018e..bfbd15824 100644 --- a/srsue/src/stack/mac_nr/mac_nr.cc +++ b/srsue/src/stack/mac_nr/mac_nr.cc @@ -97,6 +97,11 @@ void mac_nr::reset() void mac_nr::run_tti(const uint32_t tti) { + // Early exit if MAC NR isn't used + if (not started) { + return; + } + // Step all procedures logger.debug("Running MAC tti=%d", tti); @@ -124,6 +129,10 @@ void mac_nr::update_buffer_states() mac_buffer_states.lcg_buffer_size[channel.lcg] += buffer_len; } logger.info("%s", mac_buffer_states.to_string()); + // Count TTI for metrics + for (uint32_t i = 0; i < SRSRAN_MAX_CARRIERS; ++i) { + metrics[i].nof_tti++; + } } mac_interface_phy_nr::sched_rnti_t mac_nr::get_ul_sched_rnti_nr(const uint32_t tti) @@ -252,12 +261,13 @@ void mac_nr::tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant) // Push DL PDUs to queue for back-ground processing for (uint32_t i = 0; i < SRSRAN_MAX_CODEWORDS; ++i) { if (grant.tb[i] != nullptr) { + metrics[cc_idx].rx_pkts++; + metrics[cc_idx].rx_brate += grant.tb[i]->N_bytes; pdu_queue.push(std::move(grant.tb[i])); } } } - metrics[cc_idx].rx_pkts++; stack_task_dispatch_queue.push([this]() { process_pdus(); }); } @@ -364,7 +374,31 @@ bool mac_nr::is_valid_crnti(const uint16_t crnti) return (crnti >= 0x0001 && crnti <= 0xFFEF); } -void mac_nr::get_metrics(mac_metrics_t m[SRSRAN_MAX_CARRIERS]) {} +void mac_nr::get_metrics(mac_metrics_t m[SRSRAN_MAX_CARRIERS]) +{ + int tx_pkts = 0; + int tx_errors = 0; + int tx_brate = 0; + int rx_pkts = 0; + int rx_errors = 0; + int rx_brate = 0; + int ul_buffer = 0; + float dl_avg_ret = 0; + int dl_avg_ret_count = 0; + + for (const auto& cc : metrics) { + tx_pkts += cc.tx_pkts; + tx_errors += cc.tx_errors; + tx_brate += cc.tx_brate; + rx_pkts += cc.rx_pkts; + rx_errors += cc.rx_errors; + rx_brate += cc.rx_brate; + ul_buffer += cc.ul_buffer; + } + + memcpy(m, metrics.data(), sizeof(mac_metrics_t) * SRSRAN_MAX_CARRIERS); + metrics = {}; +} /** * Called from the main stack thread to process received PDUs diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 12dc2d4b8..4942c514d 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -299,6 +299,7 @@ bool ue_stack_lte::get_metrics(stack_metrics_t* metrics) stack_metrics_t metrics{}; metrics.ul_dropped_sdus = ul_dropped_sdus; mac.get_metrics(metrics.mac); + mac_nr.get_metrics(metrics.mac_nr); rlc.get_metrics(metrics.rlc, metrics.mac[0].nof_tti); nas.get_metrics(&metrics.nas); rrc.get_metrics(metrics.rrc); @@ -411,9 +412,11 @@ void ue_stack_lte::run_tti_impl(uint32_t tti, uint32_t tti_jump) for (uint32_t i = 0; i < tti_jump; ++i) { uint32_t next_tti = TTI_SUB(tti, (tti_jump - i - 1)); mac.run_tti(next_tti); + mac_nr.run_tti(next_tti); task_sched.tic(); } rrc.run_tti(); + rrc_nr.run_tti(tti); nas.run_tti(); if (args.have_tti_time_stats) { diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index 380b1bba9..3de79e8a2 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -335,6 +335,7 @@ bool ue::get_metrics(ue_metrics_t* m) stack->get_metrics(&m->stack); gw_inst->get_metrics(m->gw, m->stack.mac[0].nof_tti); m->sys = sys_proc.get_metrics(); + m->phy_nr.nof_active_cc = args.phy.nof_nr_carriers; // FIXME: temporary until PHY metrics are complete return true; }