From 6b37d183cefdd0a8e72e022c792c948b96e49659 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 11 Mar 2024 19:13:42 +0100 Subject: [PATCH] Remove set_latency_target(), add lock_memory_to_ram() set_latency_target() attempts to set keep "low latency" by - writing a specific latency to /dev/cpu_dma_latency - setting manually the minimum CPU processor frequency to be the maximum There is no functionality to undo this after stopping the softmodem(s), and most users are probably not even aware that OAI does this. It is generally preferable to set this beforehand using a governor or by disabling sleep states (as outlined in the tutorial, and in a follow-up commit in the performance tuning docs). The previous mlockall() call, to lock memory to RAM, is retained in a new function. There were additional mlockall() calls, which have been replaced with lock_memory_to_ram(), where necessary. --- common/utils/system.c | 39 +++++---------------------- common/utils/system.h | 2 +- executables/lte-softmodem.c | 3 +-- executables/lte-uesoftmodem.c | 3 +-- executables/main_ru.c | 4 +-- executables/nr-softmodem.c | 3 +-- executables/nr-uesoftmodem.c | 2 +- openair1/PHY/TOOLS/calibration_test.c | 3 +-- 8 files changed, 14 insertions(+), 45 deletions(-) diff --git a/common/utils/system.c b/common/utils/system.c index d8570fe14e..4e332a4ee4 100644 --- a/common/utils/system.c +++ b/common/utils/system.c @@ -326,37 +326,10 @@ void thread_top_init(char *thread_name, } } - -// Block CPU C-states deep sleep -void set_latency_target(void) { - int ret; - static int latency_target_fd=-1; - uint32_t latency_target_value=2; // in microseconds - if (latency_target_fd == -1) { - if ( (latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR)) != -1 ) { - ret = write(latency_target_fd, &latency_target_value, sizeof(latency_target_value)); - if (ret == 0) { - printf("# error setting cpu_dma_latency to %u!: %s\n", latency_target_value, strerror(errno)); - close(latency_target_fd); - latency_target_fd=-1; - return; - } - } - } - if (latency_target_fd != -1) - LOG_I(HW,"# /dev/cpu_dma_latency set to %u us\n", latency_target_value); - else - LOG_E(HW,"Can't set /dev/cpu_dma_latency to %u us\n", latency_target_value); - - // Set CPU frequency to it's maximum - int system_ret = system("for d in /sys/devices/system/cpu/cpu[0-9]*; do cat $d/cpufreq/cpuinfo_max_freq > $d/cpufreq/scaling_min_freq; done"); - if (system_ret == -1) { - LOG_E(HW, "Can't set cpu frequency: [%d] %s\n", errno, strerror(errno)); - return; - } - if (!((WIFEXITED(system_ret)) && (WEXITSTATUS(system_ret) == 0))) { - LOG_E(HW, "Can't set cpu frequency\n"); - } - mlockall(MCL_CURRENT | MCL_FUTURE); - +/* \brief lock memory to RAM to avoid delays */ +void lock_memory_to_ram(void) +{ + int rc = mlockall(MCL_CURRENT | MCL_FUTURE); + if (rc != 0) + LOG_W(UTIL, "mlockall() failed: %d, %s\n", errno, strerror(errno)); } diff --git a/common/utils/system.h b/common/utils/system.h index 1b7c0c570f..1c36f29ea3 100644 --- a/common/utils/system.h +++ b/common/utils/system.h @@ -42,7 +42,7 @@ int background_system(char *command); void start_background_system(void); -void set_latency_target(void); +void lock_memory_to_ram(void); void threadCreate(pthread_t *t, void *(*func)(void *), void *param, char *name, int affinity, int priority); diff --git a/executables/lte-softmodem.c b/executables/lte-softmodem.c index 9e1adf1cbe..615f6106fe 100644 --- a/executables/lte-softmodem.c +++ b/executables/lte-softmodem.c @@ -448,7 +448,7 @@ int main ( int argc, char **argv ) mode = normal_txrx; logInit(); - set_latency_target(); + lock_memory_to_ram(); printf("Reading in command-line options\n"); get_options(uniqCfg); @@ -518,7 +518,6 @@ int main ( int argc, char **argv ) // init UE_PF_PO and mutex lock pthread_mutex_init(&ue_pf_po_mutex, NULL); memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*MAX_MOBILES_PER_ENB*MAX_NUM_CCs); - mlockall(MCL_CURRENT | MCL_FUTURE); pthread_cond_init(&sync_cond,NULL); pthread_mutex_init(&sync_mutex, NULL); diff --git a/executables/lte-uesoftmodem.c b/executables/lte-uesoftmodem.c index a8f6d01227..47f6c884c4 100644 --- a/executables/lte-uesoftmodem.c +++ b/executables/lte-uesoftmodem.c @@ -530,7 +530,7 @@ int main( int argc, char **argv ) { mode = normal_txrx; memset(&openair0_cfg[0],0,sizeof(openair0_config_t)*MAX_CARDS); logInit(); - set_latency_target(); + lock_memory_to_ram(); printf("Reading in command-line options\n"); for (int i=0; i