Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 处理“Wframe大于”的建议-内核模块上的警告_C_Linux Kernel_Kbuild - Fatal编程技术网

C 处理“Wframe大于”的建议-内核模块上的警告

C 处理“Wframe大于”的建议-内核模块上的警告,c,linux-kernel,kbuild,C,Linux Kernel,Kbuild,大家好,新年快乐 我正在研究一个内核模块。为了正确设置设备,有必要对某些参数进行数值计算。 该函数工作正常,但gcc编译器(我使用的是kbuild)向我发出警告: warning: the frame size of 1232 bytes is larger than 1024 bytes [-Wframe-larger-than=] 如果我是对的,这意味着空间局部变量超过了编译模块的机器给定的限制 现在有一些问题: 此警告是指模块、此显式函数或此函数及其子函数所需的全部内存空间吗 这有多重要

大家好,新年快乐

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

warning: the frame size of 1232 bytes is larger than 1024 bytes [-Wframe-larger-than=]
如果我是对的,这意味着空间局部变量超过了编译模块的机器给定的限制

现在有一些问题:

  • 此警告是指模块、此显式函数或此函数及其子函数所需的全部内存空间吗
  • 这有多重要
  • 我看不到减少所需内存的方法。对此有什么建议吗?有什么方法吗 也许这会有帮助:计算使用64位定点算法。此库的所有函数都是内联函数

    提前谢谢

    亚历克斯


    按照@Tsyvarev的建议,问题可能会归结为函数中的分配,如本例所示(我知道代码没有意义-它只用于显示我如何声明函数中的变量):

    uint8\u t getVal(uint8\u t)
    {
    uint64_t ar1[128]={0};
    uint64_t ar2[128]={0};
    uint8_t val;
    //很多东西
    返回val;
    }
    虚空乐趣(虚空)
    {
    uint64_t ar1[128]={0};
    uint64_t ar2[128]={0};
    uint8_t cnt;
    对于(cnt=0;cnt至第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);
      }
    }
    
    uint8\u t getVal(uint8\u t)
    {
    uint64_t*ar1;
    uint64_t*ar2;
    uint8_t val,cnt;
    //在堆上分配内存
    ar1=kmalloc(sizeof(uint64_t),128);
    ar2=kmalloc(sizeof(uint64_t),128);
    //初始化数组
    
    对于(cnt=0;内核线程的cntStack大小仅为8 KB,因此使用消耗1 KB堆栈的函数是不好的。减少堆栈消耗的一般方法是将数据存储在堆上而不是堆栈上。@Tsyvarev谢谢你的好答案。我不明白为什么有人认为有必要搁置我的问题。导致是太大了,用一个小例子是无法实现的。所以我试图描述这种行为,我认为这更有意义,也更清楚。正如我所看到的,一些接近票数的人反对“太广泛”原因:减少堆栈使用的方法通常太多了。如果您需要针对特定情况提供建议,则需要提供代码,您需要对其进行优化。当然,由于您的代码可能很大,因此可以提供部分代码,以便仅优化此部分。但此部分在某种程度上应该是自给自足的(请参阅原因说明中的链接)。您目前的解释还不够充分。那么在堆上而不是堆栈上存储
    arr
    数组有什么问题?没问题。正如您所建议的,我现在使用
    kmalloc
    arr
    存储到堆中。早些时候我没有看到这一点。我真的很想感谢您在这方面的帮助“已解决”。但我不能。我说kmalloc现在的工作方式不同了,对吗?现在它应该是size
    sizeof(uint64\u t)*128
    作为第一个参数,然后是一些
    gfp\t
    标志作为第二个参数?
    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);
      }
    }