From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: Re: [PATCH 8/8] x86/AMD: Clean up context_update() in AMD VPMU code Date: Thu, 11 Apr 2013 16:42:34 -0400 Message-ID: <5167203A.5030607@oracle.com> References: <1365528379-2516-1-git-send-email-boris.ostrovsky@oracle.com> <1365528379-2516-9-git-send-email-boris.ostrovsky@oracle.com> <5167137D.6000300@amd.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <5167137D.6000300@amd.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: Suravee Suthikulpanit Cc: jacob.shin@amd.com, haitao.shan@intel.com, jun.nakajima@intel.com, dietmar.hahn@ts.fujitsu.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On 04/11/2013 03:48 PM, Suravee Suthikulpanit wrote: > Boris, > > I have a couple questions. After patched, here is the final code: > > static int amd_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) > { > struct vcpu *v = current; > struct vpmu_struct *vpmu = vcpu_vpmu(v); > > if ( vpmu_is_set(vpmu, VPMU_STOPPED) ) > { > context_load(v); > vpmu_reset(vpmu, VPMU_STOPPED); > } > > if ( !vpmu_is_set(vpmu, VPMU_CONTEXT_LOADED) ) > context_read(msr, msr_content); > else > rdmsrl(msr, *msr_content); > > return 1; > } > > 1. Why do you need to call context_load() here since you checking if > the we are in VPMU_CONTEXT_LOADED and get the appropriate copy before > returning the msr_content? It is possible to be both LOADED and STOPPED. Example: guest writes control register (but does not enable the counters, so VPMU is not RUNNING). In this case amd_vpmu_load() will not get called from vpmu_load() so subsequent rdmsr of this control register in the guest will need to read from context and not from HW (since HW register is zero). In this case context_load() really only needs to load control registers; the counters themselves are the same in both context and HW. > 2. If you have already called context_load() above, shouldn't you have > to call "vpmu_set(vpmu, VPMU_CONTEXT_LOADED)" as well? But then, you > wouldn't be needing the latter logic, isn't it? Yes, you are right. I think we can get rid if context_read() completely and simply load the context if it is not LOADED or is STOPPED. Just like it is done in amd_vpmu_do_wrmsr(). -boris