bitmap.c (a68725f930a0d186fe3f8941941e2047e03589d4) | bitmap.c (d73415a315471ac0b127ed3fad45c8ec5d711de1) |
---|---|
1/* 2 * Bitmap Module 3 * 4 * Stolen from linux/src/lib/bitmap.c 5 * 6 * Copyright (C) 2010 Corentin Chary 7 * 8 * This source code is licensed under the GNU General Public License, --- 176 unchanged lines hidden (view full) --- 185 const long size = start + nr; 186 int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); 187 unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); 188 189 assert(start >= 0 && nr >= 0); 190 191 /* First word */ 192 if (nr - bits_to_set > 0) { | 1/* 2 * Bitmap Module 3 * 4 * Stolen from linux/src/lib/bitmap.c 5 * 6 * Copyright (C) 2010 Corentin Chary 7 * 8 * This source code is licensed under the GNU General Public License, --- 176 unchanged lines hidden (view full) --- 185 const long size = start + nr; 186 int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); 187 unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); 188 189 assert(start >= 0 && nr >= 0); 190 191 /* First word */ 192 if (nr - bits_to_set > 0) { |
193 atomic_or(p, mask_to_set); | 193 qatomic_or(p, mask_to_set); |
194 nr -= bits_to_set; 195 bits_to_set = BITS_PER_LONG; 196 mask_to_set = ~0UL; 197 p++; 198 } 199 200 /* Full words */ 201 if (bits_to_set == BITS_PER_LONG) { 202 while (nr >= BITS_PER_LONG) { 203 *p = ~0UL; 204 nr -= BITS_PER_LONG; 205 p++; 206 } 207 } 208 209 /* Last word */ 210 if (nr) { 211 mask_to_set &= BITMAP_LAST_WORD_MASK(size); | 194 nr -= bits_to_set; 195 bits_to_set = BITS_PER_LONG; 196 mask_to_set = ~0UL; 197 p++; 198 } 199 200 /* Full words */ 201 if (bits_to_set == BITS_PER_LONG) { 202 while (nr >= BITS_PER_LONG) { 203 *p = ~0UL; 204 nr -= BITS_PER_LONG; 205 p++; 206 } 207 } 208 209 /* Last word */ 210 if (nr) { 211 mask_to_set &= BITMAP_LAST_WORD_MASK(size); |
212 atomic_or(p, mask_to_set); | 212 qatomic_or(p, mask_to_set); |
213 } else { | 213 } else { |
214 /* If we avoided the full barrier in atomic_or(), issue a | 214 /* If we avoided the full barrier in qatomic_or(), issue a |
215 * barrier to account for the assignments in the while loop. 216 */ 217 smp_mb(); 218 } 219} 220 221void bitmap_clear(unsigned long *map, long start, long nr) 222{ --- 25 unchanged lines hidden (view full) --- 248 unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); 249 unsigned long dirty = 0; 250 unsigned long old_bits; 251 252 assert(start >= 0 && nr >= 0); 253 254 /* First word */ 255 if (nr - bits_to_clear > 0) { | 215 * barrier to account for the assignments in the while loop. 216 */ 217 smp_mb(); 218 } 219} 220 221void bitmap_clear(unsigned long *map, long start, long nr) 222{ --- 25 unchanged lines hidden (view full) --- 248 unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); 249 unsigned long dirty = 0; 250 unsigned long old_bits; 251 252 assert(start >= 0 && nr >= 0); 253 254 /* First word */ 255 if (nr - bits_to_clear > 0) { |
256 old_bits = atomic_fetch_and(p, ~mask_to_clear); | 256 old_bits = qatomic_fetch_and(p, ~mask_to_clear); |
257 dirty |= old_bits & mask_to_clear; 258 nr -= bits_to_clear; 259 bits_to_clear = BITS_PER_LONG; 260 mask_to_clear = ~0UL; 261 p++; 262 } 263 264 /* Full words */ 265 if (bits_to_clear == BITS_PER_LONG) { 266 while (nr >= BITS_PER_LONG) { 267 if (*p) { | 257 dirty |= old_bits & mask_to_clear; 258 nr -= bits_to_clear; 259 bits_to_clear = BITS_PER_LONG; 260 mask_to_clear = ~0UL; 261 p++; 262 } 263 264 /* Full words */ 265 if (bits_to_clear == BITS_PER_LONG) { 266 while (nr >= BITS_PER_LONG) { 267 if (*p) { |
268 old_bits = atomic_xchg(p, 0); | 268 old_bits = qatomic_xchg(p, 0); |
269 dirty |= old_bits; 270 } 271 nr -= BITS_PER_LONG; 272 p++; 273 } 274 } 275 276 /* Last word */ 277 if (nr) { 278 mask_to_clear &= BITMAP_LAST_WORD_MASK(size); | 269 dirty |= old_bits; 270 } 271 nr -= BITS_PER_LONG; 272 p++; 273 } 274 } 275 276 /* Last word */ 277 if (nr) { 278 mask_to_clear &= BITMAP_LAST_WORD_MASK(size); |
279 old_bits = atomic_fetch_and(p, ~mask_to_clear); | 279 old_bits = qatomic_fetch_and(p, ~mask_to_clear); |
280 dirty |= old_bits & mask_to_clear; 281 } else { 282 if (!dirty) { 283 smp_mb(); 284 } 285 } 286 287 return dirty != 0; 288} 289 290void bitmap_copy_and_clear_atomic(unsigned long *dst, unsigned long *src, 291 long nr) 292{ 293 while (nr > 0) { | 280 dirty |= old_bits & mask_to_clear; 281 } else { 282 if (!dirty) { 283 smp_mb(); 284 } 285 } 286 287 return dirty != 0; 288} 289 290void bitmap_copy_and_clear_atomic(unsigned long *dst, unsigned long *src, 291 long nr) 292{ 293 while (nr > 0) { |
294 *dst = atomic_xchg(src, 0); | 294 *dst = qatomic_xchg(src, 0); |
295 dst++; 296 src++; 297 nr -= BITS_PER_LONG; 298 } 299} 300 301#define ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) 302 --- 187 unchanged lines hidden --- | 295 dst++; 296 src++; 297 nr -= BITS_PER_LONG; 298 } 299} 300 301#define ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) 302 --- 187 unchanged lines hidden --- |