All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Igor Mammedov <imammedo@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	x86@kernel.org, jacob.jun.pan@linux.intel.com,
	alan@linux.intel.com, feng.tang@intel.com,
	konrad.wilk@oracle.com, avi@redhat.com, glommer@redhat.com,
	johnstul@us.ibm.com, riel@redhat.com, tj@kernel.org,
	kosaki.motohiro@jp.fujitsu.com, akpm@linux-foundation.org,
	amit.shah@redhat.com
Subject: Re: [PATCH RFC] pvclock: Make pv_clock more robust and fixup it if overflow happens
Date: Mon, 13 Feb 2012 15:48:37 -0200	[thread overview]
Message-ID: <20120213174837.GA11513@amt.cnet> (raw)
In-Reply-To: <1329147959-22472-1-git-send-email-imammedo@redhat.com>

On Mon, Feb 13, 2012 at 04:45:59PM +0100, Igor Mammedov wrote:
> Instead of hunting misterious stalls/hungs all over the kernel when
> overflow occurs at pvclock.c:pvclock_get_nsec_offset
> 
>     u64 delta = native_read_tsc() - shadow->tsc_timestamp;
> 
> and introducing hooks when places of unexpected access found, pv_clock
> should be initialized for the calling cpu if overflow condition is detected.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Igor,

I disagree. This is fixing the symptom not the root cause. Additionally,
Xen also uses pvclock_clocksource_read.

How about adding a BUG_ON to detect the overflow, this way hunting for
the problem is not necessary.

>  arch/x86/kernel/pvclock.c |   18 +++++++++++++++---
>  1 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
> index 42eb330..b486756 100644
> --- a/arch/x86/kernel/pvclock.c
> +++ b/arch/x86/kernel/pvclock.c
> @@ -41,9 +41,14 @@ void pvclock_set_flags(u8 flags)
>  	valid_flags = flags;
>  }
>  
> -static u64 pvclock_get_nsec_offset(struct pvclock_shadow_time *shadow)
> +static u64 pvclock_get_nsec_offset(struct pvclock_shadow_time *shadow,
> +				   bool *overflow)
>  {
> -	u64 delta = native_read_tsc() - shadow->tsc_timestamp;
> +	u64 delta;
> +	u64 tsc = native_read_tsc();
> +	u64 shadow_timestamp = shadow->tsc_timestamp;
> +	*overflow = tsc < shadow_timestamp;
> +	delta = tsc - shadow_timestamp;
>  	return pvclock_scale_delta(delta, shadow->tsc_to_nsec_mul,
>  				   shadow->tsc_shift);
>  }
> @@ -94,12 +99,19 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
>  	unsigned version;
>  	cycle_t ret, offset;
>  	u64 last;
> +	bool overflow;
>  
>  	do {
>  		version = pvclock_get_time_values(&shadow, src);
>  		barrier();
> -		offset = pvclock_get_nsec_offset(&shadow);
> +		offset = pvclock_get_nsec_offset(&shadow, &overflow);
>  		ret = shadow.system_timestamp + offset;
> +		if (unlikely(overflow)) {
> +			memset(src, 0, sizeof(*src));
> +			barrier();
> +			x86_cpuinit.early_percpu_clock_init();
> +			continue;
> +		}
>  		barrier();
>  	} while (version != src->version);
>  
> -- 
> 1.7.7.6
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2012-02-13 17:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-07 21:05 x86: kvmclock: abstract save/restore sched_clock_state Marcelo Tosatti
2012-02-08 10:53 ` Igor Mammedov
2012-02-09 12:27 ` Amit Shah
2012-02-09 15:13   ` Igor Mammedov
2012-02-10 10:02     ` Amit Shah
2012-02-10 10:11       ` Igor Mammedov
2012-02-10 10:23         ` Amit Shah
2012-02-10 12:32       ` Marcelo Tosatti
2012-02-10 12:33         ` Marcelo Tosatti
2012-02-10 12:43           ` Igor Mammedov
2012-02-13 12:46             ` Amit Shah
2012-02-13 12:56           ` Amit Shah
2012-02-10 13:18         ` Amit Shah
2012-02-10 20:58           ` Igor Mammedov
2012-02-13 12:39             ` Amit Shah
2012-02-13 13:07 ` x86: kvmclock: abstract save/restore sched_clock_state (v2) Marcelo Tosatti
2012-02-13 15:20   ` Igor Mammedov
2012-02-13 15:52     ` Marcelo Tosatti
2012-02-15 10:28       ` Avi Kivity
2012-02-13 15:45   ` [PATCH RFC] pvclock: Make pv_clock more robust and fixup it if overflow happens Igor Mammedov
2012-02-13 17:48     ` Marcelo Tosatti [this message]
2012-02-13 18:15       ` Igor Mammedov
2012-02-13 16:26   ` x86: kvmclock: abstract save/restore sched_clock_state (v2) Amit Shah
2012-03-01  9:58 ` x86: kvmclock: abstract save/restore sched_clock_state Thomas Gleixner

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=20120213174837.GA11513@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@linux.intel.com \
    --cc=amit.shah@redhat.com \
    --cc=avi@redhat.com \
    --cc=feng.tang@intel.com \
    --cc=glommer@redhat.com \
    --cc=hpa@zytor.com \
    --cc=imammedo@redhat.com \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=johnstul@us.ibm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=x86@kernel.org \
    /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.