mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: David Hildenbrand <david@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: paulus@ozlabs.org, stable@vger.kernel.org
Subject: Re: [PATCH] kvm: avoid unused variable warning for UP builds
Date: Wed, 5 Jul 2017 14:24:16 +0200	[thread overview]
Message-ID: <7f7ee5d9-22b6-383f-e7c8-d39ced64314a@redhat.com> (raw)
In-Reply-To: <be118bdc-42c5-04a2-fecb-a242d973769f@redhat.com>



On 05/07/2017 14:22, David Hildenbrand wrote:
>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>> index f0fe9d02f6bb..09368501d9cf 100644
>> --- a/virt/kvm/kvm_main.c
>> +++ b/virt/kvm/kvm_main.c
>> @@ -187,12 +187,23 @@ static void ack_flush(void *_completed)
>>  {
>>  }
>>  
>> +static inline bool kvm_kick_many_cpus(const struct cpumask *cpus, bool wait)
>> +{
>> +	if (unlikely(!cpus))
>> +		cpus = cpu_online_mask;
>> +
>> +	if (cpumask_empty(cpus))
>> +		return false;
>> +
>> +	smp_call_function_many(cpus, ack_flush, NULL, wait);
>> +	return true;
>> +}
> 
> wonder if the !cpus case would be worth moving into smp_call_function_many.
> 
> smp_call_function_many() might also not kick any cpu, so we could make
> it return if it actually kicked/called this on any cpu. Then you could
> even get rid of the special handling of cpumask_empty(cpus) here and
> simply return the result of smp_call_function_many.

Separate patch of course. :)

>> +
>>  bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req)
>>  {
>>  	int i, cpu, me;
>>  	cpumask_var_t cpus;
>> -	bool called = true;
>> -	bool wait = req & KVM_REQUEST_WAIT;
>> +	bool called;
>>  	struct kvm_vcpu *vcpu;
>>  
>>  	zalloc_cpumask_var(&cpus, GFP_ATOMIC);
>> @@ -207,14 +218,9 @@ bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req)
>>  
>>  		if (cpus != NULL && cpu != -1 && cpu != me &&
>>  		    kvm_request_needs_ipi(vcpu, req))
>> -			cpumask_set_cpu(cpu, cpus);
>> +			__cpumask_set_cpu(cpu, cpus);
>>  	}
>> -	if (unlikely(cpus == NULL))
>> -		smp_call_function_many(cpu_online_mask, ack_flush, NULL, wait);
>> -	else if (!cpumask_empty(cpus))
>> -		smp_call_function_many(cpus, ack_flush, NULL, wait);
>> -	else
>> -		called = false;
>> +	called = kvm_kick_many_cpus(cpus, !!(req & KVM_REQUEST_WAIT));
> 
> Is the !! really needed here? I think not.

I prefer having it.  There are corner cases (e.g. isolating bit 32 or
higher and the function accepting an unsigned int instead of a bool)
where it can save your butt, and it's idiomatic C.

Paolo

>>  	put_cpu();
>>  	free_cpumask_var(cpus);
>>  	return called;
>>
> 
> I like this from a cleanup point as well.
> 
> 

  reply	other threads:[~2017-07-05 12:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-05 10:35 Paolo Bonzini
2017-07-05 12:22 ` David Hildenbrand
2017-07-05 12:24   ` Paolo Bonzini [this message]
2017-07-05 12:26     ` David Hildenbrand
2017-07-06  8:13 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7f7ee5d9-22b6-383f-e7c8-d39ced64314a@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulus@ozlabs.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®