From e48df9cb5ec9e48cd836ec227127f42c5cc99aa1 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 17 Jun 2016 11:26:57 +0200 Subject: Set SCHED_RR prio for all data processing threads This includes Modulator, FIR Filter and UHD worker --- src/DabMod.cpp | 4 ++++ src/FIRFilter.cpp | 3 +++ src/OutputUHD.cpp | 6 ++++++ src/Utils.cpp | 9 +++++++++ src/Utils.h | 2 ++ 5 files changed, 24 insertions(+) diff --git a/src/DabMod.cpp b/src/DabMod.cpp index e0e7f8e..b5e3568 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -751,6 +751,10 @@ int launch_modulator(int argc, char* argv[]) } #endif + // Set thread priority to realtime + if (int r = set_realtime_prio(1)) { + etiLog.level(error) << "Could not set priority for modulator:" << r; + } while (run_again) { Flowgraph flowgraph; diff --git a/src/FIRFilter.cpp b/src/FIRFilter.cpp index e217288..ebd4518 100644 --- a/src/FIRFilter.cpp +++ b/src/FIRFilter.cpp @@ -29,6 +29,7 @@ #include "FIRFilter.h" #include "PcDebug.h" +#include "Utils.h" #include #include @@ -55,6 +56,8 @@ void FIRFilterWorker::process(struct FIRFilterWorkerData *fwd) struct timespec time_start; struct timespec time_end; + set_realtime_prio(1); + // This thread creates the dataOut buffer, and deletes // the incoming buffer diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index a49b659..dff0fd2 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -45,6 +45,7 @@ #include #include #include +#include using namespace std; @@ -595,6 +596,11 @@ void OutputUHD::check_gps() void UHDWorker::process_errhandler() { + // Set thread priority to realtime + if (int ret = set_realtime_prio(1)) { + etiLog.level(error) << "Could not set priority for UHD worker:" << ret; + } + process(); uwd->running = false; etiLog.level(warn) << "UHD worker terminated"; diff --git a/src/Utils.cpp b/src/Utils.cpp index 4805374..ab1866c 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -114,4 +114,13 @@ void printVersion(void) } +int set_realtime_prio(int prio) +{ + // Set thread priority to realtime + const int policy = SCHED_RR; + sched_param sp; + sp.sched_priority = sched_get_priority_min(policy) + prio; + int ret = pthread_setschedparam(pthread_self(), policy, &sp); + return ret; +} diff --git a/src/Utils.h b/src/Utils.h index f023646..7f65fa3 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -57,6 +57,8 @@ inline long timespecdiff_us(struct timespec& oldTime, struct timespec& time) return tv_sec * 1000 + tv_nsec / 1000; } +// Set SCHED_RR with priority prio (0=lowest) +int set_realtime_prio(int prio); #endif -- cgit v1.2.3