From 8413778453742aeb3ad6b38d5f4440a0dbabca7d Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 21 Jan 2014 10:46:52 +0100 Subject: globally limit the maximum number of CPUs We now globally limit the number of VCPUs. Especially, there is no way one can specify more than max_cpus VCPUs for a VM. This allows us the restore the ppc max_cpus limitation to the upstream default and minimize the ppc hack in kvm-all.c. Signed-off-by: David Hildenbrand Signed-off-by: Miroslav Rezanina Signed-off-by: Danilo Cesar Lemes de Paula --- accel/kvm/kvm-all.c | 12 ++++++++++++ vl.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index eb7db92..c2e7095 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1586,6 +1586,18 @@ static int kvm_init(MachineState *ms) soft_vcpus_limit = kvm_recommended_vcpus(s); hard_vcpus_limit = kvm_max_vcpus(s); +#ifdef HOST_PPC64 + /* + * On POWER, the kernel advertises a soft limit based on the + * number of CPU threads on the host. We want to allow exceeding + * this for testing purposes, so we don't want to set hard limit + * to soft limit as on x86. + */ +#else + /* RHEL doesn't support nr_vcpus > soft_vcpus_limit */ + hard_vcpus_limit = soft_vcpus_limit; +#endif + while (nc->name) { if (nc->num > soft_vcpus_limit) { warn_report("Number of %s cpus requested (%d) exceeds " diff --git a/vl.c b/vl.c index 43c4b78..b50dbe4 100644 --- a/vl.c +++ b/vl.c @@ -133,6 +133,8 @@ int main(int argc, char **argv) #define MAX_VIRTIO_CONSOLES 1 +#define RHEL_MAX_CPUS 384 + static const char *data_dir[16]; static int data_dir_idx; const char *bios_name = NULL; @@ -1430,6 +1432,20 @@ MachineClass *find_default_machine(void) return mc; } +/* Maximum number of CPUs limited for Red Hat Enterprise Linux */ +static void limit_max_cpus_in_machines(void) +{ + GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); + + for (el = machines; el; el = el->next) { + MachineClass *mc = el->data; + + if (mc->max_cpus > RHEL_MAX_CPUS) { + mc->max_cpus = RHEL_MAX_CPUS; + } + } +} + MachineInfoList *qmp_query_machines(Error **errp) { GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); @@ -3993,6 +4009,8 @@ int main(int argc, char **argv, char **envp) "mutually exclusive"); exit(EXIT_FAILURE); } + /* Maximum number of CPUs limited for Red Hat Enterprise Linux */ + limit_max_cpus_in_machines(); machine_class = select_machine(); -- 1.8.3.1