From 1a6efcac0a19bd89d178f0e7d013cd9a384f1d7f Mon Sep 17 00:00:00 2001 From: Vladislav P Date: Wed, 7 Sep 2022 07:24:46 +0300 Subject: [PATCH] gnss_synchro_monitor: reduce CPU consumption For some unknown reason gnss_synchro_monitor stays in a tight loop trying to catch all syncros and sometimes consumes the whole CPU core. Triggering the gnss_syncro_monitor from sample counter as it is done with observables greatly reduces CPU usage from ~60...90% to <1%. Signed-off-by: Vladislav P --- src/core/monitor/gnss_synchro_monitor.cc | 7 +++++-- src/core/receiver/gnss_flowgraph.cc | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/monitor/gnss_synchro_monitor.cc b/src/core/monitor/gnss_synchro_monitor.cc index 502a5ed48..f57517150 100644 --- a/src/core/monitor/gnss_synchro_monitor.cc +++ b/src/core/monitor/gnss_synchro_monitor.cc @@ -55,11 +55,13 @@ gnss_synchro_monitor::gnss_synchro_monitor(int n_channels, void gnss_synchro_monitor::forecast(int noutput_items __attribute__((unused)), gr_vector_int& ninput_items_required) { - for (int32_t channel_index = 0; channel_index < d_nchannels; channel_index++) + for (int32_t channel_index = 0; channel_index < d_nchannels - 1; channel_index++) { // Set the required number of inputs to 0 so that a lone input on any channel can be pushed to UDP ninput_items_required[channel_index] = 0; } + // last input channel is the sample counter, triggered each ms + ninput_items_required[d_nchannels - 1] = 1; } @@ -70,7 +72,7 @@ int gnss_synchro_monitor::general_work(int noutput_items __attribute__((unused)) const auto** in = reinterpret_cast(&input_items[0]); // Loop through each input stream channel - for (int channel_index = 0; channel_index < d_nchannels; channel_index++) + for (int channel_index = 0; channel_index < d_nchannels - 1; channel_index++) { // Loop through each item in each input stream channel int count = 0; @@ -91,6 +93,7 @@ int gnss_synchro_monitor::general_work(int noutput_items __attribute__((unused)) } } } + consume(d_nchannels - 1, ninput_items[d_nchannels - 1]); // Not producing any outputs return 0; diff --git a/src/core/receiver/gnss_flowgraph.cc b/src/core/receiver/gnss_flowgraph.cc index d5505b4f9..cf5d93c05 100644 --- a/src/core/receiver/gnss_flowgraph.cc +++ b/src/core/receiver/gnss_flowgraph.cc @@ -206,7 +206,8 @@ void GNSSFlowgraph::init() udp_addr_vec.erase(std::unique(udp_addr_vec.begin(), udp_addr_vec.end()), udp_addr_vec.end()); // Instantiate monitor object - GnssSynchroMonitor_ = gnss_synchro_make_monitor(channels_count_, + // last input channel is the sample counter, triggered each ms + GnssSynchroMonitor_ = gnss_synchro_make_monitor(channels_count_ + 1, configuration_->property("Monitor.decimation_factor", 1), configuration_->property("Monitor.udp_port", 1234), udp_addr_vec, enable_protobuf); @@ -1216,6 +1217,7 @@ int GNSSFlowgraph::connect_gnss_synchro_monitor() { top_block_->connect(observables_->get_right_block(), i, GnssSynchroMonitor_, i); } + top_block_->connect(ch_out_sample_counter_, 0, GnssSynchroMonitor_, channels_count_); // extra port for the sample counter pulse } catch (const std::exception& e) {