Skip to content

Commit 36d4b36

Browse files
committed
lib/nodemask: inline next_node_in() and node_random()
The functions are pretty thin wrappers around find_bit engine, and keeping them in c-file prevents compiler from small_const_nbits() optimization, which must take place for all systems with MAX_NUMNODES less than BITS_PER_LONG (default is 16 for me). Moving them to header file doesn't blow up the kernel size: add/remove: 1/2 grow/shrink: 9/5 up/down: 968/-88 (880) CC: Andy Shevchenko <[email protected]> CC: Benjamin Herrenschmidt <[email protected]> CC: Michael Ellerman <[email protected]> CC: Paul Mackerras <[email protected]> CC: Rasmus Villemoes <[email protected]> CC: Stephen Rothwell <[email protected]> CC: [email protected] Signed-off-by: Yury Norov <[email protected]>
1 parent 3e73120 commit 36d4b36

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3540,7 +3540,6 @@ F: lib/bitmap.c
35403540
F: lib/cpumask.c
35413541
F: lib/find_bit.c
35423542
F: lib/find_bit_benchmark.c
3543-
F: lib/nodemask.c
35443543
F: lib/test_bitmap.c
35453544
F: tools/include/linux/bitmap.h
35463545
F: tools/include/linux/find.h

include/linux/nodemask.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include <linux/bitmap.h>
9595
#include <linux/minmax.h>
9696
#include <linux/numa.h>
97+
#include <linux/random.h>
9798

9899
typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
99100
extern nodemask_t _unused_nodemask_arg_;
@@ -276,7 +277,14 @@ static inline unsigned int __next_node(int n, const nodemask_t *srcp)
276277
* the first node in src if needed. Returns MAX_NUMNODES if src is empty.
277278
*/
278279
#define next_node_in(n, src) __next_node_in((n), &(src))
279-
unsigned int __next_node_in(int node, const nodemask_t *srcp);
280+
static inline unsigned int __next_node_in(int node, const nodemask_t *srcp)
281+
{
282+
unsigned int ret = __next_node(node, srcp);
283+
284+
if (ret == MAX_NUMNODES)
285+
ret = __first_node(srcp);
286+
return ret;
287+
}
280288

281289
static inline void init_nodemask_of_node(nodemask_t *mask, int node)
282290
{
@@ -493,14 +501,20 @@ static inline int num_node_state(enum node_states state)
493501

494502
#endif
495503

504+
static inline int node_random(const nodemask_t *maskp)
505+
{
496506
#if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1)
497-
extern int node_random(const nodemask_t *maskp);
507+
int w, bit = NUMA_NO_NODE;
508+
509+
w = nodes_weight(*maskp);
510+
if (w)
511+
bit = bitmap_ord_to_pos(maskp->bits,
512+
get_random_int() % w, MAX_NUMNODES);
513+
return bit;
498514
#else
499-
static inline int node_random(const nodemask_t *mask)
500-
{
501515
return 0;
502-
}
503516
#endif
517+
}
504518

505519
#define node_online_map node_states[N_ONLINE]
506520
#define node_possible_map node_states[N_POSSIBLE]

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
3333
flex_proportions.o ratelimit.o show_mem.o \
3434
is_single_threaded.o plist.o decompress.o kobject_uevent.o \
3535
earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
36-
nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \
36+
nmi_backtrace.o win_minmax.o memcat_p.o \
3737
buildid.o
3838

3939
lib-$(CONFIG_PRINTK) += dump_stack.o

lib/nodemask.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
#include <linux/module.h>
44
#include <linux/random.h>
55

6-
unsigned int __next_node_in(int node, const nodemask_t *srcp)
7-
{
8-
unsigned int ret = __next_node(node, srcp);
9-
10-
if (ret == MAX_NUMNODES)
11-
ret = __first_node(srcp);
12-
return ret;
13-
}
146
EXPORT_SYMBOL(__next_node_in);
157

168
#ifdef CONFIG_NUMA

0 commit comments

Comments
 (0)