Skip to contentSkip to conversation

rcuscale: add srcu_atomic scale type

PATCH Superseded Kunwu Chan 3 participants 4 messages Sep 27 – Oct 2

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kunwu Chan

author
#0 lore raw

PATCH 1/1 rcuscale: add srcu_atomic scale type

Add support for scaling atomic SRCU grace periods using srcu_read_lock_atomic()/srcu_read_unlock_atomic() and synchronize_srcu_atomic().

---
 kernel/rcu/rcuscale.c | 47 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
kernel/rcu/rcuscale.c +46 -1
index 5aca31c3c01d..86f1a912ebee 100644
@@ -264,6 +264,51 @@ static struct rcu_scale_ops srcu_ops = {
 	.name		= "srcu"
 };
 
+static struct srcu_struct srcu_atomic_ctlp;
+
+static int srcu_scale_atomic_read_lock(void)
+{
+	return srcu_read_lock_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_scale_atomic_read_unlock(int idx)
+{
+	srcu_read_unlock_atomic(&srcu_atomic_ctlp, idx);
+}
+
+static void srcu_scale_atomic_synchronize(void)
+{
+	synchronize_srcu_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_atomic_scale_init(void)
+{
+	init_srcu_struct_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_atomic_scale_cleanup(void)
+{
+	cleanup_srcu_struct(&srcu_atomic_ctlp);
+}
+
+static unsigned long srcu_atomic_scale_completed(void)
+{
+	return srcu_batches_completed(&srcu_atomic_ctlp);
+}
+
+static struct rcu_scale_ops srcu_atomic_ops = {
+	.ptype		= SRCU_FLAVOR,
+	.init		= srcu_atomic_scale_init,
+	.cleanup	= srcu_atomic_scale_cleanup,
+	.readlock	= srcu_scale_atomic_read_lock,
+	.readunlock	= srcu_scale_atomic_read_unlock,
+	.get_gp_seq	= srcu_atomic_scale_completed,
+	.gp_diff	= rcu_seq_diff,
+	.exp_completed	= srcu_atomic_scale_completed,
+	.sync		= srcu_scale_atomic_synchronize,
+	.name		= "srcu_atomic"
+};
+
 static struct srcu_struct srcud;
 
 static void srcu_sync_scale_init(void)
@@ -1176,7 +1221,7 @@ rcu_scale_init(void)
 	long i;
 	long j;
 	static struct rcu_scale_ops *scale_ops[] = {
-		&rcu_ops, &srcu_ops, &srcud_ops,
+		&rcu_ops, &srcu_ops, &srcu_atomic_ops, &srcud_ops,
 		TASKS_OPS TASKS_RUDE_OPS TASKS_TRACING_OPS
 		HAZPTR_SCALE_OPS
 	};
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Kunwu Chan

Add support for scaling atomic SRCU grace periods using srcu_read_lock_atomic()/srcu_read_unlock_atomic() and synchronize_srcu_atomic().

Ummm. Ok then!

Quoted 63 lines

---
kernel/rcu/rcuscale.c | 47 ++++++++++++++++++++++++++++++++++++++++++-

1 file changed, 46 insertions(+), 1 deletion(-)
kernel/rcu/rcuscale.c +45 -0
index 5aca31c3c01d..86f1a912ebee 100644
@@ -264,6 +264,51 @@ static struct rcu_scale_ops srcu_ops = {
 	.name		= "srcu"
 };
 
+static struct srcu_struct srcu_atomic_ctlp;
+
+static int srcu_scale_atomic_read_lock(void)
+{
+	return srcu_read_lock_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_scale_atomic_read_unlock(int idx)
+{
+	srcu_read_unlock_atomic(&srcu_atomic_ctlp, idx);
+}
+
+static void srcu_scale_atomic_synchronize(void)
+{
+	synchronize_srcu_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_atomic_scale_init(void)
+{
+	init_srcu_struct_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_atomic_scale_cleanup(void)
+{
+	cleanup_srcu_struct(&srcu_atomic_ctlp);
+}
+
+static unsigned long srcu_atomic_scale_completed(void)
+{
+	return srcu_batches_completed(&srcu_atomic_ctlp);
+}
+
+static struct rcu_scale_ops srcu_atomic_ops = {
+	.ptype		= SRCU_FLAVOR,
+	.init		= srcu_atomic_scale_init,
+	.cleanup	= srcu_atomic_scale_cleanup,
+	.readlock	= srcu_scale_atomic_read_lock,
+	.readunlock	= srcu_scale_atomic_read_unlock,
+	.get_gp_seq	= srcu_atomic_scale_completed,
+	.gp_diff	= rcu_seq_diff,
+	.exp_completed	= srcu_atomic_scale_completed,
+	.sync		= srcu_scale_atomic_synchronize,
+	.name		= "srcu_atomic"
+};
+
 static struct srcu_struct srcud;
 
 static void srcu_sync_scale_init(void)

kernel/rcu/rcuscale.c rcu_scale_init(void) · line 1227

Quoted 8 lines
kernel/rcu/rcuscale.c +1 -1
@@ -1176,7 +1221,7 @@ rcu_scale_init(void)
 	long i;
 	long j;
 	static struct rcu_scale_ops *scale_ops[] = {
-		&rcu_ops, &srcu_ops, &srcud_ops,
+		&rcu_ops, &srcu_ops, &srcu_atomic_ops, &srcud_ops,
 		TASKS_OPS TASKS_RUDE_OPS TASKS_TRACING_OPS
 		HAZPTR_SCALE_OPS
 	};

--- Thanks!
"I'm not a very positive person" - Linus torvalds

maintainer
#2 lore raw
In reply to Kunwu Chan
Quoted 5 lines · Kunwu Chan

Add support for scaling atomic SRCU grace periods using srcu_read_lock_atomic()/srcu_read_unlock_atomic() and synchronize_srcu_atomic().

Nice, thank you!!!

Some suggestions below.

Thanx, Paul

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 267

Quoted 13 lines
---
 kernel/rcu/rcuscale.c | 47 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
kernel/rcu/rcuscale.c +1 -0
index 5aca31c3c01d..86f1a912ebee 100644
@@ -264,6 +264,51 @@ static struct rcu_scale_ops srcu_ops = {
 	.name		= "srcu"
 };
 
+static struct srcu_struct srcu_atomic_ctlp;

The trailing "p" suggests that this is a pointer, for example, see the difference between srcu_ctl_scale and srcu_ctlp. You could make this consistent with "srcud" and save a few lines of code as follows:

static struct srcu_struct srcua;

Quoted 7 lines
kernel/rcu/rcuscale.c +7 -0
+static int srcu_scale_atomic_read_lock(void)
+{
+	return srcu_read_lock_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_scale_atomic_read_unlock(int idx)
+{

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 285

Quoted 10 lines
kernel/rcu/rcuscale.c +10 -0
+	srcu_read_unlock_atomic(&srcu_atomic_ctlp, idx);
+}
+
+static void srcu_scale_atomic_synchronize(void)
+{
+	synchronize_srcu_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_atomic_scale_init(void)
+{
	srcu_ctlp = &srcua;

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 292

Quoted 7 lines
kernel/rcu/rcuscale.c +7 -0
+	init_srcu_struct_atomic(srcu_ctlp);
+}
+
+static void srcu_atomic_scale_cleanup(void)
+{
+	cleanup_srcu_struct(&srcu_atomic_ctlp);
+}

You can then drop srcu_atomic_scale_cleanup() and just use the existing srcu_sync_scale_cleanup().

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 297

Quoted 4 lines
kernel/rcu/rcuscale.c +4 -0
+static unsigned long srcu_atomic_scale_completed(void)
+{
+	return srcu_batches_completed(&srcu_atomic_ctlp);
+}

You can also drop srcu_atomic_scale_completed() and just use the existing srcu_scale_completed(). Of course, both this and the above require adjusting the srcu_atomic_ops initializer.

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 308

Quoted 10 lines
kernel/rcu/rcuscale.c +10 -0
+static struct rcu_scale_ops srcu_atomic_ops = {
+	.ptype		= SRCU_FLAVOR,
+	.init		= srcu_atomic_scale_init,
+	.cleanup	= srcu_atomic_scale_cleanup,
+	.readlock	= srcu_scale_atomic_read_lock,
+	.readunlock	= srcu_scale_atomic_read_unlock,
+	.get_gp_seq	= srcu_atomic_scale_completed,
+	.gp_diff	= rcu_seq_diff,
+	.exp_completed	= srcu_atomic_scale_completed,
+	.sync		= srcu_scale_atomic_synchronize,

You can also then do this to get more debug data:

	.stats		= srcu_scale_stats,

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 309

Quoted 1 line
kernel/rcu/rcuscale.c +1 -0
+	.name		= "srcu_atomic"

Then this could be "srcua". Or maybe more typing on the rcuscale scale_type module parameter is OK. If so, maybe we should change "srcud" to "srcu_dynamic", but this would require quite a few other changes as well. (At least if we want the rcutorture names to be consistent.)

Thoughts?

Quoted 17 lines
kernel/rcu/rcuscale.c +3 -1
+};
+
 static struct srcu_struct srcud;
 
 static void srcu_sync_scale_init(void)
@@ -1176,7 +1221,7 @@ rcu_scale_init(void)
 	long i;
 	long j;
 	static struct rcu_scale_ops *scale_ops[] = {
-		&rcu_ops, &srcu_ops, &srcud_ops,
+		&rcu_ops, &srcu_ops, &srcu_atomic_ops, &srcud_ops,
 		TASKS_OPS TASKS_RUDE_OPS TASKS_TRACING_OPS
 		HAZPTR_SCALE_OPS
 	};
Signature · 1 line
2.43.0
author
#3 lore raw

Thanks Paul for the review and suggestions!

Quoted 26 lines · Paul E. McKenney
Quoted 5 lines · Kunwu Chan

Add support for scaling atomic SRCU grace periods using srcu_read_lock_atomic()/srcu_read_unlock_atomic() and synchronize_srcu_atomic().

Nice, thank you!!!

Some suggestions below.

Thanx, Paul

Quoted 12 lines
---
 kernel/rcu/rcuscale.c | 47 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
kernel/rcu/rcuscale.c +0 -0
index 5aca31c3c01d..86f1a912ebee 100644
@@ -264,6 +264,51 @@ static struct rcu_scale_ops srcu_ops = {
      .name           = "srcu"
 };
 
Quoted 8 lines

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 267

Quoted 1 line
kernel/rcu/rcuscale.c +1 -0
+static struct srcu_struct srcu_atomic_ctlp;

The trailing "p" suggests that this is a pointer, for example, see the difference between srcu_ctl_scale and srcu_ctlp. You could make this consistent with "srcud" and save a few lines of code as follows:

static struct srcu_struct srcua;

The srcu_ctlp reuse approach looks good. I will switch to a separate srcua instance, assign srcu_ctlp during init, and reuse the existing SRCU helpers.

Quoted 29 lines
Quoted 7 lines
kernel/rcu/rcuscale.c +7 -0
+static int srcu_scale_atomic_read_lock(void)
+{
+     return srcu_read_lock_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_scale_atomic_read_unlock(int idx)
+{

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 285

Quoted 10 lines
kernel/rcu/rcuscale.c +10 -0
+     srcu_read_unlock_atomic(&srcu_atomic_ctlp, idx);
+}
+
+static void srcu_scale_atomic_synchronize(void)
+{
+     synchronize_srcu_atomic(&srcu_atomic_ctlp);
+}
+
+static void srcu_atomic_scale_init(void)
+{
        srcu_ctlp = &srcua;

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 292

Quoted 7 lines
kernel/rcu/rcuscale.c +7 -0
+     init_srcu_struct_atomic(srcu_ctlp);
+}
+
+static void srcu_atomic_scale_cleanup(void)
+{
+     cleanup_srcu_struct(&srcu_atomic_ctlp);
+}

You can then drop srcu_atomic_scale_cleanup() and just use the existing srcu_sync_scale_cleanup().

Quoted 9 lines

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 297

Quoted 4 lines
kernel/rcu/rcuscale.c +4 -0
+static unsigned long srcu_atomic_scale_completed(void)
+{
+     return srcu_batches_completed(&srcu_atomic_ctlp);
+}

You can also drop srcu_atomic_scale_completed() and just use the existing srcu_scale_completed(). Of course, both this and the above require adjusting the srcu_atomic_ops initializer.

That makes sense. I will drop srcu_atomic_scale_cleanup() and srcu_atomic_scale_completed(), and adjust the ops initializer accordingly.

Quoted 11 lines

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 308

Quoted 10 lines
kernel/rcu/rcuscale.c +10 -0
+static struct rcu_scale_ops srcu_atomic_ops = {
+     .ptype          = SRCU_FLAVOR,
+     .init           = srcu_atomic_scale_init,
+     .cleanup        = srcu_atomic_scale_cleanup,
+     .readlock       = srcu_scale_atomic_read_lock,
+     .readunlock     = srcu_scale_atomic_read_unlock,
+     .get_gp_seq     = srcu_atomic_scale_completed,
+     .gp_diff        = rcu_seq_diff,
+     .exp_completed  = srcu_atomic_scale_completed,
+     .sync           = srcu_scale_atomic_synchronize,
Quoted 3 lines

You can also then do this to get more debug data:

.stats = srcu_scale_stats,

I will add .stats = srcu_scale_stats as suggested.

Quoted 11 lines

kernel/rcu/rcuscale.c static struct rcu_scale_ops srcu_ops = { · line 309

Quoted 2 lines
kernel/rcu/rcuscale.c +1 -0
+     .name           = "srcu_atomic"

Then this could be "srcua". Or maybe more typing on the rcuscale scale_type module parameter is OK. If so, maybe we should change "srcud" to "srcu_dynamic", but this would require quite a few other changes as well. (At least if we want the rcutorture names to be consistent.)

Thoughts?

For the name, I will use srcua to stay consistent with the existing srcud naming style.
If we want to improve readability without renaming the existing scale types, we could also
add a short comment or update the test scripts to mention that srcua refers to atomic SRCU.

If we prefer more descriptive names such as srcu_atomic and srcu_dynamic, I can help with a follow-up cleanup to rename the existing srcud as well and keep
the related rcutorture and rcuscale names consistent.

Thanks,
Kunwu

Quoted 17 lines
Quoted 17 lines
kernel/rcu/rcuscale.c +3 -2
+};
+
 static struct srcu_struct srcud;
 
 static void srcu_sync_scale_init(void)
@@ -1176,7 +1221,7 @@ rcu_scale_init(void)
      long i;
      long j;
      static struct rcu_scale_ops *scale_ops[] = {
-             &rcu_ops, &srcu_ops, &srcud_ops,
+             &rcu_ops, &srcu_ops, &srcu_atomic_ops, &srcud_ops,
              TASKS_OPS TASKS_RUDE_OPS TASKS_TRACING_OPS
              HAZPTR_SCALE_OPS
      };
--

2.43.0