From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: [PATCH v5 1/3] x86: Use native RDTSC(P) execution when guest and host frequencies are the same Date: Wed, 16 Apr 2014 18:59:23 -0400 Message-ID: <1397689165-5242-2-git-send-email-boris.ostrovsky@oracle.com> References: <1397689165-5242-1-git-send-email-boris.ostrovsky@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1397689165-5242-1-git-send-email-boris.ostrovsky@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: kevin.tian@intel.com, suravee.suthikulpanit@amd.com, eddie.dong@intel.com, jbeulich@suse.com, jun.nakajima@intel.com, boris.ostrovsky@oracle.com List-Id: xen-devel@lists.xenproject.org We should be able to continue using native RDTSC(P) execution on HVM/PVH guests after migration if host and guest frequencies are equal (this includes the case when the frequencies are made equal by TSC scaling feature). This also allows us to revert main part of commit 4aab59a3 (svm: Do not intercept RDTSC(P) when TSC scaling is supported by hardware) which was wrong: while RDTSC intercepts were disabled domain's vtsc could still be set, leading to inconsistent view of guest's TSC. Signed-off-by: Boris Ostrovsky --- xen/arch/x86/hvm/svm/svm.c | 2 +- xen/arch/x86/time.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 4fd5376..813e775 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -728,7 +728,7 @@ static void svm_set_rdtsc_exiting(struct vcpu *v, bool_t enable) general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC; general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP; - if ( enable && !cpu_has_tsc_ratio ) + if ( enable ) { general1_intercepts |= GENERAL1_INTERCEPT_RDTSC; general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP; diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 07bceda..555f7c8 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -37,6 +37,7 @@ #include #include #include /* for early_time_init */ +#include /* for cpu_has_tsc_ratio */ #include /* opt_clocksource: Force clocksource to one of: pit, hpet, acpi. */ @@ -1889,10 +1890,16 @@ void tsc_set_info(struct domain *d, d->arch.vtsc_offset = get_s_time() - elapsed_nsec; d->arch.tsc_khz = gtsc_khz ? gtsc_khz : cpu_khz; set_time_scale(&d->arch.vtsc_to_ns, d->arch.tsc_khz * 1000 ); - /* use native TSC if initial host has safe TSC, has not migrated - * yet and tsc_khz == cpu_khz */ - if ( host_tsc_is_safe() && incarnation == 0 && - d->arch.tsc_khz == cpu_khz ) + /* + * Use native TSC if the host has safe TSC and: + * HVM/PVH: host and guest frequencies are the same (either + * "naturally" or via TSC scaling) + * PV: guest has not migrated yet (and thus arch.tsc_khz == cpu_khz) + */ + if ( host_tsc_is_safe() && + ((has_hvm_container_domain(d) && + (d->arch.tsc_khz == cpu_khz || cpu_has_tsc_ratio)) || + incarnation == 0) ) d->arch.vtsc = 0; else d->arch.ns_to_vtsc = scale_reciprocal(d->arch.vtsc_to_ns); -- 1.7.1