Skip to content

Commit 2248ccd

Browse files
svanheuleYuryNorov
authored andcommitted
lib/cpumask: add inline cpumask_next_wrap() for UP
In the uniprocessor case, cpumask_next_wrap() can be simplified, as the number of valid argument combinations is limited: - 'start' can only be 0 - 'n' can only be -1 or 0 The only valid CPU that can then be returned, if any, will be the first one set in the provided 'mask'. For NR_CPUS == 1, include/linux/cpumask.h now provides an inline definition of cpumask_next_wrap(), which will conflict with the one provided by lib/cpumask.c. Make building of lib/cpumask.o again depend on CONFIG_SMP=y (i.e. NR_CPUS > 1) to avoid the re-definition. Suggested-by: Yury Norov <[email protected]> Signed-off-by: Sander Vanheule <[email protected]> Signed-off-by: Yury Norov <[email protected]>
1 parent be59924 commit 2248ccd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

include/linux/cpumask.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,26 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
262262
(cpu) = cpumask_next_zero((cpu), (mask)), \
263263
(cpu) < nr_cpu_ids;)
264264

265+
#if NR_CPUS == 1
266+
static inline
267+
unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
268+
{
269+
cpumask_check(start);
270+
if (n != -1)
271+
cpumask_check(n);
272+
273+
/*
274+
* Return the first available CPU when wrapping, or when starting before cpu0,
275+
* since there is only one valid option.
276+
*/
277+
if (wrap && n >= 0)
278+
return nr_cpumask_bits;
279+
280+
return cpumask_first(mask);
281+
}
282+
#else
265283
unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap);
284+
#endif
266285

267286
/**
268287
* for_each_cpu_wrap - iterate over every cpu in a mask, starting at a specified location

lib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ lib-y := ctype.o string.o vsprintf.o cmdline.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 \
3636
nmi_backtrace.o win_minmax.o memcat_p.o \
37-
buildid.o cpumask.o
37+
buildid.o
3838

3939
lib-$(CONFIG_PRINTK) += dump_stack.o
40+
lib-$(CONFIG_SMP) += cpumask.o
4041

4142
lib-y += kobject.o klist.o
4243
obj-y += lockref.o

0 commit comments

Comments
 (0)