Skip to content

Commit

Permalink
Apps start as single threaded by default to avoid downclocking on lap…
Browse files Browse the repository at this point in the history
…top cpus
  • Loading branch information
williamyang98 committed Jan 16, 2024
1 parent 8190eba commit a235d43
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
8 changes: 4 additions & 4 deletions examples/basic_radio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,17 @@ 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"
);
}

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;
Expand Down
4 changes: 2 additions & 2 deletions examples/basic_radio_app_no_demod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand All @@ -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) {
Expand Down
13 changes: 9 additions & 4 deletions examples/basic_radio_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class App
std::unique_ptr<BasicRadio> 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<BasicRadio>(params);
radio = std::make_unique<BasicRadio>(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) {
Expand Down Expand Up @@ -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"
Expand All @@ -80,16 +81,20 @@ 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;
break;
case 'M':
transmission_mode = (int)(atof(optarg));
break;
case 't':
total_threads = (int)(atof(optarg));
break;
case 'D':
is_decode_data = false;
break;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions examples/basic_radio_scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions examples/basic_radio_scraper_no_demod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class App
std::unique_ptr<BasicRadio> radio;
std::unique_ptr<BasicScraper> 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<BasicRadio>(params, total_demod_threads);
radio = std::make_unique<BasicRadio>(params, total_radio_threads);
scraper = std::make_unique<BasicScraper>(*(radio.get()), dir);
}
void Run() {
Expand All @@ -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"
);
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/ofdm_demod_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ 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"
);
}

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;
Expand Down
4 changes: 2 additions & 2 deletions examples/ofdm_demod_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions examples/radio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DeviceSelector>())
explicit App(const int _total_demod_threads, const int _total_radio_threads)
: device_selector(std::make_unique<DeviceSelector>()),
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<DoubleBuffer<viterbi_bit_t>>(dab_params.nb_frame_bits);
raw_double_buffer = std::make_unique<DoubleBuffer<std::complex<float>>>(0);
Expand Down Expand Up @@ -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<BasicRadio>(dab_params);
auto radio = std::make_unique<BasicRadio>(dab_params, total_radio_threads);
auto view_controller = std::make_unique<BasicRadioViewController>(*(radio.get()));
auto instance = std::make_unique<RadioInstance>(
std::move(radio),
Expand Down Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit a235d43

Please sign in to comment.