From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: Re: [PATCH] Fix clock_gettime to increment monotonically onPV-domain/x86 Date: Fri, 15 Jun 2007 13:12:21 +0200 Message-ID: <46729035.76E4.0078.0@novell.com> References: <467283C5.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Atsushi SAKAI , Keir Fraser Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org An alternative to a spin lock would be to use a 64-bit variable storing = the raw nanosecond value, and use cmpxchg to check/update it. I did it this way = for the clocksource monotonicity: static cycle_t xen_clocksource_read(void) { int cpu =3D get_cpu(); struct shadow_time_info *shadow =3D &per_cpu(shadow_time, cpu); cycle_t ret; get_time_values_from_xen(cpu); ret =3D shadow->system_timestamp + get_nsec_offset(shadow); put_cpu(); #ifdef CONFIG_SMP for (;;) { static cycle_t last_ret; #ifndef CONFIG_64BIT cycle_t last =3D cmpxchg64(&last_ret, 0, 0); #else cycle_t last =3D last_ret; #define cmpxchg64 cmpxchg #endif if ((s64)(ret - last) < 0) { if (last - ret > permitted_clock_jitter && printk_ratelimit()) printk(KERN_WARNING "clocksource/%d: " "Time went backwards: " "delta=3D%Ld shadow=3D%Lu offset=3D%= Lu\n", cpu, ret - last, shadow->system_timestamp, get_nsec_offset(shadow)); ret =3D last; } if (cmpxchg64(&last_ret, last, ret) =3D=3D last) break; } #endif return ret; } Jan >>> Keir Fraser 15.06.07 12:26 >>> Yeah, it needs a spinlock. Which is a shame, but it's still going to be = much faster than trapping into the hypervisor, which is the only other way = we're going to be able to achieve guaranteed monotonic time. We could avoid the lock if we guaranteed monotonic time only per task (thread). Or is that not really good enough? :-) -- Keir On 15/6/07 11:19, "Jan Beulich" wrote: > I'm afraid this isn't MP-safe - you're in a (pseudo-)read-locked section = of > code, > yet write a global variable (and even in two pieces). Jan >=20 >>>> Atsushi SAKAI 15.06.07 11:47 >>> > Hi, Keir >=20 > This patch intends to increment do_gettimeofday monotonically. > This is for PV-domain/x86. >=20 > Signed-off-by: Atsushi SAKAI >=20 > By applying patch, the time rollback for SMP is fixed. > This is important fixes for database software. >=20 > Thanks > Atsushi SAKAI >=20 >=20 >=20 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com=20 > http://lists.xensource.com/xen-devel=20