From bf8b6219955fc64079615754f2d78aef36041534 Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani <sakthivel.velumani@eurecom.fr>
Date: Fri, 16 Apr 2021 17:36:48 +0200
Subject: [PATCH] Adding timing stats for ul indication and scheduler

---
 executables/nr-gnb.c                       | 4 ++++
 openair1/PHY/defs_gNB.h                    | 1 +
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 1 +
 3 files changed, 6 insertions(+)

diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c
index e980818002..f38fcd22a9 100644
--- a/executables/nr-gnb.c
+++ b/executables/nr-gnb.c
@@ -230,6 +230,7 @@ void rx_func(void *param) {
 
   // Call the scheduler
 
+  start_meas(&gNB->ul_indication_stats);
   pthread_mutex_lock(&gNB->UL_INFO_mutex);
   gNB->UL_INFO.frame     = frame_rx;
   gNB->UL_INFO.slot      = slot_rx;
@@ -237,6 +238,7 @@ void rx_func(void *param) {
   gNB->UL_INFO.CC_id     = gNB->CC_id;
   gNB->if_inst->NR_UL_indication(&gNB->UL_INFO);
   pthread_mutex_unlock(&gNB->UL_INFO_mutex);
+  stop_meas(&gNB->ul_indication_stats);
   
   // RX processing
   int tx_slot_type         = nr_slot_select(cfg,frame_tx,slot_tx);
@@ -326,6 +328,7 @@ static void *process_stats_thread(void *param) {
   reset_meas(&gNB->phy_proc_tx);
   reset_meas(&gNB->dlsch_encoding_stats);
   reset_meas(&gNB->phy_proc_rx);
+  reset_meas(&gNB->ul_indication_stats);
   reset_meas(&gNB->rx_pusch_stats);
   reset_meas(&gNB->ulsch_decoding_stats);
 
@@ -337,6 +340,7 @@ static void *process_stats_thread(void *param) {
     print_meas(&gNB->phy_proc_tx, "L1 Tx processing", NULL, NULL);
     print_meas(&gNB->dlsch_encoding_stats, "DLSCH encoding", NULL, NULL);
     print_meas(&gNB->phy_proc_rx, "L1 Rx processing", NULL, NULL);
+    print_meas(&gNB->ul_indication_stats, "UL Indication", NULL, NULL);
     print_meas(&gNB->rx_pusch_stats, "PUSCH inner-receiver", NULL, NULL);
     print_meas(&gNB->ulsch_decoding_stats, "PUSCH decoding", NULL, NULL);
   }
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index a165aa1984..edb19f7501 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -824,6 +824,7 @@ typedef struct PHY_VARS_gNB_s {
   time_stats_t dlsch_segmentation_stats;
 
   time_stats_t rx_pusch_stats;
+  time_stats_t ul_indication_stats;
   time_stats_t ulsch_decoding_stats;
   time_stats_t ulsch_rate_unmatching_stats;
   time_stats_t ulsch_ldpc_decoding_stats;
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
index f18908ff32..35fbafb2ba 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
@@ -92,6 +92,7 @@ void dump_mac_stats(gNB_MAC_INST *gNB)
         LOG_I(MAC, "UE %d: LCID %d: %d bytes RX\n", UE_id, lc_id, stats->lc_bytes_rx[lc_id]);
     }
   }
+  print_meas(&gNB->eNB_scheduler, "DL & UL scheduling timing stats", NULL, NULL);
 }
 
 void clear_nr_nfapi_information(gNB_MAC_INST * gNB,
-- 
2.26.2