From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>,
qemu-ppc@nongnu.org, David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PATCH 03/22] pseries: Support SMT systems for KVM Book3S-HV
Date: Sun, 30 Oct 2011 21:22:54 +0100 [thread overview]
Message-ID: <1320006193-15219-4-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1320006193-15219-1-git-send-email-agraf@suse.de>
From: David Gibson <david@gibson.dropbear.id.au>
Alex Graf has already made qemu support KVM for the pseries machine
when using the Book3S-PR KVM variant (which runs the guest in
usermode, emulating supervisor operations). This code allows gets us
very close to also working with KVM Book3S-HV (using the hypervisor
capabilities of recent POWER CPUs).
This patch moves us another step towards Book3S-HV support by
correctly handling SMT (multithreaded) POWER CPUs. There are two
parts to this:
* Querying KVM to check SMT capability, and if present, adjusting the
cpu numbers that qemu assigns to cause KVM to assign guest threads
to cores in the right way (this isn't automatic, because the POWER
HV support has a limitation that different threads on a single core
cannot be in different guests at the same time).
* Correctly informing the guest OS of the SMT thread to core mappings
via the device tree.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
hw/spapr.c | 24 +++++++++++++++++++++---
target-ppc/helper.c | 11 +++++++++++
target-ppc/kvm.c | 8 ++++++++
target-ppc/kvm_ppc.h | 6 ++++++
4 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/hw/spapr.c b/hw/spapr.c
index 63e5d33..c2675e1 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -29,6 +29,9 @@
#include "elf.h"
#include "net.h"
#include "blockdev.h"
+#include "cpus.h"
+#include "kvm.h"
+#include "kvm_ppc.h"
#include "hw/boards.h"
#include "hw/ppc.h"
@@ -105,6 +108,7 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
uint32_t interrupt_server_ranges_prop[] = {0, cpu_to_be32(smp_cpus)};
int i;
char *modelname;
+ int smt = kvmppc_smt_threads();
#define _FDT(exp) \
do { \
@@ -164,13 +168,18 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
for (env = first_cpu; env != NULL; env = env->next_cpu) {
int index = env->cpu_index;
- uint32_t gserver_prop[] = {cpu_to_be32(index), 0}; /* HACK! */
+ uint32_t servers_prop[smp_threads];
+ uint32_t gservers_prop[smp_threads * 2];
char *nodename;
uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40),
0xffffffff, 0xffffffff};
uint32_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TIMEBASE_FREQ;
uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq() : 1000000000;
+ if ((index % smt) != 0) {
+ continue;
+ }
+
if (asprintf(&nodename, "%s@%x", modelname, index) < 0) {
fprintf(stderr, "Allocation failure\n");
exit(1);
@@ -195,9 +204,18 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
pft_size_prop, sizeof(pft_size_prop))));
_FDT((fdt_property_string(fdt, "status", "okay")));
_FDT((fdt_property(fdt, "64-bit", NULL, 0)));
- _FDT((fdt_property_cell(fdt, "ibm,ppc-interrupt-server#s", index)));
+
+ /* Build interrupt servers and gservers properties */
+ for (i = 0; i < smp_threads; i++) {
+ servers_prop[i] = cpu_to_be32(index + i);
+ /* Hack, direct the group queues back to cpu 0 */
+ gservers_prop[i*2] = cpu_to_be32(index + i);
+ gservers_prop[i*2 + 1] = 0;
+ }
+ _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+ servers_prop, sizeof(servers_prop))));
_FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
- gserver_prop, sizeof(gserver_prop))));
+ gservers_prop, sizeof(gservers_prop))));
if (env->mmu_model & POWERPC_MMU_1TSEG) {
_FDT((fdt_property(fdt, "ibm,processor-segment-sizes",
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 6339be3..137a494 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -26,6 +26,8 @@
#include "helper_regs.h"
#include "qemu-common.h"
#include "kvm.h"
+#include "kvm_ppc.h"
+#include "cpus.h"
//#define DEBUG_MMU
//#define DEBUG_BATS
@@ -3189,6 +3191,15 @@ CPUPPCState *cpu_ppc_init (const char *cpu_model)
if (tcg_enabled()) {
ppc_translate_init();
}
+ /* Adjust cpu index for SMT */
+#if !defined(CONFIG_USER_ONLY)
+ if (kvm_enabled()) {
+ int smt = kvmppc_smt_threads();
+
+ env->cpu_index = (env->cpu_index / smp_threads)*smt
+ + (env->cpu_index % smp_threads);
+ }
+#endif /* !CONFIG_USER_ONLY */
env->cpu_model_str = cpu_model;
cpu_ppc_register_internal(env, def);
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 75832d8..6c7ca6f 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -28,6 +28,7 @@
#include "kvm_ppc.h"
#include "cpu.h"
#include "device_tree.h"
+#include "hw/spapr.h"
#include "hw/sysbus.h"
#include "hw/spapr.h"
@@ -53,6 +54,7 @@ static int cap_interrupt_unset = false;
static int cap_interrupt_level = false;
static int cap_segstate;
static int cap_booke_sregs;
+static int cap_ppc_smt;
/* XXX We have a race condition where we actually have a level triggered
* interrupt, but the infrastructure can't expose that yet, so the guest
@@ -76,6 +78,7 @@ int kvm_arch_init(KVMState *s)
cap_interrupt_level = kvm_check_extension(s, KVM_CAP_PPC_IRQ_LEVEL);
cap_segstate = kvm_check_extension(s, KVM_CAP_PPC_SEGSTATE);
cap_booke_sregs = kvm_check_extension(s, KVM_CAP_PPC_BOOKE_SREGS);
+ cap_ppc_smt = kvm_check_extension(s, KVM_CAP_PPC_SMT);
if (!cap_interrupt_level) {
fprintf(stderr, "KVM: Couldn't find level irq capability. Expect the "
@@ -750,6 +753,11 @@ fail:
cpu_abort(env, "This KVM version does not support PAPR\n");
}
+int kvmppc_smt_threads(void)
+{
+ return cap_ppc_smt ? cap_ppc_smt : 1;
+}
+
bool kvm_arch_stop_on_emulation_error(CPUState *env)
{
return true;
diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h
index c484e60..c298411 100644
--- a/target-ppc/kvm_ppc.h
+++ b/target-ppc/kvm_ppc.h
@@ -18,6 +18,7 @@ uint64_t kvmppc_get_clockfreq(void);
int kvmppc_get_hypercall(CPUState *env, uint8_t *buf, int buf_len);
int kvmppc_set_interrupt(CPUState *env, int irq, int level);
void kvmppc_set_papr(CPUState *env);
+int kvmppc_smt_threads(void);
#else
@@ -45,6 +46,11 @@ static inline void kvmppc_set_papr(CPUState *env)
{
}
+static inline int kvmppc_smt_threads(void)
+{
+ return 1;
+}
+
#endif
#ifndef CONFIG_KVM
--
1.6.0.2
next prev parent reply other threads:[~2011-10-30 20:14 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-30 20:22 [Qemu-devel] [PULL 00/22] ppc patch queue 2011-10-30 Alexander Graf
2011-10-30 20:22 ` [Qemu-devel] [PATCH 01/22] ppc/e500_pci: Fix code style Alexander Graf
2011-10-30 20:22 ` [Qemu-devel] [PATCH 02/22] ppc/e500_pci: Fix an array overflow issue Alexander Graf
2011-10-30 20:22 ` Alexander Graf [this message]
2011-10-30 20:22 ` [Qemu-devel] [PATCH 04/22] pseries: Allow KVM Book3S-HV on PPC970 CPUS Alexander Graf
2011-10-30 20:22 ` [Qemu-devel] [PATCH 05/22] pseries: Use Book3S-HV TCE acceleration capabilities Alexander Graf
2011-10-30 20:22 ` [Qemu-devel] [PATCH 06/22] pseries: Update SLOF firmware image Alexander Graf
2011-10-30 20:22 ` [Qemu-devel] [PATCH 07/22] Set an invalid-bits mask for each SPE instructions Alexander Graf
2011-10-30 20:22 ` [Qemu-devel] [PATCH 08/22] ppc: Generalize the kvmppc_get_clockfreq() function Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 09/22] pseries: Add device tree properties for VMX/VSX and DFP under kvm Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 10/22] pseries: Update SLOF firmware image Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 11/22] ppc: Remove broken partial PVR matching Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 12/22] ppc: First cut implementation of -cpu host Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 13/22] ppc: Add cpu defs for POWER7 revisions 2.1 and 2.3 Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 14/22] pseries: Under kvm use guest cpu = host cpu by default Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 15/22] PPC: Bump qemu-system-ppc to 64-bit physical address space Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 16/22] PPC: Disable non-440 CPUs for ppcemb target Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 17/22] ppc: Avoid decrementer related kvm exits Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 18/22] PPC: Fail configure when libfdt is not available Alexander Graf
2011-11-01 19:28 ` Blue Swirl
2011-11-01 20:42 ` Alexander Graf
2011-11-01 23:59 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2011-10-30 20:23 ` [Qemu-devel] [PATCH 19/22] pseries: Correct vmx/dfp handling in both KVM and TCG cases Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 20/22] ppc: Fix up usermode only builds Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 21/22] KVM: PPC: Override host vmx/vsx/dfp only when information known Alexander Graf
2011-10-30 20:23 ` [Qemu-devel] [PATCH 22/22] pseries: Allow writes to KVM accelerated TCE table Alexander Graf
2011-10-31 4:03 ` [Qemu-devel] [PULL 00/22] ppc patch queue 2011-10-30 Alexander Graf
2011-10-31 4:12 ` [Qemu-devel] [PATCH 23/22] ppc: Alter CPU state to mask out TCG unimplemented instructions as appropriate Alexander Graf
2011-10-31 4:12 ` [Qemu-devel] [PATCH 24/22] pseries: Add partial support for PCI Alexander Graf
2011-11-01 21:05 ` [Qemu-devel] [PULL 00/22] ppc patch queue 2011-10-30 Blue Swirl
2011-11-01 21:41 ` Anthony Liguori
2011-11-01 22:14 ` Alexander Graf
2011-11-01 22:16 ` Anthony Liguori
2011-11-01 22:28 ` Alexander Graf
2011-11-01 22:32 ` Anthony Liguori
2011-11-02 0:12 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2011-11-02 19:59 ` [Qemu-devel] " Blue Swirl
2011-11-02 20:11 ` Anthony Liguori
2011-11-02 20:38 ` Alexander Graf
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=1320006193-15219-4-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=blauwirbel@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).