From: Andre Przywara <andre.przywara@amd.com>
To: anthony@codemonkey.ws
Cc: Andre Przywara <andre.przywara@amd.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/3] extend -smp parsing to include cores= and threads= options
Date: Wed, 19 Aug 2009 15:42:40 +0200 [thread overview]
Message-ID: <1250689362-11067-2-git-send-email-andre.przywara@amd.com> (raw)
In-Reply-To: <1250689362-11067-1-git-send-email-andre.przywara@amd.com>
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 <andre.przywara@amd.com>
---
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;
--
1.6.1.3
next prev parent reply other threads:[~2009-08-19 13:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-19 13:42 [Qemu-devel] [PATCH 0/3]: Introduce multi-core and multi-thread support for guests Andre Przywara
2009-08-19 13:42 ` Andre Przywara [this message]
2009-08-19 13:42 ` [Qemu-devel] [PATCH 2/3] push CPUID level to 4 to allow Intel multicore decoding Andre Przywara
2009-08-20 10:06 ` Avi Kivity
2009-08-20 10:36 ` Andre Przywara
2009-08-20 11:06 ` Avi Kivity
2009-08-20 19:03 ` [Qemu-devel] [PATCH] allow overriding of CPUID level on command line Andre Przywara
2009-08-25 12:21 ` [Qemu-devel] [PATCH 2/3] push CPUID level to 4 to allow Intel multicore decoding Andre Przywara
2009-08-20 19:30 ` Jamie Lokier
2009-08-20 21:35 ` Andre Przywara
2009-08-19 13:42 ` [Qemu-devel] [PATCH 3/3] set CPUID bits to present cores and threads topology Andre Przywara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1250689362-11067-2-git-send-email-andre.przywara@amd.com \
--to=andre.przywara@amd.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).