From: Nicholas Piggin <npiggin@gmail.com>
To: qemu-ppc@nongnu.org
Cc: Nicholas Piggin <npiggin@gmail.com>,
qemu-devel@nongnu.org,
Richard Henderson <richard.henderson@linaro.org>
Subject: [RFC PATCH 2/3] target/ppc: define TARGET_HAS_LAZY_ICACHE
Date: Tue, 1 Apr 2025 01:54:22 +1000 [thread overview]
Message-ID: <20250331155423.619451-3-npiggin@gmail.com> (raw)
In-Reply-To: <20250331155423.619451-1-npiggin@gmail.com>
Use the new incoherent icache (incoherent TB) feature in the ppc target.
Performance problems with notdirty write accesses have been encountered
in two places now. One is where a large number of executable pages have
been freed (typically in KVM when a guest exits) and are being cleared
for reuse, most stores in a page will take the notdirty slowpath, which
can cause such s slowdown that the OS reports lockups. The other case is
PowerVM boot firmware which has real-mode interrupt handler code that
stores to memory in the same page-sized region as interrupt handler code
which causes significant slowdowns.
ppc implements TARGET_HAS_LAZY_ICACHE by calling tb_flush_incoherent()
from the ICBI instruction, which should conform to the ISA's CMODX (aka
SMC) requirement.
---
target/ppc/cpu.h | 16 ++++++++++++++++
target/ppc/mem_helper.c | 2 ++
target/ppc/translate.c | 1 +
3 files changed, 19 insertions(+)
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 74ed28c8dac..de274d29637 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -34,6 +34,22 @@
#define TARGET_PAGE_BITS_64K 16
#define TARGET_PAGE_BITS_16M 24
+/* icaches are not kept coherent with dcaches. target is to call
+ * tb_flush_incoherent() to bring them into coherency */
+#define TARGET_HAS_LAZY_ICACHE
+/*
+ * Note that this does not model implementation specific behaviour of all
+ * CPUs, notably recent Power CPUs do keep i/d coherent, and only require
+ * context synchronization after code modification to ensure CPU pipeline
+ * is coherent. The ISA and User Manuals do say that icbi (to any address) ;
+ * isync should be used even for these CPUs, so tb_flush_incoherent() in
+ * icbi should work reasonably. The ppc target should continue to work without
+ * TARGET_HAS_LAZY_ICACHE, but some performance corner cases benefit (e.g.,
+ * KVM when clearing a lot of memory freed from a guest that has a lot of exec
+ * pages; PowerVM PFW/boot firmware that stores to globals in the same page as
+ * it executes from).
+ */
+
#if defined(TARGET_PPC64)
#define PPC_ELF_MACHINE EM_PPC64
#else
diff --git a/target/ppc/mem_helper.c b/target/ppc/mem_helper.c
index 51b137febd6..647d37195dd 100644
--- a/target/ppc/mem_helper.c
+++ b/target/ppc/mem_helper.c
@@ -24,6 +24,7 @@
#include "exec/helper-proto.h"
#include "helper_regs.h"
#include "exec/cpu_ldst.h"
+#include "exec/tb-flush.h"
#include "internal.h"
#include "qemu/atomic128.h"
@@ -335,6 +336,7 @@ void helper_icbi(CPUPPCState *env, target_ulong addr)
* do the load "by hand".
*/
cpu_ldl_data_ra(env, addr, GETPC());
+ tb_flush_incoherent(env_cpu(env));
}
void helper_icbiep(CPUPPCState *env, target_ulong addr)
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 7f933537aaa..5e610bf29a5 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -4565,6 +4565,7 @@ static void gen_dss(DisasContext *ctx)
static void gen_icbi(DisasContext *ctx)
{
TCGv t0;
+ translator_io_start(&ctx->base);
gen_set_access_type(ctx, ACCESS_CACHE);
t0 = tcg_temp_new();
gen_addr_reg_index(ctx, t0);
--
2.47.1
next prev parent reply other threads:[~2025-03-31 15:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 15:54 [RFC PATCH 0/3] translation performance improvements Nicholas Piggin
2025-03-31 15:54 ` [RFC PATCH 1/3] accel/tcg: Option to permit incoherent translation block cache vs stores Nicholas Piggin
2025-03-31 19:51 ` Richard Henderson
2025-04-01 8:34 ` Nicholas Piggin
2025-04-01 8:42 ` Philippe Mathieu-Daudé
2025-03-31 15:54 ` Nicholas Piggin [this message]
2025-03-31 15:54 ` [RFC PATCH 3/3] target/ppc: Allow goto-tb on fixed real mode translations Nicholas Piggin
2025-03-31 19:40 ` [RFC PATCH 0/3] translation performance improvements Richard Henderson
2025-04-01 8:33 ` Nicholas Piggin
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=20250331155423.619451-3-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.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).