From b5ba3a69f1dbf6acf4ce5d7947e235d2bfd031f3 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 9 Feb 2024 13:02:50 +0100 Subject: [PATCH] O-RAN 7.2: set CPU affinity for ru_thread explicitly Force the CPU affinity for ru_thread explicitly to ru_thread_core. It is already done via threadCreate(), but force again as per change request. Delete commented 7.2 code that did the equivalent. We cannot set it in the driver, as we don't have access to variable ru->ru_thread_core. Closes: #732 (suggestion 2) Suggested-by: Andrew Sergeev --- executables/nr-ru.c | 12 ++++++++++++ radio/fhi_72/oran-init.c | 31 ------------------------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/executables/nr-ru.c b/executables/nr-ru.c index c61088dc88..3e4ebec5cc 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -1204,6 +1204,18 @@ void *ru_thread( void *param ) { malloc_IF4p5_buffer(ru); } + int cpu = sched_getcpu(); + if (ru->ru_thread_core > -1 && cpu != ru->ru_thread_core) { + /* we start the ru_thread using threadCreate(), which already sets CPU + * affinity; let's force it here again as per feature request #732 */ + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(ru->ru_thread_core, &cpuset); + int ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); + AssertFatal(ret == 0, "Error in pthread_getaffinity_np(): ret: %d, errno: %d", ret, errno); + LOG_I(PHY, "RU %d: manually set CPU affinity to CPU %d\n", ru->idx, ru->ru_thread_core); + } + LOG_I(PHY,"Starting IF interface for RU %d, nb_rx %d\n",ru->idx,ru->nb_rx); AssertFatal(ru->nr_start_if(ru,NULL) == 0, "Could not start the IF device\n"); diff --git a/radio/fhi_72/oran-init.c b/radio/fhi_72/oran-init.c index 6586b2cda7..f05ae260c5 100644 --- a/radio/fhi_72/oran-init.c +++ b/radio/fhi_72/oran-init.c @@ -78,32 +78,6 @@ static uint32_t get_nFpgaToSW_FTH_RxBufferLen(int mu) } } -/* is this necessary? -int32_t set_main_core(uint32_t main_core) -{ - struct sched_param sched_param; - cpu_set_t cpuset; - int32_t result = 0; - memset(&sched_param, 0, sizeof(struct sched_param)); - // set main thread affinity mask to CPU2 - sched_param.sched_priority = 99; - CPU_ZERO(&cpuset); - - printf("This system has %d processors configured and %d processors available.\n", get_nprocs_conf(), get_nprocs()); - - if (main_core < get_nprocs_conf()) - CPU_SET(main_core, &cpuset); - else - return -1; - - if ((result = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset))) { - printf("pthread_setaffinity_np failed: coreId = 2, result = %d\n", result); - } - printf("%s [CPU %2d] [PID: %6d]\n", __FUNCTION__, sched_getcpu(), getpid()); - return result; -} -*/ - static struct xran_prb_map get_xran_prb_map_dl(const struct xran_fh_config *f) { struct xran_prb_map prbmap = { @@ -432,11 +406,6 @@ int *oai_oran_initialize(const openair0_config_t *openair0_cfg) print_fh_config(&xran_fh_config[o_xu_id]); } - // if ((xret = set_main_core(init.something)) < 0) { - // printf("set_main_core() failed %d\n", xret); - // exit(-1); - // } - xret = xran_init(0, NULL, &init, NULL, &gxran_handle); if (xret != XRAN_STATUS_SUCCESS) { printf("xran_init failed %d\n", xret);