Skip to contentSkip to conversation

net: pktgen: Use wait_event_freezable_timeout() for freezable kthread

PATCH In review Kevin Hao 2 participants 3 messages Dec 16, 2023 – Dec 19, 2023

Subsystems (2)
lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

PATCH 1/1 net: pktgen: Use wait_event_freezable_timeout() for freezable kthread

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_timeout();
try_to_freeze();

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

---
 net/core/pktgen.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/pktgen.c +2 -4
index 57cea67b7562..2b59fc66fe26 100644
@@ -3669,10 +3669,8 @@ static int pktgen_thread_worker(void *arg)
 		if (unlikely(!pkt_dev && t->control == 0)) {
 			if (t->net->pktgen_exiting)
 				break;
-			wait_event_interruptible_timeout(t->queue,
-							 t->control != 0,
-							 HZ/10);
-			try_to_freeze();
+			wait_event_freezable_timeout(t->queue,
+						     t->control != 0, HZ/10);
 			continue;
 		}
 
Signature · 1 line
2.39.2
maintainer
#1 lore raw
Quoted 19 lines · 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_timeout();
try_to_freeze();

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

---
 net/core/pktgen.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/pktgen.c +0 -0
index 57cea67b7562..2b59fc66fe26 100644

net/core/pktgen.c static int pktgen_thread_worker(void *arg) · line 3673

Quoted 9 lines
net/core/pktgen.c +2 -4
@@ -3669,10 +3669,8 @@ static int pktgen_thread_worker(void *arg)
 		if (unlikely(!pkt_dev && t->control == 0)) {
 			if (t->net->pktgen_exiting)
 				break;
-			wait_event_interruptible_timeout(t->queue,
-							 t->control != 0,
-							 HZ/10);
-			try_to_freeze();
+			wait_event_freezable_timeout(t->queue,
+						     t->control != 0, HZ/10);

The patch looks functionally correct to me, so I'm sorry to nit-pick.

Since you touch the last line just for a 'cosmetic' change, please make checkpatch happy, too: please replace 'HZ/10' with 'HZ / 10'.

Thanks!

Paolo

author
#2 lore raw
Quoted 32 lines · Paolo Abeni
Quoted 19 lines · 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_timeout();
try_to_freeze();

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

---
 net/core/pktgen.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/pktgen.c +0 -0
index 57cea67b7562..2b59fc66fe26 100644

net/core/pktgen.c static int pktgen_thread_worker(void *arg) · line 3673

Quoted 9 lines
net/core/pktgen.c +2 -4
@@ -3669,10 +3669,8 @@ static int pktgen_thread_worker(void *arg)
 		if (unlikely(!pkt_dev && t->control == 0)) {
 			if (t->net->pktgen_exiting)
 				break;
-			wait_event_interruptible_timeout(t->queue,
-							 t->control != 0,
-							 HZ/10);
-			try_to_freeze();
+			wait_event_freezable_timeout(t->queue,
+						     t->control != 0, HZ/10);

The patch looks functionally correct to me, so I'm sorry to nit-pick.

Quoted 2 lines

Since you touch the last line just for a 'cosmetic' change, please make checkpatch happy, too: please replace 'HZ/10' with 'HZ / 10'.

Yes, I saw the complaint from checkpatch before sending this patch, but I thought I should keep it as it is. :-)
Anyway, v2 is coming.

Thanks,
Kevin

Quoted 5 lines

Thanks!

Paolo