kvm:vmx:code changes in handle_io() to save some CPU cycles.
PATCH 1/1 kvm:vmx:code changes in handle_io() to save some CPU cycles.
code changes in handle_io() to save some CPU cycles.
--- arch/x86/kvm/vmx/vmx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/vmx.c +2 -3
@@ -4899,15 +4899,14 @@ static int handle_triple_fault(struct kvm_vcpu *vcpu)static int handle_io (struct kvm_vcpu *vcpu) {unsigned long exit_qualification; -int size, in, string; +int size, in;unsigned port; exit_qualification =vmx_get_exit_qual (vcpu); - string = (exit_qualification &16 ) !=0 ; ++vcpu->stat.io_exits; -if (string) +if (exit_qualification &16 )return kvm_emulate_instruction (vcpu,0 ); port = exit_qualification >>16 ;
Signature · 1 line
1.8.3.1
Quoted 19 lines · Stephen Zhang
code changes in
handle_io()to save some CPU cycles.Signed-off-by Stephen Zhang <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)arch/x86/kvm/vmx/vmx.c +1
-1@@ -4899,15 +4899,14 @@ static int handle_triple_fault(struct kvm_vcpu *vcpu)static int handle_io (struct kvm_vcpu *vcpu) {unsigned long exit_qualification; -int size, in, string; +int size, in;unsigned port;
arch/x86/kvm/vmx/vmx.c static int handle_triple_fault(struct kvm_vcpu *vcpu) · line 4912
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +1
-2exit_qualification =vmx_get_exit_qual (vcpu); - string = (exit_qualification &16 ) !=0 ; ++vcpu->stat.io_exits; -if (string) +if (exit_qualification &16 )return kvm_emulate_instruction (vcpu,0 ); port = exit_qualification >>16 ;
I seriously doubt this can save any CPU cycles as compiler will likely re-order and optimize this check anyway, I don't expect to see any push/pop operations here. I agree that having local 'string' variable is likely an overkill, however, the 'exit_qualification & 16' check we have is hard to read so 'string' here works as a comment :-)
I would've liked the patch in the following shape more:
arch/x86/kvm/vmx/vmx.c +3 -3
@@ -4898,15 +4898,15 @@ static int handle_triple_fault(struct kvm_vcpu *vcpu)static int handle_io (struct kvm_vcpu *vcpu) {unsigned long exit_qualification; -int size, in, string; +int size, in;unsigned port; exit_qualification =vmx_get_exit_qual (vcpu); - string = (exit_qualification &16 ) !=0 ; ++vcpu->stat.io_exits; -if (string) +/* String instruction */ +if (exit_qualification &BIT (4 ))return kvm_emulate_instruction (vcpu,0 ); port = exit_qualification >>16 ;
Also, the changelog needs to be re-phrased to state code cleanup and not CPU cycles optimization.
Signature · 1 line
Vitaly
Paolo Bonzini
maintainerQuoted 20 lines · Stephen Zhang
code changes in
handle_io()to save some CPU cycles.Signed-off-by Stephen Zhang <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)arch/x86/kvm/vmx/vmx.c +1
-1@@ -4899,15 +4899,14 @@ static int handle_triple_fault(struct kvm_vcpu *vcpu)static int handle_io (struct kvm_vcpu *vcpu) {unsigned long exit_qualification; -int size, in, string; +int size, in;unsigned port;
arch/x86/kvm/vmx/vmx.c static int handle_triple_fault(struct kvm_vcpu *vcpu) · line 4912
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +1
-2exit_qualification =vmx_get_exit_qual (vcpu); - string = (exit_qualification &16 ) !=0 ; ++vcpu->stat.io_exits; -if (string) +if (exit_qualification &16 )return kvm_emulate_instruction (vcpu,0 ); port = exit_qualification >>16 ;
I would be very surprised if there's any change in the assembly code after this patch.
Paolo