From patchwork Wed Aug 19 13:42:40 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 31645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 48A14B70B0 for ; Wed, 19 Aug 2009 23:52:27 +1000 (EST) Received: from localhost ([127.0.0.1]:40816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MdlaQ-0007uW-Od for incoming@patchwork.ozlabs.org; Wed, 19 Aug 2009 09:52:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MdlVU-0005Qs-9z for qemu-devel@nongnu.org; Wed, 19 Aug 2009 09:47:16 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MdlVO-0005Lt-PU for qemu-devel@nongnu.org; Wed, 19 Aug 2009 09:47:15 -0400 Received: from [199.232.76.173] (port=55344 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MdlVO-0005Lg-FX for qemu-devel@nongnu.org; Wed, 19 Aug 2009 09:47:10 -0400 Received: from va3ehsobe002.messaging.microsoft.com ([216.32.180.12]:24006 helo=VA3EHSOBE002.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1MdlVN-0001wv-Ku for qemu-devel@nongnu.org; Wed, 19 Aug 2009 09:47:10 -0400 Received: from mail155-va3-R.bigfish.com (10.7.14.251) by VA3EHSOBE002.bigfish.com (10.7.40.22) with Microsoft SMTP Server id 8.1.340.0; Wed, 19 Aug 2009 13:47:02 +0000 Received: from mail155-va3 (localhost.localdomain [127.0.0.1]) by mail155-va3-R.bigfish.com (Postfix) with ESMTP id C243613980D0; Wed, 19 Aug 2009 13:47:02 +0000 (UTC) X-SpamScore: -7 X-BigFish: VPS-7(zz98aRzz1202hzzz32i203h43j62h) X-Spam-TCS-SCL: 1:0 X-FB-SS: 5, Received: by mail155-va3 (MessageSwitch) id 125068962147472_24153; Wed, 19 Aug 2009 13:47:01 +0000 (UCT) Received: from ausb3extmailp01.amd.com (unknown [163.181.251.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail155-va3.bigfish.com (Postfix) with ESMTP id B152D13400E9; Wed, 19 Aug 2009 13:47:00 +0000 (UTC) Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n7JDks5W020886; Wed, 19 Aug 2009 08:46:57 -0500 X-WSS-ID: 0KOMMA4-02-16Z-02 X-M-MSG: Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.0) with ESMTP id 2B709C8578; Wed, 19 Aug 2009 08:46:51 -0500 (CDT) Received: from sausexmb2.amd.com ([163.181.3.157]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 19 Aug 2009 08:46:55 -0500 Received: from SDRSEXMB1.amd.com ([172.20.3.116]) by sausexmb2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 19 Aug 2009 08:46:56 -0500 Received: from localhost.localdomain ([165.204.15.42]) by SDRSEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 19 Aug 2009 15:46:44 +0200 From: Andre Przywara To: anthony@codemonkey.ws Date: Wed, 19 Aug 2009 15:42:40 +0200 Message-ID: <1250689362-11067-2-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.1.3 In-Reply-To: <1250689362-11067-1-git-send-email-andre.przywara@amd.com> References: <1250689362-11067-1-git-send-email-andre.przywara@amd.com> X-OriginalArrivalTime: 19 Aug 2009 13:46:44.0882 (UTC) FILETIME=[7D7A0F20:01CA20D3] MIME-Version: 1.0 X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ Cc: Andre Przywara , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 1/3] extend -smp parsing to include cores= and threads= options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For injecting multi-core and multi-threading CPU topology into guests extend the -smp syntax to accommodate cores and threads specification. Syntax: -smp smp_value[,cores=nr_cores][,threads=nr_threads]\ [,socket=nr_sockets][,maxcpus=max_cpus] smp_value is the legacy value specifying the total number of vCPUs for the guest. If you specify one of cores, threads or sockets this value can be omitted. Missing values will be computed to fulfill: smp_value = nr_cores * nr_threads * nr_sockets where it will favour sockets over cores over threads (to mimic the current behavior, which will only inject multiple sockets.) So -smp 4,threads=2 will inject two sockets with 2 threads each, -smp cores=4 is an abbreviation for -smp 4,cores=4,threads=1,sockets=1. If max_cpus (the number of hotpluggable CPUs) is omitted, it will be set to smp_value. Signed-off-by: Andre Przywara --- cpu-defs.h | 2 + vl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/cpu-defs.h b/cpu-defs.h index 5b80b1b..b6c8b95 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -185,6 +185,8 @@ typedef struct CPUWatchpoint { int cpu_index; /* CPU index (informative) */ \ uint32_t host_tid; /* host thread ID */ \ int numa_node; /* NUMA node this cpu is belonging to */ \ + int nr_cores; /* number of cores within this CPU package */ \ + int nr_threads;/* number of threads within this CPU */ \ int running; /* Nonzero if cpu is currently running(usermode). */ \ /* user data */ \ void *opaque; \ diff --git a/vl.c b/vl.c index 8b2b289..0cce808 100644 --- a/vl.c +++ b/vl.c @@ -220,6 +220,8 @@ int usb_enabled = 0; int singlestep = 0; int smp_cpus = 1; int max_cpus = 0; +int smp_cores = 1; +int smp_threads = 1; const char *vnc_display; int acpi_enabled = 1; int no_hpet = 0; @@ -2363,6 +2365,56 @@ static void numa_add(const char *optarg) return; } +static void smp_parse(const char *optarg) +{ + int smp, sockets = 0, threads = 0, cores = 0; + char *endptr; + char option[128]; + + smp = strtoul(optarg, &endptr, 10); + if (endptr != optarg) { + if (*endptr == ',') { + endptr++; + } + } + if (get_param_value(option, 128, "sockets", endptr) != 0) + sockets = strtoull(option, NULL, 10); + if (get_param_value(option, 128, "cores", endptr) != 0) + cores = strtoull(option, NULL, 10); + if (get_param_value(option, 128, "threads", endptr) != 0) + threads = strtoull(option, NULL, 10); + if (get_param_value(option, 128, "maxcpus", endptr) != 0) + max_cpus = strtoull(option, NULL, 10); + + /* compute missing values, prefer sockets over cores over threads */ + if (smp == 0 || sockets == 0) { + sockets = sockets > 0 ? sockets : 1; + cores = cores > 0 ? cores : 1; + threads = threads > 0 ? threads : 1; + if (smp == 0) { + smp = cores * threads * sockets; + } else { + sockets = smp / (cores * threads); + } + } else { + if (cores == 0) { + threads = threads > 0 ? threads : 1; + cores = smp / (sockets * threads); + } else { + if (sockets == 0) { + sockets = smp / (cores * threads); + } else { + threads = smp / (cores * sockets); + } + } + } + smp_cpus = smp; + smp_cores = cores > 0 ? cores : 1; + smp_threads = threads > 0 ? threads : 1; + if (max_cpus == 0) + max_cpus = smp_cpus; +} + /***********************************************************/ /* USB devices */ @@ -3572,6 +3624,8 @@ void qemu_init_vcpu(void *_env) if (kvm_enabled()) kvm_init_vcpu(env); + env->nr_cores = smp_cores; + env->nr_threads = smp_threads; return; } @@ -3899,6 +3953,8 @@ void qemu_init_vcpu(void *_env) kvm_start_vcpu(env); else tcg_init_vcpu(env); + env->nr_cores = smp_cores; + env->nr_threads = smp_threads; } void qemu_notify_event(void) @@ -5403,18 +5459,11 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_smp: - { - char *p; - char option[128]; - smp_cpus = strtol(optarg, &p, 10); + smp_parse(optarg); if (smp_cpus < 1) { fprintf(stderr, "Invalid number of CPUs\n"); exit(1); } - if (*p++ != ',') - break; - if (get_param_value(option, 128, "maxcpus", p)) - max_cpus = strtol(option, NULL, 0); if (max_cpus < smp_cpus) { fprintf(stderr, "maxcpus must be equal to or greater than " "smp\n"); @@ -5425,7 +5474,6 @@ int main(int argc, char **argv, char **envp) exit(1); } break; - } case QEMU_OPTION_vnc: display_type = DT_VNC; vnc_display = optarg;