kvm tools: Remove KVM_NR_CPUS
PATCH 1/1 kvm tools: Remove KVM_NR_CPUS
The KVM_NR_CPUS define is only really used to statically size the global kvm_cpus array, which can just as easily be allocated on startup. There is some checking of the -c <nr cpus> value given against NR_CPUs but this is later again checked against a dynamically-determined limit from KVM_CAP_MAX_VCPUS anyway. The hardwired limit is arbitrary and not strictly necessary.
This patch removes the #define, replacing the statically-sized array with a malloc; the array is kvm->nrcpus+1 in size so that any iterator can halt at the end (this is done in kvm_cpu__reboot, which doesn't have access to a struct kvm* and therefore kvm->nrcpus).
An unused #define in x86/mptable.c is also removed.
Signed-off-by Matt Evans <[email protected]>
--- tools/kvm/builtin-run.c | 9 ++++++--- tools/kvm/kvm-cpu.c | 8 ++++++-- tools/kvm/kvm.c | 2 +- tools/kvm/powerpc/include/kvm/kvm-arch.h | 2 -- tools/kvm/x86/include/kvm/kvm-arch.h | 2 -- tools/kvm/x86/mptable.c | 8 -------- 6 files changed, 13 insertions(+), 18 deletions(-)
tools/kvm/builtin-run.c +6 -3
@@ -64,7 +64,7 @@ const char *DEFAULT_SANDBOX_FILENAME = "guest/sandbox.sh";#define MIN_RAM_SIZE_BYTE (MIN_RAM_SIZE_MB << MB_SHIFT)struct kvm *kvm; -struct kvm_cpu *kvm_cpus[KVM_NR_CPUS ]; +struct kvm_cpu **kvm_cpus; __threadstruct kvm_cpu *current_kvm_cpu;static u64 ram_size;
@@ -875,8 +875,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)if (nrcpus ==0 ) nrcpus = nr_online_cpus; -else if (nrcpus <1 || nrcpus >KVM_NR_CPUS ) -die ("Number of CPUs %d is out of [1;%d] range" , nrcpus,KVM_NR_CPUS );if (!ram_size) ram_size =get_ram_size (nrcpus);
@@ -947,6 +945,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) kvm->nrcpus = nrcpus; +/* Alloc one pointer too many, so array ends up 0-terminated */ + kvm_cpus =calloc (nrcpus +1 ,sizeof (void *)); +if (!kvm_cpus) +die ("Couldn't allocate array for %d CPUs" , nrcpus); +irq__init (kvm);pci__init ();
tools/kvm/kvm-cpu.c +6 -2
@@ -12,7 +12,7 @@#include <errno.h> #include <stdio.h> -extern struct kvm_cpu *kvm_cpus[KVM_NR_CPUS ]; +extern struct kvm_cpu **kvm_cpus;extern __threadstruct kvm_cpu *current_kvm_cpu;void kvm_cpu__enable_singlestep (struct kvm_cpu *vcpu)
@@ -66,9 +66,13 @@ void kvm_cpu__reboot(void) {int i; -for (i =0 ; i <KVM_NR_CPUS ; i++) +/* The kvm_cpus array contains a null pointer in the last location */ +for (i =0 ; ; i++) {if (kvm_cpus[i])pthread_kill (kvm_cpus[i]->thread,SIGKVMEXIT ); +else +break ; + } }int kvm_cpu__start (struct kvm_cpu *cpu)
tools/kvm/kvm.c +1 -1
@@ -55,7 +55,7 @@ const char *kvm_exit_reasons[] = { };extern struct kvm *kvm; -extern struct kvm_cpu *kvm_cpus[KVM_NR_CPUS ]; +extern struct kvm_cpu **kvm_cpus;static int pause_event;static DEFINE_MUTEX (pause_lock);extern struct kvm_ext kvm_req_ext[];
tools/kvm/powerpc/include/kvm/kvm-arch.h +0 -2
@@ -15,8 +15,6 @@#include <linux/types.h> #include <time.h> -#define KVM_NR_CPUS (255) -/* * MMIO lives after RAM, but it'd be nice if it didn't constantly move. * Choose a suitably high address, e.g. 63T... This limits RAM size.
tools/kvm/x86/include/kvm/kvm-arch.h +0 -2
@@ -8,8 +8,6 @@#include <linux/types.h> #include <time.h> -#define KVM_NR_CPUS (255) -/* * The hole includes VESA framebuffer and PCI memory. */
tools/kvm/x86/mptable.c +0 -8
@@ -8,14 +8,6 @@#include <linux/kernel.h> #include <string.h> -/* -* If kernel is not configured yet this macro -* might not be defined, fix it by own definition -*/ -#ifndef NR_CPUS -#define NR_CPUS KVM_NR_CPUS -#endif -#include <asm/mpspec_def.h> #include <linux/types.h>
Signature · 1 line
1.7.0.4