LCOV - code coverage report
Current view: top level - include/asm-generic - getorder.h (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_qemu_modules_combined.info Lines: 8 8 100.0 %
Date: 2020-09-30 20:25:01 Functions: 1 1 100.0 %
Branches: 45 72 62.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: GPL-2.0 */
       2                 :            : #ifndef __ASM_GENERIC_GETORDER_H
       3                 :            : #define __ASM_GENERIC_GETORDER_H
       4                 :            : 
       5                 :            : #ifndef __ASSEMBLY__
       6                 :            : 
       7                 :            : #include <linux/compiler.h>
       8                 :            : #include <linux/log2.h>
       9                 :            : 
      10                 :            : /**
      11                 :            :  * get_order - Determine the allocation order of a memory size
      12                 :            :  * @size: The size for which to get the order
      13                 :            :  *
      14                 :            :  * Determine the allocation order of a particular sized block of memory.  This
      15                 :            :  * is on a logarithmic scale, where:
      16                 :            :  *
      17                 :            :  *      0 -> 2^0 * PAGE_SIZE and below
      18                 :            :  *      1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1
      19                 :            :  *      2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1
      20                 :            :  *      3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1
      21                 :            :  *      4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1
      22                 :            :  *      ...
      23                 :            :  *
      24                 :            :  * The order returned is used to find the smallest allocation granule required
      25                 :            :  * to hold an object of the specified size.
      26                 :            :  *
      27                 :            :  * The result is undefined if the size is 0.
      28                 :            :  */
      29                 :    4369146 : static inline __attribute_const__ int get_order(unsigned long size)
      30                 :            : {
      31         [ +  + ]:    4369146 :         if (__builtin_constant_p(size)) {
      32         [ +  + ]:    4229032 :                 if (!size)
      33                 :            :                         return BITS_PER_LONG - PAGE_SHIFT;
      34                 :            : 
      35         [ +  + ]:    4229056 :                 if (size < (1UL << PAGE_SHIFT))
      36                 :            :                         return 0;
      37                 :            : 
      38   [ +  -  +  +  :    4228904 :                 return ilog2((size) - 1) - PAGE_SHIFT + 1;
          +  +  +  -  +  
          +  +  +  +  +  
          +  +  +  -  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  -  
          +  +  +  +  +  
          +  +  +  -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      39                 :            :         }
      40                 :            : 
      41                 :     140114 :         size--;
      42                 :     140114 :         size >>= PAGE_SHIFT;
      43                 :            : #if BITS_PER_LONG == 32
      44                 :     140114 :         return fls(size);
      45                 :            : #else
      46                 :            :         return fls64(size);
      47                 :            : #endif
      48                 :            : }
      49                 :            : 
      50                 :            : #endif  /* __ASSEMBLY__ */
      51                 :            : 
      52                 :            : #endif  /* __ASM_GENERIC_GETORDER_H */

Generated by: LCOV version 1.14