From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-ppc@nongnu.org
Subject: [Qemu-devel] [PATCH v5 1/2] target-ppc: add PowerPCCPU::cpu_dt_id
Date: Tue, 3 Dec 2013 14:30:46 +1100 [thread overview]
Message-ID: <1386041447-16586-2-git-send-email-aik@ozlabs.ru> (raw)
In-Reply-To: <1386041447-16586-1-git-send-email-aik@ozlabs.ru>
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,POWER7@XX
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 <aik@ozlabs.ru>
---
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
next prev parent reply other threads:[~2013-12-03 3:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-03 3:30 [Qemu-devel] [PATCH v5 0/2] target-ppc: CPU device tree id Alexey Kardashevskiy
2013-12-03 3:30 ` Alexey Kardashevskiy [this message]
2013-12-03 3:30 ` [Qemu-devel] [PATCH v5 2/2] target-ppc: spapr: e500: fix to use cpu_dt_id Alexey Kardashevskiy
2014-01-31 14:09 ` [Qemu-devel] [Qemu-ppc] " Alexander Graf
2013-12-10 8:16 ` [Qemu-devel] [PATCH v5 0/2] target-ppc: CPU device tree id Alexey Kardashevskiy
2013-12-19 13:16 ` Alexey Kardashevskiy
2014-01-10 8:20 ` Alexey Kardashevskiy
2014-01-22 4:20 ` Alexey Kardashevskiy
2014-01-31 6:07 ` Alexey Kardashevskiy
2014-01-31 10:45 ` Thomas Huth
2014-01-31 11:45 ` Andreas Färber
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=1386041447-16586-2-git-send-email-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--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).