lib/bitmap.c: enhance map pattern
Subsystems (3)
PATCH 1/1 lib/bitmap.c: enhance map pattern
From: Noam Camus <[email protected]>
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 format 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.:
<cpu range>%modulo=<range of reminders>
For example above pattern can be described in new format like this:
0-4095%16=0-7
Note that this patch is backward compatible.
--- lib/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-)
lib/bitmap.c +40 -4
@@ -496,6 +496,9 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);* ranges. Consecutively set bits are shown as two hyphen-separated * decimal numbers, the smallest and largest bit numbers set in * the range. +* Optionally each range can be postfixed to denote that only parts of it +* should be set. The parts are the range of reminders modulo some value. +* i.e. range%mod=rem_range e.g. 0-1023%256=0-2 ==> 0,1,256,257,512,513,768,769 * * Returns 0 on success, -errno on invalid input strings. * Error values:
@@ -507,12 +510,14 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, int is_user, unsigned long *maskp, int nmaskbits) { - unsigned a, b; + unsigned int a, b, old_a, old_b, mod_val, mod_a, mod_b;int c, old_c, totaldigits, ndigits;const char __user __force *ubuf = (const char __user __force *)buf;int at_start, in_range; totaldigits = c =0 ; + old_a = old_b =0 ; + mod_val = mod_a = mod_b =0 ;bitmap_zero (maskp, nmaskbits); do { at_start = 1;
@@ -547,6 +552,23 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,if ((totaldigits != ndigits) &&isspace (old_c))return -EINVAL ; +if (c =='=' ) { + mod_val = a; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } + +if (c =='%' ) { + old_a = a; + old_b = b; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } +if (c =='-' ) {if (at_start || in_range)return -EINVAL ;
@@ -567,17 +589,31 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, }if (ndigits == totaldigits)continue ; +if (mod_val) { + mod_a = a; + mod_b = b; + a = old_a; + b = old_b; + old_a = old_b =0 ; + }/* if no digit is after '-', it's wrong*/ if (at_start && in_range)return -EINVAL ; -if (!(a <= b)) +if (!(a <= b) || !(mod_a <= mod_b))return -EINVAL ; -if (b >= nmaskbits) +if (b >= nmaskbits || (mod_val && (mod_b >= mod_val)))return -ERANGE ;while (a <= b) { -set_bit (a, maskp); +if (mod_val) { +unsigned int rem = a % mod_val; + +if (rem >= mod_a && rem <= mod_b) +set_bit (a, maskp); + }else +set_bit (a, maskp); a++; } + mod_val = mod_a = mod_b =0 ; }while (buflen && c ==',' );return 0 ; }
Signature · 1 line
1.7.1
Quoted 15 lines · Noam Camus
From: Noam Camus <[email protected]>
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
Quoted 4 lines
This patch introduce new format 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.:
%modulo=
This is a fairly awful syntax, and I question whether it belongs in this generic code.
[...]
Quoted 3 lines
+ * Optionally each range can be postfixed to denote that only parts of it
+ * should be set. The parts are the range of reminders modulo some value.
+ * i.e. range%mod=rem_range e.g. 0-1023%256=0-2 ==> 0,1,256,257,512,513,768,769
[...]
This example seems to be wrong - did you mean '=0-1'?
Ben.
Signature · 2 lines
Ben Hutchings Once a job is fouled up, anything done to improve it makes it worse.
PATCH v2 1/1 lib/bitmap.c: enhance bitmap syntax
In reply to Noam CamusFrom: Noam Camus <[email protected]>
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>%modulo=<range of reminders>
For example, above map can be described in new symtax like this:
0-4095%16=0-7
Note that this patch is backward compatible with current syntax.
---
Change Log:
Fixed typo at below example:
"0-1023%256=0-2" turned into "0-1023%256=0-1"
Syntax need to be yet more eligible for such generic code, ideas are welcomed.
--- lib/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-)
lib/bitmap.c +40 -4
@@ -496,6 +496,9 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);* ranges. Consecutively set bits are shown as two hyphen-separated * decimal numbers, the smallest and largest bit numbers set in * the range. +* Optionally each range can be postfixed to denote that only parts of it +* should be set. The parts are the range of reminders modulo some value. +* i.e. range%mod=rem_range e.g. 0-1023%256=0-1 ==> 0,1,256,257,512,513,768,769 * * Returns 0 on success, -errno on invalid input strings. * Error values:
@@ -507,12 +510,14 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, int is_user, unsigned long *maskp, int nmaskbits) { - unsigned a, b; + unsigned int a, b, old_a, old_b, mod_val, mod_a, mod_b;int c, old_c, totaldigits, ndigits;const char __user __force *ubuf = (const char __user __force *)buf;int at_start, in_range; totaldigits = c =0 ; + old_a = old_b =0 ; + mod_val = mod_a = mod_b =0 ;bitmap_zero (maskp, nmaskbits); do { at_start = 1;
@@ -547,6 +552,23 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,if ((totaldigits != ndigits) &&isspace (old_c))return -EINVAL ; +if (c =='=' ) { + mod_val = a; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } + +if (c =='%' ) { + old_a = a; + old_b = b; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } +if (c =='-' ) {if (at_start || in_range)return -EINVAL ;
@@ -567,17 +589,31 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, }if (ndigits == totaldigits)continue ; +if (mod_val) { + mod_a = a; + mod_b = b; + a = old_a; + b = old_b; + old_a = old_b =0 ; + }/* if no digit is after '-', it's wrong*/ if (at_start && in_range)return -EINVAL ; -if (!(a <= b)) +if (!(a <= b) || !(mod_a <= mod_b))return -EINVAL ; -if (b >= nmaskbits) +if (b >= nmaskbits || (mod_val && (mod_b >= mod_val)))return -ERANGE ;while (a <= b) { -set_bit (a, maskp); +if (mod_val) { +unsigned int rem = a % mod_val; + +if (rem >= mod_a && rem <= mod_b) +set_bit (a, maskp); + }else +set_bit (a, maskp); a++; } + mod_val = mod_a = mod_b =0 ; }while (buflen && c ==',' );return 0 ; }
Signature · 1 line
1.7.1
PATCH v3 1/1 lib/bitmap.c: enhance bitmap syntax
From: Noam Camus <[email protected]>
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>%modulo=<range of reminders>
For example, above map can be described in new syntax like this:
0-4095%16=0-7
Note that this patch is backward compatible with current syntax.
---
Any sugestions for simpler syntax which keeps its generality are welcomed.
Change Log:
V2: Fix typo in example at function header for __bitmap_parselist()
V3: Fix typo in commit log and also typo at example
--- lib/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-)
lib/bitmap.c +40 -4
@@ -496,6 +496,9 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);* ranges. Consecutively set bits are shown as two hyphen-separated * decimal numbers, the smallest and largest bit numbers set in * the range. +* Optionally each range can be postfixed to denote that only parts of it +* should be set. The parts are the range of reminders modulo some value. +* i.e. range%mod=rem_range e.g. 0-1023%256=0-1 ==> 0,1,256,257,512,513,768,769 * * Returns 0 on success, -errno on invalid input strings. * Error values:
@@ -507,12 +510,14 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, int is_user, unsigned long *maskp, int nmaskbits) { - unsigned a, b; + unsigned int a, b, old_a, old_b, mod_val, mod_a, mod_b;int c, old_c, totaldigits, ndigits;const char __user __force *ubuf = (const char __user __force *)buf;int at_start, in_range; totaldigits = c =0 ; + old_a = old_b =0 ; + mod_val = mod_a = mod_b =0 ;bitmap_zero (maskp, nmaskbits); do { at_start = 1;
@@ -547,6 +552,23 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,if ((totaldigits != ndigits) &&isspace (old_c))return -EINVAL ; +if (c =='=' ) { + mod_val = a; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } + +if (c =='%' ) { + old_a = a; + old_b = b; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } +if (c =='-' ) {if (at_start || in_range)return -EINVAL ;
@@ -567,17 +589,31 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, }if (ndigits == totaldigits)continue ; +if (mod_val) { + mod_a = a; + mod_b = b; + a = old_a; + b = old_b; + old_a = old_b =0 ; + }/* if no digit is after '-', it's wrong*/ if (at_start && in_range)return -EINVAL ; -if (!(a <= b)) +if (!(a <= b) || !(mod_a <= mod_b))return -EINVAL ; -if (b >= nmaskbits) +if (b >= nmaskbits || (mod_val && (mod_b >= mod_val)))return -ERANGE ;while (a <= b) { -set_bit (a, maskp); +if (mod_val) { +unsigned int rem = a % mod_val; + +if (rem >= mod_a && rem <= mod_b) +set_bit (a, maskp); + }else +set_bit (a, maskp); a++; } + mod_val = mod_a = mod_b =0 ; }while (buflen && c ==',' );return 0 ; }
Signature · 1 line
1.7.1
Re: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Quoted 15 lines · Noam Camus
From: Noam Camus <[email protected]>
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
Quoted 8 lines
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>%modulo=<range of reminders>For example, above map can be described in new syntax like this:
0-4095%16=0-7
I really think it is better to implement one function to generic a string which contanis the cpus you want to boot on, then pass this string to __bitmap_parselist.
Quoted 103 lines
Note that this patch is backward compatible with current syntax.
Signed-off-by Noam Camus <[email protected]>---
Any sugestions for simpler syntax which keeps its generality are welcomed.Change Log:
V2: Fix typo in example at function header for__bitmap_parselist()
V3: Fix typo in commit log and also typo at example--- lib/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-)lib/bitmap.c +40
-4@@ -496,6 +496,9 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);* ranges. Consecutively set bits are shown as two hyphen-separated * decimal numbers, the smallest and largest bit numbers set in * the range. +* Optionally each range can be postfixed to denote that only parts of it +* should be set. The parts are the range of reminders modulo some value. +* i.e. range%mod=rem_range e.g. 0-1023%256=0-1 ==> 0,1,256,257,512,513,768,769 * * Returns 0 on success, -errno on invalid input strings. * Error values: @@ -507,12 +510,14 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, int is_user, unsigned long *maskp, int nmaskbits) { - unsigned a, b; + unsigned int a, b, old_a, old_b, mod_val, mod_a, mod_b;int c, old_c, totaldigits, ndigits;const char __user __force *ubuf = (const char __user __force *)buf;int at_start, in_range; totaldigits = c =0 ; + old_a = old_b =0 ; + mod_val = mod_a = mod_b =0 ;bitmap_zero (maskp, nmaskbits); do { at_start = 1;@@ -547,6 +552,23 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,if ((totaldigits != ndigits) &&isspace (old_c))return -EINVAL ; +if (c =='=' ) { + mod_val = a; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } + +if (c =='%' ) { + old_a = a; + old_b = b; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } +if (c =='-' ) {if (at_start || in_range)return -EINVAL ;@@ -567,17 +589,31 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, }if (ndigits == totaldigits)continue ; +if (mod_val) { + mod_a = a; + mod_b = b; + a = old_a; + b = old_b; + old_a = old_b =0 ; + }/* if no digit is after '-', it's wrong*/ if (at_start && in_range)return -EINVAL ; -if (!(a <= b)) +if (!(a <= b) || !(mod_a <= mod_b))return -EINVAL ; -if (b >= nmaskbits) +if (b >= nmaskbits || (mod_val && (mod_b >= mod_val)))return -ERANGE ;while (a <= b) { -set_bit (a, maskp); +if (mod_val) { +unsigned int rem = a % mod_val; + +if (rem >= mod_a && rem <= mod_b) +set_bit (a, maskp); + }else +set_bit (a, maskp); a++; } + mod_val = mod_a = mod_b =0 ; }while (buflen && c ==',' );return 0 ; }
Re: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Quoted 23 lines · Pan Xinhui
Quoted 20 lines · Noam Camus
From: Noam Camus <[email protected]>
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-4087This 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>%modulo=<range of reminders>
Quoted 6 lines
Quoted 3 lines
For example, above map can be described in new syntax like this:
0-4095%16=0-7I really think it is better to implement one function to generic a string which contanis the cpus you want to boot on, then pass this string to
__bitmap_parselist.
sorry, typos.
generic -> generate.
Quoted 103 lines
Quoted 103 lines
Note that this patch is backward compatible with current syntax.
Signed-off-by Noam Camus <[email protected]>---
Any sugestions for simpler syntax which keeps its generality are welcomed.Change Log:
V2: Fix typo in example at function header for__bitmap_parselist()
V3: Fix typo in commit log and also typo at example--- lib/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-)lib/bitmap.c +40
-4@@ -496,6 +496,9 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);* ranges. Consecutively set bits are shown as two hyphen-separated * decimal numbers, the smallest and largest bit numbers set in * the range. +* Optionally each range can be postfixed to denote that only parts of it +* should be set. The parts are the range of reminders modulo some value. +* i.e. range%mod=rem_range e.g. 0-1023%256=0-1 ==> 0,1,256,257,512,513,768,769 * * Returns 0 on success, -errno on invalid input strings. * Error values: @@ -507,12 +510,14 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, int is_user, unsigned long *maskp, int nmaskbits) { - unsigned a, b; + unsigned int a, b, old_a, old_b, mod_val, mod_a, mod_b;int c, old_c, totaldigits, ndigits;const char __user __force *ubuf = (const char __user __force *)buf;int at_start, in_range; totaldigits = c =0 ; + old_a = old_b =0 ; + mod_val = mod_a = mod_b =0 ;bitmap_zero (maskp, nmaskbits); do { at_start = 1;@@ -547,6 +552,23 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,if ((totaldigits != ndigits) &&isspace (old_c))return -EINVAL ; +if (c =='=' ) { + mod_val = a; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } + +if (c =='%' ) { + old_a = a; + old_b = b; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } +if (c =='-' ) {if (at_start || in_range)return -EINVAL ;@@ -567,17 +589,31 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, }if (ndigits == totaldigits)continue ; +if (mod_val) { + mod_a = a; + mod_b = b; + a = old_a; + b = old_b; + old_a = old_b =0 ; + }/* if no digit is after '-', it's wrong*/ if (at_start && in_range)return -EINVAL ; -if (!(a <= b)) +if (!(a <= b) || !(mod_a <= mod_b))return -EINVAL ; -if (b >= nmaskbits) +if (b >= nmaskbits || (mod_val && (mod_b >= mod_val)))return -ERANGE ;while (a <= b) { -set_bit (a, maskp); +if (mod_val) { +unsigned int rem = a % mod_val; + +if (rem >= mod_a && rem <= mod_b) +set_bit (a, maskp); + }else +set_bit (a, maskp); a++; } + mod_val = mod_a = mod_b =0 ; }while (buflen && c ==',' );return 0 ; }
RE: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Quoted 8 lines
From: Pan Xinhui [mailto:[email protected]]
Sent: Sunday, July 17, 2016 4:59 PMQuoted 3 lines
I really think it is better to implement one function to generic a string which contanis the cpus you want to boot on, then pass this string to
__bitmap_parselist.sorry, typos.
generic -> generate.
Please explain how this will solve the syntax issue Ben commented on?
Another syntax which might be simpler is:
<first cpu-last cpu>:<numcpus selected from group>/<cpus group size> e.g.
0-1023:1/2 <==> 0,2,4,...,1022
1-1023:1/2 <==> 1,3,5,...,1023
So basically no need for modulo only divide the list into groups of cpus and for each group choose cpus from group start. It is basically achieves same and hopefully more simpler and more eligible for such generic code.
Please let me know what you think?
Is it good direction to change the syntax, or that I should turn into different approach (like Pan suggested)?
Noam.
RE: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Ping...
-----Original Message-----
From: Noam Camus
Sent: Monday, July 18, 2016 10:06 AM
To: Pan Xinhui <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Quoted 8 lines
From: Pan Xinhui [mailto:[email protected]]
Sent: Sunday, July 17, 2016 4:59 PMQuoted 3 lines
I really think it is better to implement one function to generic a string which contanis the cpus you want to boot on, then pass this string to
__bitmap_parselist.sorry, typos.
generic -> generate.
Please explain how this will solve the syntax issue Ben commented on?
Another syntax which might be simpler is:
<first cpu-last cpu>:<numcpus selected from group>/<cpus group size> e.g. 0-1023:1/2 <==> 0,2,4,...,1022
1-1023:1/2 <==> 1,3,5,...,1023
So basically no need for modulo only divide the list into groups of cpus and for each group choose cpus from group start. It is basically achieves same and hopefully more simpler and more eligible for such generic code.
Please let me know what you think?
Is it good direction to change the syntax, or that I should turn into different approach (like Pan suggested)?
Noam.
RE: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
In reply to Noam CamusHi Ben, Pan
This is a second ping.
Will appreciate your feedback wither changing syntax will do the change or that I need a different approach to achieve such enhancement. See below for new syntax suggestion.
-Noam
-----Original Message-----
From: Noam Camus
Sent: Monday, August 01, 2016 7:53 AM
To: 'Pan Xinhui' <[email protected]>; '[email protected]' <[email protected]>; 'Ben Hutchings' <[email protected]>
Cc: '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>
Subject: RE: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Ping...
-----Original Message-----
From: Noam Camus
Sent: Monday, July 18, 2016 10:06 AM
To: Pan Xinhui <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Quoted 8 lines
From: Pan Xinhui [mailto:[email protected]]
Sent: Sunday, July 17, 2016 4:59 PMQuoted 3 lines
I really think it is better to implement one function to generic a string which contanis the cpus you want to boot on, then pass this string to
__bitmap_parselist.sorry, typos.
generic -> generate.
Please explain how this will solve the syntax issue Ben commented on?
Another syntax which might be simpler is:
<first cpu-last cpu>:<numcpus selected from group>/<cpus group size> e.g. 0-1023:1/2 <==> 0,2,4,...,1022
1-1023:1/2 <==> 1,3,5,...,1023
So basically no need for modulo only divide the list into groups of cpus and for each group choose cpus from group start. It is basically achieves same and hopefully more simpler and more eligible for such generic code.
Please let me know what you think?
Is it good direction to change the syntax, or that I should turn into different approach (like Pan suggested)?
Noam.
Re: [PATCH v3] lib/bitmap.c: enhance bitmap syntax
Quoted 8 lines · Noam Camus
Hi Ben, Pan
This is a second ping.
Will appreciate your feedback wither changing syntax will do the change or that I need a different approach to achieve such enhancement.
See below for new syntax suggestion.
[...]
This syntax does look better to me.
Ben.
--
Ben Hutchings
Never put off till tomorrow what you can avoid all together.
PATCH v4 1/1 lib/bitmap.c: enhance bitmap syntax
In reply to Noam CamusFrom: Noam Camus <[email protected]>
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.
--- lib/bitmap.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 46 insertions(+), 4 deletions(-)
lib/bitmap.c +46 -4
@@ -496,6 +496,11 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);* ranges. Consecutively set bits are shown as two hyphen-separated * decimal numbers, the smallest and largest bit numbers set in * the range. +* Optionally each range can be postfixed to denote that only parts of it +* should be set. The range will divided to groups of specific size. +* 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 * * Returns 0 on success, -errno on invalid input strings. * Error values:
@@ -507,16 +512,20 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, int is_user, unsigned long *maskp, int nmaskbits) { - unsigned a, b; + unsigned int a, b, old_a, old_b; +unsigned int group_size, used_size;int c, old_c, totaldigits, ndigits;const char __user __force *ubuf = (const char __user __force *)buf; -int at_start, in_range; +int at_start, in_range, in_partial_range; totaldigits = c =0 ; + old_a = old_b =0 ; + group_size = used_size =0 ;bitmap_zero (maskp, nmaskbits); do { at_start = 1; in_range = 0; + in_partial_range = 0; a = b = 0; ndigits = totaldigits;
@@ -547,6 +556,24 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,if ((totaldigits != ndigits) &&isspace (old_c))return -EINVAL ; +if (c =='/' ) { + used_size = a; + at_start =1 ; + in_range =0 ; + a = b =0 ; +continue ; + } + +if (c ==':' ) { + old_a = a; + old_b = b; + at_start =1 ; + in_range =0 ; + in_partial_range =1 ; + a = b =0 ; +continue ; + } +if (c =='-' ) {if (at_start || in_range)return -EINVAL ;
@@ -567,15 +594,30 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, }if (ndigits == totaldigits)continue ; +if (in_partial_range) { + group_size = a; + a = old_a; + b = old_b; + old_a = old_b =0 ; + }/* if no digit is after '-', it's wrong*/ if (at_start && in_range)return -EINVAL ; -if (!(a <= b)) +if (!(a <= b) || !(used_size <= group_size))return -EINVAL ;if (b >= nmaskbits)return -ERANGE ;while (a <= b) { -set_bit (a, maskp); +if (in_partial_range) { +static int pos_in_group =1 ; + +if (pos_in_group <= used_size) +set_bit (a, maskp); + +if (a == b || ++pos_in_group > group_size) + pos_in_group =1 ; + }else +set_bit (a, maskp); a++; } }while (buflen && c ==',' );
Signature · 1 line
1.7.1
Andrew Morton
maintainerRe: [PATCH v4] lib/bitmap.c: enhance bitmap syntax
Quoted 13 lines · On Thu, 8 Sep 2016 18:33:25 +0300 Noam Camus <[email protected]> wrote:
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
Quoted 7 lines
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_sizeFor example, above map can be described in new syntax like this:
0-4095:8/16
There should be some updates to the user-facing documentation, please. Documentation/kernel-parameters.txt, mainly. Which boot parameters does this affect? For example, I think it accidentally alters isolcpus=?
It would be useful to see the patch which wires this up (to arch/arc?).
PATCH v5 1/1 lib/bitmap.c: enhance bitmap syntax
In reply to Noam CamusFrom: Noam Camus <[email protected]>
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.
--- Documentation/kernel-parameters.txt | 15 ++++++++++ lib/bitmap.c | 50 ++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 4 deletions(-)
Documentation/kernel-parameters.txt +15 -0
@@ -33,6 +33,21 @@ can also be entered as Double-quotes can be used to protect spaces in values, e.g.: param="spaces in here" +Some of the kernel parameters takes list of CPUs as value e.g.: +isolcpus, task_isolation, nohz_full, irqaffinity, rcu_nocbs. +The format of this list is: +<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> +Note that for special case of range one can split range into equal size of groups +and for each group to use some amount form the begin of that group. +<cpu number>-cpu number>:<used size>/<group size> +For example one can add to its command line following parameter: +isolcpus=1,2,10-20,100-2000:2/25 + This document may not be entirely up to date and comprehensive. The command "modinfo -p ${modulename}" shows a current list of all parameters of a loadable module. Loadable modules, after being loaded into the running kernel, also
lib/bitmap.c +46 -4
89 lines not on this page · raw message
Signature · 1 line
1.7.1
Andrew Morton
maintainerRe: [PATCH v5] lib/bitmap.c: enhance bitmap syntax
Quoted 36 lines · On Sun, 11 Sep 2016 10:40:29 +0300 Noam Camus <[email protected]> wrote:
From: Noam Camus <[email protected]>
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-4087This 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_sizeFor example, above map can be described in new syntax like this:
0-4095:8/16Note that this patch is backward compatible with current syntax.
Signed-off-by Noam Camus <[email protected]>--- Documentation/kernel-parameters.txt | 15 ++++++++++ lib/bitmap.c | 50 ++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 4 deletions(-)Documentation/kernel-parameters.txt +0
-0
Documentation/kernel-parameters.txt can also be entered as · line 37
Quoted 5 lines
Documentation/kernel-parameters.txt +2
-0@@ -33,6 +33,21 @@ can also be entered as Double-quotes can be used to protect spaces in values, e.g.: param="spaces in here" +Some of the kernel parameters takes list of CPUs as value e.g.: +isolcpus, task_isolation, nohz_full, irqaffinity, rcu_nocbs.
I don't think we have a "task_isolation". What are you trying to refer to here?
Documentation/kernel-parameters.txt can also be entered as · line 50
Quoted 13 lines
Documentation/kernel-parameters.txt +13
-0+The format of this list is: +<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> +Note that for special case of range one can split range into equal size of groups +and for each group to use some amount form the begin of that group. +<cpu number>-cpu number>:<used size>/<group size> +For example one can add to its command line following parameter: +isolcpus=1,2,10-20,100-2000:2/25 +
I think we can do better here. Please review:
Documentation/kernel-parameters.txt renamed from Documentation/kernel-parameters.txt~lib-bitmapc-enhance-bitmap-syntax-fix +32 -25
@@ -33,20 +33,36 @@ can also be entered as Double-quotes can be used to protect spaces in values, e.g.: param="spaces in here" -Some of the kernel parameters takes list of CPUs as value e.g.: -isolcpus, task_isolation, nohz_full, irqaffinity, rcu_nocbs. -The format of this list is: -<cpu number>,...,<cpu number> +cpu lists: +---------- + +Some kernel parameters take a list of CPUs as a value, e.g. isolcpus, +nohz_full, irqaffinity, rcu_nocbs. The format of this list is: + + <cpu number>,...,<cpu number> + or -<cpu number>-<cpu number> -(must be a positive range in ascending order) + + <cpu number>-<cpu number> + (must be a positive range in ascending order) + or a mixture + <cpu number>,...,<cpu number>-<cpu number> -Note that for special case of range one can split range into equal size of groups -and for each group to use some amount form the begin of that group. -<cpu number>-cpu number>:<used size>/<group size> -For example one can add to its command line following parameter: -isolcpus=1,2,10-20,100-2000:2/25 + +Note that for the special case of a range one can split the range into equal +sized groups and for each group use some amount from the beginning of that +group: + + <cpu number>-cpu number>:<used size>/<group size> + +For example one can add to the command line following parameter: + + isolcpus=1,2,10-20,100-2000:2/25 + +where the final item represents CPUs 100,101,125,126,150,151,... + + This document may not be entirely up to date and comprehensive. The command "modinfo -p ${modulename}" shows a current list of all parameters of a loadable
@@ -1776,13 +1792,7 @@ bytes respectively. Such letter suffixes See Documentation/filesystems/nfs/nfsroot.txt. irqaffinity= [SMP] Set the default irq affinity mask - 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> + The argument is a cpu list, as described above. irqfixup [HW] When an interrupt is not handled search all handlers
@@ -1799,13 +1809,7 @@ bytes respectively. Such letter suffixes Format: <RDP>,<reset>,<pci_scan>,<verbosity> isolcpus= [KNL,SMP] Isolate CPUs from the general scheduler. - 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> + The argument is a cpu list, as described above. This option can be used to specify one or more CPUs to isolate from the general SMP balancing and scheduling
@@ -2666,6 +2670,7 @@ bytes respectively. Such letter suffixes Default: on nohz_full= [KNL,BOOT] + The argument is a cpu list, as described above. In kernels built with CONFIG_NO_HZ_FULL=y, set the specified list of CPUs whose tick will be stopped whenever possible. The boot CPU will be forced outside
@@ -3268,6 +3273,8 @@ bytes respectively. Such letter suffixes See Documentation/blockdev/ramdisk.txt. rcu_nocbs= [KNL] + The argument is a cpu list, as described above. + In kernels built with CONFIG_RCU_NOCB_CPU=y, set the specified list of CPUs to be no-callback CPUs. Invocation of these CPUs' RCU callbacks will
RE: [PATCH v5] lib/bitmap.c: enhance bitmap syntax
Quoted 12 lines
From: Andrew Morton [mailto:[email protected]]
Sent: Wednesday, September 14, 2016 1:54 AMQuoted 9 lines
Documentation/kernel-parameters.txt +0
-0@@ -33,6 +33,21 @@ can also be entered as Double-quotes can be usedto protect spaces in values, e.g.:
param="spaces in here"
Quoted 4 lines
Documentation/kernel-parameters.txt
Quoted 2 lines
Documentation/kernel-parameters.txt +2
-0+Some of the kernel parameters takes list of CPUs as value e.g.: +isolcpus, task_isolation, nohz_full, irqaffinity, rcu_nocbs.I don't think we have a "
task_isolation". What are you trying to refer to here?
Sorry, my glitch, it is another parameter I use which is still not accepted to mainline. See this url:
https://lkml.kernel.org/g/[email protected]
Quoted 6 lines
Quoted 6 lines
Documentation/kernel-parameters.txt +6
-0+The format of this list is: +<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> Note that for special case of
Quoted 8 lines
Documentation/kernel-parameters.txt
Quoted 6 lines
Documentation/kernel-parameters.txt +6
-0+range one can split range into equal size of groups and for each +group to use some amount form the begin of that group. +<cpu number>-cpu number>:<used size>/<group size> For example one can +add to its command line following parameter: +isolcpus=1,2,10-20,100-2000:2/25 +I think we can do better here. Please review:
Thanks, I reviewed and it looks great.
- Noam