From 16878967303cd0c5099181b5e6e08724350bc2cf Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sun, 22 Nov 2020 13:50:35 -0500 Subject: [PATCH] Log the processor info like scheduler policy And CPU affinity. Also, use mlockall to keep our memory from being swapped out. --- common/utils/ocp_itti/intertask_interface.cpp | 38 +++++++++++++++++++ common/utils/ocp_itti/intertask_interface.h | 2 + targets/RT/USER/lte-softmodem.c | 8 +++- targets/RT/USER/lte-ue.c | 2 + targets/RT/USER/lte-uesoftmodem.c | 7 +++- 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/common/utils/ocp_itti/intertask_interface.cpp b/common/utils/ocp_itti/intertask_interface.cpp index 3776dc4106..07ce9bfdd6 100644 --- a/common/utils/ocp_itti/intertask_interface.cpp +++ b/common/utils/ocp_itti/intertask_interface.cpp @@ -444,4 +444,42 @@ task_list_t tasks[TASK_MAX]; // Stupid function, kept for compatibility (the parameter is meaningless!!!) } int signal_mask(void) { return 0;} + +void log_scheduler(const char* label) +{ + int policy = sched_getscheduler(0); + struct sched_param param; + if (sched_getparam(0, ¶m) == -1) + { + LOG_E(HW, "sched_getparam: %s\n", strerror(errno)); + abort(); + } + + cpu_set_t cpu_set; + if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) == -1) + { + LOG_E(HW, "sched_getaffinity: %s\n", strerror(errno)); + abort(); + } + int num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + if (num_cpus < 1) + { + LOG_E(HW, "sysconf(_SC_NPROCESSORS_ONLN): %s\n", strerror(errno)); + abort(); + } + char buffer[num_cpus]; + for (int i = 0; i < num_cpus; i++) + { + buffer[i] = CPU_ISSET(i, &cpu_set) ? 'Y' : '-'; + } + + LOG_A(HW, "Scheduler policy=%d priority=%d affinity=[%d]%.*s label=%s\n", + policy, + param.sched_priority, + num_cpus, + num_cpus, + buffer, + label); } + +} // namespace diff --git a/common/utils/ocp_itti/intertask_interface.h b/common/utils/ocp_itti/intertask_interface.h index 0cd25ee231..0d7f2e5ebf 100644 --- a/common/utils/ocp_itti/intertask_interface.h +++ b/common/utils/ocp_itti/intertask_interface.h @@ -567,6 +567,8 @@ int timer_remove(long timer_id); int signal_handle(int *end); int signal_mask(void); +void log_scheduler(const char *label); + #ifdef __cplusplus } #endif diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c index 7ef1281c66..70cdb3197a 100644 --- a/targets/RT/USER/lte-softmodem.c +++ b/targets/RT/USER/lte-softmodem.c @@ -520,7 +520,12 @@ int main ( int argc, char **argv ) }; if (sched_setscheduler( 0, SCHED_RR, ¶m ) == -1 ) { - fprintf(stderr,"error setting scheduler ... are you root?\n"); + fprintf(stderr, "sched_setscheduler: %s\n", strerror(errno)); + return EXIT_FAILURE; + } + if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) + { + fprintf(stderr, "mlockall: %s\n", strerror(errno)); return EXIT_FAILURE; } @@ -726,6 +731,7 @@ int main ( int argc, char **argv ) pthread_mutex_unlock(&sync_mutex); config_check_unknown_cmdlineopt(CONFIG_CHECKALLSECTIONS); } + log_scheduler("eNB-main"); create_tasks_mbms(1); // wait for end of program diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index 0b95029710..6aacc7bacc 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -2031,6 +2031,8 @@ void *UE_thread(void *arg) oai_exit=1; } + log_scheduler(__func__); + while (!oai_exit) { if (IS_SOFTMODEM_BASICSIM) while (!(UE->proc.instance_cnt_synch < 0)) { diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index a2b575182b..2e4f9710f3 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -548,7 +548,12 @@ int main( int argc, char **argv ) { }; if (sched_setscheduler( 0, SCHED_RR, ¶m ) == -1 ) { - fprintf(stderr,"error setting scheduler ... are you root?\n"); + fprintf(stderr, "sched_setscheduler: %s\n", strerror(errno)); + return EXIT_FAILURE; + } + if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) + { + fprintf(stderr, "mlockall: %s\n", strerror(errno)); return EXIT_FAILURE; }