Skip to content

Commit 22f2e28

Browse files
Derek FultsLinus Torvalds
authored andcommitted
[PATCH] get_options to allow a hypenated range for isolcpus
This allows a hyphenated range of positive numbers in the string passed to command line helper function, get_options. Currently the command line option "isolcpus=" takes as its argument a list of cpus. Format: <cpu number>,...,<cpu number> Valid values of <cpu_number> include all cpus, 0 to "number of CPUs in system - 1". This can get extremely long when isolating the majority of cpus on a large system. The kernel isolcpus code would not need any changing to use this feature. To use it, the change would be in the command line format for 'isolcpus=' Format: <cpu number>,...,<cpu number> or <cpu number>-<cpu number> (must be a positive range in ascending order.) or a mixture <cpu number>,...,<cpu number>-<cpu number> Signed-off-by: Derek Fults <dfults@sgi.com> Cc: "Randy.Dunlap" <rdunlap@xenotime.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 8f63fdb commit 22f2e28

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,12 @@ and is between 256 and 4096 characters. It is defined in the file
714714
Format: <RDP>,<reset>,<pci_scan>,<verbosity>
715715

716716
isolcpus= [KNL,SMP] Isolate CPUs from the general scheduler.
717-
Format: <cpu number>,...,<cpu number>
717+
Format:
718+
<cpu number>,...,<cpu number>
719+
or
720+
<cpu number>-<cpu number> (must be a positive range in ascending order)
721+
or a mixture
722+
<cpu number>,...,<cpu number>-<cpu number>
718723
This option can be used to specify one or more CPUs
719724
to isolate from the general SMP balancing and scheduling
720725
algorithms. The only way to move a process onto or off

‎lib/cmdline.c‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@
1616
#include <linux/kernel.h>
1717
#include <linux/string.h>
1818

19+
/*
20+
* If a hyphen was found in get_option, this will handle the
21+
* range of numbers, M-N. This will expand the range and insert
22+
* the values[M, M+1, ..., N] into the ints array in get_options.
23+
*/
24+
25+
static int get_range(char **str, int *pint)
26+
{
27+
int x, inc_counter, upper_range;
28+
29+
(*str)++;
30+
upper_range = simple_strtol((*str), NULL, 0);
31+
inc_counter = upper_range - *pint;
32+
for (x = *pint; x < upper_range; x++)
33+
*pint++ = x;
34+
return inc_counter;
35+
}
1936

2037
/**
2138
* get_option - Parse integer from an option string
@@ -29,6 +46,7 @@
2946
* 0 : no int in string
3047
* 1 : int found, no subsequent comma
3148
* 2 : int found including a subsequent comma
49+
* 3 : hyphen found to denote a range
3250
*/
3351

3452
int get_option (char **str, int *pint)
@@ -44,6 +62,8 @@ int get_option (char **str, int *pint)
4462
(*str)++;
4563
return 2;
4664
}
65+
if (**str == '-')
66+
return 3;
4767

4868
return 1;
4969
}
@@ -55,7 +75,8 @@ int get_option (char **str, int *pint)
5575
* @ints: integer array
5676
*
5777
* This function parses a string containing a comma-separated
58-
* list of integers. The parse halts when the array is
78+
* list of integers, a hyphen-separated range of _positive_ integers,
79+
* or a combination of both. The parse halts when the array is
5980
* full, or when no more numbers can be retrieved from the
6081
* string.
6182
*
@@ -72,6 +93,18 @@ char *get_options(const char *str, int nints, int *ints)
7293
res = get_option ((char **)&str, ints + i);
7394
if (res == 0)
7495
break;
96+
if (res == 3) {
97+
int range_nums;
98+
range_nums = get_range((char **)&str, ints + i);
99+
if (range_nums < 0)
100+
break;
101+
/*
102+
* Decrement the result by one to leave out the
103+
* last number in the range. The next iteration
104+
* will handle the upper number in the range
105+
*/
106+
i += (range_nums - 1);
107+
}
75108
i++;
76109
if (res == 1)
77110
break;

0 commit comments

Comments
 (0)