From 754566b28f6e90a76c4caca4efef60a2fdce18ec Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 25 Jan 2018 15:02:11 +0100 Subject: [PATCH] Changed priorities to below UHD in srsUE --- lib/include/srslte/common/metrics_hub.h | 3 ++- lib/include/srslte/common/threads.h | 3 +++ lib/src/common/threads.c | 14 ++++++++++++++ lib/src/phy/rf/rf_uhd_imp.c | 5 ++++- srsue/hdr/mac/mac.h | 4 ++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 5dc22f7c1..ac0b6a8a7 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -38,7 +38,8 @@ public: bool init(metrics_interface *m_, float report_period_secs_=1.0) { m = m_; report_period_secs = report_period_secs_; - start_periodic(report_period_secs*1e6); + // Start with user-default priority + start_periodic(report_period_secs*1e6, -2); return true; } void stop() { diff --git a/lib/include/srslte/common/threads.h b/lib/include/srslte/common/threads.h index 077dda72b..e87407870 100644 --- a/lib/include/srslte/common/threads.h +++ b/lib/include/srslte/common/threads.h @@ -30,6 +30,9 @@ #include #include +// Default priority for all threads below UHD threads +#define DEFAULT_PRIORITY 60 + #ifdef __cplusplus extern "C" { #endif // __cplusplus diff --git a/lib/src/common/threads.c b/lib/src/common/threads.c index 0533aa1b6..b6fa31778 100644 --- a/lib/src/common/threads.c +++ b/lib/src/common/threads.c @@ -67,6 +67,20 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void fprintf(stderr, "Error not enough privileges to set Scheduling priority\n"); } attr_enable = true; + } else if (prio_offset == -1) { + param.sched_priority = sched_get_priority_max(SCHED_FIFO) - DEFAULT_PRIORITY; + pthread_attr_init(&attr); + if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) { + perror("pthread_attr_setinheritsched"); + } + if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) { + perror("pthread_attr_setschedpolicy"); + } + if (pthread_attr_setschedparam(&attr, ¶m)) { + perror("pthread_attr_setschedparam"); + fprintf(stderr, "Error not enough privileges to set Scheduling priority\n"); + } + attr_enable = true; } else if (prio_offset == -2) { param.sched_priority = 0; pthread_attr_init(&attr); diff --git a/lib/src/phy/rf/rf_uhd_imp.c b/lib/src/phy/rf/rf_uhd_imp.c index c9c3c4866..c57a63095 100644 --- a/lib/src/phy/rf/rf_uhd_imp.c +++ b/lib/src/phy/rf/rf_uhd_imp.c @@ -562,7 +562,10 @@ int rf_uhd_open_multi(char *args, void **h, uint32_t nof_channels) perror("pthread_create"); return -1; } - + + /* Restore priorities */ + uhd_set_thread_priority(0, false); + return 0; } else { return SRSLTE_ERROR_INVALID_INPUTS; diff --git a/srsue/hdr/mac/mac.h b/srsue/hdr/mac/mac.h index b1b649de7..ee79456fc 100644 --- a/srsue/hdr/mac/mac.h +++ b/srsue/hdr/mac/mac.h @@ -112,8 +112,8 @@ public: private: void run_thread(); - static const int MAC_MAIN_THREAD_PRIO = 5; - static const int MAC_PDU_THREAD_PRIO = 6; + static const int MAC_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD + static const int MAC_PDU_THREAD_PRIO = -1; static const int MAC_NOF_HARQ_PROC = 2*HARQ_DELAY_MS; // Interaction with PHY