建议在内核模块上处理`Wframe-than-than`警告

时间:2016-01-07 16:12:27

标签: c linux-kernel kbuild

你好,新年快乐,

我正在研究内核模块。有必要对某些参数进行数值计算以正确设置设备。 该函数工作正常,但gcc编译器(我使用kbuild)给了我警告:

warning: the frame size of 1232 bytes is larger than 1024 bytes [-Wframe-larger-than=]

如果我正确,这意味着空间局部变量超出了模块编译的机器给出的限制。

现在有一些问题:

  1. 此警告是否涉及模块,此显式函数或此函数及其子函数所需的整个内存空间?
  2. 这有多重要?
  3. 我没有看到减少所需内存的方法。有一些建议可以解决这个问题吗?任何方法?
  4. 也许它很有帮助:计算使用64位定点算术。该库的所有功能都是inline函数。

    提前致谢

    亚历

    根据@Tsyvarev的建议,问题可能会减少到函数中的分配,正如这个例子所示(我知道代码没有意义 - 它仅用于显示我如何声明变量在函数内部:

    uint8_t getVal ( uint8_t )
    {
      uint64_t ar1[128] = {0};
      uint64_t ar2[128] = {0};
      uint8_t val;
    
      // a much of stuff
    
      return val;
    }
    
    void fun ( void )
    {
      uint64_t ar1[128] = {0};
      uint64_t ar2[128] = {0};
      uint8_t cnt;
    
      for(cnt=0; cnt<128; cnt++)
      {
        ar1[cnt] = getVal(cnt);
        ar1[cnt] = getVal(cnt);
      }
    }
    

1 个答案:

答案 0 :(得分:1)

指向第3点:

正如建议的那样,解决方案是使用kmalloc将数据存储到堆中,而不是堆栈。

uint8_t getVal ( uint8_t )
{
  uint64_t *ar1;
  uint64_t *ar2;
  uint8_t val, cnt;

  // allocate memory on the heap
  ar1 = kmalloc(sizeof(uint64_t), 128);
  ar2 = kmalloc(sizeof(uint64_t), 128);

  // initialize the arrays
  for(cnt=0; cnt<128; cnt++)
  {
    ar1[cnt] = 0;
    ar2[cnt] = 0;
  }

  // a much of stuff

  return val;
}

void fun ( void )
{
  uint64_t *ar1;
  uint64_t *ar2;
  uint8_t cnt;

  // allocate memory on the heap
  ar1 = kmalloc(sizeof(uint64_t), 128);
  ar2 = kmalloc(sizeof(uint64_t), 128);

  // initialize the arrays
  for(cnt=0; cnt<128; cnt++)
  {
    ar1[cnt] = 0;
    ar2[cnt] = 0;
  }

 for(cnt=0; cnt<128; cnt++)
  {
    ar1[cnt] = getVal(cnt);
    ar1[cnt] = getVal(cnt);
  }
}
相关问题