kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* set_current_state() use in loops confusion
@ 2015-06-07 16:37 Nicholas Mc Guire
  2015-06-08 10:06 ` Nicholas Mc Guire
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2015-06-07 16:37 UTC (permalink / raw)
  To: kernelnewbies


Hi !

 Noticed that in a number of cases - often while(!kthread_should_stop()){ loops
 the call to set_current_state(...) is inside the loop - but e.g. in the below
 case why would that be needed ? schedule() is not changing the state visibly
 for the loop - so what is the point of setting the state inside the loop ?

e.g. net/core/pktgen.c
        /* Wait for kthread_stop */
        while (!kthread_should_stop()) {
                set_current_state(TASK_INTERRUPTIBLE);
                schedule();
        }

from code review it seems to be that this would be equivalent

        set_current_state(TASK_INTERRUPTIBLE);
        while (!kthread_should_stop()) {
                schedule();
        }

what did I miss ?

thx!
hofrat

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

* set_current_state() use in loops confusion
  2015-06-07 16:37 set_current_state() use in loops confusion Nicholas Mc Guire
@ 2015-06-08 10:06 ` Nicholas Mc Guire
  0 siblings, 0 replies; 2+ messages in thread
From: Nicholas Mc Guire @ 2015-06-08 10:06 UTC (permalink / raw)
  To: kernelnewbies

On Sun, 07 Jun 2015, Nicholas Mc Guire wrote:

> 
> Hi !
> 
>  Noticed that in a number of cases - often while(!kthread_should_stop()){ loops
>  the call to set_current_state(...) is inside the loop - but e.g. in the below
>  case why would that be needed ? schedule() is not changing the state visibly
>  for the loop - so what is the point of setting the state inside the loop ?
> 
> e.g. net/core/pktgen.c
>         /* Wait for kthread_stop */
>         while (!kthread_should_stop()) {
>                 set_current_state(TASK_INTERRUPTIBLE);
>                 schedule();
>         }
> 
> from code review it seems to be that this would be equivalent
> 
>         set_current_state(TASK_INTERRUPTIBLE);
>         while (!kthread_should_stop()) {
>                 schedule();
>         }
> 
> what did I miss ?
>
rereading __schedule() - state after schedule() is always 
TASK_RUNNING - so setting it back to !=TASK_RUNNING would be 
needed in the loop - but in the above case I still don't get the point of
flipping the task state between TASK_INTERRUPTIBLE and TASK_RUNNING
the set_current_state(TASK_INTERRUPTIBLE); seems to have no real
effect as at the end of the loop state is TASK_RUNNING in any case 
and ntermediately it is in TASK_RUNNING state as well ?

so I still seem to be missing something here...

thx!
hofrat

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

end of thread, other threads:[~2015-06-08 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-07 16:37 set_current_state() use in loops confusion Nicholas Mc Guire
2015-06-08 10:06 ` Nicholas Mc Guire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).