diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 8 | ||||
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/cpumask.c | 62 | ||||
-rw-r--r-- | lib/find_last_bit.c | 45 |
4 files changed, 113 insertions, 3 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 2ba43c4a5b07..03c2c24b9083 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -13,6 +13,10 @@ config GENERIC_FIND_FIRST_BIT | |||
13 | config GENERIC_FIND_NEXT_BIT | 13 | config GENERIC_FIND_NEXT_BIT |
14 | bool | 14 | bool |
15 | 15 | ||
16 | config GENERIC_FIND_LAST_BIT | ||
17 | bool | ||
18 | default y | ||
19 | |||
16 | config CRC_CCITT | 20 | config CRC_CCITT |
17 | tristate "CRC-CCITT functions" | 21 | tristate "CRC-CCITT functions" |
18 | help | 22 | help |
@@ -166,4 +170,8 @@ config CPUMASK_OFFSTACK | |||
166 | them on the stack. This is a bit more expensive, but avoids | 170 | them on the stack. This is a bit more expensive, but avoids |
167 | stack overflow. | 171 | stack overflow. |
168 | 172 | ||
173 | config DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | ||
174 | bool "Disable obsolete cpumask functions" if DEBUG_PER_CPU_MAPS | ||
175 | depends on EXPERIMENTAL && BROKEN | ||
176 | |||
169 | endmenu | 177 | endmenu |
diff --git a/lib/Makefile b/lib/Makefile index 80fe8a3ec12a..32b0e64ded27 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -37,6 +37,7 @@ lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o | |||
37 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | 37 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o |
38 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o | 38 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o |
39 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o | 39 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o |
40 | lib-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o | ||
40 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o | 41 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o |
41 | obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o | 42 | obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o |
42 | obj-$(CONFIG_PLIST) += plist.o | 43 | obj-$(CONFIG_PLIST) += plist.o |
diff --git a/lib/cpumask.c b/lib/cpumask.c index 8d03f22c6ced..3389e2440da0 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c | |||
@@ -76,15 +76,28 @@ int cpumask_any_but(const struct cpumask *mask, unsigned int cpu) | |||
76 | 76 | ||
77 | /* These are not inline because of header tangles. */ | 77 | /* These are not inline because of header tangles. */ |
78 | #ifdef CONFIG_CPUMASK_OFFSTACK | 78 | #ifdef CONFIG_CPUMASK_OFFSTACK |
79 | bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) | 79 | /** |
80 | * alloc_cpumask_var_node - allocate a struct cpumask on a given node | ||
81 | * @mask: pointer to cpumask_var_t where the cpumask is returned | ||
82 | * @flags: GFP_ flags | ||
83 | * | ||
84 | * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is | ||
85 | * a nop returning a constant 1 (in <linux/cpumask.h>) | ||
86 | * Returns TRUE if memory allocation succeeded, FALSE otherwise. | ||
87 | * | ||
88 | * In addition, mask will be NULL if this fails. Note that gcc is | ||
89 | * usually smart enough to know that mask can never be NULL if | ||
90 | * CONFIG_CPUMASK_OFFSTACK=n, so does code elimination in that case | ||
91 | * too. | ||
92 | */ | ||
93 | bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node) | ||
80 | { | 94 | { |
81 | if (likely(slab_is_available())) | 95 | if (likely(slab_is_available())) |
82 | *mask = kmalloc(cpumask_size(), flags); | 96 | *mask = kmalloc_node(cpumask_size(), flags, node); |
83 | else { | 97 | else { |
84 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS | 98 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS |
85 | printk(KERN_ERR | 99 | printk(KERN_ERR |
86 | "=> alloc_cpumask_var: kmalloc not available!\n"); | 100 | "=> alloc_cpumask_var: kmalloc not available!\n"); |
87 | dump_stack(); | ||
88 | #endif | 101 | #endif |
89 | *mask = NULL; | 102 | *mask = NULL; |
90 | } | 103 | } |
@@ -94,21 +107,64 @@ bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) | |||
94 | dump_stack(); | 107 | dump_stack(); |
95 | } | 108 | } |
96 | #endif | 109 | #endif |
110 | /* FIXME: Bandaid to save us from old primitives which go to NR_CPUS. */ | ||
111 | if (*mask) { | ||
112 | unsigned int tail; | ||
113 | tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long); | ||
114 | memset(cpumask_bits(*mask) + cpumask_size() - tail, | ||
115 | 0, tail); | ||
116 | } | ||
117 | |||
97 | return *mask != NULL; | 118 | return *mask != NULL; |
98 | } | 119 | } |
120 | EXPORT_SYMBOL(alloc_cpumask_var_node); | ||
121 | |||
122 | /** | ||
123 | * alloc_cpumask_var - allocate a struct cpumask | ||
124 | * @mask: pointer to cpumask_var_t where the cpumask is returned | ||
125 | * @flags: GFP_ flags | ||
126 | * | ||
127 | * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is | ||
128 | * a nop returning a constant 1 (in <linux/cpumask.h>). | ||
129 | * | ||
130 | * See alloc_cpumask_var_node. | ||
131 | */ | ||
132 | bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) | ||
133 | { | ||
134 | return alloc_cpumask_var_node(mask, flags, numa_node_id()); | ||
135 | } | ||
99 | EXPORT_SYMBOL(alloc_cpumask_var); | 136 | EXPORT_SYMBOL(alloc_cpumask_var); |
100 | 137 | ||
138 | /** | ||
139 | * alloc_bootmem_cpumask_var - allocate a struct cpumask from the bootmem arena. | ||
140 | * @mask: pointer to cpumask_var_t where the cpumask is returned | ||
141 | * | ||
142 | * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is | ||
143 | * a nop (in <linux/cpumask.h>). | ||
144 | * Either returns an allocated (zero-filled) cpumask, or causes the | ||
145 | * system to panic. | ||
146 | */ | ||
101 | void __init alloc_bootmem_cpumask_var(cpumask_var_t *mask) | 147 | void __init alloc_bootmem_cpumask_var(cpumask_var_t *mask) |
102 | { | 148 | { |
103 | *mask = alloc_bootmem(cpumask_size()); | 149 | *mask = alloc_bootmem(cpumask_size()); |
104 | } | 150 | } |
105 | 151 | ||
152 | /** | ||
153 | * free_cpumask_var - frees memory allocated for a struct cpumask. | ||
154 | * @mask: cpumask to free | ||
155 | * | ||
156 | * This is safe on a NULL mask. | ||
157 | */ | ||
106 | void free_cpumask_var(cpumask_var_t mask) | 158 | void free_cpumask_var(cpumask_var_t mask) |
107 | { | 159 | { |
108 | kfree(mask); | 160 | kfree(mask); |
109 | } | 161 | } |
110 | EXPORT_SYMBOL(free_cpumask_var); | 162 | EXPORT_SYMBOL(free_cpumask_var); |
111 | 163 | ||
164 | /** | ||
165 | * free_bootmem_cpumask_var - frees result of alloc_bootmem_cpumask_var | ||
166 | * @mask: cpumask to free | ||
167 | */ | ||
112 | void __init free_bootmem_cpumask_var(cpumask_var_t mask) | 168 | void __init free_bootmem_cpumask_var(cpumask_var_t mask) |
113 | { | 169 | { |
114 | free_bootmem((unsigned long)mask, cpumask_size()); | 170 | free_bootmem((unsigned long)mask, cpumask_size()); |
diff --git a/lib/find_last_bit.c b/lib/find_last_bit.c new file mode 100644 index 000000000000..5d202e36bdd8 --- /dev/null +++ b/lib/find_last_bit.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* find_last_bit.c: fallback find next bit implementation | ||
2 | * | ||
3 | * Copyright (C) 2008 IBM Corporation | ||
4 | * Written by Rusty Russell <rusty@rustcorp.com.au> | ||
5 | * (Inspired by David Howell's find_next_bit implementation) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version | ||
10 | * 2 of the License, or (at your option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include <linux/bitops.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <asm/types.h> | ||
16 | #include <asm/byteorder.h> | ||
17 | |||
18 | unsigned long find_last_bit(const unsigned long *addr, unsigned long size) | ||
19 | { | ||
20 | unsigned long words; | ||
21 | unsigned long tmp; | ||
22 | |||
23 | /* Start at final word. */ | ||
24 | words = size / BITS_PER_LONG; | ||
25 | |||
26 | /* Partial final word? */ | ||
27 | if (size & (BITS_PER_LONG-1)) { | ||
28 | tmp = (addr[words] & (~0UL >> (BITS_PER_LONG | ||
29 | - (size & (BITS_PER_LONG-1))))); | ||
30 | if (tmp) | ||
31 | goto found; | ||
32 | } | ||
33 | |||
34 | while (words) { | ||
35 | tmp = addr[--words]; | ||
36 | if (tmp) { | ||
37 | found: | ||
38 | return words * BITS_PER_LONG + __fls(tmp); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | /* Not found */ | ||
43 | return size; | ||
44 | } | ||
45 | EXPORT_SYMBOL(find_last_bit); | ||