2005-04-17 02:20:36 +04:00
|
|
|
#ifndef __LINUX_BITMAP_H
|
|
|
|
#define __LINUX_BITMAP_H
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/string.h>
|
2007-10-19 10:40:37 +04:00
|
|
|
#include <linux/kernel.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* bitmaps provide bit arrays that consume one or more unsigned
|
|
|
|
* longs. The bitmap interface and available operations are listed
|
|
|
|
* here, in bitmap.h
|
|
|
|
*
|
|
|
|
* Function implementations generic to all architectures are in
|
|
|
|
* lib/bitmap.c. Functions implementations that are architecture
|
|
|
|
* specific are in various include/asm-<arch>/bitops.h headers
|
|
|
|
* and other arch/<arch> specific files.
|
|
|
|
*
|
|
|
|
* See lib/bitmap.c for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The available bitmap operations and their rough meaning in the
|
|
|
|
* case that the bitmap is a single unsigned long are thus:
|
|
|
|
*
|
2006-06-26 15:57:10 +04:00
|
|
|
* Note that nbits should be always a compile time evaluable constant.
|
|
|
|
* Otherwise many inlines will generate horrible code.
|
|
|
|
*
|
2005-04-17 02:20:36 +04:00
|
|
|
* bitmap_zero(dst, nbits) *dst = 0UL
|
|
|
|
* bitmap_fill(dst, nbits) *dst = ~0UL
|
|
|
|
* bitmap_copy(dst, src, nbits) *dst = *src
|
|
|
|
* bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
|
|
|
|
* bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
|
|
|
|
* bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2
|
|
|
|
* bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2)
|
|
|
|
* bitmap_complement(dst, src, nbits) *dst = ~(*src)
|
|
|
|
* bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
|
|
|
|
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
|
|
|
|
* bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2?
|
|
|
|
* bitmap_empty(src, nbits) Are all bits zero in *src?
|
|
|
|
* bitmap_full(src, nbits) Are all bits set in *src?
|
|
|
|
* bitmap_weight(src, nbits) Hamming Weight: number set bits
|
2009-12-16 03:48:25 +03:00
|
|
|
* bitmap_set(dst, pos, nbits) Set specified bit area
|
|
|
|
* bitmap_clear(dst, pos, nbits) Clear specified bit area
|
|
|
|
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
|
2014-12-13 03:54:45 +03:00
|
|
|
* bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above
|
2005-04-17 02:20:36 +04:00
|
|
|
* bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n
|
|
|
|
* bitmap_shift_left(dst, src, n, nbits) *dst = *src << n
|
2005-10-31 02:02:33 +03:00
|
|
|
* bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src)
|
|
|
|
* bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit)
|
mempolicy: add bitmap_onto() and bitmap_fold() operations
The following adds two more bitmap operators, bitmap_onto() and bitmap_fold(),
with the usual cpumask and nodemask wrappers.
The bitmap_onto() operator computes one bitmap relative to another. If the
n-th bit in the origin mask is set, then the m-th bit of the destination mask
will be set, where m is the position of the n-th set bit in the relative mask.
The bitmap_fold() operator folds a bitmap into a second that has bit m set iff
the input bitmap has some bit n set, where m == n mod sz, for the specified sz
value.
There are two substantive changes between this patch and its
predecessor bitmap_relative:
1) Renamed bitmap_relative() to be bitmap_onto().
2) Added bitmap_fold().
The essential motivation for bitmap_onto() is to provide a mechanism for
converting a cpuset-relative CPU or Node mask to an absolute mask. Cpuset
relative masks are written as if the current task were in a cpuset whose CPUs
or Nodes were just the consecutive ones numbered 0..N-1, for some N. The
bitmap_onto() operator is provided in anticipation of adding support for the
first such cpuset relative mask, by the mbind() and set_mempolicy() system
calls, using a planned flag of MPOL_F_RELATIVE_NODES. These bitmap operators
(and their nodemask wrappers, in particular) will be used in code that
converts the user specified cpuset relative memory policy to a specific system
node numbered policy, given the current mems_allowed of the tasks cpuset.
Such cpuset relative mempolicies will address two deficiencies
of the existing interface between cpusets and mempolicies:
1) A task cannot at present reliably establish a cpuset
relative mempolicy because there is an essential race
condition, in that the tasks cpuset may be changed in
between the time the task can query its cpuset placement,
and the time the task can issue the applicable mbind or
set_memplicy system call.
2) A task cannot at present establish what cpuset relative
mempolicy it would like to have, if it is in a smaller
cpuset than it might have mempolicy preferences for,
because the existing interface only allows specifying
mempolicies for nodes currently allowed by the cpuset.
Cpuset relative mempolicies are useful for tasks that don't distinguish
particularly between one CPU or Node and another, but only between how many of
each are allowed, and the proper placement of threads and memory pages on the
various CPUs and Nodes available.
The motivation for the added bitmap_fold() can be seen in the following
example.
Let's say an application has specified some mempolicies that presume 16 memory
nodes, including say a mempolicy that specified MPOL_F_RELATIVE_NODES (cpuset
relative) nodes 12-15. Then lets say that application is crammed into a
cpuset that only has 8 memory nodes, 0-7. If one just uses bitmap_onto(),
this mempolicy, mapped to that cpuset, would ignore the requested relative
nodes above 7, leaving it empty of nodes. That's not good; better to fold the
higher nodes down, so that some nodes are included in the resulting mapped
mempolicy. In this case, the mempolicy nodes 12-15 are taken modulo 8 (the
weight of the mems_allowed of the confining cpuset), resulting in a mempolicy
specifying nodes 4-7.
Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: <kosaki.motohiro@jp.fujitsu.com>
Cc: <ray-lk@madrabbit.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-04-28 13:12:29 +04:00
|
|
|
* bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap
|
|
|
|
* bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz
|
2005-04-17 02:20:36 +04:00
|
|
|
* bitmap_scnprintf(buf, len, src, nbits) Print bitmap src to buf
|
2006-10-11 12:21:55 +04:00
|
|
|
* bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf
|
|
|
|
* bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf
|
2005-04-17 02:20:36 +04:00
|
|
|
* bitmap_scnlistprintf(buf, len, src, nbits) Print bitmap src as list to buf
|
bitmap, irq: add smp_affinity_list interface to /proc/irq
Manually adjusting the smp_affinity for IRQ's becomes unwieldy when the
cpu count is large.
Setting smp affinity to cpus 256 to 263 would be:
echo 000000ff,00000000,00000000,00000000,00000000,00000000,00000000,00000000 > smp_affinity
instead of:
echo 256-263 > smp_affinity_list
Think about what it looks like for cpus around say, 4088 to 4095.
We already have many alternate "list" interfaces:
/sys/devices/system/cpu/cpuX/indexY/shared_cpu_list
/sys/devices/system/cpu/cpuX/topology/thread_siblings_list
/sys/devices/system/cpu/cpuX/topology/core_siblings_list
/sys/devices/system/node/nodeX/cpulist
/sys/devices/pci***/***/local_cpulist
Add a companion interface, smp_affinity_list to use cpu lists instead of
cpu maps. This conforms to other companion interfaces where both a map
and a list interface exists.
This required adding a bitmap_parselist_user() function in a manner
similar to the bitmap_parse_user() function.
[akpm@linux-foundation.org: make __bitmap_parselist() static]
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jack Steiner <steiner@sgi.com>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-05-25 04:13:12 +04:00
|
|
|
* bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf
|
|
|
|
* bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf
|
2006-03-24 14:15:44 +03:00
|
|
|
* bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region
|
|
|
|
* bitmap_release_region(bitmap, pos, order) Free specified bit region
|
|
|
|
* bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region
|
2014-09-30 17:48:22 +04:00
|
|
|
* bitmap_print_to_pagebuf(list, buf, mask, nbits) Print bitmap src as list/hex
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Also the following operations in asm/bitops.h apply to bitmaps.
|
|
|
|
*
|
|
|
|
* set_bit(bit, addr) *addr |= bit
|
|
|
|
* clear_bit(bit, addr) *addr &= ~bit
|
|
|
|
* change_bit(bit, addr) *addr ^= bit
|
|
|
|
* test_bit(bit, addr) Is bit set in *addr?
|
|
|
|
* test_and_set_bit(bit, addr) Set bit and return old value
|
|
|
|
* test_and_clear_bit(bit, addr) Clear bit and return old value
|
|
|
|
* test_and_change_bit(bit, addr) Change bit and return old value
|
|
|
|
* find_first_zero_bit(addr, nbits) Position first zero bit in *addr
|
|
|
|
* find_first_bit(addr, nbits) Position first set bit in *addr
|
|
|
|
* find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
|
|
|
|
* find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used
|
|
|
|
* to declare an array named 'name' of just enough unsigned longs to
|
|
|
|
* contain all bit positions from 0 to 'bits' - 1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lib/bitmap.c provides these functions:
|
|
|
|
*/
|
|
|
|
|
lib: bitmap: make nbits parameter of bitmap_empty unsigned
Many functions in lib/bitmap.c start with an expression such as lim =
bits/BITS_PER_LONG. Since bits has type (signed) int, and since gcc
cannot know that it is in fact non-negative, it generates worse code
than it could. These patches, mostly consisting of changing various
parameters to unsigned, gives a slight overall code reduction:
add/remove: 1/1 grow/shrink: 8/16 up/down: 251/-414 (-163)
function old new delta
tick_device_uses_broadcast 335 425 +90
__irq_alloc_descs 498 554 +56
__bitmap_andnot 73 115 +42
__bitmap_and 70 101 +31
bitmap_weight - 11 +11
copy_hugetlb_page_range 752 762 +10
follow_hugetlb_page 846 854 +8
hugetlb_init 1415 1417 +2
hugetlb_nrpages_setup 130 131 +1
hugetlb_add_hstate 377 376 -1
bitmap_allocate_region 82 80 -2
select_task_rq_fair 2202 2191 -11
hweight_long 66 55 -11
__reg_op 230 219 -11
dm_stats_message 2849 2833 -16
bitmap_parselist 92 74 -18
__bitmap_weight 115 97 -18
__bitmap_subset 153 129 -24
__bitmap_full 128 104 -24
__bitmap_empty 120 96 -24
bitmap_set 179 149 -30
bitmap_clear 185 155 -30
__bitmap_equal 136 105 -31
__bitmap_intersects 148 108 -40
__bitmap_complement 109 67 -42
tick_device_setup_broadcast_func.isra 81 - -81
[The increases in __bitmap_and{,not} are due to bug fixes 17/18,18/18.
No idea why bitmap_weight suddenly appears.] While 163 bytes treewide is
insignificant, I believe the bitmap functions are often called with
locks held, so saving even a few cycles might be worth it.
While making these changes, I found a few other things that might be
worth including. 16,17,18 are actual bug fixes. The rest shouldn't
change the behaviour of any of the functions, provided no-one passed
negative nbits values. If something should come up, it should be fairly
bisectable.
A few issues I thought about, but didn't know what to do with:
* Many of the functions misbehave if nbits is compile-time 0; the
out-of-line functions generally handle 0 correctly. bitmap_fill() is
particularly bad, whether the 0 is known at compile time or not. It
would probably be nice to add detection of at least compile-time 0 and
handle that appropriately.
* I didn't change __bitmap_shift_{left,right} to use unsigned because I
want to fully understand why the algorithm works before making that
change. However, AFAICT, they behave correctly for all (positive) shift
amounts. This is not the case for the small_const_nbits versions. If
for example nbits = n = BITS_PER_LONG, the shift operators turn into
no-ops (at least on x86), so one get *dst = *src, whereas one would
expect to get *dst=0. That difference in behaviour is somewhat
annoying.
This patch (of 18):
The compiler can generate slightly smaller and simpler code when it
knows that "nbits" is non-negative. Since no-one passes a negative
bit-count, this shouldn't affect the semantics.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-08-07 03:09:49 +04:00
|
|
|
extern int __bitmap_empty(const unsigned long *bitmap, unsigned int nbits);
|
2014-08-07 03:09:51 +04:00
|
|
|
extern int __bitmap_full(const unsigned long *bitmap, unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern int __bitmap_equal(const unsigned long *bitmap1,
|
2014-08-07 03:09:53 +04:00
|
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern void __bitmap_complement(unsigned long *dst, const unsigned long *src,
|
2014-08-07 03:09:55 +04:00
|
|
|
unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern void __bitmap_shift_right(unsigned long *dst,
|
|
|
|
const unsigned long *src, int shift, int bits);
|
|
|
|
extern void __bitmap_shift_left(unsigned long *dst,
|
|
|
|
const unsigned long *src, int shift, int bits);
|
2009-08-21 20:26:15 +04:00
|
|
|
extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
2009-08-21 20:26:15 +04:00
|
|
|
extern int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern int __bitmap_intersects(const unsigned long *bitmap1,
|
2014-08-07 03:10:01 +04:00
|
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern int __bitmap_subset(const unsigned long *bitmap1,
|
2014-08-07 03:10:03 +04:00
|
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
2014-08-07 03:10:05 +04:00
|
|
|
extern int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-08-07 03:10:07 +04:00
|
|
|
extern void bitmap_set(unsigned long *map, unsigned int start, int len);
|
2014-08-07 03:10:10 +04:00
|
|
|
extern void bitmap_clear(unsigned long *map, unsigned int start, int len);
|
2014-12-13 03:54:45 +03:00
|
|
|
|
|
|
|
extern unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
|
|
|
|
unsigned long size,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned int nr,
|
|
|
|
unsigned long align_mask,
|
|
|
|
unsigned long align_offset);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bitmap_find_next_zero_area - find a contiguous aligned zero area
|
|
|
|
* @map: The address to base the search on
|
|
|
|
* @size: The bitmap size in bits
|
|
|
|
* @start: The bitnumber to start searching at
|
|
|
|
* @nr: The number of zeroed bits we're looking for
|
|
|
|
* @align_mask: Alignment mask for zero area
|
|
|
|
*
|
|
|
|
* The @align_mask should be one less than a power of 2; the effect is that
|
|
|
|
* the bit offset of all zero areas this function finds is multiples of that
|
|
|
|
* power of 2. A @align_mask of 0 means no alignment is required.
|
|
|
|
*/
|
|
|
|
static inline unsigned long
|
|
|
|
bitmap_find_next_zero_area(unsigned long *map,
|
|
|
|
unsigned long size,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned int nr,
|
|
|
|
unsigned long align_mask)
|
|
|
|
{
|
|
|
|
return bitmap_find_next_zero_area_off(map, size, start, nr,
|
|
|
|
align_mask, 0);
|
|
|
|
}
|
2009-12-16 03:48:25 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
extern int bitmap_scnprintf(char *buf, unsigned int len,
|
|
|
|
const unsigned long *src, int nbits);
|
2006-10-11 12:21:55 +04:00
|
|
|
extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user,
|
|
|
|
unsigned long *dst, int nbits);
|
|
|
|
extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long *dst, int nbits);
|
|
|
|
extern int bitmap_scnlistprintf(char *buf, unsigned int len,
|
|
|
|
const unsigned long *src, int nbits);
|
|
|
|
extern int bitmap_parselist(const char *buf, unsigned long *maskp,
|
|
|
|
int nmaskbits);
|
bitmap, irq: add smp_affinity_list interface to /proc/irq
Manually adjusting the smp_affinity for IRQ's becomes unwieldy when the
cpu count is large.
Setting smp affinity to cpus 256 to 263 would be:
echo 000000ff,00000000,00000000,00000000,00000000,00000000,00000000,00000000 > smp_affinity
instead of:
echo 256-263 > smp_affinity_list
Think about what it looks like for cpus around say, 4088 to 4095.
We already have many alternate "list" interfaces:
/sys/devices/system/cpu/cpuX/indexY/shared_cpu_list
/sys/devices/system/cpu/cpuX/topology/thread_siblings_list
/sys/devices/system/cpu/cpuX/topology/core_siblings_list
/sys/devices/system/node/nodeX/cpulist
/sys/devices/pci***/***/local_cpulist
Add a companion interface, smp_affinity_list to use cpu lists instead of
cpu maps. This conforms to other companion interfaces where both a map
and a list interface exists.
This required adding a bitmap_parselist_user() function in a manner
similar to the bitmap_parse_user() function.
[akpm@linux-foundation.org: make __bitmap_parselist() static]
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jack Steiner <steiner@sgi.com>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-05-25 04:13:12 +04:00
|
|
|
extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
|
|
|
|
unsigned long *dst, int nbits);
|
2005-10-31 02:02:33 +03:00
|
|
|
extern void bitmap_remap(unsigned long *dst, const unsigned long *src,
|
|
|
|
const unsigned long *old, const unsigned long *new, int bits);
|
|
|
|
extern int bitmap_bitremap(int oldbit,
|
|
|
|
const unsigned long *old, const unsigned long *new, int bits);
|
mempolicy: add bitmap_onto() and bitmap_fold() operations
The following adds two more bitmap operators, bitmap_onto() and bitmap_fold(),
with the usual cpumask and nodemask wrappers.
The bitmap_onto() operator computes one bitmap relative to another. If the
n-th bit in the origin mask is set, then the m-th bit of the destination mask
will be set, where m is the position of the n-th set bit in the relative mask.
The bitmap_fold() operator folds a bitmap into a second that has bit m set iff
the input bitmap has some bit n set, where m == n mod sz, for the specified sz
value.
There are two substantive changes between this patch and its
predecessor bitmap_relative:
1) Renamed bitmap_relative() to be bitmap_onto().
2) Added bitmap_fold().
The essential motivation for bitmap_onto() is to provide a mechanism for
converting a cpuset-relative CPU or Node mask to an absolute mask. Cpuset
relative masks are written as if the current task were in a cpuset whose CPUs
or Nodes were just the consecutive ones numbered 0..N-1, for some N. The
bitmap_onto() operator is provided in anticipation of adding support for the
first such cpuset relative mask, by the mbind() and set_mempolicy() system
calls, using a planned flag of MPOL_F_RELATIVE_NODES. These bitmap operators
(and their nodemask wrappers, in particular) will be used in code that
converts the user specified cpuset relative memory policy to a specific system
node numbered policy, given the current mems_allowed of the tasks cpuset.
Such cpuset relative mempolicies will address two deficiencies
of the existing interface between cpusets and mempolicies:
1) A task cannot at present reliably establish a cpuset
relative mempolicy because there is an essential race
condition, in that the tasks cpuset may be changed in
between the time the task can query its cpuset placement,
and the time the task can issue the applicable mbind or
set_memplicy system call.
2) A task cannot at present establish what cpuset relative
mempolicy it would like to have, if it is in a smaller
cpuset than it might have mempolicy preferences for,
because the existing interface only allows specifying
mempolicies for nodes currently allowed by the cpuset.
Cpuset relative mempolicies are useful for tasks that don't distinguish
particularly between one CPU or Node and another, but only between how many of
each are allowed, and the proper placement of threads and memory pages on the
various CPUs and Nodes available.
The motivation for the added bitmap_fold() can be seen in the following
example.
Let's say an application has specified some mempolicies that presume 16 memory
nodes, including say a mempolicy that specified MPOL_F_RELATIVE_NODES (cpuset
relative) nodes 12-15. Then lets say that application is crammed into a
cpuset that only has 8 memory nodes, 0-7. If one just uses bitmap_onto(),
this mempolicy, mapped to that cpuset, would ignore the requested relative
nodes above 7, leaving it empty of nodes. That's not good; better to fold the
higher nodes down, so that some nodes are included in the resulting mapped
mempolicy. In this case, the mempolicy nodes 12-15 are taken modulo 8 (the
weight of the mems_allowed of the confining cpuset), resulting in a mempolicy
specifying nodes 4-7.
Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: <kosaki.motohiro@jp.fujitsu.com>
Cc: <ray-lk@madrabbit.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-04-28 13:12:29 +04:00
|
|
|
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
|
|
|
|
const unsigned long *relmap, int bits);
|
|
|
|
extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
|
|
|
|
int sz, int bits);
|
2014-08-07 03:10:16 +04:00
|
|
|
extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
|
|
|
|
extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
|
|
|
|
extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
|
2008-09-17 19:34:03 +04:00
|
|
|
extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
|
2011-07-27 03:08:30 +04:00
|
|
|
extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
|
2014-09-30 17:48:22 +04:00
|
|
|
extern int bitmap_print_to_pagebuf(bool list, char *buf,
|
|
|
|
const unsigned long *maskp, int nmaskbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-07-13 09:14:24 +04:00
|
|
|
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
|
2005-04-17 02:20:36 +04:00
|
|
|
#define BITMAP_LAST_WORD_MASK(nbits) \
|
|
|
|
( \
|
|
|
|
((nbits) % BITS_PER_LONG) ? \
|
|
|
|
(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
|
|
|
|
)
|
|
|
|
|
2008-12-30 01:35:13 +03:00
|
|
|
#define small_const_nbits(nbits) \
|
|
|
|
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static inline void bitmap_zero(unsigned long *dst, int nbits)
|
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
*dst = 0UL;
|
|
|
|
else {
|
|
|
|
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
|
|
|
memset(dst, 0, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bitmap_fill(unsigned long *dst, int nbits)
|
|
|
|
{
|
|
|
|
size_t nlongs = BITS_TO_LONGS(nbits);
|
2008-12-30 01:35:13 +03:00
|
|
|
if (!small_const_nbits(nbits)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
int len = (nlongs - 1) * sizeof(unsigned long);
|
|
|
|
memset(dst, 0xff, len);
|
|
|
|
}
|
|
|
|
dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
|
|
|
|
int nbits)
|
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
*dst = *src;
|
|
|
|
else {
|
|
|
|
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
|
|
|
memcpy(dst, src, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-21 20:26:15 +04:00
|
|
|
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *src2, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2014-08-07 03:10:22 +04:00
|
|
|
return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
2009-08-21 20:26:15 +04:00
|
|
|
return __bitmap_and(dst, src1, src2, nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *src2, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
*dst = *src1 | *src2;
|
|
|
|
else
|
|
|
|
__bitmap_or(dst, src1, src2, nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *src2, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
*dst = *src1 ^ *src2;
|
|
|
|
else
|
|
|
|
__bitmap_xor(dst, src1, src2, nbits);
|
|
|
|
}
|
|
|
|
|
2009-08-21 20:26:15 +04:00
|
|
|
static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
|
2014-08-07 03:09:59 +04:00
|
|
|
const unsigned long *src2, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2014-08-07 03:10:24 +04:00
|
|
|
return (*dst = *src1 & ~(*src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
2009-08-21 20:26:15 +04:00
|
|
|
return __bitmap_andnot(dst, src1, src2, nbits);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bitmap_complement(unsigned long *dst, const unsigned long *src,
|
2014-08-07 03:09:55 +04:00
|
|
|
unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2014-08-07 03:09:57 +04:00
|
|
|
*dst = ~(*src);
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
|
|
|
__bitmap_complement(dst, src, nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bitmap_equal(const unsigned long *src1,
|
2014-08-07 03:09:55 +04:00
|
|
|
const unsigned long *src2, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
|
|
|
|
else
|
|
|
|
return __bitmap_equal(src1, src2, nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bitmap_intersects(const unsigned long *src1,
|
2014-08-07 03:10:01 +04:00
|
|
|
const unsigned long *src2, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
|
|
|
else
|
|
|
|
return __bitmap_intersects(src1, src2, nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bitmap_subset(const unsigned long *src1,
|
2014-08-07 03:10:03 +04:00
|
|
|
const unsigned long *src2, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits));
|
|
|
|
else
|
|
|
|
return __bitmap_subset(src1, src2, nbits);
|
|
|
|
}
|
|
|
|
|
lib: bitmap: make nbits parameter of bitmap_empty unsigned
Many functions in lib/bitmap.c start with an expression such as lim =
bits/BITS_PER_LONG. Since bits has type (signed) int, and since gcc
cannot know that it is in fact non-negative, it generates worse code
than it could. These patches, mostly consisting of changing various
parameters to unsigned, gives a slight overall code reduction:
add/remove: 1/1 grow/shrink: 8/16 up/down: 251/-414 (-163)
function old new delta
tick_device_uses_broadcast 335 425 +90
__irq_alloc_descs 498 554 +56
__bitmap_andnot 73 115 +42
__bitmap_and 70 101 +31
bitmap_weight - 11 +11
copy_hugetlb_page_range 752 762 +10
follow_hugetlb_page 846 854 +8
hugetlb_init 1415 1417 +2
hugetlb_nrpages_setup 130 131 +1
hugetlb_add_hstate 377 376 -1
bitmap_allocate_region 82 80 -2
select_task_rq_fair 2202 2191 -11
hweight_long 66 55 -11
__reg_op 230 219 -11
dm_stats_message 2849 2833 -16
bitmap_parselist 92 74 -18
__bitmap_weight 115 97 -18
__bitmap_subset 153 129 -24
__bitmap_full 128 104 -24
__bitmap_empty 120 96 -24
bitmap_set 179 149 -30
bitmap_clear 185 155 -30
__bitmap_equal 136 105 -31
__bitmap_intersects 148 108 -40
__bitmap_complement 109 67 -42
tick_device_setup_broadcast_func.isra 81 - -81
[The increases in __bitmap_and{,not} are due to bug fixes 17/18,18/18.
No idea why bitmap_weight suddenly appears.] While 163 bytes treewide is
insignificant, I believe the bitmap functions are often called with
locks held, so saving even a few cycles might be worth it.
While making these changes, I found a few other things that might be
worth including. 16,17,18 are actual bug fixes. The rest shouldn't
change the behaviour of any of the functions, provided no-one passed
negative nbits values. If something should come up, it should be fairly
bisectable.
A few issues I thought about, but didn't know what to do with:
* Many of the functions misbehave if nbits is compile-time 0; the
out-of-line functions generally handle 0 correctly. bitmap_fill() is
particularly bad, whether the 0 is known at compile time or not. It
would probably be nice to add detection of at least compile-time 0 and
handle that appropriately.
* I didn't change __bitmap_shift_{left,right} to use unsigned because I
want to fully understand why the algorithm works before making that
change. However, AFAICT, they behave correctly for all (positive) shift
amounts. This is not the case for the small_const_nbits versions. If
for example nbits = n = BITS_PER_LONG, the shift operators turn into
no-ops (at least on x86), so one get *dst = *src, whereas one would
expect to get *dst=0. That difference in behaviour is somewhat
annoying.
This patch (of 18):
The compiler can generate slightly smaller and simpler code when it
knows that "nbits" is non-negative. Since no-one passes a negative
bit-count, this shouldn't affect the semantics.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-08-07 03:09:49 +04:00
|
|
|
static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
|
|
|
|
else
|
|
|
|
return __bitmap_empty(src, nbits);
|
|
|
|
}
|
|
|
|
|
2014-08-07 03:09:51 +04:00
|
|
|
static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
|
|
|
|
else
|
|
|
|
return __bitmap_full(src, nbits);
|
|
|
|
}
|
|
|
|
|
2014-08-07 03:10:05 +04:00
|
|
|
static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2006-06-26 15:57:10 +04:00
|
|
|
return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
|
2005-04-17 02:20:36 +04:00
|
|
|
return __bitmap_weight(src, nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bitmap_shift_right(unsigned long *dst,
|
|
|
|
const unsigned long *src, int n, int nbits)
|
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2014-08-07 03:10:20 +04:00
|
|
|
*dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> n;
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
|
|
|
__bitmap_shift_right(dst, src, n, nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bitmap_shift_left(unsigned long *dst,
|
|
|
|
const unsigned long *src, int n, int nbits)
|
|
|
|
{
|
2008-12-30 01:35:13 +03:00
|
|
|
if (small_const_nbits(nbits))
|
2005-04-17 02:20:36 +04:00
|
|
|
*dst = (*src << n) & BITMAP_LAST_WORD_MASK(nbits);
|
|
|
|
else
|
|
|
|
__bitmap_shift_left(dst, src, n, nbits);
|
|
|
|
}
|
|
|
|
|
2006-10-11 12:21:55 +04:00
|
|
|
static inline int bitmap_parse(const char *buf, unsigned int buflen,
|
|
|
|
unsigned long *maskp, int nmaskbits)
|
|
|
|
{
|
|
|
|
return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
|
|
|
|
#endif /* __LINUX_BITMAP_H */
|