[RTEMS Project] #1727: Reading of timestamps is not atomic in general

RTEMS trac trac at rtems.org
Thu Dec 18 09:23:06 UTC 2014


#1727: Reading of timestamps is not atomic in general
-----------------------------+----------------------------
 Reporter:  sebastian.huber  |       Owner:  joel.sherrill
     Type:  defect           |      Status:  closed
 Priority:  normal           |   Milestone:  4.11
Component:  cpukit           |     Version:  4.11
 Severity:  normal           |  Resolution:  wontfix
 Keywords:                   |
-----------------------------+----------------------------
Changes (by sebastian.huber):

 * status:  new => closed
 * resolution:   => wontfix


Old description:

> We use
>
> int64_t
>
> or
>
> struct timespec {
>   long tv_nsec;
>   long tv_sec;
> };
>
> for timestamps in the Score (Timestamp_Control).  The read of such values
> is in general not atomic.  We should provide a function
>
> void _Timestamp_Get( Timestamp_Control *val )
>
> for atomic reads of timestamps.  We can use interrupt enable/disable for
> this, or exploit the monotonic property of timestamps:
>
> do {
>   s0 = val->tv_sec;
>   ns0 = val->tv_nsec;
>   RTEMS_COMPILER_MEMORY_BARRIER();
>   s1 = val->tv_sec;
> } while (s0 != s1);
>
> I prefer the interrupt enable/disable variant.

New description:

 We use

 int64_t

 or

 struct timespec {
   long tv_nsec;
   long tv_sec;
 };

 for timestamps in the Score (Timestamp_Control).  The read of such values
 is in general not atomic.  We should provide a function

 void _Timestamp_Get( Timestamp_Control *val )

 for atomic reads of timestamps.  We can use interrupt enable/disable for
 this, or exploit the monotonic property of timestamps:

 do {
   s0 = val->tv_sec;
   ns0 = val->tv_nsec;
   RTEMS_COMPILER_MEMORY_BARRIER();
   s1 = val->tv_sec;
 } while (s0 != s1);

 I prefer the interrupt enable/disable variant.

--

Comment:

 In _TOD_Get_with_nanoseconds() interrupts are disabled for the snapshot.
 No plans to add a general  _Timestamp_Get().  The timestamp implementation
 should be replaced with FreeBSD timecounters.

--
Ticket URL: <http://devel.rtems.org/ticket/1727#comment:3>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list