Pino Toscano, le Mon 02 Apr 2012 22:33:36 +0200, a écrit :
> @@ -103,6 +104,16 @@
>               mtime->microseconds = (time)->microseconds;     \
>               asm volatile("":::"memory");                    \
>               mtime->seconds = (time)->seconds;               \
> +             asm volatile("":::"memory");                    \
> +             mtime->clock_rt.seconds = (time)->seconds;      \
> +             asm volatile("":::"memory");                    \
> +             mtime->clock_rt.nanoseconds =                   \
> +                     (time)->microseconds * 1000;            \
> +             asm volatile("":::"memory");                    \
> +             mtime->clock_mt.seconds = (monotonic)->seconds; \
> +             asm volatile("":::"memory");                    \
> +             mtime->clock_mt.nanoseconds =                   \
> +                     (monotonic)->microseconds * 1000;       \
>       }                                                       \
>  MACRO_END
>  

This does not actually bring read safety. The original code uses
memory barriers to make sure that microsecond update happens
between check_seconds and seconds are updated, so that code like
record_time_stamp works. That part needs to be kept as is for
compatibility, and additions need to implement something similar. Just
putting memory barriers will not work, you'd also need a similar
check_foo field, and test it in the reader part; or use a generation
number, like xnu's commpage_set_nanotime, something like:

sav = mtime->generation;
mtime->generation = 0
asm volatile("":::"memory");
mtime->clock_rt.seconds = (time)->seconds
mtime->clock_rt.nanoseconds = (time)->microseconds * 1000.
mtime->clock_mt.seconds = (monotonic)->seconds
mtime->clock_mt.nanoseconds = (monotonic)->microseconds * 1000.
asm volatile("":::"memory");
mtime->generation = sav+1;

Samuel

Reply via email to