gettimeofday seconds rollover problem?

Thomas Rauscher trauscher at loytec.com
Thu Feb 23 12:52:26 UTC 2006


  

> -----Original Message-----
> From: Joel Sherrill [mailto:joel.sherrill at oarcorp.com] 
> Sent: Thursday, February 23, 2006 1:26 PM
> To: Thomas Rauscher
> Cc: rtems-users; Thomas Doerfler; Andrew Sinclair
> Subject: Re: gettimeofday seconds rollover problem?
> 
> Thomas Rauscher wrote:
> 
> >The following macro is used in the Linux kernel. It tells the
> >compiler that the asm statement globbers memory in an
> >unpredictable way. The compiler cannot schedule instructions
> >over this barrier and has to forget all memory values kept in 
> >registers.
> >
> >/* Optimization barrier */
> >/* The "volatile" is due to gcc bugs */
> >#define barrier() __asm__ __volatile__("": : :"memory")
> >
> >I hope, this helps.
> >  
> >
> 
> Is this just a gcc 3.x issue or is it an issue with newer compilers.
> 

I've seen this with gcc 3.4. 

The compiler can delay stores to optimize CPU pipelining.
Then it is possible that a critical section is executed without having
written
back the memory location. I believe (though I'm not sure) that this
is even true for volatiles. This should be correct, as a C
compiler does not know about interrupts and threads.

I think this is the reason why Linux uses the barrier macros.

Regards,
Thomas Rauscher

--
Thomas Rauscher
LOYTEC electronics GmbH




More information about the users mailing list