Skip to contentSkip to conversation

powerpc: Fixes and optimization for the freezable kthread

PATCH Applied Kevin Hao 4 participants 7 messages Dec 21, 2023 – Dec 31, 2023

Subsystems (3)
lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

cover powerpc: Fixes and optimization for the freezable kthread

Hi,

The main changes include:
- Invoke set_freezable() for the kthread which could be frozen
- Drop redundant try_to_freeze() invocation

Kevin Hao (3):
powerpc: mpc83xx: Add the missing set_freezable() for
agent_thread_fn()
powerpc: mpc83xx: Use wait_event_freezable() for freezable kthread
powerpc: ps3: Add missing set_freezable() for ps3_probe_thread()

 arch/powerpc/platforms/83xx/suspend.c    | 5 +++--
 arch/powerpc/platforms/ps3/device-init.c | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.2
author
#1 lore raw

PATCH 1/3 powerpc: mpc83xx: Add the missing set_freezable() for agent_thread_fn()

The kernel thread function agent_thread_fn() invokes the try_to_freeze() in its loop. But all the kernel threads are non-freezable by default. So if we want to make a kernel thread to be freezable, we have to invoke set_freezable() explicitly.

---
 arch/powerpc/platforms/83xx/suspend.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/platforms/83xx/suspend.c +2 -0
index 9833c36bda83..eed325ed08cc 100644
@@ -261,6 +261,8 @@ static int mpc83xx_suspend_begin(suspend_state_t state)
 
 static int agent_thread_fn(void *data)
 {
+	set_freezable();
+
 	while (1) {
 		wait_event_interruptible(agent_wq, pci_pm_state >= 2);
 		try_to_freeze();
Signature · 1 line
2.39.2
author
#2 lore raw

PATCH 2/3 powerpc: mpc83xx: Use wait_event_freezable() for freezable kthread

In reply to Kevin Hao

A freezable kernel thread can enter frozen state during freezing by either calling try_to_freeze() or using wait_event_freezable() and its variants. So for the following snippet of code in a kernel thread loop:
wait_event_interruptible();
try_to_freeze();

We can change it to a simple wait_event_freezable() and then eliminate a function call.

---
 arch/powerpc/platforms/83xx/suspend.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/platforms/83xx/suspend.c +1 -2
index eed325ed08cc..c9664e46b03d 100644
@@ -264,8 +264,7 @@ static int agent_thread_fn(void *data)
 	set_freezable();
 
 	while (1) {
-		wait_event_interruptible(agent_wq, pci_pm_state >= 2);
-		try_to_freeze();
+		wait_event_freezable(agent_wq, pci_pm_state >= 2);
 
 		if (signal_pending(current) || pci_pm_state < 2)
 			continue;
Signature · 1 line
2.39.2
author
#3 lore raw

PATCH 3/3 powerpc: ps3: Add missing set_freezable() for ps3_probe_thread()

In reply to Kevin Hao

The kernel thread function ps3_probe_thread() invokes the try_to_freeze() in its loop. But all the kernel threads are non-freezable by default. So if we want to make a kernel thread to be freezable, we have to invoke set_freezable() explicitly.

---
 arch/powerpc/platforms/ps3/device-init.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/platforms/ps3/device-init.c +1 -0
index e87360a0fb40..878bc160246e 100644
@@ -827,6 +827,7 @@ static int ps3_probe_thread(void *data)
 	if (res)
 		goto fail_free_irq;
 
+	set_freezable();
 	/* Loop here processing the requested notification events. */
 	do {
 		try_to_freeze();
Signature · 1 line
2.39.2
maintainer
#4 lore raw

Re: [PATCH 3/3] powerpc: ps3: Add missing set_freezable() for ps3_probe_thread()

Hi Kevin,

Quoted 15 lines · Kevin Hao

The kernel thread function ps3_probe_thread() invokes the try_to_freeze() in its loop. But all the kernel threads are non-freezable by default. So if we want to make a kernel thread to be freezable, we have to invoke set_freezable() explicitly.

---
 arch/powerpc/platforms/ps3/device-init.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/platforms/ps3/device-init.c +0 -0
index e87360a0fb40..878bc160246e 100644

arch/powerpc/platforms/ps3/device-init.c static int ps3_probe_thread(void *data) · line 833

Quoted 7 lines
arch/powerpc/platforms/ps3/device-init.c +1 -0
@@ -827,6 +827,7 @@ static int ps3_probe_thread(void *data)
 	if (res)
 		goto fail_free_irq;
 
+	set_freezable();
 	/* Loop here processing the requested notification events. */
 	do {
 		try_to_freeze();

Seems like a reasonable addition.

#5 lore raw

Re: [PATCH 3/3] powerpc: ps3: Add missing set_freezable() for ps3_probe_thread()

Quoted 21 lines · Geoff Levand

Hi Kevin,

Quoted 18 lines · Kevin Hao

The kernel thread function ps3_probe_thread() invokes the try_to_freeze() in its loop. But all the kernel threads are non-freezable by default. So if we want to make a kernel thread to be freezable, we have to invoke set_freezable() explicitly.

---
 arch/powerpc/platforms/ps3/device-init.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/platforms/ps3/device-init.c +0 -0
index e87360a0fb40..878bc160246e 100644
@@ -827,6 +827,7 @@ static int ps3_probe_thread(void *data)
 	if (res)
 		goto fail_free_irq;
 
Quoted 8 lines

arch/powerpc/platforms/ps3/device-init.c static int ps3_probe_thread(void *data) · line 833

Quoted 4 lines
arch/powerpc/platforms/ps3/device-init.c +1 -0
+	set_freezable();
 	/* Loop here processing the requested notification events. */
 	do {
 		try_to_freeze();

Seems like a reasonable addition.

I turned that into an Acked-by, which I think is what you meant :)

cheers

#6 lore raw
In reply to Kevin Hao
Quoted 11 lines · Kevin Hao

The main changes include:
- Invoke set_freezable() for the kthread which could be frozen
- Drop redundant try_to_freeze() invocation

Kevin Hao (3):
powerpc: mpc83xx: Add the missing set_freezable() for
agent_thread_fn()
powerpc: mpc83xx: Use wait_event_freezable() for freezable kthread
powerpc: ps3: Add missing set_freezable() for ps3_probe_thread()

[...]

Applied to powerpc/next.

[1/3] powerpc: mpc83xx: Add the missing set_freezable() for agent_thread_fn()

      https://git.kernel.org/powerpc/c/6addc560e69cd1b2e68ef43ad62a878ac1956f51
[2/3] powerpc: mpc83xx: Use wait_event_freezable() for freezable kthread
      https://git.kernel.org/powerpc/c/11611d254c15cce1f58431b2965c6edb5aa7e610
[3/3] powerpc: ps3: Add missing set_freezable() for ps3_probe_thread()
      https://git.kernel.org/powerpc/c/ccc0f7b7673e63139ba9d916f4567d4fadb14b55

cheers