[1/5] target-ppc: Give a meaningful error if too many threads are specified

Message ID 1358917501-1897-2-git-send-email-david@gibson.dropbear.id.au
State New
Headers show

Commit Message

David Gibson Jan. 23, 2013, 5:04 a.m.
From: Mike Qiu <qiudayu@linux.vnet.ibm.com>

Currently the target-ppc tcg code only supports a single thread.  You can
specify more, but they're treated identically to multiple cores.  On KVM
we obviously can't support more threads than the hardware; if more are
specified it will cause strange and cryptic errors.

This patch clarifies the situation by giving a simple meaningful error if
more threads are specified than we can support.

Signed-off-by: Mike Qiu <qiudayu@linux.vnet.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
v2: Make sure we never invoke kvmppc_smp_threads() if KVM is not enabled.
Previously it depended on whether KVM was compiled in, which is not right.
 target-ppc/translate_init.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)


diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 2d78529..4f767c9 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -28,6 +28,7 @@ 
 #include <sysemu/kvm.h>
 #include "kvm_ppc.h"
 #include "sysemu/arch_init.h"
+#include "sysemu/cpus.h"
 //#define PPC_DUMP_CPU
 //#define PPC_DEBUG_SPR
@@ -10036,6 +10037,17 @@  static void ppc_cpu_realize(Object *obj, Error **errp)
     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
     ppc_def_t *def = pcc->info;
     Error *local_err = NULL;
+#if !defined(CONFIG_USER_ONLY)
+    int max_smt = kvm_enabled() ? kvmppc_smt_threads() : 1;
+#if !defined(CONFIG_USER_ONLY)
+    if (smp_threads > max_smt) {
+        fprintf(stderr, "Cannot support more than %d threads on PPC with %s\n",
+                max_smt, kvm_enabled() ? "KVM" : "TCG");
+        exit(1);
+    }
     if (kvm_enabled()) {
         if (kvmppc_fixup_cpu(cpu) != 0) {