Skip to content

Commit 2d13e6c

Browse files
Noam Camustorvalds
authored andcommitted
lib/bitmap.c: enhance bitmap syntax
Today there are platforms with many CPUs (up to 4K). Trying to boot only part of the CPUs may result in too long string. For example lets take NPS platform that is part of arch/arc. This platform have SMP system with 256 cores each with 16 HW threads (SMT machine) where HW thread appears as CPU to the kernel. In this example there is total of 4K CPUs. When one tries to boot only part of the HW threads from each core the string representing the map may be long... For example if for sake of performance we decided to boot only first half of HW threads of each core the map will look like: 0-7,16-23,32-39,...,4080-4087 This patch introduce new syntax to accommodate with such use case. I added an optional postfix to a range of CPUs which will choose according to given modulo the desired range of reminders i.e.: <cpus range>:sed_size/group_size For example, above map can be described in new syntax like this: 0-4095:8/16 Note that this patch is backward compatible with current syntax. [akpm@linux-foundation.org: rework documentation] Link: http://lkml.kernel.org/r/1473579629-4283-1-git-send-email-noamca@mellanox.com Signed-off-by: Noam Camus <noamca@mellanox.com> Cc: David Decotigny <decot@googlers.com> Cc: Ben Hutchings <ben@decadent.org.uk> Cc: David S. Miller <davem@davemloft.net> Cc: Pan Xinhui <xinhui@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8cfd56d commit 2d13e6c

2 files changed

Lines changed: 82 additions & 18 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ can also be entered as
3333
Double-quotes can be used to protect spaces in values, e.g.:
3434
param="spaces in here"
3535

36+
cpu lists:
37+
----------
38+
39+
Some kernel parameters take a list of CPUs as a value, e.g. isolcpus,
40+
nohz_full, irqaffinity, rcu_nocbs. The format of this list is:
41+
42+
<cpu number>,...,<cpu number>
43+
44+
or
45+
46+
<cpu number>-<cpu number>
47+
(must be a positive range in ascending order)
48+
49+
or a mixture
50+
51+
<cpu number>,...,<cpu number>-<cpu number>
52+
53+
Note that for the special case of a range one can split the range into equal
54+
sized groups and for each group use some amount from the beginning of that
55+
group:
56+
57+
<cpu number>-cpu number>:<used size>/<group size>
58+
59+
For example one can add to the command line following parameter:
60+
61+
isolcpus=1,2,10-20,100-2000:2/25
62+
63+
where the final item represents CPUs 100,101,125,126,150,151,...
64+
65+
66+
3667
This document may not be entirely up to date and comprehensive. The command
3768
"modinfo -p ${modulename}" shows a current list of all parameters of a loadable
3869
module. Loadable modules, after being loaded into the running kernel, also
@@ -1789,13 +1820,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
17891820
See Documentation/filesystems/nfs/nfsroot.txt.
17901821

17911822
irqaffinity= [SMP] Set the default irq affinity mask
1792-
Format:
1793-
<cpu number>,...,<cpu number>
1794-
or
1795-
<cpu number>-<cpu number>
1796-
(must be a positive range in ascending order)
1797-
or a mixture
1798-
<cpu number>,...,<cpu number>-<cpu number>
1823+
The argument is a cpu list, as described above.
17991824

18001825
irqfixup [HW]
18011826
When an interrupt is not handled search all handlers
@@ -1812,13 +1837,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
18121837
Format: <RDP>,<reset>,<pci_scan>,<verbosity>
18131838

18141839
isolcpus= [KNL,SMP] Isolate CPUs from the general scheduler.
1815-
Format:
1816-
<cpu number>,...,<cpu number>
1817-
or
1818-
<cpu number>-<cpu number>
1819-
(must be a positive range in ascending order)
1820-
or a mixture
1821-
<cpu number>,...,<cpu number>-<cpu number>
1840+
The argument is a cpu list, as described above.
18221841

18231842
This option can be used to specify one or more CPUs
18241843
to isolate from the general SMP balancing and scheduling
@@ -2680,6 +2699,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
26802699
Default: on
26812700

26822701
nohz_full= [KNL,BOOT]
2702+
The argument is a cpu list, as described above.
26832703
In kernels built with CONFIG_NO_HZ_FULL=y, set
26842704
the specified list of CPUs whose tick will be stopped
26852705
whenever possible. The boot CPU will be forced outside
@@ -3285,6 +3305,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
32853305
See Documentation/blockdev/ramdisk.txt.
32863306

32873307
rcu_nocbs= [KNL]
3308+
The argument is a cpu list, as described above.
3309+
32883310
In kernels built with CONFIG_RCU_NOCB_CPU=y, set
32893311
the specified list of CPUs to be no-callback CPUs.
32903312
Invocation of these CPUs' RCU callbacks will

‎lib/bitmap.c‎

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);
496496
* ranges. Consecutively set bits are shown as two hyphen-separated
497497
* decimal numbers, the smallest and largest bit numbers set in
498498
* the range.
499+
* Optionally each range can be postfixed to denote that only parts of it
500+
* should be set. The range will divided to groups of specific size.
501+
* From each group will be used only defined amount of bits.
502+
* Syntax: range:used_size/group_size
503+
* Example: 0-1023:2/256 ==> 0,1,256,257,512,513,768,769
499504
*
500505
* Returns 0 on success, -errno on invalid input strings.
501506
* Error values:
@@ -507,16 +512,20 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
507512
int is_user, unsigned long *maskp,
508513
int nmaskbits)
509514
{
510-
unsigned a, b;
515+
unsigned int a, b, old_a, old_b;
516+
unsigned int group_size, used_size;
511517
int c, old_c, totaldigits, ndigits;
512518
const char __user __force *ubuf = (const char __user __force *)buf;
513-
int at_start, in_range;
519+
int at_start, in_range, in_partial_range;
514520

515521
totaldigits = c = 0;
522+
old_a = old_b = 0;
523+
group_size = used_size = 0;
516524
bitmap_zero(maskp, nmaskbits);
517525
do {
518526
at_start = 1;
519527
in_range = 0;
528+
in_partial_range = 0;
520529
a = b = 0;
521530
ndigits = totaldigits;
522531

@@ -547,6 +556,24 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
547556
if ((totaldigits != ndigits) && isspace(old_c))
548557
return -EINVAL;
549558

559+
if (c == '/') {
560+
used_size = a;
561+
at_start = 1;
562+
in_range = 0;
563+
a = b = 0;
564+
continue;
565+
}
566+
567+
if (c == ':') {
568+
old_a = a;
569+
old_b = b;
570+
at_start = 1;
571+
in_range = 0;
572+
in_partial_range = 1;
573+
a = b = 0;
574+
continue;
575+
}
576+
550577
if (c == '-') {
551578
if (at_start || in_range)
552579
return -EINVAL;
@@ -567,15 +594,30 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
567594
}
568595
if (ndigits == totaldigits)
569596
continue;
597+
if (in_partial_range) {
598+
group_size = a;
599+
a = old_a;
600+
b = old_b;
601+
old_a = old_b = 0;
602+
}
570603
/* if no digit is after '-', it's wrong*/
571604
if (at_start && in_range)
572605
return -EINVAL;
573-
if (!(a <= b))
606+
if (!(a <= b) || !(used_size <= group_size))
574607
return -EINVAL;
575608
if (b >= nmaskbits)
576609
return -ERANGE;
577610
while (a <= b) {
578-
set_bit(a, maskp);
611+
if (in_partial_range) {
612+
static int pos_in_group = 1;
613+
614+
if (pos_in_group <= used_size)
615+
set_bit(a, maskp);
616+
617+
if (a == b || ++pos_in_group > group_size)
618+
pos_in_group = 1;
619+
} else
620+
set_bit(a, maskp);
579621
a++;
580622
}
581623
} while (buflen && c == ',');

0 commit comments

Comments
 (0)