diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-06-29 15:35:22 +0200 |
---|---|---|
committer | Tom Tsou <tom@tsou.cc> | 2017-07-20 18:36:01 +0000 |
commit | 81486e053cfdc64ebc0bec71311df8172e716b91 (patch) | |
tree | 5dd69811a42ee9f63803bd989b7d748405cf0f9a /Transceiver52M/osmo-trx.cpp | |
parent | 28d8081e25abbf6151bee7fc325510545c9c799d (diff) |
Add '-t' command line option to enable SCHED_RR
SCHED_RR allows us to operate osmo-trx reliable even under exceptionally
high system load, as the realtime scheduler priority will have higher
priority than the other "regular" tasks on the system.
Change-Id: Ia2452b9763960b2be37fbeee9d832554da68a53f
Closes: OS#2344
Diffstat (limited to 'Transceiver52M/osmo-trx.cpp')
-rw-r--r-- | Transceiver52M/osmo-trx.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp index 31a99cf..61b3098 100644 --- a/Transceiver52M/osmo-trx.cpp +++ b/Transceiver52M/osmo-trx.cpp @@ -27,6 +27,7 @@ #include <signal.h> #include <stdlib.h> #include <unistd.h> +#include <sched.h> #include <GSMCommon.h> #include <Logger.h> @@ -77,6 +78,7 @@ struct trx_config { double rssi_offset; bool swap_channels; bool edge; + int sched_rr; }; ConfigurationTable gConfig; @@ -259,7 +261,8 @@ static void print_help() " -r Random Normal Burst test mode with TSC\n" " -A Random Access Burst test mode with delay\n" " -R RSSI to dBm offset in dB (default=0)\n" - " -S Swap channels (UmTRX only)\n", + " -S Swap channels (UmTRX only)\n" + " -t SCHED_RR real-time priority (1..32)\n", "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG"); } @@ -283,8 +286,9 @@ static void handle_options(int argc, char **argv, struct trx_config *config) config->rssi_offset = 0.0; config->swap_channels = false; config->edge = false; + config->sched_rr = -1; - while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxgfo:s:b:r:A:R:Se")) != -1) { + while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxgfo:s:b:r:A:R:Set:")) != -1) { switch (option) { case 'h': print_help(); @@ -343,6 +347,9 @@ static void handle_options(int argc, char **argv, struct trx_config *config) case 'e': config->edge = true; break; + case 't': + config->sched_rr = atoi(optarg); + break; default: print_help(); exit(0); @@ -386,6 +393,21 @@ bad_config: exit(0); } +static int set_sched_rr(int prio) +{ + struct sched_param param; + int rc; + memset(¶m, 0, sizeof(param)); + param.sched_priority = prio; + printf("Setting SCHED_RR priority(%d)\n", param.sched_priority); + rc = sched_setscheduler(getpid(), SCHED_RR, ¶m); + if (rc != 0) { + std::cerr << "Config: Setting SCHED_RR failed" << std::endl; + return -1; + } + return 0; +} + int main(int argc, char *argv[]) { int type, chans, ref; @@ -424,6 +446,11 @@ int main(int argc, char *argv[]) handle_options(argc, argv, &config); + if (config.sched_rr != -1) { + if (set_sched_rr(config.sched_rr) < 0) + return EXIT_FAILURE; + } + setup_signal_handlers(); /* Check database sanity */ |