While this is done for all bitmaps, the original use case in mind was for CPU masks and cpulist_parse() as described below.
It seems that a common configuration is to use the 1st couple cores for housekeeping tasks. This tends to leave the remaining ones to form a pool of similarly configured cores to take on the real workload of interest to the user. So on machine A - with 32 cores, it could be 0-3 for "system" and then 4-31 being used in boot args like nohz_full=, or rcu_nocbs= as part of setting up the worker pool of CPUs. But then newer machine B is added, and it has 48 cores, and so while the 0-3 part remains unchanged, the pool setup cpu list becomes 4-47. Multiple deployment becomes easier when we can just simply replace 31 and 47 with "N" and let the system substitute in the actual number at boot; a number that it knows better than we do. Cc: Yury Norov <yury.no...@gmail.com> Cc: Peter Zijlstra <pet...@infradead.org> Cc: "Paul E. McKenney" <paul...@kernel.org> Cc: Rasmus Villemoes <li...@rasmusvillemoes.dk> Cc: Andy Shevchenko <andriy.shevche...@linux.intel.com> Suggested-by: Yury Norov <yury.no...@gmail.com> Signed-off-by: Paul Gortmaker <paul.gortma...@windriver.com> --- Documentation/admin-guide/kernel-parameters.rst | 2 ++ lib/bitmap.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.rst b/Documentation/admin-guide/kernel-parameters.rst index 682ab28b5c94..850917f19476 100644 --- a/Documentation/admin-guide/kernel-parameters.rst +++ b/Documentation/admin-guide/kernel-parameters.rst @@ -68,6 +68,8 @@ For example one can add to the command line following parameter: where the final item represents CPUs 100,101,125,126,150,151,... +The value "N" can be used to represent the numerically last CPU on the system, +i.e "foo_cpus=16-N" would be equivalent to "16-31" on a 32 core system. This document may not be entirely up to date and comprehensive. The command diff --git a/lib/bitmap.c b/lib/bitmap.c index f65be2f148fd..2fdd00b312c3 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -519,11 +519,17 @@ static int bitmap_check_region(const struct region *r) return 0; } -static const char *bitmap_getnum(const char *str, unsigned int *num) +static const char *__bitmap_getnum(const char *str, unsigned int nbits, + unsigned int *num) { unsigned long long n; unsigned int len; + if (str[0] == 'N') { + *num = nbits - 1; + return str + 1; + } + len = _parse_integer(str, 10, &n); if (!len) return ERR_PTR(-EINVAL); @@ -533,7 +539,7 @@ static const char *bitmap_getnum(const char *str, unsigned int *num) *num = n; return str + len; } -#define bitmap_getrnum(s, r, pos) bitmap_getnum(s, &(r->pos)) +#define bitmap_getrnum(s, r, pos) __bitmap_getnum(s, r->nbits, &(r->pos)) static inline bool end_of_str(char c) { @@ -626,6 +632,8 @@ static const char *bitmap_parse_region(const char *str, struct region *r) * From each group will be used only defined amount of bits. * Syntax: range:used_size/group_size * Example: 0-1023:2/256 ==> 0,1,256,257,512,513,768,769 + * The value 'N' can be used as a dynamically substituted token for the + * maximum allowed value; i.e (nmaskbits - 1). * * Returns: 0 on success, -errno on invalid input strings. Error values: * -- 2.17.1