Skip to contentSkip to conversation

rcu/torture replace wait_event with wait_event_idle

PATCH In review [email protected] 3 participants 7 messages May 2, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rcu/torture replace wait_event with wait_event_idle

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

---
 kernel/rcu/rcuscale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcuscale.c +1 -1
index 91fb5905a008..d99c586939d1 100644
@@ -771,7 +771,7 @@ kfree_scale_cleanup(void)
 static int
 kfree_scale_shutdown(void *arg)
 {
-	wait_event(shutdown_wq,
+	wait_event_idle(shutdown_wq,
 		   atomic_read(&n_kfree_scale_thread_ended) >= kfree_nrealthreads);
 
 	smp_mb(); /* Wake before output. */
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 10 lines · On Tue, May 02, 2023 at 08:01:41AM +0800, [email protected] wrote:

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

Good catch, thank you!

However, this commit beat you to it:

ef1ef3d47677 ("rcuscale: Move shutdown from wait_event() to wait_event_idle()")

Thanx, Paul

Quoted 20 lines
---
 kernel/rcu/rcuscale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcuscale.c +1 -1
index 91fb5905a008..d99c586939d1 100644
@@ -771,7 +771,7 @@ kfree_scale_cleanup(void)
 static int
 kfree_scale_shutdown(void *arg)
 {
-	wait_event(shutdown_wq,
+	wait_event_idle(shutdown_wq,
 		   atomic_read(&n_kfree_scale_thread_ended) >= kfree_nrealthreads);
 
 	smp_mb(); /* Wake before output. */
Signature · 1 line
2.34.1
#2 lore raw
Quoted 10 lines · Paul E. McKenney
Quoted 8 lines · On Tue, May 02, 2023 at 08:01:41AM +0800, [email protected] wrote:

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

Quoted 8 lines
Quoted 2 lines

Good catch, thank you!

However, this commit beat you to it:

ef1ef3d47677 ("rcuscale: Move shutdown from wait_event() to wait_event_idle()")

You are very welcome ;-) Still, this is a very fruitful learning process for me ;-)

Cheers
Zhouyi

Quoted 23 lines

Thanx, Paul

Quoted 20 lines
---
 kernel/rcu/rcuscale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcuscale.c +1 -2
index 91fb5905a008..d99c586939d1 100644
@@ -771,7 +771,7 @@ kfree_scale_cleanup(void)
 static int
 kfree_scale_shutdown(void *arg)
 {
-     wait_event(shutdown_wq,
+     wait_event_idle(shutdown_wq,
                 atomic_read(&n_kfree_scale_thread_ended) >= kfree_nrealthreads);
 
      smp_mb(); /* Wake before output. */
--

2.34.1

#3 lore raw
Quoted 18 lines · Zhouyi Zhou
Quoted 13 lines · Paul E. McKenney
Quoted 12 lines · On Tue, May 02, 2023 at 08:01:41AM +0800, [email protected] wrote:

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

Quoted 7 lines
Quoted 5 lines

Good catch, thank you!

However, this commit beat you to it:

ef1ef3d47677 ("rcuscale: Move shutdown from wait_event() to wait_event_idle()")

You are very welcome ;-) Still, this is a very fruitful learning process for me ;-)

Speaking of learning, can you explain why it fixes the issue? ;-)

Your change log lacked the real reason but that is Ok since change logs can only tell you so much. I admit I myself did not know the reason till I read some code.

Quiz: why exactly does this all work out in the end even though the hung task detector saw it hung?

Thanks,

- Joel

Quoted 26 lines

Cheers
Zhouyi

Quoted 23 lines

Thanx, Paul

Quoted 20 lines

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

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcuscale.c +0 -0
index 91fb5905a008..d99c586939d1 100644
@@ -771,7 +771,7 @@ kfree_scale_cleanup(void)

static int
kfree_scale_shutdown(void *arg)
{

kernel/rcu/rcuscale.c +1 -2
-     wait_event(shutdown_wq,
+     wait_event_idle(shutdown_wq,
                atomic_read(&n_kfree_scale_thread_ended) >= kfree_nrealthreads);
 
     smp_mb(); /* Wake before output. */
--

2.34.1

#4 lore raw

Thank Joel for your guidance ;-)

Quoted 23 lines · Joel Fernandes
Quoted 23 lines · Zhouyi Zhou
Quoted 17 lines · Paul E. McKenney
Quoted 12 lines · On Tue, May 02, 2023 at 08:01:41AM +0800, [email protected] wrote:

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

Good catch, thank you!

However, this commit beat you to it:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

ef1ef3d47677 ("rcuscale: Move shutdown from wait_event() to wait_event_idle()")

You are very welcome ;-) Still, this is a very fruitful learning process for me ;-)

Speaking of learning, can you explain why it fixes the issue? ;-)

Your change log lacked the real reason but that is Ok since change logs can only tell you so much. I admit I myself did not know the reason till I read some code.

When I found "blocked for more than" report in console.log, I did a grep in kernel source tree, and found check_hung_task will only be invoked
from check_hung_uninterruptible_tasks when (state & TASK_UNINTERRUPTIBLE) and !(state & TASK_WAKEKILL) and !(state & TASK_NOLOAD), so I send my first patch [1], and Paul tell me wait_event_idle is the right answer, then I do a grep for recursively expansion of macro wait_event_idle, which finally set current->state to TASK_IDLE ((TASK_UNINTERRUPTIBLE | TASK_NOLOAD)), then I conclude that check_hung_task will not be called. Yes, _interruptible() variant indicates that wakeups due to things like POSIX signals are permitted, which are not our case.

I should investigate more on what wait_event_idle really means, instead of merely grep and debug what wait_event_idle does.
I should write my change log more clearly and explain why wait_event_idle works.

I discovered [1] during the testing of the patch, this is also a very fruitful learning process.

I will write my change log more indicative next time, and do better work to our RCU community (and thanks for remove linux-kernel from CC list ;-))

Thanks
Zhouyi
[1] Link: https://lore.kernel.org/lkml/CAABZP2yS5=ZUwEZQ7iHkV0wDm_HgO8K-TeAhyJrZhavzKDa44Q@mail.gmail.com/T/

Quoted 23 lines · Joel Fernandes
Quoted 23 lines · Zhouyi Zhou
Quoted 17 lines · Paul E. McKenney
Quoted 12 lines · On Tue, May 02, 2023 at 08:01:41AM +0800, [email protected] wrote:

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

Good catch, thank you!

However, this commit beat you to it:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

ef1ef3d47677 ("rcuscale: Move shutdown from wait_event() to wait_event_idle()")

You are very welcome ;-) Still, this is a very fruitful learning process for me ;-)

Speaking of learning, can you explain why it fixes the issue? ;-)

Your change log lacked the real reason but that is Ok since change logs can only tell you so much. I admit I myself did not know the reason till I read some code.

When I found "task xxx blocked for more than" report in console.log, I did a grep in kernel source tree, and found check_hung_task will only be invoked
from check_hung_uninterruptible_tasks when (state & TASK_UNINTERRUPTIBLE) and !(state & TASK_NOLOAD), so I send my first patch [1], and Paul tell me wait_event_idle is the right answer, then I do a grep for recursively expansion of macro wait_event_idle, which finally set current->state to TASK_IDLE ((TASK_UNINTERRUPTIBLE | TASK_NOLOAD)), then
I conclude that

[1] https://lore.kernel.org/lkml/[email protected]/T/

Quoted 30 lines

Quiz: why exactly does this all work out in the end even though the hung task detector saw it hung?

Thanks,

- Joel

Quoted 22 lines

Cheers
Zhouyi

Quoted 19 lines

Thanx, Paul

Quoted 16 lines

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

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcuscale.c +0 -0
index 91fb5905a008..d99c586939d1 100644
@@ -771,7 +771,7 @@ kfree_scale_cleanup(void)

static int
kfree_scale_shutdown(void *arg)
{

kernel/rcu/rcuscale.c +1 -1
-     wait_event(shutdown_wq,
+     wait_event_idle(shutdown_wq,
                atomic_read(&n_kfree_scale_thread_ended) >= kfree_nrealthreads);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
     smp_mb(); /* Wake before output. */

--
2.34.1

[1] https://lore.kernel.org/lkml/[email protected]/T/

Quoted 34 lines

Quiz: why exactly does this all work out in the end even though the hung task detector saw it hung?

Thanks,

- Joel

Quoted 26 lines

Cheers
Zhouyi

Quoted 23 lines

Thanx, Paul

Quoted 20 lines

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

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcuscale.c +0 -0
index 91fb5905a008..d99c586939d1 100644
@@ -771,7 +771,7 @@ kfree_scale_cleanup(void)

static int
kfree_scale_shutdown(void *arg)
{

kernel/rcu/rcuscale.c +1 -2
-     wait_event(shutdown_wq,
+     wait_event_idle(shutdown_wq,
                atomic_read(&n_kfree_scale_thread_ended) >= kfree_nrealthreads);
 
     smp_mb(); /* Wake before output. */
--

2.34.1

#5 lore raw
In reply to Joel Fernandes

Sorry for the bad format of my previous email, there is always something wrong when I press Ctrl+C and Ctrl+V in my browser. Sorry for the inconvenience that I bring.

Quoted 24 lines · Joel Fernandes
Quoted 24 lines · Zhouyi Zhou
Quoted 18 lines · Paul E. McKenney
Quoted 12 lines · On Tue, May 02, 2023 at 08:01:41AM +0800, [email protected] wrote:

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

Good catch, thank you!

However, this commit beat you to it:

ef1ef3d47677 ("rcuscale: Move shutdown from wait_event() to wait_event_idle()")

Quoted 8 lines
Quoted 2 lines

You are very welcome ;-) Still, this is a very fruitful learning process for me ;-)

Speaking of learning, can you explain why it fixes the issue? ;-)

Your change log lacked the real reason but that is Ok since change logs can only tell you so much. I admit I myself did not know the reason till I read some code.

Quiz: why exactly does this all work out in the end even though the hung task detector saw it hung?

When I found "blocked for more than" report in console.log, I did a grep in kernel source tree, and found check_hung_task will only be invoked
from check_hung_uninterruptible_tas
ks when (state & TASK_UNINTERRUPTIBLE) and !(state & TASK_WAKEKILL) and !(state &
TASK_NOLOAD), so I send my first patch [1], and Paul tell me wait_event_idle is the right answer, then I do a grep for recursively expansion of macro wait_event_idle, which finally set current->state to TASK_IDLE ((TASK_UNINTERRUPTIBLE | TASK_NOLOAD)), then I conclude that check_hung_task will not be called. Yes, _interruptible() variant indicates that wakeups due to things like POSIX signals are permitted, which are not our case.

I should investigate more on what wait_event_idle really means, instead of merely grep and debug what wait_event_idle does.
I should write my change log more clearly and explain why wait_event_idle works.

I discovered [2] during the testing of the patch, this is also a very fruitful learning process.

I will write my change log more indicative next time, and do better work to our RCU community (and thanks for remove linux-kernel from CC list ;-))

Thanks
Zhouyi
[1] https://lore.kernel.org/lkml/[email protected]/T/
[2] https://lore.kernel.org/lkml/CAABZP2yS5=ZUwEZQ7iHkV0wDm_HgO8K-TeAhyJrZhavzKDa44Q@mail.gmail.com/T/

Quoted 31 lines

Thanks,

- Joel

Quoted 26 lines

Cheers
Zhouyi

Quoted 23 lines

Thanx, Paul

Quoted 20 lines

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

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcuscale.c +0 -0
index 91fb5905a008..d99c586939d1 100644
@@ -771,7 +771,7 @@ kfree_scale_cleanup(void)

static int
kfree_scale_shutdown(void *arg)
{

kernel/rcu/rcuscale.c +1 -2
-     wait_event(shutdown_wq,
+     wait_event_idle(shutdown_wq,
                atomic_read(&n_kfree_scale_thread_ended) >= kfree_nrealthreads);
 
     smp_mb(); /* Wake before output. */
--

2.34.1

#6 lore raw
Quoted 38 lines · Zhouyi Zhou

Sorry for the bad format of my previous email, there is always something wrong when I press Ctrl+C and Ctrl+V in my browser. Sorry for the inconvenience that I bring.

Quoted 24 lines · Joel Fernandes
Quoted 24 lines · Zhouyi Zhou
Quoted 18 lines · Paul E. McKenney
Quoted 12 lines · On Tue, May 02, 2023 at 08:01:41AM +0800, [email protected] wrote:

From: Zhouyi Zhou <[email protected]>

In kfree_rcu_test, kfree_scale_shutdown will be detected as hung task if kfree_loops is too big. Replace wait_event with wait_event_idle to avoid false positive.

Tested in the PPC VM of Open Source Lab of Oregon State University.

Good catch, thank you!

However, this commit beat you to it:

ef1ef3d47677 ("rcuscale: Move shutdown from wait_event() to wait_event_idle()")

Quoted 8 lines
Quoted 2 lines

You are very welcome ;-) Still, this is a very fruitful learning process for me ;-)

Speaking of learning, can you explain why it fixes the issue? ;-)

Your change log lacked the real reason but that is Ok since change logs can only tell you so much. I admit I myself did not know the reason till I read some code.

Quiz: why exactly does this all work out in the end even though the hung task detector saw it hung?

Quoted 13 lines

When I found "blocked for more than" report in console.log, I did a grep in kernel source tree, and found check_hung_task will only be invoked
from check_hung_uninterruptible_tas
ks when (state & TASK_UNINTERRUPTIBLE) and !(state & TASK_WAKEKILL) and !(state &
TASK_NOLOAD), so I send my first patch [1], and Paul tell me wait_event_idle is the right answer, then I do a grep for recursively expansion of macro wait_event_idle, which finally set current->state to TASK_IDLE ((TASK_UNINTERRUPTIBLE | TASK_NOLOAD)), then I conclude that check_hung_task will not be called. Yes, _interruptible() variant indicates that wakeups due to things like POSIX signals are permitted, which are not our case.

That sounds right!

Quoted 3 lines

I should investigate more on what wait_event_idle really means, instead of merely grep and debug what wait_event_idle does.
I should write my change log more clearly and explain why wait_event_idle works.

Sounds good, the header comments around those APIs should also help.

Quoted 7 lines

I discovered [2] during the testing of the patch, this is also a very fruitful learning process.

I will write my change log more indicative next time, and do better work to our RCU community (and thanks for remove linux-kernel from CC list ;-))

Sounds good, have fun! :)

- Joel