diff mbox series

[net-next] net: pktgen: Use wait_event_freezable_timeout() for freezable kthread

Message ID 20231216112632.2255398-1-haokexin@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: pktgen: Use wait_event_freezable_timeout() for freezable kthread | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1115 this patch: 1115
netdev/cc_maintainers warning 1 maintainers not CCed: liangchen.linux@gmail.com
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch warning CHECK: spaces preferred around that '/' (ctx:VxV)
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Kevin Hao Dec. 16, 2023, 11:26 a.m. UTC
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.

Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
 net/core/pktgen.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Paolo Abeni Dec. 19, 2023, 12:37 p.m. UTC | #1
On Sat, 2023-12-16 at 19:26 +0800, Kevin Hao wrote:
> 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.
> 
> Signed-off-by: Kevin Hao <haokexin@gmail.com>
> ---
>  net/core/pktgen.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 57cea67b7562..2b59fc66fe26 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -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
Kevin Hao Dec. 19, 2023, 11:24 p.m. UTC | #2
On Tue, Dec 19, 2023 at 01:37:23PM +0100, Paolo Abeni wrote:
> On Sat, 2023-12-16 at 19:26 +0800, Kevin Hao wrote:
> > 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.
> > 
> > Signed-off-by: Kevin Hao <haokexin@gmail.com>
> > ---
> >  net/core/pktgen.c | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> > index 57cea67b7562..2b59fc66fe26 100644
> > --- a/net/core/pktgen.c
> > +++ b/net/core/pktgen.c
> > @@ -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'.

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
> 
> Thanks!
> 
> Paolo
>
diff mbox series

Patch

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 57cea67b7562..2b59fc66fe26 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -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;
 		}