Re: [Xen-devel] [PATCH v2 2/3] x86/vmx: optimize vmx_read/write_guest_msr()

2017-02-22 Thread Jan Beulich
>>> On 17.02.17 at 16:42,  wrote:
> --- a/xen/arch/x86/hvm/vmx/vmcs.c
> +++ b/xen/arch/x86/hvm/vmx/vmcs.c
> @@ -1347,17 +1347,12 @@ struct vmx_msr_entry *vmx_find_msr(u32 msr, int type)
>  
>  int vmx_read_guest_msr(u32 msr, u64 *val)
>  {
> -struct vcpu *curr = current;
> -unsigned int i, msr_count = curr->arch.hvm_vmx.msr_count;
> -const struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area;
> +struct vmx_msr_entry *ent;
>  
> -for ( i = 0; i < msr_count; i++ )
> +if ( (ent = vmx_find_msr(msr, VMX_GUEST_MSR)) != NULL )

I think this would read better (less parentheses etc) as

struct vmx_msr_entry *ent = vmx_find_msr(msr, VMX_GUEST_MSR);
 
if ( ent )

but either way
Reviewed-by: Jan Beulich 

Jan


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 2/3] x86/vmx: optimize vmx_read/write_guest_msr()

2017-02-21 Thread Tian, Kevin
> From: Sergey Dyasli [mailto:sergey.dya...@citrix.com]
> Sent: Friday, February 17, 2017 11:43 PM
> 
> Replace linear scan with vmx_find_msr().  This way the time complexity
> of searching for required MSR reduces from linear to logarithmic.
> 
> Signed-off-by: Sergey Dyasli 

Acked-by: Kevin Tian 

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v2 2/3] x86/vmx: optimize vmx_read/write_guest_msr()

2017-02-17 Thread Sergey Dyasli
Replace linear scan with vmx_find_msr().  This way the time complexity
of searching for required MSR reduces from linear to logarithmic.

Signed-off-by: Sergey Dyasli 
---
v1 --> v2:
- a new patch, factored out from v1 1/2

 xen/arch/x86/hvm/vmx/vmcs.c | 26 --
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
index 49587d6..6c86147 100644
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -1347,17 +1347,12 @@ struct vmx_msr_entry *vmx_find_msr(u32 msr, int type)
 
 int vmx_read_guest_msr(u32 msr, u64 *val)
 {
-struct vcpu *curr = current;
-unsigned int i, msr_count = curr->arch.hvm_vmx.msr_count;
-const struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area;
+struct vmx_msr_entry *ent;
 
-for ( i = 0; i < msr_count; i++ )
+if ( (ent = vmx_find_msr(msr, VMX_GUEST_MSR)) != NULL )
 {
-if ( msr_area[i].index == msr )
-{
-*val = msr_area[i].data;
-return 0;
-}
+*val = ent->data;
+return 0;
 }
 
 return -ESRCH;
@@ -1365,17 +1360,12 @@ int vmx_read_guest_msr(u32 msr, u64 *val)
 
 int vmx_write_guest_msr(u32 msr, u64 val)
 {
-struct vcpu *curr = current;
-unsigned int i, msr_count = curr->arch.hvm_vmx.msr_count;
-struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area;
+struct vmx_msr_entry *ent;
 
-for ( i = 0; i < msr_count; i++ )
+if ( (ent = vmx_find_msr(msr, VMX_GUEST_MSR)) != NULL )
 {
-if ( msr_area[i].index == msr )
-{
-msr_area[i].data = val;
-return 0;
-}
+ent->data = val;
+return 0;
 }
 
 return -ESRCH;
-- 
2.9.3


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel