Blame view

include/asm-generic/getorder.h 1.41 KB
5b17e1cd8   Arnd Bergmann   asm-generic: rena...
1
2
  #ifndef __ASM_GENERIC_GETORDER_H
  #define __ASM_GENERIC_GETORDER_H
fd4fd5aac   Stephen Rothwell   [PATCH] mm: conso...
3

fd4fd5aac   Stephen Rothwell   [PATCH] mm: conso...
4
  #ifndef __ASSEMBLY__
38f332303   Linus Torvalds   Revert "[PATCH] L...
5
  #include <linux/compiler.h>
d66acc39c   David Howells   bitops: Optimise ...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <linux/log2.h>
  
  /*
   * Runtime evaluation of get_order()
   */
  static inline __attribute_const__
  int __get_order(unsigned long size)
  {
  	int order;
  
  	size--;
  	size >>= PAGE_SHIFT;
  #if BITS_PER_LONG == 32
  	order = fls(size);
  #else
  	order = fls64(size);
  #endif
  	return order;
  }
fd4fd5aac   Stephen Rothwell   [PATCH] mm: conso...
25

e0891a981   David Howells   bitops: Adjust th...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  /**
   * get_order - Determine the allocation order of a memory size
   * @size: The size for which to get the order
   *
   * Determine the allocation order of a particular sized block of memory.  This
   * is on a logarithmic scale, where:
   *
   *	0 -> 2^0 * PAGE_SIZE and below
   *	1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1
   *	2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1
   *	3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1
   *	4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1
   *	...
   *
   * The order returned is used to find the smallest allocation granule required
   * to hold an object of the specified size.
   *
   * The result is undefined if the size is 0.
   *
   * This function may be used to initialise variables with compile time
   * evaluations of constants.
   */
d66acc39c   David Howells   bitops: Optimise ...
48
49
50
  #define get_order(n)						\
  (								\
  	__builtin_constant_p(n) ? (				\
b893485db   Joerg Roedel   bitops: Add missi...
51
52
  		((n) == 0UL) ? BITS_PER_LONG - PAGE_SHIFT :	\
  		(((n) < (1UL << PAGE_SHIFT)) ? 0 :		\
d66acc39c   David Howells   bitops: Optimise ...
53
54
55
56
  		 ilog2((n) - 1) - PAGE_SHIFT + 1)		\
  	) :							\
  	__get_order(n)						\
  )
fd4fd5aac   Stephen Rothwell   [PATCH] mm: conso...
57
58
  
  #endif	/* __ASSEMBLY__ */
fd4fd5aac   Stephen Rothwell   [PATCH] mm: conso...
59

5b17e1cd8   Arnd Bergmann   asm-generic: rena...
60
  #endif	/* __ASM_GENERIC_GETORDER_H */