[PATCH] kvm tools: Default guest cpu count to host cpu count

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If user haven't specified cpu count for the guest, use
the amount of online cpus on the host.

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 tools/kvm/kvm-run.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index 63181bf..1517264 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 [<options>] [<kernel image>]",
@@ -409,6 +409,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);
@@ -439,7 +441,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)
@@ -575,7 +579,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++) {
-- 
1.7.5.rc3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux