All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: suravee.suthikulpanit@amd.com
Cc: JBeulich@suse.com, xen-devel@lists.xen.org
Subject: Re: [PATCH] Always save/restore performance counters when HVM guest switching VCPU
Date: Fri, 01 Mar 2013 18:02:50 -0500	[thread overview]
Message-ID: <5131339A.2070009@oracle.com> (raw)
In-Reply-To: <1362170975-2884-1-git-send-email-suravee.suthikulpanit@amd.com>

On 03/01/2013 03:49 PM, suravee.suthikulpanit@amd.com wrote:
> From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
>
> Currently, the performance counter registers are saved/restores
> when the HVM guest switchs VCPUs only if they are running.
> However, PERF has one check where it writes the MSR and read back
> the value to check if the MSR is working.  This has shown to fails
> the check if the VCPU is moved in between rdmsr and wrmsr and
> resulting in the values are different.
>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>

Description may need to be cleaned up a bit but other than that

Acked-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>

> ---
>   xen/arch/x86/hvm/svm/vpmu.c |   62 ++++++++++++++++++++++++-------------------
>   1 file changed, 35 insertions(+), 27 deletions(-)
>
> diff --git a/xen/arch/x86/hvm/svm/vpmu.c b/xen/arch/x86/hvm/svm/vpmu.c
> index bf186fe..4854cf3 100644
> --- a/xen/arch/x86/hvm/svm/vpmu.c
> +++ b/xen/arch/x86/hvm/svm/vpmu.c
> @@ -172,12 +172,16 @@ static inline void context_restore(struct vcpu *v)
>       {
>           wrmsrl(counters[i], ctxt->counters[i]);
>   
> +        if ( !vpmu_is_set(vpmu, VPMU_RUNNING) )
> +            continue;
> +
>           /* Force an interrupt to allow guest reset the counter,
>           if the value is positive */
>           if ( is_overflowed(ctxt->counters[i]) && (ctxt->counters[i] > 0) )
>           {
>               gdprintk(XENLOG_WARNING, "VPMU: Force a performance counter "
> -                "overflow interrupt!\n");
> +                "overflow interrupt! (counter:%u value:0x%lx)\n",
> +                i, ctxt->counters[i]);
>               amd_vpmu_do_interrupt(0);
>           }
>       }
> @@ -188,12 +192,13 @@ static void amd_vpmu_restore(struct vcpu *v)
>       struct vpmu_struct *vpmu = vcpu_vpmu(v);
>       struct amd_vpmu_context *ctxt = vpmu->context;
>   
> -    if ( !(vpmu_is_set(vpmu, VPMU_CONTEXT_ALLOCATED) &&
> -           vpmu_is_set(vpmu, VPMU_RUNNING)) )
> +    if ( !(vpmu_is_set(vpmu, VPMU_CONTEXT_ALLOCATED)) )
>           return;
>   
>       context_restore(v);
> -    apic_write(APIC_LVTPC, ctxt->hw_lapic_lvtpc);
> +
> +    if ( vpmu_is_set(vpmu, VPMU_RUNNING) )
> +        apic_write(APIC_LVTPC, ctxt->hw_lapic_lvtpc);
>   }
>   
>   static inline void context_save(struct vcpu *v)
> @@ -214,13 +219,16 @@ static void amd_vpmu_save(struct vcpu *v)
>       struct vpmu_struct *vpmu = vcpu_vpmu(v);
>       struct amd_vpmu_context *ctx = vpmu->context;
>   
> -    if ( !(vpmu_is_set(vpmu, VPMU_CONTEXT_ALLOCATED) &&
> -           vpmu_is_set(vpmu, VPMU_RUNNING)) )
> +    if ( !(vpmu_is_set(vpmu, VPMU_CONTEXT_ALLOCATED)) )
>           return;
>   
>       context_save(v);
> -    ctx->hw_lapic_lvtpc = apic_read(APIC_LVTPC);
> -    apic_write(APIC_LVTPC,  ctx->hw_lapic_lvtpc | APIC_LVT_MASKED);
> +
> +    if ( vpmu_is_set(vpmu, VPMU_RUNNING) )
> +    {
> +        ctx->hw_lapic_lvtpc = apic_read(APIC_LVTPC);
> +        apic_write(APIC_LVTPC,  ctx->hw_lapic_lvtpc | APIC_LVT_MASKED);
> +    }
>   }
>   
>   static void context_update(unsigned int msr, u64 msr_content)
> @@ -303,25 +311,25 @@ static int amd_vpmu_initialise(struct vcpu *v)
>   
>       if ( counters == NULL )
>       {
> -         switch ( family )
> -	 {
> -	 case 0x15:
> -	     num_counters = F15H_NUM_COUNTERS;
> -	     counters = AMD_F15H_COUNTERS;
> -	     ctrls = AMD_F15H_CTRLS;
> -	     k7_counters_mirrored = 1;
> -	     break;
> -	 case 0x10:
> -	 case 0x12:
> -	 case 0x14:
> -	 case 0x16:
> -	 default:
> -	     num_counters = F10H_NUM_COUNTERS;
> -	     counters = AMD_F10H_COUNTERS;
> -	     ctrls = AMD_F10H_CTRLS;
> -	     k7_counters_mirrored = 0;
> -	     break;
> -	 }
> +        switch ( family )
> +        {
> +        case 0x15:
> +            num_counters = F15H_NUM_COUNTERS;
> +            counters = AMD_F15H_COUNTERS;
> +            ctrls = AMD_F15H_CTRLS;
> +            k7_counters_mirrored = 1;
> +            break;
> +        case 0x10:
> +        case 0x12:
> +        case 0x14:
> +        case 0x16:
> +        default:
> +            num_counters = F10H_NUM_COUNTERS;
> +            counters = AMD_F10H_COUNTERS;
> +            ctrls = AMD_F10H_CTRLS;
> +            k7_counters_mirrored = 0;
> +            break;
> +        }
>       }
>   
>       ctxt = xzalloc(struct amd_vpmu_context);

  reply	other threads:[~2013-03-01 23:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-01 20:49 [PATCH] Always save/restore performance counters when HVM guest switching VCPU suravee.suthikulpanit
2013-03-01 23:02 ` Boris Ostrovsky [this message]
2013-03-04 12:42 ` George Dunlap
2013-03-08  8:47   ` Jan Beulich
2013-03-08 22:52     ` Suravee Suthikulanit
  -- strict thread matches above, loose matches on Subject: below --
2013-03-08 14:50 Boris Ostrovsky
2013-03-08 14:56 ` George Dunlap
2013-03-08 15:15   ` Jan Beulich
2013-03-08 15:11 Boris Ostrovsky
2013-03-11 11:11 ` George Dunlap
2013-03-11 14:53   ` Konrad Rzeszutek Wilk
2013-03-11 14:59     ` George Dunlap
2013-03-11 15:54       ` Boris Ostrovsky
2013-03-11 16:03     ` Jan Beulich
2013-03-12  8:18     ` Dietmar Hahn
2013-03-12 15:12       ` Konrad Rzeszutek Wilk

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=5131339A.2070009@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=xen-devel@lists.xen.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.