From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vitaly Kuznetsov Subject: Re: [PATCH v4 5/8] KVM: introduce kvm_make_vcpus_request_mask() API Date: Mon, 11 Jun 2018 13:57:01 +0200 Message-ID: <87bmchtu2a.fsf@vitty.brq.redhat.com> References: <20180516152131.30689-1-vkuznets@redhat.com> <20180516152131.30689-6-vkuznets@redhat.com> <20180526144946.GF23390@flask> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: kvm@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Roman Kagan , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley \(EOSG\)" , Mohammed Gamal , Cathy Avery , linux-kernel@vger.kernel.org To: Radim =?utf-8?B?S3LEjW3DocWZ?= Return-path: In-Reply-To: <20180526144946.GF23390@flask> ("Radim \=\?utf-8\?B\?S3LEjW3DocWZ\?\= \=\?utf-8\?B\?Iidz\?\= message of "Sat, 26 May 2018 16:49:47 +0200") Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org Radim Krčmář writes: > 2018-05-16 17:21+0200, Vitaly Kuznetsov: >> Hyper-V style PV TLB flush hypercalls inmplementation will use this API. >> To avoid memory allocation in CONFIG_CPUMASK_OFFSTACK case add >> cpumask_var_t argument. >> >> Signed-off-by: Vitaly Kuznetsov >> --- >> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c >> -bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req) >> +bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, >> + unsigned long *vcpu_bitmap, cpumask_var_t tmp) >> { >> int i, cpu, me; >> - cpumask_var_t cpus; >> - bool called; >> struct kvm_vcpu *vcpu; >> - >> - zalloc_cpumask_var(&cpus, GFP_ATOMIC); >> + bool called; >> >> me = get_cpu(); >> + > > Two optimizations come to mind: First is to use for_each_set_bit instead > of kvm_for_each_vcpu to improve the sparse case. > I think I had such version at some point but then for some reason I decided I'm re-implementing kvm_for_each_vcpu for no particular reason. >> kvm_for_each_vcpu(i, vcpu, kvm) { >> + if (!test_bit(i, vcpu_bitmap)) > > And the second is to pass vcpu_bitmap = NULL instead of building the > bitmap with all VCPUs. Doesn't looks too good in the end, though: > > #define kvm_for_each_vcpu_bitmap(idx, vcpup, kvm, bitmap, len) \ > for (idx = (bitmap ? find_first_bit(bitmap, len) : 0); \ > idx < len && (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \ > bitmap ? find_next_bit(bitmap, len, idx + 1) : idx++) I'll take a try, thanks! -- Vitaly