All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] net/dev.c : Remove redundant state settings after waking up
@ 2023-01-10  9:14 李哲
  2023-01-10  9:29 ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: 李哲 @ 2023-01-10  9:14 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, bigeasy, imagedong, kuniyu, petrm
  Cc: netdev, linux-kernel, 李哲

the task status has been set to TASK_RUNNING in shcedule(),
no need to set again here

Signed-off-by: 李哲 <sensor1010@163.com>
---
 net/core/dev.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index b76fb37b381e..4bd2d4b954c9 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6580,7 +6580,6 @@ static int napi_thread_wait(struct napi_struct *napi)
 		schedule();
 		/* woken being true indicates this thread owns this napi. */
 		woken = true;
-		set_current_state(TASK_INTERRUPTIBLE);
 	}
 	__set_current_state(TASK_RUNNING);
 
-- 
2.17.1


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

* Re: [PATCH v1] net/dev.c : Remove redundant state settings after waking up
  2023-01-10  9:14 [PATCH v1] net/dev.c : Remove redundant state settings after waking up 李哲
@ 2023-01-10  9:29 ` Eric Dumazet
  2023-01-11  0:30   ` Jakub Kicinski
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2023-01-10  9:29 UTC (permalink / raw)
  To: 李哲, Wei Wang
  Cc: davem, kuba, pabeni, bigeasy, imagedong, kuniyu, petrm, netdev,
	linux-kernel

On Tue, Jan 10, 2023 at 10:15 AM 李哲 <sensor1010@163.com> wrote:
>
> the task status has been set to TASK_RUNNING in shcedule(),
> no need to set again here

Changelog is rather confusing, this does not match the patch, which
removes one set_current_state(TASK_INTERRUPTIBLE);

TASK_INTERRUPTIBLE != TASK_RUNNING

Patch itself looks okay (but has nothing to do with thread state after
schedule()),
you should have CC Wei Wang because she
authored commit cb038357937e net: fix race between napi kthread mode
and busy poll

>
> Signed-off-by: 李哲 <sensor1010@163.com>
> ---
>  net/core/dev.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index b76fb37b381e..4bd2d4b954c9 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -6580,7 +6580,6 @@ static int napi_thread_wait(struct napi_struct *napi)
>                 schedule();
>                 /* woken being true indicates this thread owns this napi. */
>                 woken = true;
> -               set_current_state(TASK_INTERRUPTIBLE);
>         }
>         __set_current_state(TASK_RUNNING);
>
> --
> 2.17.1
>

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

* Re: [PATCH v1] net/dev.c : Remove redundant state settings after waking up
  2023-01-10  9:29 ` Eric Dumazet
@ 2023-01-11  0:30   ` Jakub Kicinski
  2023-01-11  0:42     ` Wei Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2023-01-11  0:30 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: 李哲,
	Wei Wang, davem, pabeni, bigeasy, imagedong, kuniyu, petrm,
	netdev, linux-kernel

On Tue, 10 Jan 2023 10:29:20 +0100 Eric Dumazet wrote:
> > the task status has been set to TASK_RUNNING in shcedule(),
> > no need to set again here  
> 
> Changelog is rather confusing, this does not match the patch, which
> removes one set_current_state(TASK_INTERRUPTIBLE);
> 
> TASK_INTERRUPTIBLE != TASK_RUNNING
> 
> Patch itself looks okay (but has nothing to do with thread state after
> schedule()),
> you should have CC Wei Wang because she
> authored commit cb038357937e net: fix race between napi kthread mode
> and busy poll

AFAIU this is the semi-idiomatic way of handling wait loops.
It's not schedule() that may set the task state to TASK_RUNNING,
it's whoever wakes the process and makes the "wait condition" true.
In this case - test_bit(NAPI_STATE_SCHED, &napi->state)

I vote to not futz with this logic.

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

* Re: [PATCH v1] net/dev.c : Remove redundant state settings after waking up
  2023-01-11  0:30   ` Jakub Kicinski
@ 2023-01-11  0:42     ` Wei Wang
  2023-01-11  7:32       ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 8+ messages in thread
From: Wei Wang @ 2023-01-11  0:42 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Eric Dumazet, 李哲,
	davem, pabeni, bigeasy, imagedong, kuniyu, petrm, netdev,
	linux-kernel

I was not able to see the entire changelog, but I don't think
> -               set_current_state(TASK_INTERRUPTIBLE);
is redundant.

It makes sure that if the previous if statement:
    if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state) || woken)
is false, this napi thread yields the CPU to other threads waiting to
be run by calling schedule().

And the napi thread gets into running state again after the next
wake_up_process() is called from ____napi_schedule().


On Tue, Jan 10, 2023 at 4:30 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Tue, 10 Jan 2023 10:29:20 +0100 Eric Dumazet wrote:
> > > the task status has been set to TASK_RUNNING in shcedule(),
> > > no need to set again here
> >
> > Changelog is rather confusing, this does not match the patch, which
> > removes one set_current_state(TASK_INTERRUPTIBLE);
> >
> > TASK_INTERRUPTIBLE != TASK_RUNNING
> >
> > Patch itself looks okay (but has nothing to do with thread state after
> > schedule()),
> > you should have CC Wei Wang because she
> > authored commit cb038357937e net: fix race between napi kthread mode
> > and busy poll
>
> AFAIU this is the semi-idiomatic way of handling wait loops.
> It's not schedule() that may set the task state to TASK_RUNNING,
> it's whoever wakes the process and makes the "wait condition" true.
> In this case - test_bit(NAPI_STATE_SCHED, &napi->state)
>
> I vote to not futz with this logic.

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

* Re: [PATCH v1] net/dev.c : Remove redundant state settings after waking up
  2023-01-11  0:42     ` Wei Wang
@ 2023-01-11  7:32       ` Sebastian Andrzej Siewior
  2023-01-11 18:20         ` Jakub Kicinski
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-01-11  7:32 UTC (permalink / raw)
  To: Wei Wang
  Cc: Jakub Kicinski, Eric Dumazet, 李哲,
	davem, pabeni, imagedong, kuniyu, petrm, netdev, linux-kernel

On 2023-01-10 16:42:56 [-0800], Wei Wang wrote:
> I was not able to see the entire changelog, but I don't think
> > -               set_current_state(TASK_INTERRUPTIBLE);
> is redundant.
> 
> It makes sure that if the previous if statement:
>     if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state) || woken)
> is false, this napi thread yields the CPU to other threads waiting to
> be run by calling schedule().

It made sense in the beginning but now the suggested patch is a clean
up. First the `woken' parameter was added in commit
   cb038357937ee ("net: fix race between napi kthread mode and busy poll")

and then the `napi_disable_pending' check was removed in commit
   27f0ad71699de ("net: fix hangup on napi_disable for threaded napi")

which renders the code to:
|         while (!kthread_should_stop()) {
|                 if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state) || woken) {
|                         WARN_ON(!list_empty(&napi->poll_list));
|                         __set_current_state(TASK_RUNNING);
|                         return 0;
|                 }
| 
|                 schedule();
|                 /* woken being true indicates this thread owns this napi. */
|                 woken = true;
|                 set_current_state(TASK_INTERRUPTIBLE);
|         }
|         __set_current_state(TASK_RUNNING);

so when you get out of schedule() woken is set and even if
NAPI_STATE_SCHED_THREADED is not set, the while() loop is left due to
`woken = true'. So changing state to TASK_INTERRUPTIBLE makes no sense
since it will be set back to TASK_RUNNING cycles later.

Sebastian

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

* Re: [PATCH v1] net/dev.c : Remove redundant state settings after waking up
  2023-01-11  7:32       ` Sebastian Andrzej Siewior
@ 2023-01-11 18:20         ` Jakub Kicinski
  2023-01-11 19:39           ` Wei Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2023-01-11 18:20 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Wei Wang, Eric Dumazet, 李哲,
	davem, pabeni, imagedong, kuniyu, petrm, netdev, linux-kernel

On Wed, 11 Jan 2023 08:32:42 +0100 Sebastian Andrzej Siewior wrote:
> It made sense in the beginning but now the suggested patch is a clean
> up. First the `woken' parameter was added in commit
>    cb038357937ee ("net: fix race between napi kthread mode and busy poll")
> 
> and then the `napi_disable_pending' check was removed in commit
>    27f0ad71699de ("net: fix hangup on napi_disable for threaded napi")
> 
> which renders the code to:
> |         while (!kthread_should_stop()) {
> |                 if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state) || woken) {
> |                         WARN_ON(!list_empty(&napi->poll_list));
> |                         __set_current_state(TASK_RUNNING);
> |                         return 0;
> |                 }
> | 
> |                 schedule();
> |                 /* woken being true indicates this thread owns this napi. */
> |                 woken = true;
> |                 set_current_state(TASK_INTERRUPTIBLE);
> |         }
> |         __set_current_state(TASK_RUNNING);
> 
> so when you get out of schedule() woken is set and even if
> NAPI_STATE_SCHED_THREADED is not set, the while() loop is left due to
> `woken = true'. So changing state to TASK_INTERRUPTIBLE makes no sense
> since it will be set back to TASK_RUNNING cycles later.

Ah, fair point, forgot about the woken optimization.

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

* Re: [PATCH v1] net/dev.c : Remove redundant state settings after waking up
  2023-01-11 18:20         ` Jakub Kicinski
@ 2023-01-11 19:39           ` Wei Wang
       [not found]             ` <706ea669.7a09.1869dce0851.Coremail.sensor1010@163.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Wei Wang @ 2023-01-11 19:39 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Sebastian Andrzej Siewior, Eric Dumazet, 李哲,
	davem, pabeni, imagedong, kuniyu, petrm, netdev, linux-kernel

On Wed, Jan 11, 2023 at 10:21 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 11 Jan 2023 08:32:42 +0100 Sebastian Andrzej Siewior wrote:
> > It made sense in the beginning but now the suggested patch is a clean
> > up. First the `woken' parameter was added in commit
> >    cb038357937ee ("net: fix race between napi kthread mode and busy poll")
> >
> > and then the `napi_disable_pending' check was removed in commit
> >    27f0ad71699de ("net: fix hangup on napi_disable for threaded napi")
> >
> > which renders the code to:
> > |         while (!kthread_should_stop()) {
> > |                 if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state) || woken) {
> > |                         WARN_ON(!list_empty(&napi->poll_list));
> > |                         __set_current_state(TASK_RUNNING);
> > |                         return 0;
> > |                 }
> > |
> > |                 schedule();
> > |                 /* woken being true indicates this thread owns this napi. */
> > |                 woken = true;
> > |                 set_current_state(TASK_INTERRUPTIBLE);
> > |         }
> > |         __set_current_state(TASK_RUNNING);
> >
> > so when you get out of schedule() woken is set and even if
> > NAPI_STATE_SCHED_THREADED is not set, the while() loop is left due to
> > `woken = true'. So changing state to TASK_INTERRUPTIBLE makes no sense
> > since it will be set back to TASK_RUNNING cycles later.
>
> Ah, fair point, forgot about the woken optimization.

Agree. I think it is OK to remove this, since woken is set, and this
function will set TASK_RUNNING and return 0. And the next time, it
will enter with TASK_INTERRUPTIBLE and woken = false.

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

* Re: [PATCH v1] net/dev.c : Remove redundant state settings after waking up
       [not found]             ` <706ea669.7a09.1869dce0851.Coremail.sensor1010@163.com>
@ 2023-03-01 17:07               ` Jakub Kicinski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2023-03-01 17:07 UTC (permalink / raw)
  To: lizhe
  Cc: Wei Wang, Sebastian Andrzej Siewior, Eric Dumazet, davem, pabeni,
	imagedong, kuniyu, petrm, netdev, linux-kernel

On Wed, 1 Mar 2023 23:32:50 +0800 (CST) lizhe wrote:
> HI : 
>       if want to merge this patch into the main line, what should i do ?

Stop sending HTML emails please, the list only accepts plain text.

Read this:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

Improve the commit message and the subject line (look at other related
commits to find examples). Repost when appropriate (net-next is closed).

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

end of thread, other threads:[~2023-03-01 17:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10  9:14 [PATCH v1] net/dev.c : Remove redundant state settings after waking up 李哲
2023-01-10  9:29 ` Eric Dumazet
2023-01-11  0:30   ` Jakub Kicinski
2023-01-11  0:42     ` Wei Wang
2023-01-11  7:32       ` Sebastian Andrzej Siewior
2023-01-11 18:20         ` Jakub Kicinski
2023-01-11 19:39           ` Wei Wang
     [not found]             ` <706ea669.7a09.1869dce0851.Coremail.sensor1010@163.com>
2023-03-01 17:07               ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.