From b17a5189b7a40faf033df690e6b5ad057bdf7201 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Tue, 12 Oct 2021 10:27:15 -0700 Subject: [PATCH] Adding timing informtion to rx'd slot indictions Ensuring in the NRUE that the slot indications we process are 500us apart. --- executables/nr-ue.c | 20 ++++++++++++---- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 5 ++++ openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 26 +++++++++++++++------ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 2ac77f66b2..493fdf5deb 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -391,8 +391,9 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) NR_UL_TIME_ALIGNMENT_t ul_time_alignment; memset(&ul_time_alignment, 0, sizeof(ul_time_alignment)); int last_sfn_slot = -1; - uint16_t *sfn_slot_p; int sfn_slot; + uint64_t last_time_stamp = 0; + sfn_slot_info_t *sfn_slot_info; while (!oai_exit) { @@ -401,14 +402,14 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) LOG_E(NR_MAC, "sem_wait() error\n"); abort(); } - sfn_slot_p = get_queue(&nr_sfn_slot_queue); - if (sfn_slot_p == NULL) + sfn_slot_info = get_queue(&nr_sfn_slot_queue); + if (sfn_slot_info == NULL) { LOG_D(MAC, "get_queue(&nr_sfn_slot_queue) == NULL!\n"); continue; } - sfn_slot = *sfn_slot_p; + sfn_slot = sfn_slot_info->sfn_slot; if (sfn_slot == last_sfn_slot) { LOG_D(NR_MAC, "repeated sfn_sf = %d.%d\n", @@ -416,6 +417,17 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) continue; } last_sfn_slot = sfn_slot; + LOG_D(NR_MAC, "The received sfn/slot [%d %d], last time stamp %ld, current time stamp %ld\n", + NFAPI_SFNSLOT2SFN(sfn_slot), NFAPI_SFNSLOT2SLOT(sfn_slot), last_time_stamp, sfn_slot_info->time_stamp); + + uint64_t delta = sfn_slot_info->time_stamp - last_time_stamp; + if (delta < 500) + { + LOG_D(NR_MAC, "sfn/slot [%d %d] has been received too quickly! Delta = %ld. Will sleep for %ld us\n", + NFAPI_SFNSLOT2SFN(sfn_slot), NFAPI_SFNSLOT2SLOT(sfn_slot), delta, 500 - delta); + usleep(500 - delta); + } + last_time_stamp = sfn_slot_info->time_stamp; module_id_t mod_id = 0; NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 8aa1be3e59..4873b0027c 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -443,6 +443,11 @@ typedef struct { } NR_UE_MAC_INST_t; +typedef struct sfn_slot_info { + uint16_t sfn_slot; + uint64_t time_stamp; +} sfn_slot_info_t; + typedef enum seach_space_mask_e { type0_pdcch = 0x1, type0a_pdcch = 0x2, diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index c1d5a04a2d..64182330ff 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -748,7 +748,17 @@ static void enqueue_nr_nfapi_msg(void *buffer, ssize_t len, nfapi_p7_message_hea return; } -uint16_t sfn_slot_pool[512]; +static uint64_t clock_usec() +{ + struct timespec t; + if (clock_gettime(CLOCK_MONOTONIC, &t) == -1) + { + abort(); + } + return (uint64_t)t.tv_sec * 1000000 + (t.tv_nsec / 1000); +} + +sfn_slot_info_t sfn_slot_pool[512]; uint16_t sfn_slot_id; void *nrue_standalone_pnf_task(void *context) { @@ -783,7 +793,12 @@ void *nrue_standalone_pnf_task(void *context) memcpy((void *)&sfn_slot, buffer, sizeof(sfn_slot)); current_sfn_slot = sfn_slot; - sfn_slot_pool[sfn_slot_id] = sfn_slot; + sfn_slot_pool[sfn_slot_id].sfn_slot = sfn_slot; + sfn_slot_pool[sfn_slot_id].time_stamp = clock_usec(); + sfn = NFAPI_SFNSLOT2SFN(sfn_slot); + slot = NFAPI_SFNSLOT2SLOT(sfn_slot); + LOG_I(NR_PHY, "Received from proxy sfn %d slot %d and time_stamp = %ld\n", + sfn, slot, sfn_slot_pool[sfn_slot_id].time_stamp); if (!put_queue(&nr_sfn_slot_queue, &sfn_slot_pool[sfn_slot_id])) { @@ -797,10 +812,6 @@ void *nrue_standalone_pnf_task(void *context) LOG_E(NR_PHY, "sem_post() error\n"); abort(); } - - sfn = NFAPI_SFNSLOT2SFN(sfn_slot); - slot = NFAPI_SFNSLOT2SLOT(sfn_slot); - LOG_I(NR_PHY, "Received from proxy sfn %d slot %d\n", sfn, slot); } else if (len == sizeof(nr_phy_channel_params_t)) { @@ -808,7 +819,8 @@ void *nrue_standalone_pnf_task(void *context) memcpy(&ch_info, buffer, sizeof(nr_phy_channel_params_t)); current_sfn_slot = ch_info.sfn_slot; - sfn_slot_pool[sfn_slot_id] = ch_info.sfn_slot; + sfn_slot_pool[sfn_slot_id].sfn_slot = ch_info.sfn_slot; + sfn_slot_pool[sfn_slot_id].time_stamp = clock_usec(); if (!put_queue(&nr_sfn_slot_queue, &sfn_slot_pool[sfn_slot_id])) {