diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-22 12:13:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-22 12:13:24 -0400 |
commit | e17fdf5c6778ff77d93dd769910992e4073b9348 (patch) | |
tree | d1a7ca2b1faf4301b39300fbd82f9b91e605a77e /include/asm-generic | |
parent | 95211279c5ad00a317c98221d7e4365e02f20836 (diff) | |
parent | a240ada241dafe290e7532d1ddeb98fdf1419068 (diff) |
Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86/asm changes from Ingo Molnar
* 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86: Include probe_roms.h in probe_roms.c
x86/32: Print control and debug registers for kerenel context
x86: Tighten dependencies of CPU_SUP_*_32
x86/numa: Improve internode cache alignment
x86: Fix the NMI nesting comments
x86-64: Improve insn scheduling in SAVE_ARGS_IRQ
x86-64: Fix CFI annotations for NMI nesting code
bitops: Add missing parentheses to new get_order macro
bitops: Optimise get_order()
bitops: Adjust the comment on get_order() to describe the size==0 case
x86/spinlocks: Eliminate TICKET_MASK
x86-64: Handle byte-wise tail copying in memcpy() without a loop
x86-64: Fix memcpy() to support sizes of 4Gb and above
x86-64: Fix memset() to support sizes of 4Gb and above
x86-64: Slightly shorten copy_page()
Diffstat (limited to 'include/asm-generic')
-rw-r--r-- | include/asm-generic/getorder.h | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/include/asm-generic/getorder.h b/include/asm-generic/getorder.h index 67e7245dc9b3..65e4468ac53d 100644 --- a/include/asm-generic/getorder.h +++ b/include/asm-generic/getorder.h | |||
@@ -4,21 +4,58 @@ | |||
4 | #ifndef __ASSEMBLY__ | 4 | #ifndef __ASSEMBLY__ |
5 | 5 | ||
6 | #include <linux/compiler.h> | 6 | #include <linux/compiler.h> |
7 | #include <linux/log2.h> | ||
7 | 8 | ||
8 | /* Pure 2^n version of get_order */ | 9 | /* |
9 | static inline __attribute_const__ int get_order(unsigned long size) | 10 | * Runtime evaluation of get_order() |
11 | */ | ||
12 | static inline __attribute_const__ | ||
13 | int __get_order(unsigned long size) | ||
10 | { | 14 | { |
11 | int order; | 15 | int order; |
12 | 16 | ||
13 | size = (size - 1) >> (PAGE_SHIFT - 1); | 17 | size--; |
14 | order = -1; | 18 | size >>= PAGE_SHIFT; |
15 | do { | 19 | #if BITS_PER_LONG == 32 |
16 | size >>= 1; | 20 | order = fls(size); |
17 | order++; | 21 | #else |
18 | } while (size); | 22 | order = fls64(size); |
23 | #endif | ||
19 | return order; | 24 | return order; |
20 | } | 25 | } |
21 | 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 | |||
22 | #endif /* __ASSEMBLY__ */ | 59 | #endif /* __ASSEMBLY__ */ |
23 | 60 | ||
24 | #endif /* __ASM_GENERIC_GETORDER_H */ | 61 | #endif /* __ASM_GENERIC_GETORDER_H */ |