qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v5 1/2] target-ppc: add PowerPCCPU::cpu_dt_id


From: Alexey Kardashevskiy
Subject: [Qemu-devel] [PATCH v5 1/2] target-ppc: add PowerPCCPU::cpu_dt_id
Date: Tue, 3 Dec 2013 14:30:46 +1100

Normally CPUState::cpu_index is used to pick the right CPU for various
operations. However default consecutive numbering does not always work
for POWERPC.

These indexes are reflected in /proc/device-tree/cpus/PowerPC,address@hidden
and used to call KVM VCPU's ioctls. In order to achieve this,
kvmppc_fixup_cpu() was introduced. Roughly speaking, it multiplies
cpu_index by the number of threads per core.

This approach has disadvantages such as:
1. NUMA configuration stays broken after the fixup;
2. CPU-targeted commands from the QEMU Monitor do not work properly as
CPU indexes have been fixed and there is no clear way for the user to
know what the new CPU indexes are.

This introduces a @cpu_dt_id field in the CPUPPCState struct which
is initialized from @cpu_index by default and can be fixed later
to meet the device tree requirements.

This adds an API to handle @cpu_dt_id.

This will be used later in machine code.

Signed-off-by: Alexey Kardashevskiy <address@hidden>
---
 hw/ppc/ppc.c         | 33 +++++++++++++++++++++++++++++++++
 target-ppc/cpu-qom.h |  2 ++
 target-ppc/cpu.h     | 27 +++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index bf2d3d4..0184e11 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -26,6 +26,7 @@
 #include "hw/ppc/ppc_e500.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/cpus.h"
 #include "hw/timer/m48t59.h"
 #include "qemu/log.h"
 #include "hw/loader.h"
@@ -1362,3 +1363,35 @@ int PPC_NVRAM_set_params (nvram_t *nvram, uint16_t 
NVRAM_size,
 
     return 0;
 }
+
+/* CPU device-tree ID helpers */
+int ppc_get_vcpu_dt_id(PowerPCCPU *cpu)
+{
+    return cpu->cpu_dt_id;
+}
+
+PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id)
+{
+    CPUState *cs;
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+
+        if (cpu->cpu_dt_id == cpu_dt_id) {
+            return cpu;
+        }
+    }
+
+    return NULL;
+}
+
+void ppc_fixup_cpu_dt_id(PowerPCCPU *cpu)
+{
+    CPUState *cs = CPU(cpu);
+    int smt;
+
+    /* Adjust cpu index for SMT */
+    smt = kvmppc_smt_threads();
+    cpu->cpu_dt_id = (cs->cpu_index / smp_threads) * smt
+        + (cs->cpu_index % smp_threads);
+}
diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h
index 72b2232..b17c024 100644
--- a/target-ppc/cpu-qom.h
+++ b/target-ppc/cpu-qom.h
@@ -79,6 +79,7 @@ typedef struct PowerPCCPUClass {
 /**
  * PowerPCCPU:
  * @env: #CPUPPCState
+ * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too
  *
  * A PowerPC CPU.
  */
@@ -88,6 +89,7 @@ typedef struct PowerPCCPU {
     /*< public >*/
 
     CPUPPCState env;
+    int cpu_dt_id;
 } PowerPCCPU;
 
 static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index bb84767..abb3ad7 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -2154,4 +2154,31 @@ static inline bool cpu_has_work(CPUState *cpu)
 
 void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env);
 
+/**
+ * ppc_get_vcpu_dt_id:
+ * @cs: a PowerPCCPU struct.
+ *
+ * Returns a device-tree ID for a CPU.
+ */
+int ppc_get_vcpu_dt_id(PowerPCCPU *cpu);
+
+/**
+ * ppc_get_vcpu_by_dt_id:
+ * @cpu_dt_id: a device tree id
+ *
+ * Searches for a CPU by @cpu_dt_id.
+ *
+ * Returns: a PowerPCCPU struct
+ */
+PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id);
+
+/**
+ * ppc_fixup_cpu_dt_id:
+ * @cpu: a PowerPCCPU struct.
+ *
+ * Fixes the device-tree ID to align CPU core indexes to
+ * the threads-per-core number supported by the host hardware.
+ */
+void ppc_fixup_cpu_dt_id(PowerPCCPU *cpu);
+
 #endif /* !defined (__CPU_PPC_H__) */
-- 
1.8.4.rc4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]