KVM: x86: add paging gcc optimization
PATCH v2 1/1 KVM: x86: add paging gcc optimization
From: Davidlohr Bueso <[email protected]>
Since most guests will have paging enabled for memory management, add likely() optimization around CR0.PG checks.
--- arch/x86/kvm/x86.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.h +1 -1
@@ -64,7 +64,7 @@ static inline int is_pse(struct kvm_vcpu *vcpu)static inline int is_paging (struct kvm_vcpu *vcpu) { -return kvm_read_cr0_bits (vcpu,X86_CR0_PG ); +return likely (kvm_read_cr0_bits (vcpu,X86_CR0_PG )); }static inline u32 bit (int bitno)
Signature · 1 line
1.7.8.3
arch/x86/kvm/x86.h static inline int is_pse(struct kvm_vcpu *vcpu) · line 67
Quoted 8 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
Since most guests will have paging enabled for memory management, add
likely()optimization around CR0.PG checks.{
arch/x86/kvm/x86.h +1
-1-return kvm_read_cr0_bits (vcpu,X86_CR0_PG ); +return likely (kvm_read_cr0_bits (vcpu,X86_CR0_PG ));
IMHO likely/unlikely should be considered more as fast-path/slow-path and not as often/less often. Is that the case here? This patch might cause a mis-prediction for non-paging guests all the time.
Non-paging might be really irrelevant, so I am just making a point, since likely/unlikely is mis-used too often especially for "most users do it that way".
Christian
Quoted 6 lines · Christian Borntraeger
Quoted 4 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
Since most guests will have paging enabled for memory management, add
likely()optimization around CR0.PG checks.
Quoted 8 lines
arch/x86/kvm/x86.h static inline int is_pse(struct kvm_vcpu *vcpu) · line 67
Quoted 3 lines
{
arch/x86/kvm/x86.h +1
-1-return kvm_read_cr0_bits (vcpu,X86_CR0_PG ); +return likely (kvm_read_cr0_bits (vcpu,X86_CR0_PG ));IMHO likely/unlikely should be considered more as fast-path/slow-path and not as often/less often. Is that the case here? This patch might cause a mis-prediction for non-paging guests all the time.
Branch predictions are all about probability of occurrence, and I cannot imagine guests having paging disabled and mapping gva->gpa directly, so for most of the cases it would be beneficial. For those peculiar users that actually don't use paging, then yes, mispredictions would occur.
- Davidlohr
Quoted 8 lines
Non-paging might be really irrelevant, so I am just making a point, since likely/unlikely is mis-used too often especially for "most users do it that way".
Christian
Quoted 6 lines · Christian Borntraeger
Quoted 4 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
Since most guests will have paging enabled for memory management, add
likely()optimization around CR0.PG checks.
Quoted 6 lines
arch/x86/kvm/x86.h static inline int is_pse(struct kvm_vcpu *vcpu) · line 67
Quoted 3 lines
{
arch/x86/kvm/x86.h +1
-1-return kvm_read_cr0_bits (vcpu,X86_CR0_PG ); +return likely (kvm_read_cr0_bits (vcpu,X86_CR0_PG ));IMHO likely/unlikely should be considered more as fast-path/slow-path and not as often/less often.
Agree.
Quoted 5 lines
Is that the case here? This patch might cause a mis-prediction for non-paging guests all the time.
Non-paging might be really irrelevant, so I am just making a point, since likely/unlikely is mis-used too often especially for "most users do it that way".
In fact this is a classic example. Almost no guests use real mode (the last guests to use real mode extensively was DOS; I think Win9x switches to real mode pretty often). As it's a user-controlled setting, we're penalizing users who do things differently.
However the majority if is_paging() == true guests is so huge, and since non-paging guests don't really expect 2012 performance levels anyway (being so old) that I think in practice this is a good optimization here.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 22 lines · Avi Kivity
Quoted 6 lines · Christian Borntraeger
Quoted 4 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
Since most guests will have paging enabled for memory management, add
likely()optimization around CR0.PG checks.Quoted 6 lines
arch/x86/kvm/x86.h static inline int is_pse(struct kvm_vcpu *vcpu) · line 67
Quoted 3 lines
{
arch/x86/kvm/x86.h +1
-1-return kvm_read_cr0_bits (vcpu,X86_CR0_PG ); +return likely (kvm_read_cr0_bits (vcpu,X86_CR0_PG ));IMHO likely/unlikely should be considered more as fast-path/slow-path and not as often/less often.
Agree.
Quoted 5 lines
Is that the case here? This patch might cause a mis-prediction for non-paging guests all the time.
Non-paging might be really irrelevant, so I am just making a point, since likely/unlikely is mis-used too often especially for "most users do it that way".
Quoted 8 lines
In fact this is a classic example. Almost no guests use real mode (the last guests to use real mode extensively was DOS; I think Win9x switches to real mode pretty often). As it's a user-controlled setting, we're penalizing users who do things differently.
However the majority if
is_paging()== true guests is so huge, and since non-paging guests don't really expect 2012 performance levels anyway (being so old) that I think in practice this is a good optimization here.
Avi, will you be taking this patch? I don't see it applied or for pull in 3.4.
Thanks.
Quoted 4 lines · Davidlohr Bueso
Avi, will you be taking this patch? I don't see it applied or for pull in 3.4.
Applied now, thanks for the reminder.
Signature · 1 line
error compiling committee.c: too many arguments to function