Commit 6ef7a1bc authored by Rusty Russell's avatar Rusty Russell Committed by Avi Kivity

KVM: use modern cpumask primitives, no cpumask_t on stack

We're getting rid on on-stack cpumasks for large NR_CPUS.

1) Use cpumask_var_t/alloc_cpumask_var.
2) smp_call_function_mask -> smp_call_function_many
3) cpus_clear, cpus_empty, cpu_set -> cpumask_clear, cpumask_empty,
   cpumask_set_cpu.

This actually generates slightly smaller code than the old one with
CONFIG_CPUMASKS_OFFSTACK=n.  (gcc knows that cpus cannot be NULL in
that case, where cpumask_var_t is cpumask_t[1]).
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 49846896
...@@ -555,12 +555,14 @@ static void ack_flush(void *_completed) ...@@ -555,12 +555,14 @@ static void ack_flush(void *_completed)
static bool make_all_cpus_request(struct kvm *kvm, unsigned int req) static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
{ {
int i, cpu, me; int i, cpu, me;
cpumask_t cpus; cpumask_var_t cpus;
bool called = false; bool called = true;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
if (alloc_cpumask_var(&cpus, GFP_ATOMIC))
cpumask_clear(cpus);
me = get_cpu(); me = get_cpu();
cpus_clear(cpus);
for (i = 0; i < KVM_MAX_VCPUS; ++i) { for (i = 0; i < KVM_MAX_VCPUS; ++i) {
vcpu = kvm->vcpus[i]; vcpu = kvm->vcpus[i];
if (!vcpu) if (!vcpu)
...@@ -568,14 +570,17 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req) ...@@ -568,14 +570,17 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
if (test_and_set_bit(req, &vcpu->requests)) if (test_and_set_bit(req, &vcpu->requests))
continue; continue;
cpu = vcpu->cpu; cpu = vcpu->cpu;
if (cpu != -1 && cpu != me) if (cpus != NULL && cpu != -1 && cpu != me)
cpu_set(cpu, cpus); cpumask_set_cpu(cpu, cpus);
}
if (!cpus_empty(cpus)) {
smp_call_function_mask(cpus, ack_flush, NULL, 1);
called = true;
} }
if (unlikely(cpus == NULL))
smp_call_function_many(cpu_online_mask, ack_flush, NULL, 1);
else if (!cpumask_empty(cpus))
smp_call_function_many(cpus, ack_flush, NULL, 1);
else
called = false;
put_cpu(); put_cpu();
free_cpumask_var(cpus);
return called; return called;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment