gettimeofday seconds rollover problem?

Eric Norum norume at aps.anl.gov
Fri Feb 24 14:38:01 UTC 2006


On Feb 24, 2006, at 1:16 AM, Andrew Sinclair wrote:

>
> 1) interesting...
> 2) I think an alternative here is adding all the registers to the
> clobber list in the "barrier", we can force the compiler to reload any
> data into registers, and perform stores within the critical sections.
>
> 3) Yes, on second thoughts I think you have something here. It is  
> safer
> as one single asm volatile statement.
>
>
> For example on the Coldfire...
>
> #define m68k_disable_interrupts( _level ) \
>     do { register unsigned32   _tmpsr = 0x0700; \
>          asm __volatile__ ( "move.w %%sr,%0\n\t" \
>   		       "or.l   %0,%1\n\t" \
>   		       "move.w %1,%%sr" \
>   		       : "=d" (_level), "=d"(_tmpsr) : "1"(_tmpsr) \
>   		       :"cc","d0","d1","d2","d3","d4","d5", \
>  		       "a0","a1","a2","a3","a4","a5","a6","memory" ); \
>     } while( 0 )
>
> #define m68k_enable_interrupts( _level ) \
>     do { asm __volatile__ ( "move.w  %0,%%sr " : : "d" (_level) \
>        :"cc","d0","d1","d2","d3","d4","d5", \
>        "a0","a1","a2","a3","a4","a5","a6","memory" ); \
> 	} while( 0 )
>
> #define m68k_flash_interrupts( _level ) \
>    do { register unsigned32 _tmpsr = 0x0700; \
> 		asm __volatile__ ( "move.w %2,%%sr\n\t" \
> 		       "or.l   %2,%1\n\t" \
> 		       "move.w %1,%%sr" \
> 		       : "=d"(_tmpsr) : "0"(_tmpsr), "d"(_level) \
>  		       :"cc","d0","d1","d2","d3","d4","d5", \
>  		       "a0","a1","a2","a3","a4","a5","a6","memory" ); \
>    } while( 0 )

I *really* don't like this.
Given that the assembly instructions in question don't affect d0-d5/ 
a0-a6 why would you want to place them in the clobber list?

To summarize my position:
1) The _TOD_* variables must be declared as volatile since their  
values can change in a fashion (Deus ex machina) not apparent to  
compiler.
2) The M68K_BARRIER macro, or its equivalent addition to the enable/ 
disable macros, is required to keep the optimizer from hoisting/ 
sinking any code beyond the interrupt disable/enable operations.   My  
feeling is that it's clearer and simpler to just add the "memory",  
"cc" to the disable/enable macros, but I'm not dogmatic about this.

These two steps seem very clear to me since they impart to the  
compiler exactly the information needed.  Both steps are necessary  
and together they should be sufficient.

-- 
Eric Norum <norume at aps.anl.gov>
Advanced Photon Source
Argonne National Laboratory
(630) 252-4793





More information about the users mailing list