Gnuradio C++ 块:高 CPU

Gnuradio C++ block: high CPU

我已经创建了一个 python Gnuradio 块,现在我正在用 C++ 重新编码它。我注意到的是一些非常出乎意料的事情——C++ 块(python 流程图过程)比做同样事情的 Python 版本(18%)消耗更多 CPU(~125%)。我一定是做错了什么......所以 -

我创建了一个没有自定义代码的新块,除了将变量类型设置为 float 并将输入和输出的数量设置为 1 之外,我看到了相同的行为。我一定是做错了什么,但我不知道是什么...

$ gnuradio-config-info -v
3.7.11

Platform: Mac / x86_64

以下是我在现有模块中创建块的方式:

$ gr_modtool add -t general donothingcpp
GNU Radio module name identified: acsound
Language (python/cpp): cpp
Language: C++
Block/code identifier: donothingcpp
Enter valid argument list, including default arguments: 
Add Python QA code? [Y/n] n
Add C++ QA code? [Y/n] n
Adding file 'lib/donothingcpp_impl.h'...
Adding file 'lib/donothingcpp_impl.cc'...
Adding file 'include/acsound/donothingcpp.h'...
Editing swig/acsound_swig.i...
Adding file 'grc/acsound_donothingcpp.xml'...
Editing grc/CMakeLists.txt...

这是用于测试的流程图:

我修改了构造函数以指定一个输入和一个输出,然后我调整了 general_work 函数中的变量类型,现在看起来像这样:

int
donothingcpp_impl::general_work (int noutput_items,
                   gr_vector_int &ninput_items,
                   gr_vector_const_void_star &input_items,
                   gr_vector_void_star &output_items)
{
  const float *in = (const float *) input_items[0];
  float *out = (float *) output_items[0];

  // Do <+signal processing+>
  // Tell runtime system how many input items we consumed on
  // each input stream.
  consume_each (noutput_items);

  // Tell runtime system how many output items we produced.
  return noutput_items;
}

无论我是否在 general_work 函数中执行任何操作,该进程的 CPU 消耗量 运行 约为 125%。当然,对于每次代码更改,我都会进行清理、制作和安装,以便将块放入 gnuradio。如果我添加调试消息,我会在控制台上看到它们,所以我知道当我 运行 流程图时我的代码更改正在被看到和使用。

如果我绕过 donothing 块和 运行 流程图,它会消耗 0.3% CPU。

我尝试了 null 和 probe 信号接收器,但似乎都不是一个因素。

然而,当我 运行 自定义 C++ 块时,我无法解释高 CPU 消耗。

您正在消耗输出样本的数量,但在一般情况下这是错误的(在同步块情况下是正确的,其中输出项的数量始终与消耗的输入项的数量相同)。

现在,由于您的块不检查是否有足够的输入项,它总是被要求 运行 – 因此,燃烧 CPU。

我觉得你 "accidentally" 制作了一个通用块(使用 general_work),但打算制作一个同步块(使用 work)。