diff options
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/bitmap.h | 46 | ||||
-rw-r--r-- | include/linux/mempool.h | 7 | ||||
-rw-r--r-- | include/linux/mm.h | 8 | ||||
-rw-r--r-- | include/linux/sched/mm.h | 2 | ||||
-rw-r--r-- | include/linux/sort.h | 1 |
5 files changed, 60 insertions, 4 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index c5592a5a..54a8d52a 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -2,6 +2,7 @@ #define _PERF_BITOPS_H #include <string.h> +#include <linux/bits.h> #include <linux/bitops.h> #include <linux/kernel.h> #include <stdlib.h> @@ -34,7 +35,7 @@ static inline int __bitmap_weight(const unsigned long *bitmap, int bits) w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); return w; -} +} static inline int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits) @@ -156,6 +157,49 @@ static inline unsigned long find_next_zero_bit(const unsigned long *addr, unsign return _find_next_bit(addr, size, offset, ~0UL); } +#define FIND_NEXT_BIT(FETCH, MUNGE, size, start) \ +({ \ + unsigned long mask, idx, tmp, sz = (size), __start = (start); \ + \ + if (unlikely(__start >= sz)) \ + goto out; \ + \ + mask = MUNGE(BITMAP_FIRST_WORD_MASK(__start)); \ + idx = __start / BITS_PER_LONG; \ + \ + for (tmp = (FETCH) & mask; !tmp; tmp = (FETCH)) { \ + if ((idx + 1) * BITS_PER_LONG >= sz) \ + goto out; \ + idx++; \ + } \ + \ + sz = min(idx * BITS_PER_LONG + __ffs(MUNGE(tmp)), sz); \ +out: \ + sz; \ +}) +static inline unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsigned long *addr2, + unsigned long nbits, unsigned long start) +{ + return FIND_NEXT_BIT(addr1[idx] & ~addr2[idx], /* nop */, nbits, start); +} + +static inline unsigned long find_next_andnot_bit(const unsigned long *addr1, + const unsigned long *addr2, unsigned long size, + unsigned long offset) +{ + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr1 & ~*addr2 & __GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + + return _find_next_andnot_bit(addr1, addr2, size, offset); +} + #define find_first_bit(addr, size) find_next_bit((addr), (size), 0) #define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0) diff --git a/include/linux/mempool.h b/include/linux/mempool.h index 37325170..83875b85 100644 --- a/include/linux/mempool.h +++ b/include/linux/mempool.h @@ -9,6 +9,8 @@ #include <linux/compiler.h> #include <linux/slab.h> +#define alloc_hooks(_do, ...) _do + struct kmem_cache; typedef void * (mempool_alloc_t)(gfp_t gfp_mask, void *pool_data); @@ -46,7 +48,10 @@ extern mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn, extern int mempool_resize(mempool_t *pool, int new_min_nr); extern void mempool_destroy(mempool_t *pool); -extern void *mempool_alloc(mempool_t *pool, gfp_t gfp_mask) __malloc; +extern void *mempool_alloc_noprof(mempool_t *pool, gfp_t gfp_mask) __malloc; +#define mempool_alloc(...) \ + alloc_hooks(mempool_alloc_noprof(__VA_ARGS__)) + extern void mempool_free(void *element, mempool_t *pool); /* diff --git a/include/linux/mm.h b/include/linux/mm.h index d0fad5ab..cbcc86e6 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -23,11 +23,15 @@ struct sysinfo { __u32 mem_unit; /* Memory unit size in bytes */ }; - - static inline void si_meminfo(struct sysinfo *val) { BUG_ON(syscall(SYS_sysinfo, val)); } +extern unsigned long _totalram_pages; +static inline unsigned long totalram_pages(void) +{ + return _totalram_pages; +} + #endif /* _TOOLS_LINUX_MM_H */ diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 34045ce0..2cbe0784 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -1,6 +1,8 @@ #ifndef _LINUX_SCHED_MM_H #define _LINUX_SCHED_MM_H +#include <linux/mm.h> + #define PF_MEMALLOC 0x00000800 /* Allocating memory */ #define PF_MEMALLOC_NOFS 0x00040000 /* All allocation requests will inherit GFP_NOFS */ diff --git a/include/linux/sort.h b/include/linux/sort.h index d8a86590..4f45c7dc 100644 --- a/include/linux/sort.h +++ b/include/linux/sort.h @@ -27,5 +27,6 @@ static inline void sort(void *base, size_t num, size_t size, } #define sort_nonatomic(...) sort(__VA_ARGS__) +#define sort_r_nonatomic(...) sort_r(__VA_ARGS__) #endif |