linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rcu: init and destroy rcu_synchronize when necessary
@ 2020-04-15 22:26 Wei Yang
  2020-04-16  0:24 ` Paul E. McKenney
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Yang @ 2020-04-15 22:26 UTC (permalink / raw)
  To: paulmck, josh; +Cc: rcu, linux-kernel, Wei Yang

We would skip the rcu_synchronize if it is a duplicate call back function.

This is not necessary to init and destroy for them.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 kernel/rcu/update.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
index 6c4b862f57d6..91e44b527aad 100644
--- a/kernel/rcu/update.c
+++ b/kernel/rcu/update.c
@@ -353,13 +353,14 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array,
 			might_sleep();
 			continue;
 		}
-		init_rcu_head_on_stack(&rs_array[i].head);
-		init_completion(&rs_array[i].completion);
 		for (j = 0; j < i; j++)
 			if (crcu_array[j] == crcu_array[i])
 				break;
-		if (j == i)
+		if (j == i) {
+			init_rcu_head_on_stack(&rs_array[i].head);
+			init_completion(&rs_array[i].completion);
 			(crcu_array[i])(&rs_array[i].head, wakeme_after_rcu);
+		}
 	}
 
 	/* Wait for all callbacks to be invoked. */
@@ -370,9 +371,10 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array,
 		for (j = 0; j < i; j++)
 			if (crcu_array[j] == crcu_array[i])
 				break;
-		if (j == i)
+		if (j == i) {
 			wait_for_completion(&rs_array[i].completion);
-		destroy_rcu_head_on_stack(&rs_array[i].head);
+			destroy_rcu_head_on_stack(&rs_array[i].head);
+		}
 	}
 }
 EXPORT_SYMBOL_GPL(__wait_rcu_gp);
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rcu: init and destroy rcu_synchronize when necessary
  2020-04-15 22:26 [PATCH] rcu: init and destroy rcu_synchronize when necessary Wei Yang
@ 2020-04-16  0:24 ` Paul E. McKenney
  2020-04-16 21:44   ` Wei Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Paul E. McKenney @ 2020-04-16  0:24 UTC (permalink / raw)
  To: Wei Yang; +Cc: josh, rcu, linux-kernel

On Wed, Apr 15, 2020 at 10:26:55PM +0000, Wei Yang wrote:
> We would skip the rcu_synchronize if it is a duplicate call back function.
> 
> This is not necessary to init and destroy for them.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>

Applied, thank you!

I edited the commit log a bit.  Could you please check below to make
sure that I didn't mess anything up?

							Thanx, Paul

------------------------------------------------------------------------

commit d9eaddf545fe8e3e2725e2fa0bf87b59b5667c14
Author: Wei Yang <richard.weiyang@gmail.com>
Date:   Wed Apr 15 22:26:55 2020 +0000

    rcu: Initialize and destroy rcu_synchronize only when necessary
    
    The __wait_rcu_gp() function unconditionally initializes and cleans up
    each element of rs_array[], whether used or not.  This is slightly
    wasteful and rather confusing, so this commit skips both initialization
    and cleanup for duplicate callback functions.
    
    Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
index 3ce63a9..351c322 100644
--- a/kernel/rcu/update.c
+++ b/kernel/rcu/update.c
@@ -391,13 +391,14 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array,
 			might_sleep();
 			continue;
 		}
-		init_rcu_head_on_stack(&rs_array[i].head);
-		init_completion(&rs_array[i].completion);
 		for (j = 0; j < i; j++)
 			if (crcu_array[j] == crcu_array[i])
 				break;
-		if (j == i)
+		if (j == i) {
+			init_rcu_head_on_stack(&rs_array[i].head);
+			init_completion(&rs_array[i].completion);
 			(crcu_array[i])(&rs_array[i].head, wakeme_after_rcu);
+		}
 	}
 
 	/* Wait for all callbacks to be invoked. */
@@ -408,9 +409,10 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array,
 		for (j = 0; j < i; j++)
 			if (crcu_array[j] == crcu_array[i])
 				break;
-		if (j == i)
+		if (j == i) {
 			wait_for_completion(&rs_array[i].completion);
-		destroy_rcu_head_on_stack(&rs_array[i].head);
+			destroy_rcu_head_on_stack(&rs_array[i].head);
+		}
 	}
 }
 EXPORT_SYMBOL_GPL(__wait_rcu_gp);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rcu: init and destroy rcu_synchronize when necessary
  2020-04-16  0:24 ` Paul E. McKenney
@ 2020-04-16 21:44   ` Wei Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Yang @ 2020-04-16 21:44 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: Wei Yang, josh, rcu, linux-kernel

On Wed, Apr 15, 2020 at 05:24:00PM -0700, Paul E. McKenney wrote:
>On Wed, Apr 15, 2020 at 10:26:55PM +0000, Wei Yang wrote:
>> We would skip the rcu_synchronize if it is a duplicate call back function.
>> 
>> This is not necessary to init and destroy for them.
>> 
>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>
>Applied, thank you!
>
>I edited the commit log a bit.  Could you please check below to make
>sure that I didn't mess anything up?
>

Yep, the changelog looks good to me :-)

Glad you like it.

>							Thanx, Paul
>
>------------------------------------------------------------------------
>
>commit d9eaddf545fe8e3e2725e2fa0bf87b59b5667c14
>Author: Wei Yang <richard.weiyang@gmail.com>
>Date:   Wed Apr 15 22:26:55 2020 +0000
>
>    rcu: Initialize and destroy rcu_synchronize only when necessary
>    
>    The __wait_rcu_gp() function unconditionally initializes and cleans up
>    each element of rs_array[], whether used or not.  This is slightly
>    wasteful and rather confusing, so this commit skips both initialization
>    and cleanup for duplicate callback functions.
>    
>    Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
>
>diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
>index 3ce63a9..351c322 100644
>--- a/kernel/rcu/update.c
>+++ b/kernel/rcu/update.c
>@@ -391,13 +391,14 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array,
> 			might_sleep();
> 			continue;
> 		}
>-		init_rcu_head_on_stack(&rs_array[i].head);
>-		init_completion(&rs_array[i].completion);
> 		for (j = 0; j < i; j++)
> 			if (crcu_array[j] == crcu_array[i])
> 				break;
>-		if (j == i)
>+		if (j == i) {
>+			init_rcu_head_on_stack(&rs_array[i].head);
>+			init_completion(&rs_array[i].completion);
> 			(crcu_array[i])(&rs_array[i].head, wakeme_after_rcu);
>+		}
> 	}
> 
> 	/* Wait for all callbacks to be invoked. */
>@@ -408,9 +409,10 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array,
> 		for (j = 0; j < i; j++)
> 			if (crcu_array[j] == crcu_array[i])
> 				break;
>-		if (j == i)
>+		if (j == i) {
> 			wait_for_completion(&rs_array[i].completion);
>-		destroy_rcu_head_on_stack(&rs_array[i].head);
>+			destroy_rcu_head_on_stack(&rs_array[i].head);
>+		}
> 	}
> }
> EXPORT_SYMBOL_GPL(__wait_rcu_gp);

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-16 21:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 22:26 [PATCH] rcu: init and destroy rcu_synchronize when necessary Wei Yang
2020-04-16  0:24 ` Paul E. McKenney
2020-04-16 21:44   ` Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).