From a235d434bf21f7016c878004b8615c978fb306c3 Mon Sep 17 00:00:00 2001 From: William Yang Date: Wed, 17 Jan 2024 01:07:29 +1100 Subject: [PATCH] Apps start as single threaded by default to avoid downclocking on laptop cpus --- examples/basic_radio_app.cpp | 8 ++++---- examples/basic_radio_app_no_demod.cpp | 4 ++-- examples/basic_radio_benchmark.cpp | 13 +++++++++---- examples/basic_radio_scraper.cpp | 7 ++++--- examples/basic_radio_scraper_no_demod.cpp | 8 ++++---- examples/ofdm_demod_cli.cpp | 4 ++-- examples/ofdm_demod_gui.cpp | 4 ++-- examples/radio_app.cpp | 19 +++++++++++++------ 8 files changed, 40 insertions(+), 27 deletions(-) diff --git a/examples/basic_radio_app.cpp b/examples/basic_radio_app.cpp index a0eed24..e4a9e60 100644 --- a/examples/basic_radio_app.cpp +++ b/examples/basic_radio_app.cpp @@ -235,8 +235,8 @@ void usage() { "\t[-v Enable logging (default: false)]\n" "\t[-b block size (default: 8192)]\n" "\t[-M dab transmission mode (default: 1)]\n" - "\t[-t total ofdm demod threads (default: auto)]\n" - "\t[-T total radio threads (default: auto)]\n" + "\t[-t total ofdm demod threads (default: 1)]\n" + "\t[-T total radio threads (default: 1)]\n" "\t[-C toggle coarse frequency correction (default: true)]\n" "\t[-h (show usage)]\n" ); @@ -244,8 +244,8 @@ void usage() { INITIALIZE_EASYLOGGINGPP int main(int argc, char** argv) { - int total_demod_threads = 0; - int total_radio_threads = 0; + int total_demod_threads = 1; + int total_radio_threads = 1; char* rd_filename = NULL; int block_size = 8192; bool is_logging = false; diff --git a/examples/basic_radio_app_no_demod.cpp b/examples/basic_radio_app_no_demod.cpp index a55cd1d..16f22ec 100644 --- a/examples/basic_radio_app_no_demod.cpp +++ b/examples/basic_radio_app_no_demod.cpp @@ -157,7 +157,7 @@ void usage() { "\t[-i input filename (default: None)]\n" "\t If no file is provided then stdin is used\n" "\t[-M dab transmission mode (default: 1)]\n" - "\t[-T total radio threads (default: auto)]\n" + "\t[-T total radio threads (default: 1)]\n" "\t[-v Enable logging (default: false)]\n" "\t[-h (show usage)]\n" ); @@ -168,7 +168,7 @@ int main(int argc, char** argv) { char* rd_filename = NULL; bool is_logging = false; int transmission_mode = 1; - int total_radio_threads = 0; + int total_radio_threads = 1; int opt; while ((opt = getopt_custom(argc, argv, "i:M:T:vh")) != -1) { diff --git a/examples/basic_radio_benchmark.cpp b/examples/basic_radio_benchmark.cpp index feb96a1..9864f37 100644 --- a/examples/basic_radio_benchmark.cpp +++ b/examples/basic_radio_benchmark.cpp @@ -31,12 +31,12 @@ class App std::unique_ptr radio; Config config; public: - App(const int transmission_mode, FILE* const _fp_in) + App(const int transmission_mode, FILE* const _fp_in, const int total_threads) : fp_in(_fp_in) { auto params = get_dab_parameters(transmission_mode); frame_bits.resize(params.nb_frame_bits); - radio = std::make_unique(params); + radio = std::make_unique(params, total_threads); // Start decoding audio/data for benchmarking // We are interested in these code paths for profiling radio->On_DAB_Plus_Channel().Attach([this](subchannel_id_t subchannel_id, Basic_DAB_Plus_Channel& channel) { @@ -66,6 +66,7 @@ void usage() { "\t[-i input filename (default: None)]\n" "\t If no file is provided then stdin is used\n" "\t[-M dab transmission mode (default: 1)]\n" + "\t[-t total threads (default: 1)]\n" "\t[-D disable decode data (default: true)]\n" "\t[-A disable decode audio (default: true)]\n" "\t[-v Enable logging (default: false)]\n" @@ -80,9 +81,10 @@ int main(int argc, char** argv) { bool is_decode_data = true; bool is_decode_audio = true; int transmission_mode = 1; + int total_threads = 1; int opt; - while ((opt = getopt_custom(argc, argv, "i:M:DAvh")) != -1) { + while ((opt = getopt_custom(argc, argv, "i:M:t:DAvh")) != -1) { switch (opt) { case 'i': rd_filename = optarg; @@ -90,6 +92,9 @@ int main(int argc, char** argv) { case 'M': transmission_mode = (int)(atof(optarg)); break; + case 't': + total_threads = (int)(atof(optarg)); + break; case 'D': is_decode_data = false; break; @@ -143,7 +148,7 @@ int main(int argc, char** argv) { scraper_conf.setGlobally(el::ConfigurationType::Format, "[%level] [%thread] [%logger] %msg"); basic_scraper_logger->configure(scraper_conf); - auto app = App(transmission_mode, fp_in); + auto app = App(transmission_mode, fp_in, total_threads); auto& config = app.GetConfig(); config.is_decode_audio = is_decode_audio; config.is_decode_data = is_decode_data; diff --git a/examples/basic_radio_scraper.cpp b/examples/basic_radio_scraper.cpp index d2bf955..a251f78 100644 --- a/examples/basic_radio_scraper.cpp +++ b/examples/basic_radio_scraper.cpp @@ -132,7 +132,8 @@ void usage() { "\t[-v Enable logging (default: false)]\n" "\t[-b block size (default: 8192)]\n" "\t[-M dab transmission mode (default: 1)]\n" - "\t[-t total ofdm demod threads (default: auto)]\n" + "\t[-t total ofdm demod threads (default: 1)]\n" + "\t[-T total radio threads (default: 1)]\n" "\t[-C toggle coarse frequency correction (default: true)]\n" "\t[-h (show usage)]\n" ); @@ -142,8 +143,8 @@ INITIALIZE_EASYLOGGINGPP int main(int argc, char** argv) { const char* output_dir = NULL; const char* rd_filename = NULL; - int total_demod_threads = 0; - int total_radio_threads = 0; + int total_demod_threads = 1; + int total_radio_threads = 1; int block_size = 8192; bool is_logging = false; int transmission_mode = 1; diff --git a/examples/basic_radio_scraper_no_demod.cpp b/examples/basic_radio_scraper_no_demod.cpp index 10ebab6..1770284 100644 --- a/examples/basic_radio_scraper_no_demod.cpp +++ b/examples/basic_radio_scraper_no_demod.cpp @@ -27,12 +27,12 @@ class App std::unique_ptr radio; std::unique_ptr scraper; public: - App(const int transmission_mode, const int total_demod_threads, FILE* const _fp_in, const char* dir) + App(const int transmission_mode, const int total_radio_threads, FILE* const _fp_in, const char* dir) : fp_in(_fp_in) { auto params = get_dab_parameters(transmission_mode); frame_bits.resize(params.nb_frame_bits); - radio = std::make_unique(params, total_demod_threads); + radio = std::make_unique(params, total_radio_threads); scraper = std::make_unique(*(radio.get()), dir); } void Run() { @@ -56,7 +56,7 @@ void usage() { "\t If no file is provided then stdin is used\n" "\t[-v Enable logging (default: false)]\n" "\t[-M dab transmission mode (default: 1)]\n" - "\t[-T total radio threads (default: auto)]\n" + "\t[-T total radio threads (default: 1)]\n" "\t[-h (show usage)]\n" ); } @@ -67,7 +67,7 @@ int main(int argc, char** argv) { const char* rd_filename = NULL; bool is_logging = false; int transmission_mode = 1; - int total_radio_threads = 0; + int total_radio_threads = 1; int opt; while ((opt = getopt_custom(argc, argv, "o:i:M:T:vh")) != -1) { diff --git a/examples/ofdm_demod_cli.cpp b/examples/ofdm_demod_cli.cpp index 0ec5a3d..50ee81b 100644 --- a/examples/ofdm_demod_cli.cpp +++ b/examples/ofdm_demod_cli.cpp @@ -124,7 +124,7 @@ void usage() { "\t[-o output filename (default: None)]\n" "\t If no file is provided then stdout is used\n" "\t[-M dab transmission mode (default: 1)]\n" - "\t[-t total ofdm demod threads (default: auto)]\n" + "\t[-t total ofdm demod threads (default: 1)]\n" "\t[-D (disable output)]\n" "\t[-C (disable coarse frequency correction)]\n" "\t[-h (show usage)]\n" @@ -132,7 +132,7 @@ void usage() { } int main(int argc, char** argv) { - int total_demod_threads = 0; + int total_demod_threads = 1; int block_size = 8192; int transmission_mode = 1; bool is_output = true; diff --git a/examples/ofdm_demod_gui.cpp b/examples/ofdm_demod_gui.cpp index 525a77f..7695ad6 100644 --- a/examples/ofdm_demod_gui.cpp +++ b/examples/ofdm_demod_gui.cpp @@ -232,7 +232,7 @@ void usage() { "\t[-o output filename (default: None)]\n" "\t If no file is provided then stdout is used\n" "\t[-M dab transmission mode (default: 1)]\n" - "\t[-t total ofdm demod threads (default: auto)]\n" + "\t[-t total ofdm demod threads (default: 1)]\n" "\t[-S toggle step mode (default: false)]\n" "\t[-D toggle frame output (default: true)]\n" "\t[-C toggle coarse frequency correction (default: true)]\n" @@ -241,7 +241,7 @@ void usage() { } int main(int argc, char** argv) { - int total_demod_threads = 0; + int total_demod_threads = 1; int block_size = 8192; int transmission_mode = 1; bool is_step_mode = false; diff --git a/examples/radio_app.cpp b/examples/radio_app.cpp index 06b35ab..b0941a9 100644 --- a/examples/radio_app.cpp +++ b/examples/radio_app.cpp @@ -91,6 +91,7 @@ class App { private: const int transmission_mode = 1; + const int total_radio_threads; // When switching between block frequencies, interrupt the data flow so we dont have data from // the previous block frequency entering the data models for the new block frequency int demodulator_cooldown_max = 10; @@ -111,11 +112,12 @@ class App PaDeviceList pa_devices; AudioPipeline audio_pipeline; public: - explicit App(const int total_demod_threads) - : device_selector(std::make_unique()) + explicit App(const int _total_demod_threads, const int _total_radio_threads) + : device_selector(std::make_unique()), + total_radio_threads(_total_radio_threads) { const auto dab_params = get_dab_parameters(transmission_mode); - ofdm_demod = Create_OFDM_Demodulator(transmission_mode, total_demod_threads); + ofdm_demod = Create_OFDM_Demodulator(transmission_mode, _total_demod_threads); frame_double_buffer = std::make_unique>(dab_params.nb_frame_bits); raw_double_buffer = std::make_unique>>(0); @@ -251,7 +253,7 @@ class App private: void CreateRadio(const std::string& key) { const auto dab_params = get_dab_parameters(transmission_mode); - auto radio = std::make_unique(dab_params); + auto radio = std::make_unique(dab_params, total_radio_threads); auto view_controller = std::make_unique(*(radio.get())); auto instance = std::make_unique( std::move(radio), @@ -333,6 +335,7 @@ void usage() { fprintf(stderr, "radio_app, Complete radio app with device selector, demodulator, dab decoding\n\n" "\t[-t total ofdm demod threads (default: 1)]\n" + "\t[-T total radio threads (default: 1)]\n" "\t[-v Enable logging (default: false)]\n" "\t[-C toggle coarse frequency correction (default: true)]\n" "\t[-h (show usage)]\n" @@ -342,15 +345,19 @@ void usage() { INITIALIZE_EASYLOGGINGPP int main(int argc, char **argv) { int total_demod_threads = 1; + int total_radio_threads = 1; bool is_logging = false; bool is_coarse_freq_correction = true; int opt; - while ((opt = getopt_custom(argc, argv, "t:vCh")) != -1) { + while ((opt = getopt_custom(argc, argv, "t:T:vCh")) != -1) { switch (opt) { case 't': total_demod_threads = (int)(atof(optarg)); break; + case 'T': + total_radio_threads = (int)(atof(optarg)); + break; case 'v': is_logging = true; break; @@ -380,7 +387,7 @@ int main(int argc, char **argv) { el::Helpers::setThreadName("main-thread"); auto port_audio_handler = ScopedPaHandler(); - auto app = App(total_demod_threads); + auto app = App(total_demod_threads, total_radio_threads); auto& config = app.GetOFDMDemodulator().GetConfig(); config.sync.is_coarse_freq_correction = is_coarse_freq_correction;