From 5ccc7a3dd93b1f814b653cba9dac5a373443c861 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Wed, 18 May 2011 22:56:24 +0300 Subject: [PATCH] kvm tools: Default guest cpu count to host cpu count If user haven't specified cpu count for the guest, use the amount of online cpus on the host. Tested-by: Asias He Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/kvm-run.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 8379a52b7688..c01517f094f9 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -70,7 +70,7 @@ extern int active_console; bool do_debug_print = false; -static int nrcpus = 1; +static int nrcpus; static const char * const run_usage[] = { "kvm run [] []", @@ -410,6 +410,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) signal(SIGQUIT, handle_sigquit); signal(SIGUSR1, handle_sigusr1); + nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); + while (argc != 0) { argc = parse_options(argc, argv, options, run_usage, PARSE_OPT_STOP_AT_NON_OPTION); @@ -440,7 +442,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) vmlinux_filename = find_vmlinux(); - if (nrcpus < 1 || nrcpus > KVM_NR_CPUS) + 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) @@ -576,7 +580,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) kvm__init_ram(kvm); - nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); thread_pool__init(nr_online_cpus); for (i = 0; i < nrcpus; i++) { -- 2.39.5