* [PATCH 06/54] x86/kvm: replace bitmap_weight with bitmap_empty where appropriate [not found] <20220123183925.1052919-1-yury.norov@gmail.com> @ 2022-01-23 18:38 ` Yury Norov 2022-01-24 9:11 ` Vitaly Kuznetsov 0 siblings, 1 reply; 2+ messages in thread From: Yury Norov @ 2022-01-23 18:38 UTC (permalink / raw) To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton, Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra, David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing, Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel, Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, kvm In some places kvm/hyperv.c code calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov <yury.norov@gmail.com> --- arch/x86/kvm/hyperv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 6e38a7d22e97..2c3400dea4b3 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -90,7 +90,7 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic, { struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic); struct kvm_hv *hv = to_kvm_hv(vcpu->kvm); - int auto_eoi_old, auto_eoi_new; + bool auto_eoi_old, auto_eoi_new; if (vector < HV_SYNIC_FIRST_VALID_VECTOR) return; @@ -100,16 +100,16 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic, else __clear_bit(vector, synic->vec_bitmap); - auto_eoi_old = bitmap_weight(synic->auto_eoi_bitmap, 256); + auto_eoi_old = bitmap_empty(synic->auto_eoi_bitmap, 256); if (synic_has_vector_auto_eoi(synic, vector)) __set_bit(vector, synic->auto_eoi_bitmap); else __clear_bit(vector, synic->auto_eoi_bitmap); - auto_eoi_new = bitmap_weight(synic->auto_eoi_bitmap, 256); + auto_eoi_new = bitmap_empty(synic->auto_eoi_bitmap, 256); - if (!!auto_eoi_old == !!auto_eoi_new) + if (auto_eoi_old == auto_eoi_new) return; down_write(&vcpu->kvm->arch.apicv_update_lock); -- 2.30.2 ^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 06/54] x86/kvm: replace bitmap_weight with bitmap_empty where appropriate 2022-01-23 18:38 ` [PATCH 06/54] x86/kvm: replace bitmap_weight with bitmap_empty where appropriate Yury Norov @ 2022-01-24 9:11 ` Vitaly Kuznetsov 0 siblings, 0 replies; 2+ messages in thread From: Vitaly Kuznetsov @ 2022-01-24 9:11 UTC (permalink / raw) To: Yury Norov Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton, Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra, David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing, Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel, Paolo Bonzini, Sean Christopherson, Wanpeng Li, Jim Mattson, Joerg Roedel, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, kvm Yury Norov <yury.norov@gmail.com> writes: > In some places kvm/hyperv.c code calls bitmap_weight() to check if any bit > of a given bitmap is set. It's better to use bitmap_empty() in that case > because bitmap_empty() stops traversing the bitmap as soon as it finds > first set bit, while bitmap_weight() counts all bits unconditionally. > > Signed-off-by: Yury Norov <yury.norov@gmail.com> > --- > arch/x86/kvm/hyperv.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index 6e38a7d22e97..2c3400dea4b3 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -90,7 +90,7 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic, > { > struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic); > struct kvm_hv *hv = to_kvm_hv(vcpu->kvm); > - int auto_eoi_old, auto_eoi_new; > + bool auto_eoi_old, auto_eoi_new; > > if (vector < HV_SYNIC_FIRST_VALID_VECTOR) > return; > @@ -100,16 +100,16 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic, > else > __clear_bit(vector, synic->vec_bitmap); > > - auto_eoi_old = bitmap_weight(synic->auto_eoi_bitmap, 256); > + auto_eoi_old = bitmap_empty(synic->auto_eoi_bitmap, 256); I would've preferred this written as auto_eoi_old = !bitmap_empty(synic->auto_eoi_bitmap, 256); so the variable would indicate wether AutoEOI was previosly enabled, not disabled. > > if (synic_has_vector_auto_eoi(synic, vector)) > __set_bit(vector, synic->auto_eoi_bitmap); > else > __clear_bit(vector, synic->auto_eoi_bitmap); > > - auto_eoi_new = bitmap_weight(synic->auto_eoi_bitmap, 256); > + auto_eoi_new = bitmap_empty(synic->auto_eoi_bitmap, 256); Same here, of course. "auto_eoi_new = true" sounds like "AutoEOI is now enabled". > > - if (!!auto_eoi_old == !!auto_eoi_new) > + if (auto_eoi_old == auto_eoi_new) > return; > > down_write(&vcpu->kvm->arch.apicv_update_lock); The change look good to me otherwise, feel free to add Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com> -- Vitaly ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-24 9:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20220123183925.1052919-1-yury.norov@gmail.com>
2022-01-23 18:38 ` [PATCH 06/54] x86/kvm: replace bitmap_weight with bitmap_empty where appropriate Yury Norov
2022-01-24 9:11 ` Vitaly Kuznetsov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).