* [Qemu-devel] [PATCH v3 1/6] target/ppc: Emulate LL/SC using cmpxchg helpers
2017-04-27 5:18 [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 Nikunj A Dadhania
@ 2017-04-27 5:18 ` Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 2/6] cputlb: handle first atomic write to the page Nikunj A Dadhania
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikunj A Dadhania @ 2017-04-27 5:18 UTC (permalink / raw)
To: qemu-ppc, david; +Cc: qemu-devel, rth, alex.bennee, nikunj, bharata
Emulating LL/SC with cmpxchg is not correct, since it can suffer from
the ABA problem. However, portable parallel code is written assuming
only cmpxchg which means that in practice this is a viable alternative.
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
---
target/ppc/translate.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index f40b5a1..50b6d4d 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -73,6 +73,7 @@ static TCGv cpu_cfar;
#endif
static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca, cpu_ov32, cpu_ca32;
static TCGv cpu_reserve;
+static TCGv cpu_reserve_val;
static TCGv cpu_fpscr;
static TCGv_i32 cpu_access_type;
@@ -181,6 +182,9 @@ void ppc_translate_init(void)
cpu_reserve = tcg_global_mem_new(cpu_env,
offsetof(CPUPPCState, reserve_addr),
"reserve_addr");
+ cpu_reserve_val = tcg_global_mem_new(cpu_env,
+ offsetof(CPUPPCState, reserve_val),
+ "reserve_val");
cpu_fpscr = tcg_global_mem_new(cpu_env,
offsetof(CPUPPCState, fpscr), "fpscr");
@@ -3023,7 +3027,7 @@ static void gen_##name(DisasContext *ctx) \
} \
tcg_gen_qemu_ld_tl(gpr, t0, ctx->mem_idx, memop); \
tcg_gen_mov_tl(cpu_reserve, t0); \
- tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
+ tcg_gen_mov_tl(cpu_reserve_val, gpr); \
tcg_temp_free(t0); \
}
@@ -3155,14 +3159,27 @@ static void gen_conditional_store(DisasContext *ctx, TCGv EA,
static void gen_conditional_store(DisasContext *ctx, TCGv EA,
int reg, int memop)
{
- TCGLabel *l1;
+ TCGLabel *l1 = gen_new_label();
+ TCGLabel *l2 = gen_new_label();
+ TCGv t0;
- tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
- l1 = gen_new_label();
tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
- tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], CRF_EQ);
- tcg_gen_qemu_st_tl(cpu_gpr[reg], EA, ctx->mem_idx, memop);
+
+ t0 = tcg_temp_new();
+ tcg_gen_atomic_cmpxchg_tl(t0, cpu_reserve, cpu_reserve_val,
+ cpu_gpr[reg], ctx->mem_idx,
+ DEF_MEMOP(memop) | MO_ALIGN);
+ tcg_gen_setcond_tl(TCG_COND_EQ, t0, t0, cpu_reserve_val);
+ tcg_gen_shli_tl(t0, t0, CRF_EQ_BIT);
+ tcg_gen_or_tl(t0, t0, cpu_so);
+ tcg_gen_trunc_tl_i32(cpu_crf[0], t0);
+ tcg_temp_free(t0);
+ tcg_gen_br(l2);
+
gen_set_label(l1);
+ tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
+
+ gen_set_label(l2);
tcg_gen_movi_tl(cpu_reserve, -1);
}
#endif
--
2.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 2/6] cputlb: handle first atomic write to the page
2017-04-27 5:18 [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 1/6] target/ppc: Emulate LL/SC using cmpxchg helpers Nikunj A Dadhania
@ 2017-04-27 5:18 ` Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 3/6] target/ppc: Generate fence operations Nikunj A Dadhania
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikunj A Dadhania @ 2017-04-27 5:18 UTC (permalink / raw)
To: qemu-ppc, david; +Cc: qemu-devel, rth, alex.bennee, nikunj, bharata
In case where the conditional write is the first write to the page,
TLB_NOTDIRTY will be set and stop_the_world is triggered. Handle this as
a special case and set the dirty bit. After that fall through to the
actual atomic instruction below.
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
---
cputlb.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/cputlb.c b/cputlb.c
index f5d056c..743776a 100644
--- a/cputlb.c
+++ b/cputlb.c
@@ -930,7 +930,13 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
tlb_addr = tlbe->addr_write;
}
- /* Notice an IO access, or a notdirty page. */
+ /* Check notdirty */
+ if (unlikely(tlb_addr & TLB_NOTDIRTY)) {
+ tlb_set_dirty(ENV_GET_CPU(env), addr);
+ tlb_addr = tlb_addr & ~TLB_NOTDIRTY;
+ }
+
+ /* Notice an IO access */
if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
/* There's really nothing that can be done to
support this apart from stop-the-world. */
--
2.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 3/6] target/ppc: Generate fence operations
2017-04-27 5:18 [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 1/6] target/ppc: Emulate LL/SC using cmpxchg helpers Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 2/6] cputlb: handle first atomic write to the page Nikunj A Dadhania
@ 2017-04-27 5:18 ` Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 4/6] cpus: Fix CPU unplug for MTTCG Nikunj A Dadhania
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikunj A Dadhania @ 2017-04-27 5:18 UTC (permalink / raw)
To: qemu-ppc, david; +Cc: qemu-devel, rth, alex.bennee, nikunj, bharata
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
---
target/ppc/translate.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 50b6d4d..4a1f24a 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -2971,6 +2971,7 @@ static void gen_stswx(DisasContext *ctx)
/* eieio */
static void gen_eieio(DisasContext *ctx)
{
+ tcg_gen_mb(TCG_MO_LD_ST | TCG_BAR_SC);
}
#if !defined(CONFIG_USER_ONLY)
@@ -3008,6 +3009,7 @@ static void gen_isync(DisasContext *ctx)
if (!ctx->pr) {
gen_check_tlb_flush(ctx, false);
}
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
gen_stop_exception(ctx);
}
@@ -3028,6 +3030,7 @@ static void gen_##name(DisasContext *ctx) \
tcg_gen_qemu_ld_tl(gpr, t0, ctx->mem_idx, memop); \
tcg_gen_mov_tl(cpu_reserve, t0); \
tcg_gen_mov_tl(cpu_reserve_val, gpr); \
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); \
tcg_temp_free(t0); \
}
@@ -3177,6 +3180,10 @@ static void gen_conditional_store(DisasContext *ctx, TCGv EA,
tcg_gen_br(l2);
gen_set_label(l1);
+
+ /* Address mismatch implies failure. But we still need to provide the
+ memory barrier semantics of the instruction. */
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
gen_set_label(l2);
@@ -3308,6 +3315,7 @@ static void gen_sync(DisasContext *ctx)
if (((l == 2) || !(ctx->insns_flags & PPC_64B)) && !ctx->pr) {
gen_check_tlb_flush(ctx, true);
}
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
}
/* wait */
--
2.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 4/6] cpus: Fix CPU unplug for MTTCG
2017-04-27 5:18 [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 Nikunj A Dadhania
` (2 preceding siblings ...)
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 3/6] target/ppc: Generate fence operations Nikunj A Dadhania
@ 2017-04-27 5:18 ` Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 5/6] tcg: enable MTTCG by default for PPC64 on x86 Nikunj A Dadhania
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikunj A Dadhania @ 2017-04-27 5:18 UTC (permalink / raw)
To: qemu-ppc, david; +Cc: qemu-devel, rth, alex.bennee, nikunj, bharata
From: Bharata B Rao <bharata@linux.vnet.ibm.com>
Ensure that the unplugged CPU thread is destroyed and the waiting
thread is notified about it. This is needed for CPU unplug to work
correctly in MTTCG mode.
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
---
cpus.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/cpus.c b/cpus.c
index 740b8dc..79f780b 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1483,6 +1483,12 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
/* Ignore everything else? */
break;
}
+ } else if (cpu->unplug) {
+ qemu_tcg_destroy_vcpu(cpu);
+ cpu->created = false;
+ qemu_cond_signal(&qemu_cpu_cond);
+ qemu_mutex_unlock_iothread();
+ return NULL;
}
atomic_mb_set(&cpu->exit_request, 0);
--
2.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 5/6] tcg: enable MTTCG by default for PPC64 on x86
2017-04-27 5:18 [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 Nikunj A Dadhania
` (3 preceding siblings ...)
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 4/6] cpus: Fix CPU unplug for MTTCG Nikunj A Dadhania
@ 2017-04-27 5:18 ` Nikunj A Dadhania
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 6/6] target/ppc: do not reset reserve_addr in exec_enter Nikunj A Dadhania
2017-05-01 6:08 ` [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 David Gibson
6 siblings, 0 replies; 8+ messages in thread
From: Nikunj A Dadhania @ 2017-04-27 5:18 UTC (permalink / raw)
To: qemu-ppc, david; +Cc: qemu-devel, rth, alex.bennee, nikunj, bharata
This enables the multi-threaded system emulation by default for PPC64
guests using the x86_64 TCG back-end.
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
configure | 2 ++
target/ppc/cpu.h | 2 ++
2 files changed, 4 insertions(+)
diff --git a/configure b/configure
index c35acf1..3814617 100755
--- a/configure
+++ b/configure
@@ -6090,12 +6090,14 @@ case "$target_name" in
ppc64)
TARGET_BASE_ARCH=ppc
TARGET_ABI_DIR=ppc
+ mttcg=yes
gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
;;
ppc64le)
TARGET_ARCH=ppc64
TARGET_BASE_ARCH=ppc
TARGET_ABI_DIR=ppc
+ mttcg=yes
gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
;;
ppc64abi32)
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index e0ff041..ece535d 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -30,6 +30,8 @@
#define TARGET_LONG_BITS 64
#define TARGET_PAGE_BITS 12
+#define TCG_GUEST_DEFAULT_MO 0
+
/* Note that the official physical address space bits is 62-M where M
is implementation dependent. I've not looked up M for the set of
cpus we emulate at the system level. */
--
2.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 6/6] target/ppc: do not reset reserve_addr in exec_enter
2017-04-27 5:18 [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 Nikunj A Dadhania
` (4 preceding siblings ...)
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 5/6] tcg: enable MTTCG by default for PPC64 on x86 Nikunj A Dadhania
@ 2017-04-27 5:18 ` Nikunj A Dadhania
2017-05-01 6:08 ` [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 David Gibson
6 siblings, 0 replies; 8+ messages in thread
From: Nikunj A Dadhania @ 2017-04-27 5:18 UTC (permalink / raw)
To: qemu-ppc, david; +Cc: qemu-devel, rth, alex.bennee, nikunj, bharata
In case when atomic operation is not supported, exit_atomic is called
and we stop the world and execute the atomic operation. This results
in a following call chain:
tcg_gen_atomic_cmpxchg_tl()
-> gen_helper_exit_atomic()
-> HELPER(exit_atomic)
-> cpu_loop_exit_atomic() -> EXCP_ATOMIC
-> qemu_tcg_cpu_thread_fn() => case EXCP_ATOMIC
-> cpu_exec_step_atomic()
-> cpu_step_atomic()
-> cc->cpu_exec_enter() = ppc_cpu_exec_enter()
Sets env->reserve_addr = -1;
But by the time it return back, the reservation is erased and the code
fails, this continues forever and the lock is never taken.
Instead set this in powerpc_excp()
Now that ppc_cpu_exec_enter() doesn't have anything meaningful to do,
let us get rid of the function.
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
---
target/ppc/excp_helper.c | 3 +++
target/ppc/translate_init.c | 9 ---------
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index f4ee7aa..a6bcb47 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -728,6 +728,9 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
cs->exception_index = POWERPC_EXCP_NONE;
env->error_code = 0;
+ /* Reset the reservation */
+ env->reserve_addr = -1;
+
/* Any interrupt is context synchronizing, check if TCG TLB
* needs a delayed flush on ppc64
*/
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index e82e3e6..9b048cd 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -10436,14 +10436,6 @@ static bool ppc_cpu_has_work(CPUState *cs)
return msr_ee && (cs->interrupt_request & CPU_INTERRUPT_HARD);
}
-static void ppc_cpu_exec_enter(CPUState *cs)
-{
- PowerPCCPU *cpu = POWERPC_CPU(cs);
- CPUPPCState *env = &cpu->env;
-
- env->reserve_addr = -1;
-}
-
/* CPUClass::reset() */
static void ppc_cpu_reset(CPUState *s)
{
@@ -10660,7 +10652,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
cc->get_phys_page_debug = ppc_cpu_get_phys_page_debug;
cc->vmsd = &vmstate_ppc_cpu;
#endif
- cc->cpu_exec_enter = ppc_cpu_exec_enter;
#if defined(CONFIG_SOFTMMU)
cc->write_elf64_note = ppc64_cpu_write_elf64_note;
cc->write_elf32_note = ppc32_cpu_write_elf32_note;
--
2.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64
2017-04-27 5:18 [Qemu-devel] [PATCH v3 0/6] The series enables Multi-Threaded TCG on PPC64 Nikunj A Dadhania
` (5 preceding siblings ...)
2017-04-27 5:18 ` [Qemu-devel] [PATCH v3 6/6] target/ppc: do not reset reserve_addr in exec_enter Nikunj A Dadhania
@ 2017-05-01 6:08 ` David Gibson
6 siblings, 0 replies; 8+ messages in thread
From: David Gibson @ 2017-05-01 6:08 UTC (permalink / raw)
To: Nikunj A Dadhania; +Cc: qemu-ppc, qemu-devel, rth, alex.bennee, bharata
[-- Attachment #1: Type: text/plain, Size: 1900 bytes --]
On Thu, Apr 27, 2017 at 10:48:18AM +0530, Nikunj A Dadhania wrote:
> Patch 01: Use atomic_cmpxchg in store conditional
> 02: Handle first write to page during atomic operation
> 03: Generate memory barriers for sync/isync and load/store conditional
> 04: Fix CPU unplug in MTTCG
> 05: Enable MTTCG by default on PPC64
> 06: Fixes a bug in PPC where the reservation is reset
> causing atomic operations to never succeed
>
> Patches are based on ppc-for-2.10
Applied to ppc-for-2.10, thanks.
>
> Changelog:
> v2:
> * David found problem related to clang and "make check" that was
> root caused to a tcg bug and the patch is in mainline:
>
> 79b1af9 tcg: Initialize return value after exit_atomic
>
> * Fixed a bug in ppc_cpu_exec_enter(), which was resetting the
> reserve_addr, this should be done in powerpc_excp()
>
> v1:
> * Rewrote store_conditional as suggested by Richard
>
> Bharata B Rao (1):
> cpus: Fix CPU unplug for MTTCG
>
> Nikunj A Dadhania (5):
> target/ppc: Emulate LL/SC using cmpxchg helpers
> cputlb: handle first atomic write to the page
> target/ppc: Generate fence operations
> tcg: enable MTTCG by default for PPC64 on x86
> target/ppc: do not reset reserve_addr in exec_enter
>
> configure | 2 ++
> cpus.c | 6 ++++++
> cputlb.c | 8 +++++++-
> target/ppc/cpu.h | 2 ++
> target/ppc/excp_helper.c | 3 +++
> target/ppc/translate.c | 37 +++++++++++++++++++++++++++++++------
> target/ppc/translate_init.c | 9 ---------
> 7 files changed, 51 insertions(+), 16 deletions(-)
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread