All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <jbeulich@novell.com>
To: Atsushi SAKAI <sakaia@jp.fujitsu.com>, Keir Fraser <keir@xensource.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] Fix clock_gettime to increment monotonically onPV-domain/x86
Date: Fri, 15 Jun 2007 13:12:21 +0200	[thread overview]
Message-ID: <46729035.76E4.0078.0@novell.com> (raw)
In-Reply-To: <C29827EB.9300%keir@xensource.com>

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@xensource.com> 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@novell.com> 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@jp.fujitsu.com> 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@jp.fujitsu.com>
> 
> 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@lists.xensource.com 
> http://lists.xensource.com/xen-devel 

  reply	other threads:[~2007-06-15 11:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-15  9:47 [PATCH] Fix clock_gettime to increment monotonically on PV-domain/x86 Atsushi SAKAI
2007-06-15 10:19 ` [PATCH] Fix clock_gettime to increment monotonically onPV-domain/x86 Jan Beulich
2007-06-15 10:26   ` Keir Fraser
2007-06-15 11:12     ` Jan Beulich [this message]
2007-06-15 11:19       ` Keir Fraser
2007-06-15 12:47       ` John Levon
2007-06-15 12:59         ` Keir Fraser
2007-06-15 13:08           ` John Levon
2007-06-15 13:21             ` Keir Fraser
2007-06-15 14:00               ` John Levon
2007-06-15 14:18                 ` Keir Fraser
2007-06-15 14:32                   ` John Levon
2007-06-15 13:58             ` [PATCH] Fix clock_gettime to increment monotonicallyonPV-domain/x86 Atsushi SAKAI
2007-06-15 11:44     ` [PATCH] Fix clock_gettime to incrementmonotonically onPV-domain/x86 Atsushi SAKAI
2007-06-19  9:21       ` [PATCH] Fix clock_gettime to incrementmonotonicallyonPV-domain/x86 Atsushi SAKAI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46729035.76E4.0078.0@novell.com \
    --to=jbeulich@novell.com \
    --cc=keir@xensource.com \
    --cc=sakaia@jp.fujitsu.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.