From patchwork Wed Sep 5 08:31:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406521 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 39D6C40220 for ; Wed, 5 Sep 2012 08:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758093Ab2IEIcu (ORCPT ); Wed, 5 Sep 2012 04:32:50 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:56730 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757896Ab2IEIcr (ORCPT ); Wed, 5 Sep 2012 04:32:47 -0400 Received: by mail-wg0-f44.google.com with SMTP id dr13so389214wgb.1 for ; Wed, 05 Sep 2012 01:32:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=mGPN7cHCigzYFeTG/VczpQFn7JsLBjUsN5r2V+WNznY=; b=WzWH0zRx9e/KH2poBDK12uRZ18bHTE459ibWa1aEcFmwVba33bD/JILSGihIjX0KTS V5thh0Of0jUXRnB2wTrZ/CAz618H7d70Wj5NGEXwL+C6oFaVLI9Y86BY1jOUNxsb+FuF nmkK1VwbqFXZWsFA5trD1xhoNyapUq2dgwEb9uvNcMxnYc7B95cjO91WtUpkdy8o+ase uQIQMM8j15l2WX8VKUalrfU55QD7zH2rkGogK8VJU4q4OB1Tmc+tOfqrUTgDAThPEFSe ylDzEKOpUZRlGCYsFmdbwr6OqXSx/mp1G+LpbJzSzAG9BQhvrNvtvHpzpE/9hX0Ei4vB M+FA== Received: by 10.180.105.130 with SMTP id gm2mr36429302wib.6.1346833967158; Wed, 05 Sep 2012 01:32:47 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id q4sm27971068wix.9.2012.09.05.01.32.44 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:32:46 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 11/33] kvm tools: move nrcpus into struct kvm_config Date: Wed, 5 Sep 2012 10:31:45 +0200 Message-Id: <1346833927-15740-12-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> References: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This no longer has to be a global since we now have kvm_config. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 31 +++++++++++++++---------------- tools/kvm/include/kvm/kvm-config.h | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index cb48ead..df8e17c 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -61,7 +61,6 @@ static int kvm_run_wrapper; bool do_debug_print = false; -static int nrcpus; static int vidmode = -1; extern char _binary_guest_init_start; @@ -377,7 +376,7 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) OPT_GROUP("Basic options:"), \ OPT_STRING('\0', "name", &(cfg)->guest_name, "guest name", \ "A name for the guest"), \ - OPT_INTEGER('c', "cpus", &nrcpus, "Number of CPUs"), \ + OPT_INTEGER('c', "cpus", &(cfg)->nrcpus, "Number of CPUs"), \ OPT_U64('m', "mem", &(cfg)->ram_size, "Virtual machine memory size\ in MiB."), \ OPT_CALLBACK('\0', "shmem", NULL, \ @@ -528,7 +527,7 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg) if (!(dbg_type & KVM_DEBUG_CMD_TYPE_DUMP)) return; - for (i = 0; i < nrcpus; i++) { + for (i = 0; i < kvm->nrcpus; i++) { struct kvm_cpu *cpu = kvm_cpus[i]; if (!cpu) @@ -947,11 +946,11 @@ static int kvm_cmd_run_init(int argc, const char **argv) kvm->cfg.vmlinux_filename = find_vmlinux(); - if (nrcpus == 0) - nrcpus = nr_online_cpus; + if (kvm->cfg.nrcpus == 0) + kvm->cfg.nrcpus = nr_online_cpus; if (!kvm->cfg.ram_size) - kvm->cfg.ram_size = get_ram_size(nrcpus); + kvm->cfg.ram_size = get_ram_size(kvm->cfg.nrcpus); if (kvm->cfg.ram_size < MIN_RAM_SIZE_MB) die("Not enough memory specified: %lluMB (min %lluMB)", kvm->cfg.ram_size, MIN_RAM_SIZE_MB); @@ -1015,20 +1014,20 @@ static int kvm_cmd_run_init(int argc, const char **argv) max_cpus = kvm__max_cpus(kvm); recommended_cpus = kvm__recommended_cpus(kvm); - if (nrcpus > max_cpus) { + if (kvm->cfg.nrcpus > max_cpus) { printf(" # Limit the number of CPUs to %d\n", max_cpus); - nrcpus = max_cpus; - } else if (nrcpus > recommended_cpus) { + kvm->cfg.nrcpus = max_cpus; + } else if (kvm->cfg.nrcpus > recommended_cpus) { printf(" # Warning: The maximum recommended amount of VCPUs" " is %d\n", recommended_cpus); } - kvm->nrcpus = nrcpus; + kvm->nrcpus = kvm->cfg.nrcpus; /* Alloc one pointer too many, so array ends up 0-terminated */ - kvm_cpus = calloc(nrcpus + 1, sizeof(void *)); + kvm_cpus = calloc(kvm->nrcpus + 1, sizeof(void *)); if (!kvm_cpus) - die("Couldn't allocate array for %d CPUs", nrcpus); + die("Couldn't allocate array for %d CPUs", kvm->nrcpus); r = irq__init(kvm); if (r < 0) { @@ -1105,7 +1104,7 @@ static int kvm_cmd_run_init(int argc, const char **argv) } printf(" # %s run -k %s -m %Lu -c %d --name %s\n", KVM_BINARY_NAME, - kvm->cfg.kernel_filename, kvm->cfg.ram_size / 1024 / 1024, nrcpus, kvm->cfg.guest_name); + kvm->cfg.kernel_filename, kvm->cfg.ram_size / 1024 / 1024, kvm->cfg.nrcpus, kvm->cfg.guest_name); if (!kvm->cfg.firmware_filename) { if (!kvm__load_kernel(kvm, kvm->cfg.kernel_filename, @@ -1235,7 +1234,7 @@ static int kvm_cmd_run_init(int argc, const char **argv) } } - for (i = 0; i < nrcpus; i++) { + for (i = 0; i < kvm->nrcpus; i++) { kvm_cpus[i] = kvm_cpu__init(kvm, i); if (!kvm_cpus[i]) die("unable to initialize KVM VCPU"); @@ -1251,7 +1250,7 @@ static int kvm_cmd_run_work(void) int i, r = -1; void *ret = NULL; - for (i = 0; i < nrcpus; i++) { + for (i = 0; i < kvm->nrcpus; i++) { if (pthread_create(&kvm_cpus[i]->thread, NULL, kvm_cpu_thread, kvm_cpus[i]) != 0) die("unable to create KVM VCPU thread"); } @@ -1263,7 +1262,7 @@ static int kvm_cmd_run_work(void) kvm_cpu__delete(kvm_cpus[0]); kvm_cpus[0] = NULL; - for (i = 1; i < nrcpus; i++) { + for (i = 1; i < kvm->nrcpus; i++) { if (kvm_cpus[i]->is_running) { pthread_kill(kvm_cpus[i]->thread, SIGKVMEXIT); if (pthread_join(kvm_cpus[i]->thread, &ret) != 0) diff --git a/tools/kvm/include/kvm/kvm-config.h b/tools/kvm/include/kvm/kvm-config.h index 35cde48..1f06df3 100644 --- a/tools/kvm/include/kvm/kvm-config.h +++ b/tools/kvm/include/kvm/kvm-config.h @@ -24,6 +24,7 @@ struct kvm_config { bool virtio_rng; int active_console; int debug_iodelay; + int nrcpus; const char *kernel_cmdline; const char *kernel_filename; const char *vmlinux_filename;