Skip to contentSkip to conversation

bitmap_parselist: support 'all' semantics

PATCH Superseded Yury Norov 2 participants 8 messages Apr 20, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yury Norov

author maintainer
#0 lore raw

cover bitmap_parselist: support 'all' semantics

RCU code supports a special group 'all' which selects all bits in a bitmap. We have recently added 'N' extension for bitmap parse, so that '0-N' would have exactly the same meaning as 'all'. But because the 'all' is already used by RCU, it would be reasonable to support it in core bitmap code as a common and easy-readable alias for '0-N'.

Moving the 'all' support to core bitmap code adds another level of flexibility for system configuration by supporting patterns. For example, every second bit in cpumask may be selected like this:

	isolcpus=all:1/2

Yury Norov (2):
bitmap_parse: support 'all' semantics rcu/tree_plugin: don't handle the case of 'all' CPU range

 Documentation/admin-guide/kernel-parameters.rst | 5 +++++
 kernel/rcu/tree_plugin.h                        | 9 +++------
 lib/bitmap.c                                    | 9 +++++++++
 lib/test_bitmap.c                               | 8 +++++++-
 4 files changed, 24 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/2 bitmap_parse: support 'all' semantics

RCU code supports an 'all' group as a special case when parsing rcu_nocbs parameter. This patch moves the 'all' support to the core bitmap_parse code, so that all bitmap users can enjoy this extension.

Moving 'all' parsing to a bitmap_parse level, also allows users to pass patterns together with 'all' in regular group:pattern format

---
 Documentation/admin-guide/kernel-parameters.rst | 5 +++++
 lib/bitmap.c                                    | 9 +++++++++
 lib/test_bitmap.c                               | 8 +++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.rst +5 -0
index 3996b54158bf..7178d9c4de7f 100644
@@ -76,6 +76,11 @@ to change, such as less cores in the CPU list, then N and any ranges using N
 will also change.  Use the same on a small 4 core system, and "16-N" becomes
 "16-3" and now the same boot input will be flagged as invalid (start > end).
 
+The special case-tolerant group name "all" has a meaning of selecting all CPUs,
+such that "isolcpus=all" is the equivalent of "isolcpus=0-N".
+
+The semantics of "N" and "all" is supported on a level of bitmaps and holds for
+all users of bitmap_parse().
 
 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
lib/bitmap.c +9 -0
index 74ceb02f45e3..6e29b2aae6ba 100644
@@ -581,6 +581,14 @@ static const char *bitmap_parse_region(const char *str, struct region *r)
 {
 	unsigned int lastbit = r->nbits - 1;
 
+	if (!strncasecmp(str, "all", 3)) {
+		r->start = 0;
+		r->end = lastbit;
+		str += 3;
+
+		goto check_pattern;
+	}
+
 	str = bitmap_getnum(str, &r->start, lastbit);
 	if (IS_ERR(str))
 		return str;
@@ -595,6 +603,7 @@ static const char *bitmap_parse_region(const char *str, struct region *r)
 	if (IS_ERR(str))
 		return str;
 
+check_pattern:
 	if (end_of_region(*str))
 		goto no_pattern;
 
lib/test_bitmap.c +7 -1
index 9cd575583180..ab278cfa9145 100644
@@ -366,6 +366,13 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = {
 	{0, "0-31:1/3,1-31:1/3,2-31:1/3",	&exp1[8 * step], 32, 0},
 	{0, "1-10:8/12,8-31:24/29,0-31:0/3",	&exp1[9 * step], 32, 0},
 
+	{0,	  "all",		&exp1[8 * step], 32, 0},
+	{0,	  "0, 1, all,  ",	&exp1[8 * step], 32, 0},
+	{0,	  "all:1/2",		&exp1[4 * step], 32, 0},
+	{0,	  "ALL:1/2",		&exp1[4 * step], 32, 0},
+	{-EINVAL, "al", NULL, 8, 0},
+	{-EINVAL, "alll", NULL, 8, 0},
+
 	{-EINVAL, "-1",	NULL, 8, 0},
 	{-EINVAL, "-0",	NULL, 8, 0},
 	{-EINVAL, "10-1", NULL, 8, 0},
@@ -384,7 +391,6 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = {
 	{-EINVAL, "a-31:10/1", NULL, 8, 0},
 	{-EINVAL, "0-31:a/1", NULL, 8, 0},
 	{-EINVAL, "0-\n", NULL, 8, 0},
-
 };
 
 static void __init test_bitmap_parselist(void)
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 2/2 rcu/tree_plugin: don't handle the case of 'all' CPU range

In reply to Yury Norov

The 'all' semantics is now supported by the bitmap_parselist() so we can drop supporting it as a special case in RCU code. This patch does not add any functional changes for existing users.

---
 kernel/rcu/tree_plugin.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
kernel/rcu/tree_plugin.h +3 -6
index 464b16132866..334eaf4d561f 100644
@@ -1511,13 +1511,10 @@ static void rcu_cleanup_after_idle(void)
 static int __init rcu_nocb_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&rcu_nocb_mask);
-	if (!strcasecmp(str, "all"))		/* legacy: use "0-N" instead */
+	if (cpulist_parse(str, rcu_nocb_mask)) {
+		pr_warn("rcu_nocbs= bad CPU range, all CPUs set\n");
 		cpumask_setall(rcu_nocb_mask);
-	else
-		if (cpulist_parse(str, rcu_nocb_mask)) {
-			pr_warn("rcu_nocbs= bad CPU range, all CPUs set\n");
-			cpumask_setall(rcu_nocb_mask);
-		}
+	}
 	return 1;
 }
 __setup("rcu_nocbs=", rcu_nocb_setup);
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/2] bitmap_parse: support 'all' semantics

In reply to Yury Norov
Quoted 6 lines · Yury Norov

RCU code supports an 'all' group as a special case when parsing rcu_nocbs parameter. This patch moves the 'all' support to the core bitmap_parse code, so that all bitmap users can enjoy this extension.

Moving 'all' parsing to a bitmap_parse level, also allows users to pass patterns together with 'all' in regular group:pattern format

...

lib/test_bitmap.c static const struct test_bitmap_parselist parselist_tests[] __initconst = { · line 375

Quoted 11 lines
lib/test_bitmap.c +7 -0
 	{0, "0-31:1/3,1-31:1/3,2-31:1/3",	&exp1[8 * step], 32, 0},
 	{0, "1-10:8/12,8-31:24/29,0-31:0/3",	&exp1[9 * step], 32, 0},
 
+	{0,	  "all",		&exp1[8 * step], 32, 0},
+	{0,	  "0, 1, all,  ",	&exp1[8 * step], 32, 0},
+	{0,	  "all:1/2",		&exp1[4 * step], 32, 0},
+	{0,	  "ALL:1/2",		&exp1[4 * step], 32, 0},
 
+	{-EINVAL, "al", NULL, 8, 0},
+	{-EINVAL, "alll", NULL, 8, 0},
+

Looking at the below hunk it seems like the two above should be actually placed there.

lib/test_bitmap.c static const struct test_bitmap_parselist parselist_tests[] __initconst = { · line 387

Quoted 8 lines
lib/test_bitmap.c +0 -1
 	{-EINVAL, "-1",	NULL, 8, 0},
 	{-EINVAL, "-0",	NULL, 8, 0},
 	{-EINVAL, "10-1", NULL, 8, 0},
@@ -384,7 +391,6 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = {
 	{-EINVAL, "a-31:10/1", NULL, 8, 0},
 	{-EINVAL, "0-31:a/1", NULL, 8, 0},
 	{-EINVAL, "0-\n", NULL, 8, 0},
-

Otherwise this change doesn't belong to the series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH 2/2] rcu/tree_plugin: don't handle the case of 'all' CPU range

In reply to Yury Norov

kernel/rcu/tree_plugin.h static void rcu_cleanup_after_idle(void) · line 1514

Quoted 5 lines · Yury Norov

The 'all' semantics is now supported by the bitmap_parselist() so we can drop supporting it as a special case in RCU code. This patch does not add any functional changes for existing users.

kernel/rcu/tree_plugin.h +0 -1
-	if (!strcasecmp(str, "all"))		/* legacy: use "0-N" instead */

Perhaps move comment as well to new location.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on the v1 series
#7 lore raw
In reply to Yury Norov
Quoted 10 lines · Yury Norov

RCU code supports a special group 'all' which selects all bits in a bitmap. We have recently added 'N' extension for bitmap parse, so that '0-N' would have exactly the same meaning as 'all'. But because the 'all' is already used by RCU, it would be reasonable to support it in core bitmap code as a common and easy-readable alias for '0-N'.

Moving the 'all' support to core bitmap code adds another level of flexibility for system configuration by supporting patterns. For example, every second bit in cpumask may be selected like this:

	isolcpus=all:1/2

After addressing a couple of nit-picks,

Quoted 13 lines

Yury Norov (2):
bitmap_parse: support 'all' semantics rcu/tree_plugin: don't handle the case of 'all' CPU range

 Documentation/admin-guide/kernel-parameters.rst | 5 +++++
 kernel/rcu/tree_plugin.h                        | 9 +++------
 lib/bitmap.c                                    | 9 +++++++++
 lib/test_bitmap.c                               | 8 +++++++-
 4 files changed, 24 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#3 lore raw

Re: [PATCH 1/2] bitmap_parse: support 'all' semantics

In reply to Andy Shevchenko
Quoted 25 lines · Andy Shevchenko
Quoted 6 lines · Yury Norov

RCU code supports an 'all' group as a special case when parsing rcu_nocbs parameter. This patch moves the 'all' support to the core bitmap_parse code, so that all bitmap users can enjoy this extension.

Moving 'all' parsing to a bitmap_parse level, also allows users to pass patterns together with 'all' in regular group:pattern format

...

lib/test_bitmap.c static const struct test_bitmap_parselist parselist_tests[] __initconst = { · line 375

Quoted 11 lines
lib/test_bitmap.c +7 -0
 	{0, "0-31:1/3,1-31:1/3,2-31:1/3",	&exp1[8 * step], 32, 0},
 	{0, "1-10:8/12,8-31:24/29,0-31:0/3",	&exp1[9 * step], 32, 0},
 
+	{0,	  "all",		&exp1[8 * step], 32, 0},
+	{0,	  "0, 1, all,  ",	&exp1[8 * step], 32, 0},
+	{0,	  "all:1/2",		&exp1[4 * step], 32, 0},
+	{0,	  "ALL:1/2",		&exp1[4 * step], 32, 0},
 
+	{-EINVAL, "al", NULL, 8, 0},
+	{-EINVAL, "alll", NULL, 8, 0},
+

Looking at the below hunk it seems like the two above should be actually placed there.

Quoted 10 lines

lib/test_bitmap.c static const struct test_bitmap_parselist parselist_tests[] __initconst = { · line 387

Quoted 8 lines
lib/test_bitmap.c +0 -1
 	{-EINVAL, "-1",	NULL, 8, 0},
 	{-EINVAL, "-0",	NULL, 8, 0},
 	{-EINVAL, "10-1", NULL, 8, 0},
@@ -384,7 +391,6 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = {
 	{-EINVAL, "a-31:10/1", NULL, 8, 0},
 	{-EINVAL, "0-31:a/1", NULL, 8, 0},
 	{-EINVAL, "0-\n", NULL, 8, 0},
-

Otherwise this change doesn't belong to the series.

My bad, I'll fix it in v2.

author maintainer
#6 lore raw

Re: [PATCH 2/2] rcu/tree_plugin: don't handle the case of 'all' CPU range

In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

kernel/rcu/tree_plugin.h static void rcu_cleanup_after_idle(void) · line 1514

Quoted 5 lines · Yury Norov

The 'all' semantics is now supported by the bitmap_parselist() so we can drop supporting it as a special case in RCU code. This patch does not add any functional changes for existing users.

kernel/rcu/tree_plugin.h +0 -1
-	if (!strcasecmp(str, "all"))		/* legacy: use "0-N" instead */

Perhaps move comment as well to new location.

I actually wanted to remove this comment. The reason is that 'all' is verbose, clear and proven to be useful for at least RCU. In v2 I'll mention it explicitly in commit comment.