linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Inconsistency in changing the state of task ??
@ 2003-03-04  8:36 prash_t
  2003-03-04 17:51 ` Robert Love
  0 siblings, 1 reply; 6+ messages in thread
From: prash_t @ 2003-03-04  8:36 UTC (permalink / raw)
  To: linux-kernel

Hi,
     while browsing through fs/select.c file of 2.4.19, I came across two 
DIFFERENT ways of changing the state of the current task in do_select(): 

            set_current_state = TASK_INTERRUPTIBLE;
     AND    current->state = TASK_RUNNING; 

I am curious to know if the second line of code doesn't cause any problem in 
SMP systems.  I also see the same situation in do_poll(). 

Please cc to my id since I am not subscribed to the mailing list. 

Thanks
Prashanth

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

* Re: Inconsistency in changing the state of task ??
  2003-03-04  8:36 Inconsistency in changing the state of task ?? prash_t
@ 2003-03-04 17:51 ` Robert Love
  2003-03-06 13:11   ` prash_t
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Love @ 2003-03-04 17:51 UTC (permalink / raw)
  To: prash_t; +Cc: linux-kernel

On Tue, 2003-03-04 at 03:36, prash_t@softhome.net wrote:

>      while browsing through fs/select.c file of 2.4.19, I came across two 
> DIFFERENT ways of changing the state of the current task in do_select(): 
> 
>             set_current_state = TASK_INTERRUPTIBLE;
>      AND    current->state = TASK_RUNNING; 
> 
> I am curious to know if the second line of code doesn't cause any problem in 
> SMP systems.  I also see the same situation in do_poll().

You normally want to use set_current_state(), which is a nice
abstraction and safe for SMP.

Sometimes it is safe to use __set_current_state(), which does not
provide a memory barrier.

The above open-coded line can be changed to
__set_current_state(TASK_RUNNING).

	Robert Love


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

* Re: Inconsistency in changing the state of task ??
  2003-03-04 17:51 ` Robert Love
@ 2003-03-06 13:11   ` prash_t
  2003-03-06 13:31     ` Richard B. Johnson
  2003-03-06 20:05     ` Robert Love
  0 siblings, 2 replies; 6+ messages in thread
From: prash_t @ 2003-03-06 13:11 UTC (permalink / raw)
  To: Robert Love; +Cc: linux-kernel

Thanks Robert for the reply.
But I notice that __set_current_state() is same as current->state. So, I 
didn't understand the safety factor on using __set_current_state( ). 

Also why should I use __set_current_state() instead of set_current_state() 
when the later is SMP safe. 

Thanks in advance....
Prashanth 

Robert Love writes: 

> On Tue, 2003-03-04 at 03:36, prash_t@softhome.net wrote: 
> 
>>      while browsing through fs/select.c file of 2.4.19, I came across two 
>> DIFFERENT ways of changing the state of the current task in do_select():  
>> 
>>             set_current_state = TASK_INTERRUPTIBLE;
>>      AND    current->state = TASK_RUNNING;  
>> 
>> I am curious to know if the second line of code doesn't cause any problem in 
>> SMP systems.  I also see the same situation in do_poll().
> 
> You normally want to use set_current_state(), which is a nice
> abstraction and safe for SMP. 
> 
> Sometimes it is safe to use __set_current_state(), which does not
> provide a memory barrier. 
> 
> The above open-coded line can be changed to
> __set_current_state(TASK_RUNNING). 
> 
> 	Robert Love 
> 
 

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

* Re: Inconsistency in changing the state of task ??
  2003-03-06 13:11   ` prash_t
@ 2003-03-06 13:31     ` Richard B. Johnson
  2003-03-06 20:05     ` Robert Love
  1 sibling, 0 replies; 6+ messages in thread
From: Richard B. Johnson @ 2003-03-06 13:31 UTC (permalink / raw)
  To: prash_t; +Cc: Robert Love, linux-kernel

On Thu, 6 Mar 2003 prash_t@softhome.net wrote:

> Thanks Robert for the reply.
> But I notice that __set_current_state() is same as current->state. So, I 
> didn't understand the safety factor on using __set_current_state( ). 
> 
> Also why should I use __set_current_state() instead of set_current_state() 
> when the later is SMP safe. 
> 
> Thanks in advance....
> Prashanth 
[SNIPPED...]

Usually, it would not make any difference. However, there is a
de facto standard to not use "__functions" or "__macros" directly
in code. Those are the things that the integrator will change to
accommodate different configurations, i.e., whether you are running
on a '386, '686, PPC or Sparc, SMP/High-memory, etc. So, you use
function() instead of _function() or __function().  If you use this
standard you might start out with this in some header:

#define function(p)  __function(p)

But in SMP machines, you might need some other code. Rather than
you having to modify your source, some header changes the definition
and it might become:

#define function(p) do{ MB(); __function(p); } while (0)

How, if you had executed __function() directly in your code,
you end up tossing that driver into the scrap-heap until it
gets fixed for SMP.


Bottom line; Look at the headers. If you have a choice, don't
use a function or macro that has leading underscores. If you
copy "working" drivers, you can be copying latent bugs. Don't
blindly go where others have gone (Star-Trek fans blink).


Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.



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

* Re: Inconsistency in changing the state of task ??
  2003-03-06 13:11   ` prash_t
  2003-03-06 13:31     ` Richard B. Johnson
@ 2003-03-06 20:05     ` Robert Love
  1 sibling, 0 replies; 6+ messages in thread
From: Robert Love @ 2003-03-06 20:05 UTC (permalink / raw)
  To: prash_t; +Cc: linux-kernel

On Thu, 2003-03-06 at 08:11, prash_t@softhome.net wrote:

> Thanks Robert for the reply.
> But I notice that __set_current_state() is same as current->state. So, I 
> didn't understand the safety factor on using __set_current_state( ). 

There is no safety with __set_current_state().  It is just an
abstraction.

The safety comes from set_current_state(), which ensures memory
ordering.

This is an issue not just on SMP, but on a weakly ordered processor like
Alpha.

> Also why should I use __set_current_state() instead of set_current_state() 
> when the later is SMP safe.

You only use __set_current_state() if you know you do not need to ensure
memory ordering constraints.

	Robert Love


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

* RE: Inconsistency in changing the state of task ??
@ 2003-03-07  4:22 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 6+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-03-07  4:22 UTC (permalink / raw)
  To: 'Robert Love', 'prash_t@softhome.net'
  Cc: 'linux-kernel@vger.kernel.org'

> > Thanks Robert for the reply.
> > But I notice that __set_current_state() is same as current->state. So, I
> > didn't understand the safety factor on using __set_current_state( ).
> 
> There is no safety with __set_current_state().  It is just an
> abstraction.
> 
> The safety comes from set_current_state(), which ensures memory
> ordering.
> 
> This is an issue not just on SMP, but on a weakly ordered processor like
> Alpha.
> 
> > Also why should I use __set_current_state() instead of
> set_current_state()
> > when the later is SMP safe.
> 
> You only use __set_current_state() if you know you do not need to ensure
> memory ordering constraints.

Man, I forgot how many times I have already posted the patch to fix this ...

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)



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

end of thread, other threads:[~2003-03-07  4:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-04  8:36 Inconsistency in changing the state of task ?? prash_t
2003-03-04 17:51 ` Robert Love
2003-03-06 13:11   ` prash_t
2003-03-06 13:31     ` Richard B. Johnson
2003-03-06 20:05     ` Robert Love
2003-03-07  4:22 Perez-Gonzalez, Inaky

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).