Root/
1 | #ifndef __ASM_GENERIC_GETORDER_H |
2 | #define __ASM_GENERIC_GETORDER_H |
3 | |
4 | #ifndef __ASSEMBLY__ |
5 | |
6 | #include <linux/compiler.h> |
7 | #include <linux/log2.h> |
8 | |
9 | /* |
10 | * Runtime evaluation of get_order() |
11 | */ |
12 | static inline __attribute_const__ |
13 | int __get_order(unsigned long size) |
14 | { |
15 | int order; |
16 | |
17 | size--; |
18 | size >>= PAGE_SHIFT; |
19 | #if BITS_PER_LONG == 32 |
20 | order = fls(size); |
21 | #else |
22 | order = fls64(size); |
23 | #endif |
24 | return order; |
25 | } |
26 | |
27 | /** |
28 | * get_order - Determine the allocation order of a memory size |
29 | * @size: The size for which to get the order |
30 | * |
31 | * Determine the allocation order of a particular sized block of memory. This |
32 | * is on a logarithmic scale, where: |
33 | * |
34 | * 0 -> 2^0 * PAGE_SIZE and below |
35 | * 1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1 |
36 | * 2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1 |
37 | * 3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1 |
38 | * 4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1 |
39 | * ... |
40 | * |
41 | * The order returned is used to find the smallest allocation granule required |
42 | * to hold an object of the specified size. |
43 | * |
44 | * The result is undefined if the size is 0. |
45 | * |
46 | * This function may be used to initialise variables with compile time |
47 | * evaluations of constants. |
48 | */ |
49 | #define get_order(n) \ |
50 | ( \ |
51 | __builtin_constant_p(n) ? ( \ |
52 | ((n) == 0UL) ? BITS_PER_LONG - PAGE_SHIFT : \ |
53 | (((n) < (1UL << PAGE_SHIFT)) ? 0 : \ |
54 | ilog2((n) - 1) - PAGE_SHIFT + 1) \ |
55 | ) : \ |
56 | __get_order(n) \ |
57 | ) |
58 | |
59 | #endif /* __ASSEMBLY__ */ |
60 | |
61 | #endif /* __ASM_GENERIC_GETORDER_H */ |
62 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9