WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] Fix clock_gettime to increment monotonically onP

To: Jan Beulich <jbeulich@xxxxxxxxxx>, Atsushi SAKAI <sakaia@xxxxxxxxxxxxxx>, Keir Fraser <keir@xxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] Fix clock_gettime to increment monotonically onPV-domain/x86
From: Keir Fraser <Keir.Fraser@xxxxxxxxxxxx>
Date: Fri, 15 Jun 2007 12:19:50 +0100
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Fri, 15 Jun 2007 04:15:32 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <46729035.76E4.0078.0@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcevPxaUVVCohhsyEdyfcQAWy6hiGQ==
Thread-topic: [Xen-devel] [PATCH] Fix clock_gettime to increment monotonically onPV-domain/x86
User-agent: Microsoft-Entourage/11.3.3.061214
A spinlock is almost certainly no slower. Since the critical region is so
tiny the likelihood of spinning is very small. And the spin_lock() fast path
is probably faster than a CMPXCHG8B.

 -- Keir

On 15/6/07 12:12, "Jan Beulich" <jbeulich@xxxxxxxxxx> wrote:

> 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 = get_cpu();
> struct shadow_time_info *shadow = &per_cpu(shadow_time, cpu);
> cycle_t ret;
> 
> get_time_values_from_xen(cpu);
> 
> ret = shadow->system_timestamp + get_nsec_offset(shadow);
> 
> put_cpu();
> 
> #ifdef CONFIG_SMP
> for (;;) {
> static cycle_t last_ret;
> #ifndef CONFIG_64BIT
> cycle_t last = cmpxchg64(&last_ret, 0, 0);
> #else
> cycle_t last = 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=%Ld shadow=%Lu offset=%Lu\n",
>       cpu, ret - last,
>       shadow->system_timestamp,
>       get_nsec_offset(shadow));
> ret = last;
> }
> if (cmpxchg64(&last_ret, last, ret) == last)
> break;
> }
> #endif
> 
> return ret;
> }
> 
> Jan
> 
>>>> Keir Fraser <keir@xxxxxxxxxxxxx> 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" <jbeulich@xxxxxxxxxx> 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
>> 
>>>>> Atsushi SAKAI <sakaia@xxxxxxxxxxxxxx> 15.06.07 11:47 >>>
>> Hi, Keir
>> 
>>   This patch intends to increment do_gettimeofday monotonically.
>> This is for PV-domain/x86.
>> 
>> Signed-off-by: Atsushi SAKAI <sakaia@xxxxxxxxxxxxxx>
>> 
>> By applying patch, the time rollback for SMP is fixed.
>> This is important fixes for database software.
>> 
>> Thanks
>> Atsushi SAKAI
>> 
>> 
>> 
>> _______________________________________________
>> Xen-devel mailing list
>> Xen-devel@xxxxxxxxxxxxxxxxxxx
>> http://lists.xensource.com/xen-devel
> 
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/xen-devel



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>