Move rom and notdirty handling to cputlb
v3 cover Move rom and notdirty handling to cputlb
Ok! Third time is the charm, because this time it works.
New to v3:
* Covert io_mem_rom with a new TLB_ROM bit.
* This in turn means that there are no longer any special RAM case along along the MMIO path -- they all have devices on the other end.
* This in turn means that we can fold the bulk of memory_region_section_get_iotlb into tlb_set_page_with_attrs, a couple of redundant tests vs the MemoryRegion. The result in patch 14 is, IMO, much more understandable.
* Fold away uses of cpu->mem_io_pc in tb_invalidate_phys_page__locked, the cause of the problems for my previous two patch sets.
BTW, I was correct with my guess in the v2 cover letter that the use of memory_notdirty_write_{prepare,complete} within atomic_mmu_lookup must have been broken, for not setting mem_io_pc. :-P
* Fix a missed use of cpu->mem_io_pc in tb_check_watchpoint, which meant that the previous TLB_WATCHPOINT cleanup was a titch broken.
The remaining two users of cpu->mem_io_pc are hw/misc/mips_itu.c and target/i386/helper.c. I haven't looked, but I assume that these are legitimately on the MMIO path, and there probably isn't a decent way to remove the uses.
r~
Richard Henderson (20):
exec: Use TARGET_PAGE_BITS_MIN for TLB flags
exec: Split out variable page size support to exec-vary.c
exec: Use const alias for TARGET_PAGE_BITS_VARY
exec: Restrict TARGET_PAGE_BITS_VARY assert to CONFIG_DEBUG_TCG
exec: Promote TARGET_PAGE_MASK to target_long
exec: Tidy TARGET_PAGE_ALIGN
exec: Cache TARGET_PAGE_MASK for TARGET_PAGE_BITS_VARY
cputlb: Disable __always_inline__ without optimization
cputlb: Replace switches in load/store_helper with callback
cputlb: Introduce TLB_BSWAP
exec: Adjust notdirty tracing
cputlb: Move ROM handling from I/O path to TLB path
cputlb: Move NOTDIRTY handling from I/O path to TLB path
cputlb: Partially inline memory_region_section_get_iotlb
cputlb: Merge and move memory_notdirty_write_{prepare,complete}
cputlb: Handle TLB_NOTDIRTY in probe_access
cputlb: Remove cpu->mem_io_vaddr
cputlb: Remove tb_invalidate_phys_page_range is_cpu_write_access
cputlb: Pass retaddr to tb_invalidate_phys_page_fast
cputlb: Pass retaddr to tb_check_watchpoint
Makefile.target | 2 +- accel/tcg/translate-all.h | 8 +- include/exec/cpu-all.h | 48 ++-- include/exec/cpu-common.h | 3 - include/exec/exec-all.h | 6 +- include/exec/memory-internal.h | 65 ------ include/hw/core/cpu.h | 2 - include/qemu-common.h | 6 + include/qemu/compiler.h | 11 + accel/tcg/cputlb.c | 388 +++++++++++++++++++-------------- accel/tcg/translate-all.c | 51 ++--- exec-vary.c | 88 ++++++++ exec.c | 192 +--------------- hw/core/cpu.c | 1 - memory.c | 20 -- trace-events | 4 +- 16 files changed, 403 insertions(+), 492 deletions(-) create mode 100644 exec-vary.c
Signature · 1 line
2.17.1
PATCH v3 1/20 exec: Use TARGET_PAGE_BITS_MIN for TLB flags
These bits do not need to vary with the actual page size used by the guest.
--- include/exec/cpu-all.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
include/exec/cpu-all.h +10 -6
@@ -317,20 +317,24 @@ CPUArchState *cpu_copy(CPUArchState *env);#if !defined(CONFIG_USER_ONLY ) -/* Flags stored in the low bits of the TLB virtual address. These are -* defined so that fast path ram access is all zeros. +/* +* Flags stored in the low bits of the TLB virtual address. +* These are defined so that fast path ram access is all zeros. * The flags all must be between TARGET_PAGE_BITS and * maximum address alignment bit. +* +* Use TARGET_PAGE_BITS_MIN so that these bits are constant +* when TARGET_PAGE_BITS_VARY is in effect. */ /* Zero if TLB entry is valid. */ -#define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS - 1)) +#define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS_MIN - 1))/* Set if TLB entry references a clean RAM page. The iotlb entry will contain the page physical address. */ -#define TLB_NOTDIRTY (1 << (TARGET_PAGE_BITS - 2)) +#define TLB_NOTDIRTY (1 << (TARGET_PAGE_BITS_MIN - 2))/* Set if TLB entry is an IO callback. */ -#define TLB_MMIO (1 << (TARGET_PAGE_BITS - 3)) +#define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 3))/* Set if TLB entry contains a watchpoint. */ -#define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS - 4)) +#define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS_MIN - 4))/* Use this mask to check interception with an alignment mask * in a TCG backend.
Signature · 1 line
2.17.1
Re: [PATCH v3 01/20] exec: Use TARGET_PAGE_BITS_MIN for TLB flags
Quoted 35 lines · Richard Henderson
These bits do not need to vary with the actual page size used by the guest.
Reviewed-by Paolo Bonzini <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)include/exec/cpu-all.h +7
-4@@ -317,20 +317,24 @@ CPUArchState *cpu_copy(CPUArchState *env);#if !defined(CONFIG_USER_ONLY ) -/* Flags stored in the low bits of the TLB virtual address. These are -* defined so that fast path ram access is all zeros. +/* +* Flags stored in the low bits of the TLB virtual address. +* These are defined so that fast path ram access is all zeros. * The flags all must be between TARGET_PAGE_BITS and * maximum address alignment bit. +* +* Use TARGET_PAGE_BITS_MIN so that these bits are constant +* when TARGET_PAGE_BITS_VARY is in effect. */ /* Zero if TLB entry is valid. */ -#define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS - 1)) +#define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS_MIN - 1))/* Set if TLB entry references a clean RAM page. The iotlb entry will contain the page physical address. */ -#define TLB_NOTDIRTY (1 << (TARGET_PAGE_BITS - 2))
include/exec/cpu-all.h CPUArchState *cpu_copy(CPUArchState *env); · line 340
Quoted 10 lines
include/exec/cpu-all.h +3
-2+#define TLB_NOTDIRTY (1 << (TARGET_PAGE_BITS_MIN - 2))/* Set if TLB entry is an IO callback. */ -#define TLB_MMIO (1 << (TARGET_PAGE_BITS - 3)) +#define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 3))/* Set if TLB entry contains a watchpoint. */ -#define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS - 4)) +#define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS_MIN - 4))/* Use this mask to check interception with an alignment mask * in a TCG backend.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 2/20 exec: Split out variable page size support to exec-vary.c
In reply to Richard HendersonThe next patch will play a trick with "const" that will confuse the compiler about the uses of target_page_bits within exec.c. Moving everything to a new file prevents this confusion.
No functional change so far.
--- Makefile.target | 2 +- include/qemu-common.h | 6 +++++ exec-vary.c | 57 +++++++++++++++++++++++++++++++++++++++++++ exec.c | 34 -------------------------- 4 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 exec-vary.c
Makefile.target +1 -1
@@ -107,7 +107,7 @@ obj-y += trace/ ######################################################### # cpu emulator library -obj-y += exec.o +obj-y += exec.o exec-vary.o obj-y += accel/ obj-$(CONFIG_TCG) += tcg/tcg.o tcg/tcg-op.o tcg/tcg-op-vec.o tcg/tcg-op-gvec.o obj-$(CONFIG_TCG) += tcg/tcg-common.o tcg/optimize.o
include/qemu-common.h +6 -0
@@ -74,6 +74,12 @@ void cpu_exec_step_atomic(CPUState *cpu);*/ bool set_preferred_target_page_bits (int bits); +/** +* finalize_target_page_bits: +* Commit the final value set by set_preferred_target_page_bits. +*/ +void finalize_target_page_bits (void ); +/** * Sends a (part of) iovec down a socket, yielding when the socket is full, or * Receives data into a (part of) iovec from a socket,
exec-vary.c new file +57 -0
57 lines not on this page · raw message
exec.c +0 -34
@@ -92,11 +92,6 @@ MemoryRegion io_mem_rom, io_mem_notdirty;static MemoryRegion io_mem_unassigned;#endif -#ifdef TARGET_PAGE_BITS_VARY -int target_page_bits; -bool target_page_bits_decided; -#endif -CPUTailQ cpus =QTAILQ_HEAD_INITIALIZER (cpus);/* current CPU in the current thread. It is only valid inside
@@ -110,37 +105,8 @@ int use_icount;uintptr_t qemu_host_page_size;intptr_t qemu_host_page_mask; -bool set_preferred_target_page_bits (int bits) -{ -/* The target page size is the lowest common denominator for all -* the CPUs in the system, so we can only make it smaller, never -* larger. And we can't make it smaller once we've committed to -* a particular size. -*/ -#ifdef TARGET_PAGE_BITS_VARY -assert (bits >=TARGET_PAGE_BITS_MIN ); -if (target_page_bits ==0 || target_page_bits > bits) { -if (target_page_bits_decided) { -return false; - } - target_page_bits = bits; - } -#endif -return true; -} -#if !defined(CONFIG_USER_ONLY ) -static void finalize_target_page_bits (void ) -{ -#ifdef TARGET_PAGE_BITS_VARY -if (target_page_bits ==0 ) { - target_page_bits =TARGET_PAGE_BITS_MIN ; - } - target_page_bits_decided = true; -#endif -} -typedef struct PhysPageEntry PhysPageEntry ; struct PhysPageEntry {
Signature · 1 line
2.17.1
Re: [PATCH v3 02/20] exec: Split out variable page size support to exec-vary.c
Quoted 101 lines · Richard Henderson
The next patch will play a trick with "const" that will confuse the compiler about the uses of
target_page_bitswithinexec.c. Moving everything to a new file prevents this confusion.No functional change so far.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- Makefile.target | 2 +- include/qemu-common.h | 6 +++++ exec-vary.c | 57 +++++++++++++++++++++++++++++++++++++++++++ exec.c | 34 -------------------------- 4 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 exec-vary.cMakefile.target +1
-1@@ -107,7 +107,7 @@ obj-y += trace/ ######################################################### # cpu emulator library -obj-y += exec.o +obj-y += exec.o exec-vary.o obj-y += accel/ obj-$(CONFIG_TCG) += tcg/tcg.o tcg/tcg-op.o tcg/tcg-op-vec.o tcg/tcg-op-gvec.o obj-$(CONFIG_TCG) += tcg/tcg-common.o tcg/optimize.oinclude/qemu-common.h +6
-0@@ -74,6 +74,12 @@ void cpu_exec_step_atomic(CPUState *cpu);*/ bool set_preferred_target_page_bits (int bits); +/** +* finalize_target_page_bits: +* Commit the final value set by set_preferred_target_page_bits. +*/ +void finalize_target_page_bits (void ); +/** * Sends a (part of) iovec down a socket, yielding when the socket is full, or * Receives data into a (part of) iovec from a socket, exec-vary.c new file +47
-0@@ -0,0 +1,57 @@ +/* +* Variable page size handling +* +* Copyright (c) 2003 Fabrice Bellard +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "exec/exec-all.h" + +#ifdef TARGET_PAGE_BITS_VARY +int target_page_bits; +bool target_page_bits_decided; +#endif + +bool set_preferred_target_page_bits (int bits) +{ +/* +* The target page size is the lowest common denominator for all +* the CPUs in the system, so we can only make it smaller, never +* larger. And we can't make it smaller once we've committed to +* a particular size. +*/ +#ifdef TARGET_PAGE_BITS_VARY +assert (bits >=TARGET_PAGE_BITS_MIN ); +if (target_page_bits ==0 || target_page_bits > bits) { +if (target_page_bits_decided) { +return false; + } + target_page_bits = bits; + } +#endif +return true; +}
exec-vary.c line 57
Quoted 10 lines
exec-vary.c new file +10
-0+ +void finalize_target_page_bits (void ) +{ +#ifdef TARGET_PAGE_BITS_VARY +if (target_page_bits ==0 ) { + target_page_bits =TARGET_PAGE_BITS_MIN ; + } + target_page_bits_decided = true; +#endif +}
I wonder if it would be nicer to handle this in the header file instead, providing dummy functions there.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v3 02/20] exec: Split out variable page size support to exec-vary.c
Quoted 11 lines · David Hildenbrand
exec-vary.c line 57
Quoted 9 lines
exec-vary.c new file +9
-0+void finalize_target_page_bits (void ) +{ +#ifdef TARGET_PAGE_BITS_VARY +if (target_page_bits ==0 ) { + target_page_bits =TARGET_PAGE_BITS_MIN ; + } + target_page_bits_decided = true; +#endif +}I wonder if it would be nicer to handle this in the header file instead, providing dummy functions there.
No can do, because set_preferred_target_page_bits is used by vl.c, which is compiled once and so does not have access to cpu.h definitions.
r~
PATCH v3 3/20 exec: Use const alias for TARGET_PAGE_BITS_VARY
In reply to Richard HendersonUsing a variable that is declared "const" for this tells the compiler that it may read the value once and assume that it does not change across function calls.
For target_page_size, this means we have only one assert per function, and one read of the variable.
This reduces the size of qemu-system-aarch64 by 8k.
--- include/exec/cpu-all.h | 10 +++++---- exec-vary.c | 46 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 12 deletions(-)
include/exec/cpu-all.h +6 -4
@@ -210,10 +210,12 @@ static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val/* page related stuff */ #ifdef TARGET_PAGE_BITS_VARY -extern bool target_page_bits_decided; -extern int target_page_bits; -#define TARGET_PAGE_BITS ({ assert(target_page_bits_decided); \ - target_page_bits; }) +typedef struct { +bool decided; +int bits; +}TargetPageBits ; +extern const TargetPageBits target_page; +#define TARGET_PAGE_BITS (assert(target_page.decided), target_page.bits)#else #define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS#endif
exec-vary.c +38 -8
66 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 4/20 exec: Restrict TARGET_PAGE_BITS_VARY assert to CONFIG_DEBUG_TCG
In reply to Richard HendersonThis reduces the size of a release build by about 10k. Noticably, within the tlb miss helpers.
--- include/exec/cpu-all.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
include/exec/cpu-all.h +5 -1
@@ -215,7 +215,11 @@ typedef struct { int bits; } TargetPageBits;extern const TargetPageBits target_page; -#define TARGET_PAGE_BITS (assert(target_page.decided), target_page.bits) +# ifdef CONFIG_DEBUG_TCG +# define TARGET_PAGE_BITS (assert(target_page.decided), target_page.bits) +# else +# define TARGET_PAGE_BITS target_page.bits +# endif #else #define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS#endif
Signature · 1 line
2.17.1
PATCH v3 5/20 exec: Promote TARGET_PAGE_MASK to target_long
In reply to Richard HendersonThere are some uint64_t uses that expect TARGET_PAGE_MASK to extend for a 32-bit, so this must continue to be a signed type. Define based on TARGET_PAGE_BITS not TARGET_PAGE_SIZE; this will make a following patch more clear.
This should not have a functional effect so far.
--- include/exec/cpu-all.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/cpu-all.h +1 -1
@@ -225,7 +225,7 @@ extern const TargetPageBits target_page;#endif #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS) -#define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1) +#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS)#define TARGET_PAGE_ALIGN (addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)/* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
Signature · 1 line
2.17.1
Re: [PATCH v3 05/20] exec: Promote TARGET_PAGE_MASK to target_long
Quoted 19 lines · Richard Henderson
There are some
uint64_tuses that expectTARGET_PAGE_MASKto extend for a 32-bit, so this must continue to be a signed type. Define based onTARGET_PAGE_BITSnotTARGET_PAGE_SIZE; this will make a following patch more clear.This should not have a functional effect so far.
Reviewed-by Paolo Bonzini <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/exec/cpu-all.h +0
-0
include/exec/cpu-all.h extern const TargetPageBits target_page; · line 231
Quoted 8 lines
include/exec/cpu-all.h +1
-1@@ -225,7 +225,7 @@ extern const TargetPageBits target_page;#endif #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS) -#define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1) +#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS)#define TARGET_PAGE_ALIGN (addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)/* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 6/20 exec: Tidy TARGET_PAGE_ALIGN
In reply to Richard HendersonUse TARGET_PAGE_MASK twice instead of TARGET_PAGE_SIZE once. This is functionally identical, but will help a following patch.
--- include/exec/cpu-all.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/exec/cpu-all.h +2 -1
@@ -226,7 +226,8 @@ extern const TargetPageBits target_page;#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS) -#define TARGET_PAGE_ALIGN (addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK) +#define TARGET_PAGE_ALIGN (addr) \ + (((addr) + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK)/* Using intptr_t ensures that qemu_*_page_mask is sign-extended even * when intptr_t is 32-bit and we are aligning a long long.
Signature · 1 line
2.17.1
Re: [PATCH v3 06/20] exec: Tidy TARGET_PAGE_ALIGN
Quoted 15 lines · Richard Henderson
Use
TARGET_PAGE_MASKtwice instead ofTARGET_PAGE_SIZEonce. This is functionally identical, but will help a following patch.Reviewed-by Paolo Bonzini <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)include/exec/cpu-all.h +0
-0
include/exec/cpu-all.h extern const TargetPageBits target_page; · line 233
Quoted 9 lines
include/exec/cpu-all.h +2
-1@@ -226,7 +226,8 @@ extern const TargetPageBits target_page;#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS) -#define TARGET_PAGE_ALIGN (addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK) +#define TARGET_PAGE_ALIGN (addr) \ + (((addr) + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK)/* Using intptr_t ensures that qemu_*_page_mask is sign-extended even * when intptr_t is 32-bit and we are aligning a long long.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 7/20 exec: Cache TARGET_PAGE_MASK for TARGET_PAGE_BITS_VARY
In reply to Richard HendersonThis eliminates a set of runtime shifts. It turns out that we require TARGET_PAGE_MASK more often than TARGET_PAGE_SIZE, so redefine TARGET_PAGE_SIZE based on TARGET_PAGE_MASK instead of the other way around.
--- include/exec/cpu-all.h | 8 ++++++-- exec-vary.c | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)
include/exec/cpu-all.h +6 -2
@@ -213,19 +213,23 @@ static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t valtypedef struct {bool decided;int bits; +target_long mask; }TargetPageBits ;extern const TargetPageBits target_page;# ifdef CONFIG_DEBUG_TCG # define TARGET_PAGE_BITS (assert(target_page.decided), target_page.bits) +# define TARGET_PAGE_MASK (assert(target_page.decided), target_page.mask)# else # define TARGET_PAGE_BITS target_page.bits +# define TARGET_PAGE_MASK target_page.mask# endif +# define TARGET_PAGE_SIZE ((int)-TARGET_PAGE_MASK)#else #define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS +#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS) +#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS)#endif -#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS) -#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS)#define TARGET_PAGE_ALIGN (addr) \ (((addr) + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK)
exec-vary.c +1 -0
@@ -83,5 +83,6 @@ void finalize_target_page_bits(void) init_target_page.bits = TARGET_PAGE_BITS_MIN; } init_target_page.decided = true; + init_target_page.mask = (target_long)-1 << init_target_page.bits;#endif }
Signature · 1 line
2.17.1
Re: [PATCH v3 07/20] exec: Cache TARGET_PAGE_MASK for TARGET_PAGE_BITS_VARY
Quoted 48 lines · Richard Henderson
This eliminates a set of runtime shifts. It turns out that we require
TARGET_PAGE_MASKmore often thanTARGET_PAGE_SIZE, so redefineTARGET_PAGE_SIZEbased onTARGET_PAGE_MASKinstead of the other way around.Reviewed-by Paolo Bonzini <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 8 ++++++-- exec-vary.c | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)include/exec/cpu-all.h +6
-2@@ -213,19 +213,23 @@ static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t valtypedef struct {bool decided;int bits; +target_long mask; }TargetPageBits ;extern const TargetPageBits target_page;# ifdef CONFIG_DEBUG_TCG # define TARGET_PAGE_BITS (assert(target_page.decided), target_page.bits) +# define TARGET_PAGE_MASK (assert(target_page.decided), target_page.mask)# else # define TARGET_PAGE_BITS target_page.bits +# define TARGET_PAGE_MASK target_page.mask# endif +# define TARGET_PAGE_SIZE ((int)-TARGET_PAGE_MASK)#else #define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS +#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS) +#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS)#endif -#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS) -#define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS)#define TARGET_PAGE_ALIGN (addr) \ (((addr) + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK)exec-vary.c +0
-0
exec-vary.c void finalize_target_page_bits(void) · line 88
Quoted 6 lines
exec-vary.c +1
-0@@ -83,5 +83,6 @@ void finalize_target_page_bits(void) init_target_page.bits = TARGET_PAGE_BITS_MIN; } init_target_page.decided = true; + init_target_page.mask = (target_long)-1 << init_target_page.bits;#endif }
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 8/20 cputlb: Disable __always_inline__ without optimization
In reply to Richard HendersonThis forced inlining can result in missing symbols, which makes a debugging build harder to follow.
--- include/qemu/compiler.h | 11 +++++++++++ accel/tcg/cputlb.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-)
include/qemu/compiler.h +11 -0
@@ -170,6 +170,17 @@# define QEMU_NONSTRING #endif +/* +* Forced inlining may be desired to encourage constant propagation +* of function parameters. However, it can also make debugging harder, +* so disable it for a non-optimizing build. +*/ +#if defined(__OPTIMIZE__) &&__has_attribute (always_inline) +#define QEMU_ALWAYS_INLINE __attribute__((always_inline)) +#else +#define QEMU_ALWAYS_INLINE +#endif +/* Implement C11 _Generic via GCC builtins. Example: * * QEMU_GENERIC(x, (float, sinf), (long double, sinl), sin) (x)
accel/tcg/cputlb.c +2 -2
@@ -1281,7 +1281,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,typedef uint64_t FullLoadHelper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr); -static inline uint64_t __attribute__((always_inline)) +static inline uint64_t QEMU_ALWAYS_INLINEload_helper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op,bool code_read,FullLoadHelper *full_load)
@@ -1530,7 +1530,7 @@ tcg_target_ulong helper_be_ldsl_mmu(CPUArchState *env, target_ulong addr,* Store Helpers */ -static inline void __attribute__((always_inline)) +static inline void QEMU_ALWAYS_INLINEstore_helper (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op) {
Signature · 1 line
2.17.1
Re: [PATCH v3 08/20] cputlb: Disable __always_inline__ without optimization
Quoted 48 lines · Richard Henderson
This forced inlining can result in missing symbols, which makes a debugging build harder to follow.
Reviewed-by David Hildenbrand <[email protected]>Reported-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/qemu/compiler.h | 11 +++++++++++ accel/tcg/cputlb.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-)include/qemu/compiler.h +11
-0@@ -170,6 +170,17 @@# define QEMU_NONSTRING #endif +/* +* Forced inlining may be desired to encourage constant propagation +* of function parameters. However, it can also make debugging harder, +* so disable it for a non-optimizing build. +*/ +#if defined(__OPTIMIZE__) &&__has_attribute (always_inline) +#define QEMU_ALWAYS_INLINE __attribute__((always_inline)) +#else +#define QEMU_ALWAYS_INLINE +#endif +/* Implement C11 _Generic via GCC builtins. Example: * * QEMU_GENERIC(x, (float, sinf), (long double, sinl), sin) (x) accel/tcg/cputlb.c +1
-1@@ -1281,7 +1281,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,typedef uint64_t FullLoadHelper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr); -static inline uint64_t __attribute__((always_inline)) +static inline uint64_t QEMU_ALWAYS_INLINEload_helper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op,bool code_read,FullLoadHelper *full_load)
accel/tcg/cputlb.c tcg_target_ulong helper_be_ldsl_mmu(CPUArchState *env, target_ulong addr, · line 1536
Quoted 8 lines
accel/tcg/cputlb.c +1
-1@@ -1530,7 +1530,7 @@ tcg_target_ulong helper_be_ldsl_mmu(CPUArchState *env, target_ulong addr,* Store Helpers */ -static inline void __attribute__((always_inline)) +static inline void QEMU_ALWAYS_INLINEstore_helper (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op) {
Re: [PATCH v3 08/20] cputlb: Disable __always_inline__ without optimization
In reply to Richard Hendersoninclude/qemu/compiler.h line 179
Quoted 7 lines · Richard Henderson
include/qemu/compiler.h +7
-0+/* +* Forced inlining may be desired to encourage constant propagation +* of function parameters. However, it can also make debugging harder, +* so disable it for a non-optimizing build. +*/ +#if defined(__OPTIMIZE__) &&__has_attribute (always_inline) +#define QEMU_ALWAYS_INLINE __attribute__((always_inline))
GCC doesn't have __has_attribute, does it? I think you can just assume that it exists and #ifdef __OPTIMIZE__.
Paolo
Quoted 2 lines
include/qemu/compiler.h +2
-0+#else +#define QEMU_ALWAYS_INLINE
Re: [PATCH v3 08/20] cputlb: Disable __always_inline__ without optimization
Quoted 10 lines · Paolo Bonzini
include/qemu/compiler.h line 179
Quoted 7 lines · Richard Henderson
include/qemu/compiler.h +7
-0+/* +* Forced inlining may be desired to encourage constant propagation +* of function parameters. However, it can also make debugging harder, +* so disable it for a non-optimizing build. +*/ +#if defined(__OPTIMIZE__) &&__has_attribute (always_inline) +#define QEMU_ALWAYS_INLINE __attribute__((always_inline))GCC doesn't have
__has_attribute, does it?
It does, since at least gcc 5. And now I realize that's only a reorganization of the support and not when it was introduced.
r~
Re: [PATCH v3 08/20] cputlb: Disable __always_inline__ without optimization
Quoted 12 lines · Richard Henderson
Quoted 10 lines · Paolo Bonzini
include/qemu/compiler.h line 179
Quoted 7 lines · Richard Henderson
include/qemu/compiler.h +7
-0+/* +* Forced inlining may be desired to encourage constant propagation +* of function parameters. However, it can also make debugging harder, +* so disable it for a non-optimizing build. +*/ +#if defined(__OPTIMIZE__) &&__has_attribute (always_inline) +#define QEMU_ALWAYS_INLINE __attribute__((always_inline))GCC doesn't have
__has_attribute, does it?
Quoted 2 lines
It does, since at least gcc 5. And now I realize that's only a reorganization of the support and not when it was introduced.
Hmm, still we support 4.8 and always_inline is much older than that. So I'm not sure it's useful to test it.
Paolo
Re: [PATCH v3 08/20] cputlb: Disable __always_inline__ without optimization
Quoted 2 lines · Paolo Bonzini
Hmm, still we support 4.8 and
always_inlineis much older than that. So I'm not sure it's useful to test it.
Fair enough.
r~
PATCH v3 9/20 cputlb: Replace switches in load/store_helper with callback
In reply to Richard HendersonAdd a function parameter to perform the actual load/store to ram. With optimization, this results in identical code.
--- accel/tcg/cputlb.c | 159 +++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 76 deletions(-)
accel/tcg/cputlb.c +83 -76
@@ -1280,11 +1280,38 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,typedef uint64_t FullLoadHelper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr); +typedef uint64_t LoadHelper (const void *); + +/* Wrap the unaligned load helpers to that they have a common signature. */ +static inline uint64_t wrap_ldub (const void *haddr) +{ +return ldub_p (haddr); +} + +static inline uint64_t wrap_lduw_be (const void *haddr) +{ +return lduw_be_p (haddr); +} + +static inline uint64_t wrap_lduw_le (const void *haddr) +{ +return lduw_le_p (haddr); +} + +static inline uint64_t wrap_ldul_be (const void *haddr) +{ +return (uint32_t )ldl_be_p (haddr); +} + +static inline uint64_t wrap_ldul_le (const void *haddr) +{ +return (uint32_t )ldl_le_p (haddr); +} static inline uint64_t QEMU_ALWAYS_INLINEload_helper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op,bool code_read, -FullLoadHelper *full_load) +FullLoadHelper *full_load,LoadHelper *direct) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);
@@ -1373,33 +1400,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend); -switch (op) { -case MO_UB : - res =ldub_p (haddr); -break ; -case MO_BEUW : - res =lduw_be_p (haddr); -break ; -case MO_LEUW : - res =lduw_le_p (haddr); -break ; -case MO_BEUL : - res = (uint32_t )ldl_be_p (haddr); -break ; -case MO_LEUL : - res = (uint32_t )ldl_le_p (haddr); -break ; -case MO_BEQ : - res =ldq_be_p (haddr); -break ; -case MO_LEQ : - res =ldq_le_p (haddr); -break ; -default : -g_assert_not_reached (); - } - -return res; +return direct (haddr); }/*
@@ -1415,7 +1416,8 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,static uint64_t full_ldub_mmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) { -return load_helper (env, addr, oi, retaddr,MO_UB , false, full_ldub_mmu); +return load_helper (env, addr, oi, retaddr,MO_UB , false, + full_ldub_mmu, wrap_ldub); } tcg_target_ulong helper_ret_ldub_mmu(CPUArchState *env, target_ulong addr,
@@ -1428,7 +1430,7 @@ static uint64_t full_le_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , false, - full_le_lduw_mmu); + full_le_lduw_mmu, wrap_lduw_le); } tcg_target_ulong helper_le_lduw_mmu(CPUArchState *env, target_ulong addr,
@@ -1441,7 +1443,7 @@ static uint64_t full_be_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , false, - full_be_lduw_mmu); + full_be_lduw_mmu, wrap_lduw_be); } tcg_target_ulong helper_be_lduw_mmu(CPUArchState *env, target_ulong addr,
@@ -1454,7 +1456,7 @@ static uint64_t full_le_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , false, - full_le_ldul_mmu); + full_le_ldul_mmu, wrap_ldul_le); } tcg_target_ulong helper_le_ldul_mmu(CPUArchState *env, target_ulong addr,
@@ -1467,7 +1469,7 @@ static uint64_t full_be_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , false, - full_be_ldul_mmu); + full_be_ldul_mmu, wrap_ldul_be); } tcg_target_ulong helper_be_ldul_mmu(CPUArchState *env, target_ulong addr,
@@ -1480,14 +1482,14 @@ uint64_t helper_le_ldq_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEQ , false, - helper_le_ldq_mmu); + helper_le_ldq_mmu, ldq_le_p); }uint64_t helper_be_ldq_mmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , false, - helper_be_ldq_mmu); + helper_be_ldq_mmu, ldq_be_p); }/*
@@ -1530,9 +1532,38 @@ tcg_target_ulong helper_be_ldsl_mmu(CPUArchState *env, target_ulong addr,* Store Helpers */ +typedef void StoreHelper (void *,uint64_t ); + +/* Wrap the unaligned store helpers to that they have a common signature. */ +static inline void wrap_stb (void *haddr,uint64_t val) +{ +stb_p (haddr, val); +} + +static inline void wrap_stw_be (void *haddr,uint64_t val) +{ +stw_be_p (haddr, val); +} + +static inline void wrap_stw_le (void *haddr,uint64_t val) +{ +stw_le_p (haddr, val); +} + +static inline void wrap_stl_be (void *haddr,uint64_t val) +{ +stl_be_p (haddr, val); +} + +static inline void wrap_stl_le (void *haddr,uint64_t val) +{ +stl_le_p (haddr, val); +} + static inline void QEMU_ALWAYS_INLINEstore_helper (CPUArchState *env,target_ulong addr,uint64_t val, -TCGMemOpIdx oi,uintptr_t retaddr,MemOp op) +TCGMemOpIdx oi,uintptr_t retaddr,MemOp op, +StoreHelper *direct) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);
@@ -1657,74 +1688,49 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend); -switch (op) { -case MO_UB : -stb_p (haddr, val); -break ; -case MO_BEUW : -stw_be_p (haddr, val); -break ; -case MO_LEUW : -stw_le_p (haddr, val); -break ; -case MO_BEUL : -stl_be_p (haddr, val); -break ; -case MO_LEUL : -stl_le_p (haddr, val); -break ; -case MO_BEQ : -stq_be_p (haddr, val); -break ; -case MO_LEQ : -stq_le_p (haddr, val); -break ; -default : -g_assert_not_reached (); -break ; - } +direct (haddr, val); }void helper_ret_stb_mmu (CPUArchState *env,target_ulong addr,uint8_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_UB ); +store_helper (env, addr, val, oi, retaddr,MO_UB , wrap_stb); }void helper_le_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUW ); +store_helper (env, addr, val, oi, retaddr,MO_LEUW , wrap_stw_le); }void helper_be_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUW ); +store_helper (env, addr, val, oi, retaddr,MO_BEUW , wrap_stw_be); }void helper_le_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUL ); +store_helper (env, addr, val, oi, retaddr,MO_LEUL , wrap_stl_le); }void helper_be_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUL ); +store_helper (env, addr, val, oi, retaddr,MO_BEUL , wrap_stl_be); }void helper_le_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEQ ); +store_helper (env, addr, val, oi, retaddr,MO_LEQ , stq_le_p); }void helper_be_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEQ ); +store_helper (env, addr, val, oi, retaddr,MO_BEQ , stq_be_p); }/* First set of helpers allows passing in of OI and RETADDR. This makes
@@ -1789,7 +1795,8 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val,static uint64_t full_ldub_cmmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) { -return load_helper (env, addr, oi, retaddr,MO_8 , true, full_ldub_cmmu); +return load_helper (env, addr, oi, retaddr,MO_8 , true, + full_ldub_cmmu, wrap_ldub); } uint8_t helper_ret_ldb_cmmu(CPUArchState *env, target_ulong addr,
@@ -1802,7 +1809,7 @@ static uint64_t full_le_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , true, - full_le_lduw_cmmu); + full_le_lduw_cmmu, wrap_lduw_le); } uint16_t helper_le_ldw_cmmu(CPUArchState *env, target_ulong addr,
@@ -1815,7 +1822,7 @@ static uint64_t full_be_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , true, - full_be_lduw_cmmu); + full_be_lduw_cmmu, wrap_lduw_be); } uint16_t helper_be_ldw_cmmu(CPUArchState *env, target_ulong addr,
@@ -1828,7 +1835,7 @@ static uint64_t full_le_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , true, - full_le_ldul_cmmu); + full_le_ldul_cmmu, wrap_ldul_le); } uint32_t helper_le_ldl_cmmu(CPUArchState *env, target_ulong addr,
@@ -1841,7 +1848,7 @@ static uint64_t full_be_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , true, - full_be_ldul_cmmu); + full_be_ldul_cmmu, wrap_ldul_be); } uint32_t helper_be_ldl_cmmu(CPUArchState *env, target_ulong addr,
@@ -1854,12 +1861,12 @@ uint64_t helper_le_ldq_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEQ , true, - helper_le_ldq_cmmu); + helper_le_ldq_cmmu, ldq_le_p); }uint64_t helper_be_ldq_cmmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , true, - helper_be_ldq_cmmu); + helper_be_ldq_cmmu, ldq_be_p); }
Signature · 1 line
2.17.1
Re: [PATCH v3 09/20] cputlb: Replace switches in load/store_helper with callback
Quoted 325 lines · Richard Henderson
Add a function parameter to perform the actual load/store to ram. With optimization, this results in identical code.
Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/cputlb.c | 159 +++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 76 deletions(-)accel/tcg/cputlb.c +81
-75@@ -1280,11 +1280,38 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,typedef uint64_t FullLoadHelper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr); +typedef uint64_t LoadHelper (const void *); + +/* Wrap the unaligned load helpers to that they have a common signature. */ +static inline uint64_t wrap_ldub (const void *haddr) +{ +return ldub_p (haddr); +} + +static inline uint64_t wrap_lduw_be (const void *haddr) +{ +return lduw_be_p (haddr); +} + +static inline uint64_t wrap_lduw_le (const void *haddr) +{ +return lduw_le_p (haddr); +} + +static inline uint64_t wrap_ldul_be (const void *haddr) +{ +return (uint32_t )ldl_be_p (haddr); +} + +static inline uint64_t wrap_ldul_le (const void *haddr) +{ +return (uint32_t )ldl_le_p (haddr); +} static inline uint64_t QEMU_ALWAYS_INLINEload_helper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op,bool code_read, -FullLoadHelper *full_load) +FullLoadHelper *full_load,LoadHelper *direct) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);@@ -1373,33 +1400,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend); -switch (op) { -case MO_UB : - res =ldub_p (haddr); -break ; -case MO_BEUW : - res =lduw_be_p (haddr); -break ; -case MO_LEUW : - res =lduw_le_p (haddr); -break ; -case MO_BEUL : - res = (uint32_t )ldl_be_p (haddr); -break ; -case MO_LEUL : - res = (uint32_t )ldl_le_p (haddr); -break ; -case MO_BEQ : - res =ldq_be_p (haddr); -break ; -case MO_LEQ : - res =ldq_le_p (haddr); -break ; -default : -g_assert_not_reached (); - } - -return res; +return direct (haddr); }/* @@ -1415,7 +1416,8 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,static uint64_t full_ldub_mmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) { -return load_helper (env, addr, oi, retaddr,MO_UB , false, full_ldub_mmu); +return load_helper (env, addr, oi, retaddr,MO_UB , false, + full_ldub_mmu, wrap_ldub); } tcg_target_ulong helper_ret_ldub_mmu(CPUArchState *env, target_ulong addr,@@ -1428,7 +1430,7 @@ static uint64_t full_le_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , false, - full_le_lduw_mmu); + full_le_lduw_mmu, wrap_lduw_le); } tcg_target_ulong helper_le_lduw_mmu(CPUArchState *env, target_ulong addr,@@ -1441,7 +1443,7 @@ static uint64_t full_be_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , false, - full_be_lduw_mmu); + full_be_lduw_mmu, wrap_lduw_be); } tcg_target_ulong helper_be_lduw_mmu(CPUArchState *env, target_ulong addr,@@ -1454,7 +1456,7 @@ static uint64_t full_le_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , false, - full_le_ldul_mmu); + full_le_ldul_mmu, wrap_ldul_le); } tcg_target_ulong helper_le_ldul_mmu(CPUArchState *env, target_ulong addr,@@ -1467,7 +1469,7 @@ static uint64_t full_be_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , false, - full_be_ldul_mmu); + full_be_ldul_mmu, wrap_ldul_be); } tcg_target_ulong helper_be_ldul_mmu(CPUArchState *env, target_ulong addr,@@ -1480,14 +1482,14 @@ uint64_t helper_le_ldq_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEQ , false, - helper_le_ldq_mmu); + helper_le_ldq_mmu, ldq_le_p); }uint64_t helper_be_ldq_mmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , false, - helper_be_ldq_mmu); + helper_be_ldq_mmu, ldq_be_p); }/* @@ -1530,9 +1532,38 @@ tcg_target_ulong helper_be_ldsl_mmu(CPUArchState *env, target_ulong addr,* Store Helpers */ +typedef void StoreHelper (void *,uint64_t ); + +/* Wrap the unaligned store helpers to that they have a common signature. */ +static inline void wrap_stb (void *haddr,uint64_t val) +{ +stb_p (haddr, val); +} + +static inline void wrap_stw_be (void *haddr,uint64_t val) +{ +stw_be_p (haddr, val); +} + +static inline void wrap_stw_le (void *haddr,uint64_t val) +{ +stw_le_p (haddr, val); +} + +static inline void wrap_stl_be (void *haddr,uint64_t val) +{ +stl_be_p (haddr, val); +} + +static inline void wrap_stl_le (void *haddr,uint64_t val) +{ +stl_le_p (haddr, val); +} + static inline void QEMU_ALWAYS_INLINEstore_helper (CPUArchState *env,target_ulong addr,uint64_t val, -TCGMemOpIdx oi,uintptr_t retaddr,MemOp op) +TCGMemOpIdx oi,uintptr_t retaddr,MemOp op, +StoreHelper *direct) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);@@ -1657,74 +1688,49 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend); -switch (op) { -case MO_UB : -stb_p (haddr, val); -break ; -case MO_BEUW : -stw_be_p (haddr, val); -break ; -case MO_LEUW : -stw_le_p (haddr, val); -break ; -case MO_BEUL : -stl_be_p (haddr, val); -break ; -case MO_LEUL : -stl_le_p (haddr, val); -break ; -case MO_BEQ : -stq_be_p (haddr, val); -break ; -case MO_LEQ : -stq_le_p (haddr, val); -break ; -default : -g_assert_not_reached (); -break ; - } +direct (haddr, val); }void helper_ret_stb_mmu (CPUArchState *env,target_ulong addr,uint8_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_UB ); +store_helper (env, addr, val, oi, retaddr,MO_UB , wrap_stb); }void helper_le_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUW ); +store_helper (env, addr, val, oi, retaddr,MO_LEUW , wrap_stw_le); }void helper_be_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUW ); +store_helper (env, addr, val, oi, retaddr,MO_BEUW , wrap_stw_be); }void helper_le_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUL ); +store_helper (env, addr, val, oi, retaddr,MO_LEUL , wrap_stl_le); }void helper_be_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUL ); +store_helper (env, addr, val, oi, retaddr,MO_BEUL , wrap_stl_be); }void helper_le_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEQ ); +store_helper (env, addr, val, oi, retaddr,MO_LEQ , stq_le_p); }void helper_be_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEQ ); +store_helper (env, addr, val, oi, retaddr,MO_BEQ , stq_be_p); }/* First set of helpers allows passing in of OI and RETADDR. This makes @@ -1789,7 +1795,8 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val,static uint64_t full_ldub_cmmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) { -return load_helper (env, addr, oi, retaddr,MO_8 , true, full_ldub_cmmu); +return load_helper (env, addr, oi, retaddr,MO_8 , true, + full_ldub_cmmu, wrap_ldub); } uint8_t helper_ret_ldb_cmmu(CPUArchState *env, target_ulong addr,@@ -1802,7 +1809,7 @@ static uint64_t full_le_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , true, - full_le_lduw_cmmu); + full_le_lduw_cmmu, wrap_lduw_le); } uint16_t helper_le_ldw_cmmu(CPUArchState *env, target_ulong addr,@@ -1815,7 +1822,7 @@ static uint64_t full_be_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , true, - full_be_lduw_cmmu); + full_be_lduw_cmmu, wrap_lduw_be); } uint16_t helper_be_ldw_cmmu(CPUArchState *env, target_ulong addr,@@ -1828,7 +1835,7 @@ static uint64_t full_le_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , true, - full_le_ldul_cmmu); + full_le_ldul_cmmu, wrap_ldul_le); } uint32_t helper_le_ldl_cmmu(CPUArchState *env, target_ulong addr,@@ -1841,7 +1848,7 @@ static uint64_t full_be_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , true, - full_be_ldul_cmmu); + full_be_ldul_cmmu, wrap_ldul_be); } uint32_t helper_be_ldl_cmmu(CPUArchState *env, target_ulong addr,@@ -1854,12 +1861,12 @@ uint64_t helper_le_ldq_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) { return load_helper(env, addr, oi, retaddr, MO_LEQ, true, - helper_le_ldq_cmmu);
accel/tcg/cputlb.c uint64_t helper_le_ldq_cmmu(CPUArchState *env, target_ulong addr, · line 1872
Quoted 10 lines
accel/tcg/cputlb.c +2
-1+ helper_le_ldq_cmmu, ldq_le_p); }uint64_t helper_be_ldq_cmmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , true, - helper_be_ldq_cmmu); + helper_be_ldq_cmmu, ldq_be_p); }
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v3 09/20] cputlb: Replace switches in load/store_helper with callback
In reply to Richard HendersonQuoted 27 lines · Richard Henderson
Add a function parameter to perform the actual load/store to ram. With optimization, this results in identical code.
Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/cputlb.c | 159 +++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 76 deletions(-)accel/tcg/cputlb.c +11
-0@@ -1280,11 +1280,38 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,typedef uint64_t FullLoadHelper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr); +typedef uint64_t LoadHelper (const void *); + +/* Wrap the unaligned load helpers to that they have a common signature. */ +static inline uint64_t wrap_ldub (const void *haddr) +{ +return ldub_p (haddr); +} + +static inline uint64_t wrap_lduw_be (const void *haddr) +{ +return lduw_be_p (haddr);
accel/tcg/cputlb.c static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, · line 1303
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+} + +static inline uint64_t wrap_lduw_le (const void *haddr) +{ +return lduw_le_p (haddr); +} + +static inline uint64_t wrap_ldul_be (const void *haddr) +{ +return (uint32_t )ldl_be_p (haddr);
Quoted 298 lines
accel/tcg/cputlb.c +62
-76+} + +static inline uint64_t wrap_ldul_le (const void *haddr) +{ +return (uint32_t )ldl_le_p (haddr); +} static inline uint64_t QEMU_ALWAYS_INLINEload_helper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op,bool code_read, -FullLoadHelper *full_load) +FullLoadHelper *full_load,LoadHelper *direct) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);@@ -1373,33 +1400,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend); -switch (op) { -case MO_UB : - res =ldub_p (haddr); -break ; -case MO_BEUW : - res =lduw_be_p (haddr); -break ; -case MO_LEUW : - res =lduw_le_p (haddr); -break ; -case MO_BEUL : - res = (uint32_t )ldl_be_p (haddr); -break ; -case MO_LEUL : - res = (uint32_t )ldl_le_p (haddr); -break ; -case MO_BEQ : - res =ldq_be_p (haddr); -break ; -case MO_LEQ : - res =ldq_le_p (haddr); -break ; -default : -g_assert_not_reached (); - } - -return res; +return direct (haddr); }/* @@ -1415,7 +1416,8 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,static uint64_t full_ldub_mmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) { -return load_helper (env, addr, oi, retaddr,MO_UB , false, full_ldub_mmu); +return load_helper (env, addr, oi, retaddr,MO_UB , false, + full_ldub_mmu, wrap_ldub); } tcg_target_ulong helper_ret_ldub_mmu(CPUArchState *env, target_ulong addr,@@ -1428,7 +1430,7 @@ static uint64_t full_le_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , false, - full_le_lduw_mmu); + full_le_lduw_mmu, wrap_lduw_le); } tcg_target_ulong helper_le_lduw_mmu(CPUArchState *env, target_ulong addr,@@ -1441,7 +1443,7 @@ static uint64_t full_be_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , false, - full_be_lduw_mmu); + full_be_lduw_mmu, wrap_lduw_be); } tcg_target_ulong helper_be_lduw_mmu(CPUArchState *env, target_ulong addr,@@ -1454,7 +1456,7 @@ static uint64_t full_le_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , false, - full_le_ldul_mmu); + full_le_ldul_mmu, wrap_ldul_le); } tcg_target_ulong helper_le_ldul_mmu(CPUArchState *env, target_ulong addr,@@ -1467,7 +1469,7 @@ static uint64_t full_be_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , false, - full_be_ldul_mmu); + full_be_ldul_mmu, wrap_ldul_be); } tcg_target_ulong helper_be_ldul_mmu(CPUArchState *env, target_ulong addr,@@ -1480,14 +1482,14 @@ uint64_t helper_le_ldq_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEQ , false, - helper_le_ldq_mmu); + helper_le_ldq_mmu, ldq_le_p); }uint64_t helper_be_ldq_mmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , false, - helper_be_ldq_mmu); + helper_be_ldq_mmu, ldq_be_p); }/* @@ -1530,9 +1532,38 @@ tcg_target_ulong helper_be_ldsl_mmu(CPUArchState *env, target_ulong addr,* Store Helpers */ +typedef void StoreHelper (void *,uint64_t ); + +/* Wrap the unaligned store helpers to that they have a common signature. */ +static inline void wrap_stb (void *haddr,uint64_t val) +{ +stb_p (haddr, val); +} + +static inline void wrap_stw_be (void *haddr,uint64_t val) +{ +stw_be_p (haddr, val); +} + +static inline void wrap_stw_le (void *haddr,uint64_t val) +{ +stw_le_p (haddr, val); +} + +static inline void wrap_stl_be (void *haddr,uint64_t val) +{ +stl_be_p (haddr, val); +} + +static inline void wrap_stl_le (void *haddr,uint64_t val) +{ +stl_le_p (haddr, val); +} + static inline void QEMU_ALWAYS_INLINEstore_helper (CPUArchState *env,target_ulong addr,uint64_t val, -TCGMemOpIdx oi,uintptr_t retaddr,MemOp op) +TCGMemOpIdx oi,uintptr_t retaddr,MemOp op, +StoreHelper *direct) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);@@ -1657,74 +1688,49 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend); -switch (op) { -case MO_UB : -stb_p (haddr, val); -break ; -case MO_BEUW : -stw_be_p (haddr, val); -break ; -case MO_LEUW : -stw_le_p (haddr, val); -break ; -case MO_BEUL : -stl_be_p (haddr, val); -break ; -case MO_LEUL : -stl_le_p (haddr, val); -break ; -case MO_BEQ : -stq_be_p (haddr, val); -break ; -case MO_LEQ : -stq_le_p (haddr, val); -break ; -default : -g_assert_not_reached (); -break ; - } +direct (haddr, val); }void helper_ret_stb_mmu (CPUArchState *env,target_ulong addr,uint8_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_UB ); +store_helper (env, addr, val, oi, retaddr,MO_UB , wrap_stb); }void helper_le_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUW ); +store_helper (env, addr, val, oi, retaddr,MO_LEUW , wrap_stw_le); }void helper_be_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUW ); +store_helper (env, addr, val, oi, retaddr,MO_BEUW , wrap_stw_be); }void helper_le_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUL ); +store_helper (env, addr, val, oi, retaddr,MO_LEUL , wrap_stl_le); }void helper_be_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUL ); +store_helper (env, addr, val, oi, retaddr,MO_BEUL , wrap_stl_be); }void helper_le_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEQ ); +store_helper (env, addr, val, oi, retaddr,MO_LEQ , stq_le_p); }void helper_be_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEQ ); +store_helper (env, addr, val, oi, retaddr,MO_BEQ , stq_be_p); }/* First set of helpers allows passing in of OI and RETADDR. This makes @@ -1789,7 +1795,8 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val,static uint64_t full_ldub_cmmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) { -return load_helper (env, addr, oi, retaddr,MO_8 , true, full_ldub_cmmu); +return load_helper (env, addr, oi, retaddr,MO_8 , true, + full_ldub_cmmu, wrap_ldub); } uint8_t helper_ret_ldb_cmmu(CPUArchState *env, target_ulong addr,@@ -1802,7 +1809,7 @@ static uint64_t full_le_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , true, - full_le_lduw_cmmu); + full_le_lduw_cmmu, wrap_lduw_le); } uint16_t helper_le_ldw_cmmu(CPUArchState *env, target_ulong addr,@@ -1815,7 +1822,7 @@ static uint64_t full_be_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , true, - full_be_lduw_cmmu); + full_be_lduw_cmmu, wrap_lduw_be); } uint16_t helper_be_ldw_cmmu(CPUArchState *env, target_ulong addr,@@ -1828,7 +1835,7 @@ static uint64_t full_le_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , true, - full_le_ldul_cmmu); + full_le_ldul_cmmu, wrap_ldul_le); } uint32_t helper_le_ldl_cmmu(CPUArchState *env, target_ulong addr,@@ -1841,7 +1848,7 @@ static uint64_t full_be_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , true, - full_be_ldul_cmmu); + full_be_ldul_cmmu, wrap_ldul_be); } uint32_t helper_be_ldl_cmmu(CPUArchState *env, target_ulong addr,@@ -1854,12 +1861,12 @@ uint64_t helper_le_ldq_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEQ , true, - helper_le_ldq_cmmu); + helper_le_ldq_cmmu, ldq_le_p); }uint64_t helper_be_ldq_cmmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , true, - helper_be_ldq_cmmu); + helper_be_ldq_cmmu, ldq_be_p); }
Re: [PATCH v3 09/20] cputlb: Replace switches in load/store_helper with callback
In reply to Richard HendersonQuoted 15 lines · Richard Henderson
accel/tcg/cputlb.c +15
-0+/* Wrap the unaligned load helpers to that they have a common signature. */ +static inline uint64_t wrap_ldub (const void *haddr) +{ +return ldub_p (haddr); +} + +static inline uint64_t wrap_lduw_be (const void *haddr) +{ +return lduw_be_p (haddr); +} + +static inline uint64_t wrap_lduw_le (const void *haddr) +{ +return lduw_le_p (haddr); +}
accel/tcg/cputlb.c static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, · line 1309
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+ +static inline uint64_t wrap_ldul_be (const void *haddr) +{ +return (uint32_t )ldl_be_p (haddr); +} + +static inline uint64_t wrap_ldul_le (const void *haddr) +{ +return (uint32_t )ldl_le_p (haddr); +}
Any reason to have these five functions (plus five for stores) instead of a pair
static uint64_t ld_memop(const void *haddr, MemOp op) {
}
static uint64_t st_memop(void *haddr, MemOp op, uint64_t val) {
}
that includes the switches? Everything should be inlined just the same if you do
if (unlikely(tlb_addr & TLB_BSWAP)) {
st_memop(haddr, op ^ MO_BSWAP, val);
} else {
st_memop(haddr, op, val);
}and the like.
Paolo
Quoted 40 lines
static inline
uint64_tQEMU_ALWAYS_INLINEload_helper(CPUArchState *env,target_ulongaddr, TCGMemOpIdx oi,
uintptr_tretaddr, MemOp op, boolcode_read,accel/tcg/cputlb.c +2
-28- FullLoadHelper *full_load) + FullLoadHelper *full_load, LoadHelper *direct) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);@@ -1373,33 +1400,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend); -switch (op) { -case MO_UB : - res =ldub_p (haddr); -break ; -case MO_BEUW : - res =lduw_be_p (haddr); -break ; -case MO_LEUW : - res =lduw_le_p (haddr); -break ; -case MO_BEUL : - res = (uint32_t )ldl_be_p (haddr); -break ; -case MO_LEUL : - res = (uint32_t )ldl_le_p (haddr); -break ; -case MO_BEQ : - res =ldq_be_p (haddr); -break ; -case MO_LEQ : - res =ldq_le_p (haddr); -break ; -default : -g_assert_not_reached (); - } - -return res; +return direct (haddr);
Re: [PATCH v3 09/20] cputlb: Replace switches in load/store_helper with callback
Quoted 38 lines · Paolo Bonzini
Quoted 15 lines · Richard Henderson
accel/tcg/cputlb.c +15
-0+/* Wrap the unaligned load helpers to that they have a common signature. */ +static inline uint64_t wrap_ldub (const void *haddr) +{ +return ldub_p (haddr); +} + +static inline uint64_t wrap_lduw_be (const void *haddr) +{ +return lduw_be_p (haddr); +} + +static inline uint64_t wrap_lduw_le (const void *haddr) +{ +return lduw_le_p (haddr); +}accel/tcg/cputlb.c static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, · line 1309
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+ +static inline uint64_t wrap_ldul_be (const void *haddr) +{ +return (uint32_t )ldl_be_p (haddr); +} + +static inline uint64_t wrap_ldul_le (const void *haddr) +{ +return (uint32_t )ldl_le_p (haddr); +}Any reason to have these five functions (plus five for stores) instead of a pair
static
uint64_tld_memop(const void *haddr, MemOp op){
}static
uint64_tst_memop(void *haddr, MemOp op, uint64_t val){
}
Quoted 8 lines
that includes the switches? Everything should be inlined just the same if you do
if (unlikely(tlb_addr & TLB_BSWAP)) { st_memop(haddr, op ^ MO_BSWAP, val); } else { st_memop(haddr, op, val); }
I asked the same question on v2 and Richard explained that - for whatever reason - the compiler will not properly propagate the constant in the "op ^ MO_BSWAP" case.
Quoted 4 lines
and the like.
Paolo
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v3 09/20] cputlb: Replace switches in load/store_helper with callback
Quoted 48 lines · David Hildenbrand
Quoted 38 lines · Paolo Bonzini
Quoted 15 lines · Richard Henderson
accel/tcg/cputlb.c +15
-0+/* Wrap the unaligned load helpers to that they have a common signature. */ +static inline uint64_t wrap_ldub (const void *haddr) +{ +return ldub_p (haddr); +} + +static inline uint64_t wrap_lduw_be (const void *haddr) +{ +return lduw_be_p (haddr); +} + +static inline uint64_t wrap_lduw_le (const void *haddr) +{ +return lduw_le_p (haddr); +}accel/tcg/cputlb.c static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, · line 1309
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+ +static inline uint64_t wrap_ldul_be (const void *haddr) +{ +return (uint32_t )ldl_be_p (haddr); +} + +static inline uint64_t wrap_ldul_le (const void *haddr) +{ +return (uint32_t )ldl_le_p (haddr); +}Any reason to have these five functions (plus five for stores) instead of a pair
static
uint64_tld_memop(const void *haddr, MemOp op){
}static
uint64_tst_memop(void *haddr, MemOp op, uint64_t val){
}Quoted 8 lines
that includes the switches? Everything should be inlined just the same if you do
if (unlikely(tlb_addr & TLB_BSWAP)) { st_memop(haddr, op ^ MO_BSWAP, val); } else { st_memop(haddr, op, val); }
Quoted 3 lines
I asked the same question on v2 and Richard explained that - for whatever reason - the compiler will not properly propagate the constant in the "op ^
MO_BSWAP" case.
Even if ld_memop and st_memop are __always_inline__?
Paolo
Re: [PATCH v3 09/20] cputlb: Replace switches in load/store_helper with callback
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines · David Hildenbrand
Quoted 8 lines · Paolo Bonzini
that includes the switches? Everything should be inlined just the same if you do
if (unlikely(tlb_addr & TLB_BSWAP)) { st_memop(haddr, op ^ MO_BSWAP, val); } else { st_memop(haddr, op, val); }
Quoted 5 lines
Quoted 3 lines
I asked the same question on v2 and Richard explained that - for whatever reason - the compiler will not properly propagate the constant in the "op ^
MO_BSWAP" case.Even if
ld_memopandst_memopare__always_inline__?
I'm not sure I tried __always_inline__. I can, if you like.
r~
Re: [PATCH v3 09/20] cputlb: Replace switches in load/store_helper with callback
Quoted 12 lines · Richard Henderson
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines · David Hildenbrand
Quoted 8 lines · Paolo Bonzini
that includes the switches? Everything should be inlined just the same if you do
if (unlikely(tlb_addr & TLB_BSWAP)) { st_memop(haddr, op ^ MO_BSWAP, val); } else { st_memop(haddr, op, val); }
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I asked the same question on v2 and Richard explained that - for whatever reason - the compiler will not properly propagate the constant in the "op ^
MO_BSWAP" case.Even if
ld_memopandst_memopare__always_inline__?I'm not sure I tried
__always_inline__. I can, if you like.
FWIW, that works.
Since two of you have now asked about this, I'll change the patch.
r~
PATCH v3 10/20 cputlb: Introduce TLB_BSWAP
In reply to Richard HendersonHandle bswap on ram directly in load/store_helper. This fixes a bug with the previous implementation in that one cannot use the I/O path for RAM.
--- include/exec/cpu-all.h | 4 +- accel/tcg/cputlb.c | 108 +++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 53 deletions(-)
include/exec/cpu-all.h +3 -1
@@ -346,12 +346,14 @@ CPUArchState *cpu_copy(CPUArchState *env);#define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 3))/* Set if TLB entry contains a watchpoint. */ #define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS_MIN - 4)) +/* Set if TLB entry requires byte swap. */ +#define TLB_BSWAP (1 << (TARGET_PAGE_BITS_MIN - 5))/* Use this mask to check interception with an alignment mask * in a TCG backend. */ #define TLB_FLAGS_MASK \ - (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO | TLB_WATCHPOINT) + (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO | TLB_WATCHPOINT | TLB_BSWAP)/** * tlb_hit_page: return true if page aligned @addr is a hit against the
accel/tcg/cputlb.c +56 -52
292 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 10/20] cputlb: Introduce TLB_BSWAP
Quoted 341 lines · Richard Henderson
Handle bswap on ram directly in load/store_helper. This fixes a bug with the previous implementation in that one cannot use the I/O path for RAM.
Fixes a26fc6f5152b47f1Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 4 +- accel/tcg/cputlb.c | 108 +++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 53 deletions(-)include/exec/cpu-all.h +3
-1@@ -346,12 +346,14 @@ CPUArchState *cpu_copy(CPUArchState *env);#define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 3))/* Set if TLB entry contains a watchpoint. */ #define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS_MIN - 4)) +/* Set if TLB entry requires byte swap. */ +#define TLB_BSWAP (1 << (TARGET_PAGE_BITS_MIN - 5))/* Use this mask to check interception with an alignment mask * in a TCG backend. */ #define TLB_FLAGS_MASK \ - (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO | TLB_WATCHPOINT) + (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO | TLB_WATCHPOINT | TLB_BSWAP)/** * tlb_hit_page: return true if page aligned @addr is a hit against the accel/tcg/cputlb.c +54
-51@@ -737,8 +737,7 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, address |=TLB_INVALID_MASK ; }if (attrs.byte_swap) { -/* Force the access through the I/O slow path. */ - address |=TLB_MMIO ; + address |=TLB_BSWAP ; }if (!memory_region_is_ram (section->mr) && !memory_region_is_romd (section->mr)) {@@ -901,10 +900,6 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,bool locked = false;MemTxResult r; -if (iotlbentry->attrs.byte_swap) { - op ^=MO_BSWAP ; - } - section =iotlb_to_section (cpu, iotlbentry->addr, iotlbentry->attrs); mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr;@@ -947,10 +942,6 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry,bool locked = false;MemTxResult r; -if (iotlbentry->attrs.byte_swap) { - op ^=MO_BSWAP ; - } - section =iotlb_to_section (cpu, iotlbentry->addr, iotlbentry->attrs); mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr;@@ -1133,8 +1124,8 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, wp_access, retaddr); } -if (tlb_addr & (TLB_NOTDIRTY |TLB_MMIO )) { -/* I/O access */ +/* Reject I/O access, or other required slow-path. */ +if (tlb_addr & (TLB_NOTDIRTY |TLB_MMIO |TLB_BSWAP )) {return NULL ; }@@ -1311,7 +1302,8 @@ static inline uint64_t wrap_ldul_le(const void *haddr) static inline uint64_t QEMU_ALWAYS_INLINEload_helper (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op,bool code_read, -FullLoadHelper *full_load,LoadHelper *direct) +FullLoadHelper *full_load,LoadHelper *direct, +LoadHelper *direct_swap) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);@@ -1361,17 +1353,21 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,/* On watchpoint hit, this will longjmp out. */ cpu_check_watchpoint (env_cpu (env), addr, size, iotlbentry->attrs,BP_MEM_READ , retaddr); - -/* The backing page may or may not require I/O. */ - tlb_addr &= ~TLB_WATCHPOINT ; -if ((tlb_addr & ~TARGET_PAGE_MASK ) ==0 ) { - goto do_aligned_access; - } }/* Handle I/O access. */ -return io_readx (env, iotlbentry, mmu_idx, addr, - retaddr, access_type, op); +if (likely (tlb_addr &TLB_MMIO )) { +return io_readx (env, iotlbentry, mmu_idx, addr, + retaddr, access_type, + op ^ (tlb_addr &TLB_BSWAP ?MO_BSWAP :0 )); + } + + haddr = (void *)((uintptr_t )addr + entry->addend); + +if (unlikely (tlb_addr &TLB_BSWAP )) { +return direct_swap (haddr); + } +return direct (haddr); }/* Handle slow unaligned access (it spans two pages or IO). */ @@ -1398,7 +1394,6 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,return res &MAKE_64BIT_MASK (0 , size *8 ); } - do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend);return direct (haddr); }@@ -1417,7 +1412,7 @@ static uint64_t full_ldub_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_UB , false, - full_ldub_mmu, wrap_ldub); + full_ldub_mmu, wrap_ldub, wrap_ldub); } tcg_target_ulong helper_ret_ldub_mmu(CPUArchState *env, target_ulong addr,@@ -1430,7 +1425,7 @@ static uint64_t full_le_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , false, - full_le_lduw_mmu, wrap_lduw_le); + full_le_lduw_mmu, wrap_lduw_le, wrap_lduw_be); } tcg_target_ulong helper_le_lduw_mmu(CPUArchState *env, target_ulong addr,@@ -1443,7 +1438,7 @@ static uint64_t full_be_lduw_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , false, - full_be_lduw_mmu, wrap_lduw_be); + full_be_lduw_mmu, wrap_lduw_be, wrap_lduw_le); } tcg_target_ulong helper_be_lduw_mmu(CPUArchState *env, target_ulong addr,@@ -1456,7 +1451,7 @@ static uint64_t full_le_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , false, - full_le_ldul_mmu, wrap_ldul_le); + full_le_ldul_mmu, wrap_ldul_le, wrap_ldul_be); } tcg_target_ulong helper_le_ldul_mmu(CPUArchState *env, target_ulong addr,@@ -1469,7 +1464,7 @@ static uint64_t full_be_ldul_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , false, - full_be_ldul_mmu, wrap_ldul_be); + full_be_ldul_mmu, wrap_ldul_be, wrap_ldul_le); } tcg_target_ulong helper_be_ldul_mmu(CPUArchState *env, target_ulong addr,@@ -1482,14 +1477,14 @@ uint64_t helper_le_ldq_mmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEQ , false, - helper_le_ldq_mmu, ldq_le_p); + helper_le_ldq_mmu, ldq_le_p, ldq_be_p); }uint64_t helper_be_ldq_mmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , false, - helper_be_ldq_mmu, ldq_be_p); + helper_be_ldq_mmu, ldq_be_p, ldq_le_p); }/* @@ -1563,7 +1558,7 @@ static inline void wrap_stl_le(void *haddr, uint64_t val) static inline void QEMU_ALWAYS_INLINEstore_helper (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr,MemOp op, -StoreHelper *direct) +StoreHelper *direct,StoreHelper *direct_swap) {uintptr_t mmu_idx =get_mmuidx (oi);uintptr_t index =tlb_index (env, mmu_idx, addr);@@ -1608,16 +1603,22 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,/* On watchpoint hit, this will longjmp out. */ cpu_check_watchpoint (env_cpu (env), addr, size, iotlbentry->attrs,BP_MEM_WRITE , retaddr); - -/* The backing page may or may not require I/O. */ - tlb_addr &= ~TLB_WATCHPOINT ; -if ((tlb_addr & ~TARGET_PAGE_MASK ) ==0 ) { - goto do_aligned_access; - } }/* Handle I/O access. */ -io_writex (env, iotlbentry, mmu_idx, val, addr, retaddr, op); +if (likely (tlb_addr & (TLB_MMIO |TLB_NOTDIRTY ))) { +io_writex (env, iotlbentry, mmu_idx, val, addr, retaddr, + op ^ (tlb_addr &TLB_BSWAP ?MO_BSWAP :0 )); +return ; + } + + haddr = (void *)((uintptr_t )addr + entry->addend); + +if (unlikely (tlb_addr &TLB_BSWAP )) { +direct_swap (haddr, val); + }else { +direct (haddr, val); + }return ; }@@ -1686,7 +1687,6 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,return ; } - do_aligned_access: haddr = (void *)((uintptr_t )addr + entry->addend);direct (haddr, val); }@@ -1694,43 +1694,47 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,void helper_ret_stb_mmu (CPUArchState *env,target_ulong addr,uint8_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_UB , wrap_stb); +store_helper (env, addr, val, oi, retaddr,MO_UB , wrap_stb, wrap_stb); }void helper_le_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUW , wrap_stw_le); +store_helper (env, addr, val, oi, retaddr,MO_LEUW , + wrap_stw_le, wrap_stw_be); }void helper_be_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUW , wrap_stw_be); +store_helper (env, addr, val, oi, retaddr,MO_BEUW , + wrap_stw_be, wrap_stw_le); }void helper_le_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEUL , wrap_stl_le); +store_helper (env, addr, val, oi, retaddr,MO_LEUL , + wrap_stl_le, wrap_stl_be); }void helper_be_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEUL , wrap_stl_be); +store_helper (env, addr, val, oi, retaddr,MO_BEUL , + wrap_stl_be, wrap_stl_le); }void helper_le_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_LEQ , stq_le_p); +store_helper (env, addr, val, oi, retaddr,MO_LEQ , stq_le_p, stq_be_p); }void helper_be_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val,TCGMemOpIdx oi,uintptr_t retaddr) { -store_helper (env, addr, val, oi, retaddr,MO_BEQ , stq_be_p); +store_helper (env, addr, val, oi, retaddr,MO_BEQ , stq_be_p, stq_le_p); }/* First set of helpers allows passing in of OI and RETADDR. This makes @@ -1796,7 +1800,7 @@ static uint64_t full_ldub_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_8 , true, - full_ldub_cmmu, wrap_ldub); + full_ldub_cmmu, wrap_ldub, wrap_ldub); } uint8_t helper_ret_ldb_cmmu(CPUArchState *env, target_ulong addr,@@ -1809,7 +1813,7 @@ static uint64_t full_le_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUW , true, - full_le_lduw_cmmu, wrap_lduw_le); + full_le_lduw_cmmu, wrap_lduw_le, wrap_lduw_be); } uint16_t helper_le_ldw_cmmu(CPUArchState *env, target_ulong addr,@@ -1822,7 +1826,7 @@ static uint64_t full_be_lduw_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUW , true, - full_be_lduw_cmmu, wrap_lduw_be); + full_be_lduw_cmmu, wrap_lduw_be, wrap_lduw_le); } uint16_t helper_be_ldw_cmmu(CPUArchState *env, target_ulong addr,@@ -1835,7 +1839,7 @@ static uint64_t full_le_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_LEUL , true, - full_le_ldul_cmmu, wrap_ldul_le); + full_le_ldul_cmmu, wrap_ldul_le, wrap_ldul_be); } uint32_t helper_le_ldl_cmmu(CPUArchState *env, target_ulong addr,@@ -1848,7 +1852,7 @@ static uint64_t full_be_ldul_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEUL , true, - full_be_ldul_cmmu, wrap_ldul_be); + full_be_ldul_cmmu, wrap_ldul_be, wrap_ldul_le); } uint32_t helper_be_ldl_cmmu(CPUArchState *env, target_ulong addr,@@ -1861,12 +1865,12 @@ uint64_t helper_le_ldq_cmmu(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, uintptr_t retaddr) { return load_helper(env, addr, oi, retaddr, MO_LEQ, true, - helper_le_ldq_cmmu, ldq_le_p);
accel/tcg/cputlb.c uint64_t helper_le_ldq_cmmu(CPUArchState *env, target_ulong addr, · line 1876
Quoted 10 lines
accel/tcg/cputlb.c +2
-1+ helper_le_ldq_cmmu, ldq_le_p, ldq_be_p); }uint64_t helper_be_ldq_cmmu (CPUArchState *env,target_ulong addr,TCGMemOpIdx oi,uintptr_t retaddr) {return load_helper (env, addr, oi, retaddr,MO_BEQ , true, - helper_be_ldq_cmmu, ldq_be_p); + helper_be_ldq_cmmu, ldq_be_p, ldq_le_p); }
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 11/20 exec: Adjust notdirty tracing
In reply to Richard HendersonThe memory_region_tb_read tracepoint is unreachable, since notdirty is supposed to apply only to writes. The memory_region_tb_write tracepoint is mis-named, because notdirty is not only used for TB invalidation. It is also used for e.g. VGA RAM updates and migration.
Replace memory_region_tb_write with memory_notdirty_write_access, and place it in memory_notdirty_write_prepare where it can catch all of the instances. Add memory_notdirty_set_dirty to log when we no longer intercept writes to a page.
--- exec.c | 3 +++ memory.c | 4 ---- trace-events | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-)
exec.c +3 -0
@@ -2721,6 +2721,8 @@ void memory_notdirty_write_prepare(NotDirtyInfo *ndi, ndi->size = size; ndi->pages =NULL ; +trace_memory_notdirty_write_access (mem_vaddr, ram_addr, size); +assert (tcg_enabled ());if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) { ndi->pages =page_collection_lock (ram_addr, ram_addr + size);
@@ -2745,6 +2747,7 @@ void memory_notdirty_write_complete(NotDirtyInfo *ndi)/* we remove the notdirty callback only if the code has been flushed */ if (!cpu_physical_memory_is_clean (ndi->ram_addr)) { +trace_memory_notdirty_set_dirty (ndi->mem_vaddr);tlb_set_dirty (ndi->cpu, ndi->mem_vaddr); } }
memory.c +0 -4
@@ -438,7 +438,6 @@ static MemTxResult memory_region_read_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_read (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);
@@ -465,7 +464,6 @@ static MemTxResult memory_region_read_with_attrs_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_read (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);
@@ -490,7 +488,6 @@ static MemTxResult memory_region_write_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_write (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
@@ -515,7 +512,6 @@ static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_write (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
trace-events +2 -2
@@ -52,14 +52,14 @@ dma_map_wait(void *dbs) "dbs=%p" find_ram_offset(uint64_t size, uint64_t offset) "size: 0x%" PRIx64 " @ 0x%" PRIx64 find_ram_offset_loop(uint64_t size, uint64_t candidate, uint64_t offset, uint64_t next, uint64_t mingap) "trying size: 0x%" PRIx64 " @ 0x%" PRIx64 ", offset: 0x%" PRIx64" next: 0x%" PRIx64 " mingap: 0x%" PRIx64 ram_block_discard_range(const char *rbname, void *hva, size_t length, bool need_madvise, bool need_fallocate, int ret) "%s@%p + 0x%zx: madvise: %d fallocate: %d ret: %d" +memory_notdirty_write_access(uint64_t vaddr, uint64_t ram_addr, unsigned size) "0x%" PRIx64 " ram_addr 0x%" PRIx64 " size %u" +memory_notdirty_set_dirty(uint64_t vaddr) "0x%" PRIx64 # memory.c memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" -memory_region_tb_read(int cpu_index, uint64_t addr, uint64_t value, unsigned size) "cpu %d addr 0x%"PRIx64" value 0x%"PRIx64" size %u" -memory_region_tb_write(int cpu_index, uint64_t addr, uint64_t value, unsigned size) "cpu %d addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" flatview_new(void *view, void *root) "%p (root %p)"
Signature · 1 line
2.17.1
Re: [PATCH v3 11/20] exec: Adjust notdirty tracing
Quoted 87 lines · Richard Henderson
The
memory_region_tb_readtracepoint is unreachable, since notdirty is supposed to apply only to writes. Thememory_region_tb_writetracepoint is mis-named, because notdirty is not only used for TB invalidation. It is also used for e.g. VGA RAM updates and migration.Replace
memory_region_tb_writewithmemory_notdirty_write_access, and place it inmemory_notdirty_write_preparewhere it can catch all of the instances. Addmemory_notdirty_set_dirtyto log when we no longer intercept writes to a page.Reviewed-by David Hildenbrand <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- exec.c | 3 +++ memory.c | 4 ---- trace-events | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-)exec.c +3
-0@@ -2721,6 +2721,8 @@ void memory_notdirty_write_prepare(NotDirtyInfo *ndi, ndi->size = size; ndi->pages =NULL ; +trace_memory_notdirty_write_access (mem_vaddr, ram_addr, size); +assert (tcg_enabled ());if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) { ndi->pages =page_collection_lock (ram_addr, ram_addr + size);@@ -2745,6 +2747,7 @@ void memory_notdirty_write_complete(NotDirtyInfo *ndi)/* we remove the notdirty callback only if the code has been flushed */ if (!cpu_physical_memory_is_clean (ndi->ram_addr)) { +trace_memory_notdirty_set_dirty (ndi->mem_vaddr);tlb_set_dirty (ndi->cpu, ndi->mem_vaddr); } }memory.c +0
-4@@ -438,7 +438,6 @@ static MemTxResult memory_region_read_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_read (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);@@ -465,7 +464,6 @@ static MemTxResult memory_region_read_with_attrs_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_read (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);@@ -490,7 +488,6 @@ static MemTxResult memory_region_write_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_write (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);@@ -515,7 +512,6 @@ static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr,/* Accesses to code which has previously been translated into a TB show * up in the MMIO path, as accesses to the io_mem_notdirty * MemoryRegion. */ -trace_memory_region_tb_write (get_cpu_index (), addr, tmp, size); }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);trace-events +2
-0@@ -52,14 +52,14 @@ dma_map_wait(void *dbs) "dbs=%p" find_ram_offset(uint64_t size, uint64_t offset) "size: 0x%" PRIx64 " @ 0x%" PRIx64 find_ram_offset_loop(uint64_t size, uint64_t candidate, uint64_t offset, uint64_t next, uint64_t mingap) "trying size: 0x%" PRIx64 " @ 0x%" PRIx64 ", offset: 0x%" PRIx64" next: 0x%" PRIx64 " mingap: 0x%" PRIx64 ram_block_discard_range(const char *rbname, void *hva, size_t length, bool need_madvise, bool need_fallocate, int ret) "%s@%p + 0x%zx: madvise: %d fallocate: %d ret: %d" +memory_notdirty_write_access(uint64_t vaddr, uint64_t ram_addr, unsigned size) "0x%" PRIx64 " ram_addr 0x%" PRIx64 " size %u" +memory_notdirty_set_dirty(uint64_t vaddr) "0x%" PRIx64
trace-events dma_map_wait(void *dbs) "dbs=%p" · line 65
Quoted 10 lines
trace-events +0
-2# memory.c memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" -memory_region_tb_read(int cpu_index, uint64_t addr, uint64_t value, unsigned size) "cpu %d addr 0x%"PRIx64" value 0x%"PRIx64" size %u" -memory_region_tb_write(int cpu_index, uint64_t addr, uint64_t value, unsigned size) "cpu %d addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" flatview_new(void *view, void *root) "%p (root %p)"
PATCH v3 12/20 cputlb: Move ROM handling from I/O path to TLB path
In reply to Richard HendersonIt does not require going through the whole I/O path in order to discard a write.
--- include/exec/cpu-all.h | 5 ++++- include/exec/cpu-common.h | 1 - accel/tcg/cputlb.c | 35 +++++++++++++++++++-------------- exec.c | 41 +-------------------------------------- 4 files changed, 25 insertions(+), 57 deletions(-)
include/exec/cpu-all.h +4 -1
@@ -348,12 +348,15 @@ CPUArchState *cpu_copy(CPUArchState *env);#define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS_MIN - 4))/* Set if TLB entry requires byte swap. */ #define TLB_BSWAP (1 << (TARGET_PAGE_BITS_MIN - 5)) +/* Set if TLB entry writes ignored. */ +#define TLB_ROM (1 << (TARGET_PAGE_BITS_MIN - 6))/* Use this mask to check interception with an alignment mask * in a TCG backend. */ #define TLB_FLAGS_MASK \ - (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO | TLB_WATCHPOINT | TLB_BSWAP) + (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO \ + | TLB_WATCHPOINT | TLB_BSWAP | TLB_ROM)/** * tlb_hit_page: return true if page aligned @addr is a hit against the
include/exec/cpu-common.h +0 -1
@@ -100,7 +100,6 @@ void qemu_flush_coalesced_mmio_buffer(void);void cpu_flush_icache_range (hwaddr start,hwaddr len); -extern struct MemoryRegion io_mem_rom;extern struct MemoryRegion io_mem_notdirty;typedef int (RAMBlockIterFunc )(RAMBlock *rb,void *opaque);
accel/tcg/cputlb.c +20 -15
@@ -577,7 +577,7 @@ static void tlb_reset_dirty_range_locked(CPUTLBEntry *tlb_entry, {uintptr_t addr = tlb_entry->addr_write; -if ((addr & (TLB_INVALID_MASK |TLB_MMIO |TLB_NOTDIRTY )) ==0 ) { +if ((addr & (TLB_INVALID_MASK |TLB_MMIO |TLB_ROM |TLB_NOTDIRTY )) ==0 ) { addr &=TARGET_PAGE_MASK ; addr += tlb_entry->addend;if ((addr - start) < length) {
@@ -745,7 +745,6 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, address |=TLB_MMIO ; addend =0 ; }else { -/* TLB_MMIO for rom/romd handled below */ addend = (uintptr_t )memory_region_get_ram_ptr (section->mr) + xlat; }
@@ -822,16 +821,17 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, tn.addr_write =-1 ;if (prot &PAGE_WRITE ) { -if ((memory_region_is_ram (section->mr) && section->readonly) - ||memory_region_is_romd (section->mr)) { -/* Write access calls the I/O callback. */ - tn.addr_write = address |TLB_MMIO ; - }else if (memory_region_is_ram (section->mr) - &&cpu_physical_memory_is_clean ( -memory_region_get_ram_addr (section->mr) + xlat)) { - tn.addr_write = address |TLB_NOTDIRTY ; - }else { - tn.addr_write = address; + tn.addr_write = address; +if (memory_region_is_romd (section->mr)) { +/* Use the MMIO path so that the device can switch states. */ + tn.addr_write |=TLB_MMIO ; + }else if (memory_region_is_ram (section->mr)) { +if (section->readonly) { + tn.addr_write |=TLB_ROM ; + }else if (cpu_physical_memory_is_clean ( +memory_region_get_ram_addr (section->mr) + xlat)) { + tn.addr_write |=TLB_NOTDIRTY ; + } }if (prot &PAGE_WRITE_INV ) { tn.addr_write |=TLB_INVALID_MASK ;
@@ -904,7 +904,7 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; cpu->mem_io_pc = retaddr; -if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu->can_do_io) { +if (mr != &io_mem_notdirty && !cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); }
@@ -945,7 +945,7 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry, section =iotlb_to_section (cpu, iotlbentry->addr, iotlbentry->attrs); mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; -if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu->can_do_io) { +if (mr != &io_mem_notdirty && !cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); } cpu->mem_io_vaddr = addr;
@@ -1125,7 +1125,7 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, }/* Reject I/O access, or other required slow-path. */ -if (tlb_addr & (TLB_NOTDIRTY |TLB_MMIO |TLB_BSWAP )) { +if (tlb_addr & (TLB_NOTDIRTY |TLB_MMIO |TLB_BSWAP |TLB_ROM )) {return NULL ; }
@@ -1612,6 +1612,11 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,return ; } +/* Ignore writes to ROM. */ +if (unlikely (tlb_addr &TLB_ROM )) { +return ; + } + haddr = (void *)((uintptr_t )addr + entry->addend);if (unlikely (tlb_addr &TLB_BSWAP )) {
exec.c +1 -40
77 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 12/20] cputlb: Move ROM handling from I/O path to TLB path
Quoted 16 lines · Richard Henderson
It does not require going through the whole I/O path in order to discard a write.
Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 5 ++++- include/exec/cpu-common.h | 1 - accel/tcg/cputlb.c | 35 +++++++++++++++++++-------------- exec.c | 41 +-------------------------------------- 4 files changed, 25 insertions(+), 57 deletions(-)include/exec/cpu-all.h +0
-0
include/exec/cpu-all.h CPUArchState *cpu_copy(CPUArchState *env); · line 352
Quoted 5 lines
include/exec/cpu-all.h +2
-0@@ -348,12 +348,15 @@ CPUArchState *cpu_copy(CPUArchState *env);#define TLB_WATCHPOINT (1 << (TARGET_PAGE_BITS_MIN - 4))/* Set if TLB entry requires byte swap. */ #define TLB_BSWAP (1 << (TARGET_PAGE_BITS_MIN - 5)) +/* Set if TLB entry writes ignored. */ +#define TLB_ROM (1 << (TARGET_PAGE_BITS_MIN - 6))
I was wondering if TLB_DISCARD_WRITE/TLB_IGNORE_WRITE/TLB_READONLY would make it clearer what's actually happening here.
E.g., it isn't used for memory_region_is_romd(section->mr) but only for memory_region_is_ram(section->mr) && section->readonly.
But anyhow, changes look fine to me
Quoted 199 lines
include/exec/cpu-all.h +2
-1/* Use this mask to check interception with an alignment mask * in a TCG backend. */ #define TLB_FLAGS_MASK \ - (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO | TLB_WATCHPOINT | TLB_BSWAP) + (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO \ + | TLB_WATCHPOINT | TLB_BSWAP | TLB_ROM)/** * tlb_hit_page: return true if page aligned @addr is a hit against the include/exec/cpu-common.h +0
-1@@ -100,7 +100,6 @@ void qemu_flush_coalesced_mmio_buffer(void);void cpu_flush_icache_range (hwaddr start,hwaddr len); -extern struct MemoryRegion io_mem_rom;extern struct MemoryRegion io_mem_notdirty;typedef int (RAMBlockIterFunc )(RAMBlock *rb,void *opaque);accel/tcg/cputlb.c +20
-15@@ -577,7 +577,7 @@ static void tlb_reset_dirty_range_locked(CPUTLBEntry *tlb_entry, {uintptr_t addr = tlb_entry->addr_write; -if ((addr & (TLB_INVALID_MASK |TLB_MMIO |TLB_NOTDIRTY )) ==0 ) { +if ((addr & (TLB_INVALID_MASK |TLB_MMIO |TLB_ROM |TLB_NOTDIRTY )) ==0 ) { addr &=TARGET_PAGE_MASK ; addr += tlb_entry->addend;if ((addr - start) < length) {@@ -745,7 +745,6 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, address |=TLB_MMIO ; addend =0 ; }else { -/* TLB_MMIO for rom/romd handled below */ addend = (uintptr_t )memory_region_get_ram_ptr (section->mr) + xlat; }@@ -822,16 +821,17 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, tn.addr_write =-1 ;if (prot &PAGE_WRITE ) { -if ((memory_region_is_ram (section->mr) && section->readonly) - ||memory_region_is_romd (section->mr)) { -/* Write access calls the I/O callback. */ - tn.addr_write = address |TLB_MMIO ; - }else if (memory_region_is_ram (section->mr) - &&cpu_physical_memory_is_clean ( -memory_region_get_ram_addr (section->mr) + xlat)) { - tn.addr_write = address |TLB_NOTDIRTY ; - }else { - tn.addr_write = address; + tn.addr_write = address; +if (memory_region_is_romd (section->mr)) { +/* Use the MMIO path so that the device can switch states. */ + tn.addr_write |=TLB_MMIO ; + }else if (memory_region_is_ram (section->mr)) { +if (section->readonly) { + tn.addr_write |=TLB_ROM ; + }else if (cpu_physical_memory_is_clean ( +memory_region_get_ram_addr (section->mr) + xlat)) { + tn.addr_write |=TLB_NOTDIRTY ; + } }if (prot &PAGE_WRITE_INV ) { tn.addr_write |=TLB_INVALID_MASK ;@@ -904,7 +904,7 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; cpu->mem_io_pc = retaddr; -if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu->can_do_io) { +if (mr != &io_mem_notdirty && !cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); }@@ -945,7 +945,7 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry, section =iotlb_to_section (cpu, iotlbentry->addr, iotlbentry->attrs); mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; -if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu->can_do_io) { +if (mr != &io_mem_notdirty && !cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); } cpu->mem_io_vaddr = addr;@@ -1125,7 +1125,7 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, }/* Reject I/O access, or other required slow-path. */ -if (tlb_addr & (TLB_NOTDIRTY |TLB_MMIO |TLB_BSWAP )) { +if (tlb_addr & (TLB_NOTDIRTY |TLB_MMIO |TLB_BSWAP |TLB_ROM )) {return NULL ; }@@ -1612,6 +1612,11 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,return ; } +/* Ignore writes to ROM. */ +if (unlikely (tlb_addr &TLB_ROM )) { +return ; + } + haddr = (void *)((uintptr_t )addr + entry->addend);if (unlikely (tlb_addr &TLB_BSWAP )) {exec.c +1
-40@@ -88,7 +88,7 @@ static MemoryRegion *system_io;AddressSpace address_space_io;AddressSpace address_space_memory; -MemoryRegion io_mem_rom, io_mem_notdirty; +MemoryRegion io_mem_notdirty;static MemoryRegion io_mem_unassigned;#endif @@ -158,7 +158,6 @@ typedef struct subpage_t {#define PHYS_SECTION_UNASSIGNED 0#define PHYS_SECTION_NOTDIRTY 1 -#define PHYS_SECTION_ROM 2static void io_mem_init (void );static void memory_map_init (void );@@ -1441,8 +1440,6 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, iotlb =memory_region_get_ram_addr (section->mr) + xlat;if (!section->readonly) { iotlb |=PHYS_SECTION_NOTDIRTY ; - }else { - iotlb |=PHYS_SECTION_ROM ; } }else {AddressSpaceDispatch *d;@@ -2968,38 +2965,6 @@ static uint16_t dummy_section(PhysPageMap *map, FlatView *fv, MemoryRegion *mr)return phys_section_add (map, §ion); } -static void readonly_mem_write (void *opaque,hwaddr addr, -uint64_t val,unsigned size) -{ -/* Ignore any write to ROM. */ -} - -static bool readonly_mem_accepts (void *opaque,hwaddr addr, -unsigned size,bool is_write, -MemTxAttrs attrs) -{ -return is_write; -} - -/* This will only be used for writes, because reads are special cased -* to directly access the underlying host ram. -*/ -static const MemoryRegionOps readonly_mem_ops = { - .write = readonly_mem_write, - .valid.accepts = readonly_mem_accepts, - .endianness =DEVICE_NATIVE_ENDIAN , - .valid = { - .min_access_size =1 , - .max_access_size =8 , - .unaligned = false, - }, - .impl = { - .min_access_size =1 , - .max_access_size =8 , - .unaligned = false, - }, -}; -MemoryRegionSection *iotlb_to_section (CPUState *cpu,hwaddr index,MemTxAttrs attrs) {@@ -3013,8 +2978,6 @@ MemoryRegionSection *iotlb_to_section(CPUState *cpu,static void io_mem_init (void ) { -memory_region_init_io (&io_mem_rom,NULL , &readonly_mem_ops, -NULL ,NULL ,UINT64_MAX );memory_region_init_io (&io_mem_unassigned,NULL , &unassigned_mem_ops,NULL ,NULL ,UINT64_MAX );@@ -3035,8 +2998,6 @@ AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv)assert (n ==PHYS_SECTION_UNASSIGNED ); n =dummy_section (&d->map, fv, &io_mem_notdirty);assert (n ==PHYS_SECTION_NOTDIRTY ); - n =dummy_section (&d->map, fv, &io_mem_rom); -assert (n ==PHYS_SECTION_ROM ); d->phys_map = (PhysPageEntry ) { .ptr =PHYS_MAP_NODE_NIL , .skip =1 };
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 13/20 cputlb: Move NOTDIRTY handling from I/O path to TLB path
In reply to Richard HendersonPages that we want to track for NOTDIRTY are RAM. We do not really need to go through the I/O path to handle them.
--- include/exec/cpu-common.h | 2 -- accel/tcg/cputlb.c | 26 +++++++++++++++++--- exec.c | 50 --------------------------------------- memory.c | 16 ------------- 4 files changed, 23 insertions(+), 71 deletions(-)
include/exec/cpu-common.h +0 -2
@@ -100,8 +100,6 @@ void qemu_flush_coalesced_mmio_buffer(void);void cpu_flush_icache_range (hwaddr start,hwaddr len); -extern struct MemoryRegion io_mem_notdirty; -typedef int (RAMBlockIterFunc )(RAMBlock *rb,void *opaque);int qemu_ram_foreach_block (RAMBlockIterFunc func,void *opaque);
accel/tcg/cputlb.c +23 -3
@@ -904,7 +904,7 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; cpu->mem_io_pc = retaddr; -if (mr != &io_mem_notdirty && !cpu->can_do_io) { +if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); }
@@ -945,7 +945,7 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry, section =iotlb_to_section (cpu, iotlbentry->addr, iotlbentry->attrs); mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; -if (mr != &io_mem_notdirty && !cpu->can_do_io) { +if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); } cpu->mem_io_vaddr = addr;
@@ -1606,7 +1606,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, }/* Handle I/O access. */ -if (likely (tlb_addr & (TLB_MMIO |TLB_NOTDIRTY ))) { +if (tlb_addr &TLB_MMIO ) {io_writex (env, iotlbentry, mmu_idx, val, addr, retaddr, op ^ (tlb_addr &TLB_BSWAP ?MO_BSWAP :0 ));return ;
@@ -1619,6 +1619,26 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, haddr = (void *)((uintptr_t )addr + entry->addend); +/* Handle clean RAM pages. */ +if (tlb_addr &TLB_NOTDIRTY ) { +NotDirtyInfo ndi; + +/* We require mem_io_pc in tb_invalidate_phys_page_range. */ +env_cpu (env)->mem_io_pc = retaddr; + +memory_notdirty_write_prepare (&ndi,env_cpu (env), addr, + addr + iotlbentry->addr, size); + +if (unlikely (tlb_addr &TLB_BSWAP )) { +direct_swap (haddr, val); + }else { +direct (haddr, val); + } + +memory_notdirty_write_complete (&ndi); +return ; + } +if (unlikely (tlb_addr &TLB_BSWAP )) {direct_swap (haddr, val); }else {
exec.c +0 -50
86 lines not on this page · raw message
memory.c +0 -16
@@ -434,10 +434,6 @@ static MemTxResult memory_region_read_accessor(MemoryRegion *mr, tmp = mr->ops->read (mr->opaque, addr, size);if (mr->subpage) {trace_memory_region_subpage_read (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);
@@ -460,10 +456,6 @@ static MemTxResult memory_region_read_with_attrs_accessor(MemoryRegion *mr, r = mr->ops->read_with_attrs (mr->opaque, addr, &tmp, size, attrs);if (mr->subpage) {trace_memory_region_subpage_read (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);
@@ -484,10 +476,6 @@ static MemTxResult memory_region_write_accessor(MemoryRegion *mr,if (mr->subpage) {trace_memory_region_subpage_write (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
@@ -508,10 +496,6 @@ static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr,if (mr->subpage) {trace_memory_region_subpage_write (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
Signature · 1 line
2.17.1
Re: [PATCH v3 13/20] cputlb: Move NOTDIRTY handling from I/O path to TLB path
Quoted 217 lines · Richard Henderson
Pages that we want to track for NOTDIRTY are RAM. We do not really need to go through the I/O path to handle them.
Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-common.h | 2 -- accel/tcg/cputlb.c | 26 +++++++++++++++++--- exec.c | 50 --------------------------------------- memory.c | 16 ------------- 4 files changed, 23 insertions(+), 71 deletions(-)include/exec/cpu-common.h +0
-2@@ -100,8 +100,6 @@ void qemu_flush_coalesced_mmio_buffer(void);void cpu_flush_icache_range (hwaddr start,hwaddr len); -extern struct MemoryRegion io_mem_notdirty; -typedef int (RAMBlockIterFunc )(RAMBlock *rb,void *opaque);int qemu_ram_foreach_block (RAMBlockIterFunc func,void *opaque);accel/tcg/cputlb.c +23
-3@@ -904,7 +904,7 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; cpu->mem_io_pc = retaddr; -if (mr != &io_mem_notdirty && !cpu->can_do_io) { +if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); }@@ -945,7 +945,7 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry, section =iotlb_to_section (cpu, iotlbentry->addr, iotlbentry->attrs); mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; -if (mr != &io_mem_notdirty && !cpu->can_do_io) { +if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); } cpu->mem_io_vaddr = addr;@@ -1606,7 +1606,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, }/* Handle I/O access. */ -if (likely (tlb_addr & (TLB_MMIO |TLB_NOTDIRTY ))) { +if (tlb_addr &TLB_MMIO ) {io_writex (env, iotlbentry, mmu_idx, val, addr, retaddr, op ^ (tlb_addr &TLB_BSWAP ?MO_BSWAP :0 ));return ;@@ -1619,6 +1619,26 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, haddr = (void *)((uintptr_t )addr + entry->addend); +/* Handle clean RAM pages. */ +if (tlb_addr &TLB_NOTDIRTY ) { +NotDirtyInfo ndi; + +/* We require mem_io_pc in tb_invalidate_phys_page_range. */ +env_cpu (env)->mem_io_pc = retaddr; + +memory_notdirty_write_prepare (&ndi,env_cpu (env), addr, + addr + iotlbentry->addr, size); + +if (unlikely (tlb_addr &TLB_BSWAP )) { +direct_swap (haddr, val); + }else { +direct (haddr, val); + } + +memory_notdirty_write_complete (&ndi); +return ; + } +if (unlikely (tlb_addr &TLB_BSWAP )) {direct_swap (haddr, val); }else {exec.c +0
-50@@ -88,7 +88,6 @@ static MemoryRegion *system_io;AddressSpace address_space_io;AddressSpace address_space_memory; -MemoryRegion io_mem_notdirty;static MemoryRegion io_mem_unassigned;#endif @@ -157,7 +156,6 @@ typedef struct subpage_t { } subpage_t;#define PHYS_SECTION_UNASSIGNED 0 -#define PHYS_SECTION_NOTDIRTY 1static void io_mem_init (void );static void memory_map_init (void );@@ -1438,9 +1436,6 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu,if (memory_region_is_ram (section->mr)) {/* Normal RAM. */ iotlb =memory_region_get_ram_addr (section->mr) + xlat; -if (!section->readonly) { - iotlb |=PHYS_SECTION_NOTDIRTY ; - } }else {AddressSpaceDispatch *d;@@ -2749,42 +2744,6 @@ void memory_notdirty_write_complete(NotDirtyInfo *ndi) } } -/* Called within RCU critical section. */ -static void notdirty_mem_write (void *opaque,hwaddr ram_addr, -uint64_t val,unsigned size) -{ -NotDirtyInfo ndi; - -memory_notdirty_write_prepare (&ndi, current_cpu, current_cpu->mem_io_vaddr, - ram_addr, size); - -stn_p (qemu_map_ram_ptr (NULL , ram_addr), size, val); -memory_notdirty_write_complete (&ndi); -} - -static bool notdirty_mem_accepts (void *opaque,hwaddr addr, -unsigned size,bool is_write, -MemTxAttrs attrs) -{ -return is_write; -} - -static const MemoryRegionOps notdirty_mem_ops = { - .write = notdirty_mem_write, - .valid.accepts = notdirty_mem_accepts, - .endianness =DEVICE_NATIVE_ENDIAN , - .valid = { - .min_access_size =1 , - .max_access_size =8 , - .unaligned = false, - }, - .impl = { - .min_access_size =1 , - .max_access_size =8 , - .unaligned = false, - }, -}; -/* Generate a debug exception if a watchpoint has been hit. */ void cpu_check_watchpoint (CPUState *cpu,vaddr addr,vaddr len,MemTxAttrs attrs,int flags,uintptr_t ra)@@ -2980,13 +2939,6 @@ static void io_mem_init(void) {memory_region_init_io (&io_mem_unassigned,NULL , &unassigned_mem_ops,NULL ,NULL ,UINT64_MAX ); - -/* io_mem_notdirty calls tb_invalidate_phys_page_fast, -* which can be called without the iothread mutex. -*/ -memory_region_init_io (&io_mem_notdirty,NULL , ¬dirty_mem_ops,NULL , -NULL ,UINT64_MAX ); -memory_region_clear_global_locking (&io_mem_notdirty); }AddressSpaceDispatch *address_space_dispatch_new (FlatView *fv)@@ -2996,8 +2948,6 @@ AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv) n =dummy_section (&d->map, fv, &io_mem_unassigned);assert (n ==PHYS_SECTION_UNASSIGNED ); - n =dummy_section (&d->map, fv, &io_mem_notdirty); -assert (n ==PHYS_SECTION_NOTDIRTY ); d->phys_map = (PhysPageEntry ) { .ptr =PHYS_MAP_NODE_NIL , .skip =1 };memory.c +0
-12@@ -434,10 +434,6 @@ static MemTxResult memory_region_read_accessor(MemoryRegion *mr, tmp = mr->ops->read (mr->opaque, addr, size);if (mr->subpage) {trace_memory_region_subpage_read (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);@@ -460,10 +456,6 @@ static MemTxResult memory_region_read_with_attrs_accessor(MemoryRegion *mr, r = mr->ops->read_with_attrs (mr->opaque, addr, &tmp, size, attrs);if (mr->subpage) {trace_memory_region_subpage_read (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);@@ -484,10 +476,6 @@ static MemTxResult memory_region_write_accessor(MemoryRegion *mr,if (mr->subpage) {trace_memory_region_subpage_write (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
memory.c static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr, · line 501
Quoted 10 lines
memory.c +0
-4@@ -508,10 +496,6 @@ static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr,if (mr->subpage) {trace_memory_region_subpage_write (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
Complicated stuff but I think this is fine
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v3 13/20] cputlb: Move NOTDIRTY handling from I/O path to TLB path
In reply to Richard HendersonQuoted 217 lines · Richard Henderson
Pages that we want to track for NOTDIRTY are RAM. We do not really need to go through the I/O path to handle them.
Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-common.h | 2 -- accel/tcg/cputlb.c | 26 +++++++++++++++++--- exec.c | 50 --------------------------------------- memory.c | 16 ------------- 4 files changed, 23 insertions(+), 71 deletions(-)include/exec/cpu-common.h +0
-2@@ -100,8 +100,6 @@ void qemu_flush_coalesced_mmio_buffer(void);void cpu_flush_icache_range (hwaddr start,hwaddr len); -extern struct MemoryRegion io_mem_notdirty; -typedef int (RAMBlockIterFunc )(RAMBlock *rb,void *opaque);int qemu_ram_foreach_block (RAMBlockIterFunc func,void *opaque);accel/tcg/cputlb.c +23
-3@@ -904,7 +904,7 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; cpu->mem_io_pc = retaddr; -if (mr != &io_mem_notdirty && !cpu->can_do_io) { +if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); }@@ -945,7 +945,7 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry, section =iotlb_to_section (cpu, iotlbentry->addr, iotlbentry->attrs); mr = section->mr; mr_offset = (iotlbentry->addr &TARGET_PAGE_MASK ) + addr; -if (mr != &io_mem_notdirty && !cpu->can_do_io) { +if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); } cpu->mem_io_vaddr = addr;@@ -1606,7 +1606,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, }/* Handle I/O access. */ -if (likely (tlb_addr & (TLB_MMIO |TLB_NOTDIRTY ))) { +if (tlb_addr &TLB_MMIO ) {io_writex (env, iotlbentry, mmu_idx, val, addr, retaddr, op ^ (tlb_addr &TLB_BSWAP ?MO_BSWAP :0 ));return ;@@ -1619,6 +1619,26 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, haddr = (void *)((uintptr_t )addr + entry->addend); +/* Handle clean RAM pages. */ +if (tlb_addr &TLB_NOTDIRTY ) { +NotDirtyInfo ndi; + +/* We require mem_io_pc in tb_invalidate_phys_page_range. */ +env_cpu (env)->mem_io_pc = retaddr; + +memory_notdirty_write_prepare (&ndi,env_cpu (env), addr, + addr + iotlbentry->addr, size); + +if (unlikely (tlb_addr &TLB_BSWAP )) { +direct_swap (haddr, val); + }else { +direct (haddr, val); + } + +memory_notdirty_write_complete (&ndi); +return ; + } +if (unlikely (tlb_addr &TLB_BSWAP )) {direct_swap (haddr, val); }else {exec.c +0
-50@@ -88,7 +88,6 @@ static MemoryRegion *system_io;AddressSpace address_space_io;AddressSpace address_space_memory; -MemoryRegion io_mem_notdirty;static MemoryRegion io_mem_unassigned;#endif @@ -157,7 +156,6 @@ typedef struct subpage_t { } subpage_t;#define PHYS_SECTION_UNASSIGNED 0 -#define PHYS_SECTION_NOTDIRTY 1static void io_mem_init (void );static void memory_map_init (void );@@ -1438,9 +1436,6 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu,if (memory_region_is_ram (section->mr)) {/* Normal RAM. */ iotlb =memory_region_get_ram_addr (section->mr) + xlat; -if (!section->readonly) { - iotlb |=PHYS_SECTION_NOTDIRTY ; - } }else {AddressSpaceDispatch *d;@@ -2749,42 +2744,6 @@ void memory_notdirty_write_complete(NotDirtyInfo *ndi) } } -/* Called within RCU critical section. */ -static void notdirty_mem_write (void *opaque,hwaddr ram_addr, -uint64_t val,unsigned size) -{ -NotDirtyInfo ndi; - -memory_notdirty_write_prepare (&ndi, current_cpu, current_cpu->mem_io_vaddr, - ram_addr, size); - -stn_p (qemu_map_ram_ptr (NULL , ram_addr), size, val); -memory_notdirty_write_complete (&ndi); -} - -static bool notdirty_mem_accepts (void *opaque,hwaddr addr, -unsigned size,bool is_write, -MemTxAttrs attrs) -{ -return is_write; -} - -static const MemoryRegionOps notdirty_mem_ops = { - .write = notdirty_mem_write, - .valid.accepts = notdirty_mem_accepts, - .endianness =DEVICE_NATIVE_ENDIAN , - .valid = { - .min_access_size =1 , - .max_access_size =8 , - .unaligned = false, - }, - .impl = { - .min_access_size =1 , - .max_access_size =8 , - .unaligned = false, - }, -}; -/* Generate a debug exception if a watchpoint has been hit. */ void cpu_check_watchpoint (CPUState *cpu,vaddr addr,vaddr len,MemTxAttrs attrs,int flags,uintptr_t ra)@@ -2980,13 +2939,6 @@ static void io_mem_init(void) {memory_region_init_io (&io_mem_unassigned,NULL , &unassigned_mem_ops,NULL ,NULL ,UINT64_MAX ); - -/* io_mem_notdirty calls tb_invalidate_phys_page_fast, -* which can be called without the iothread mutex. -*/ -memory_region_init_io (&io_mem_notdirty,NULL , ¬dirty_mem_ops,NULL , -NULL ,UINT64_MAX ); -memory_region_clear_global_locking (&io_mem_notdirty); }AddressSpaceDispatch *address_space_dispatch_new (FlatView *fv)@@ -2996,8 +2948,6 @@ AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv) n =dummy_section (&d->map, fv, &io_mem_unassigned);assert (n ==PHYS_SECTION_UNASSIGNED ); - n =dummy_section (&d->map, fv, &io_mem_notdirty); -assert (n ==PHYS_SECTION_NOTDIRTY ); d->phys_map = (PhysPageEntry ) { .ptr =PHYS_MAP_NODE_NIL , .skip =1 };memory.c +0
-12@@ -434,10 +434,6 @@ static MemTxResult memory_region_read_accessor(MemoryRegion *mr, tmp = mr->ops->read (mr->opaque, addr, size);if (mr->subpage) {trace_memory_region_subpage_read (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);@@ -460,10 +456,6 @@ static MemTxResult memory_region_read_with_attrs_accessor(MemoryRegion *mr, r = mr->ops->read_with_attrs (mr->opaque, addr, &tmp, size, attrs);if (mr->subpage) {trace_memory_region_subpage_read (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_read (get_cpu_index (), mr, abs_addr, tmp, size);@@ -484,10 +476,6 @@ static MemTxResult memory_region_write_accessor(MemoryRegion *mr,if (mr->subpage) {trace_memory_region_subpage_write (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
memory.c static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr, · line 501
Quoted 10 lines
memory.c +0
-4@@ -508,10 +496,6 @@ static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr,if (mr->subpage) {trace_memory_region_subpage_write (get_cpu_index (), mr, addr, tmp, size); - }else if (mr == &io_mem_notdirty) { -/* Accesses to code which has previously been translated into a TB show -* up in the MMIO path, as accesses to the io_mem_notdirty -* MemoryRegion. */ }else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED ) {hwaddr abs_addr =memory_region_to_absolute_addr (mr, addr);trace_memory_region_ops_write (get_cpu_index (), mr, abs_addr, tmp, size);
Very nice!
PATCH v3 14/20 cputlb: Partially inline memory_region_section_get_iotlb
In reply to Richard HendersonThere is only one caller, tlb_set_page_with_attrs. We cannot inline the entire function because the AddressSpaceDispatch structure is private to exec.c, and cannot easily be moved to include/exec/memory-internal.h.
Compute is_ram and is_romd once within tlb_set_page_with_attrs. Fold the number of tests against these predicates. Compute cpu_physical_memory_is_clean outside of the tlb lock region.
--- include/exec/exec-all.h | 6 +--- accel/tcg/cputlb.c | 68 ++++++++++++++++++++++++++--------------- exec.c | 22 ++----------- 3 files changed, 47 insertions(+), 49 deletions(-)
include/exec/exec-all.h +1 -5
@@ -509,11 +509,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr, hwaddr *xlat, hwaddr *plen, MemTxAttrs attrs, int *prot);hwaddr memory_region_section_get_iotlb (CPUState *cpu, -MemoryRegionSection *section, -target_ulong vaddr, -hwaddr paddr,hwaddr xlat, -int prot, -target_ulong *address); +MemoryRegionSection *section);#endif /* vl.c */
accel/tcg/cputlb.c +43 -25
107 lines not on this page · raw message
exec.c +3 -19
@@ -1425,26 +1425,10 @@ bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap,/* Called from RCU critical section */ hwaddr memory_region_section_get_iotlb (CPUState *cpu, -MemoryRegionSection *section, -target_ulong vaddr, -hwaddr paddr,hwaddr xlat, -int prot, -target_ulong *address) +MemoryRegionSection *section) { -hwaddr iotlb; - -if (memory_region_is_ram (section->mr)) { -/* Normal RAM. */ - iotlb =memory_region_get_ram_addr (section->mr) + xlat; - }else { -AddressSpaceDispatch *d; - - d =flatview_to_dispatch (section->fv); - iotlb = section - d->map.sections; - iotlb += xlat; - } - -return iotlb; +AddressSpaceDispatch *d =flatview_to_dispatch (section->fv); +return section - d->map.sections; }#endif /* defined(CONFIG_USER_ONLY) */
Signature · 1 line
2.17.1
PATCH v3 15/20 cputlb: Merge and move memory_notdirty_write_{prepare, complete}
In reply to Richard HendersonSince 9458a9a1df1a, all readers of the dirty bitmaps wait for the rcu lock, which means that they wait until the end of any executing TranslationBlock.
As a consequence, there is no need for the actual access to happen in between the _prepare and _complete. Therefore, we can improve things by merging the two functions into notdirty_write and dropping the NotDirtyInfo structure.
In addition, the only users of notdirty_write are in cputlb.c, so move the merged function there. Pass in the CPUIOTLBEntry from which the ram_addr_t may be computed.
--- include/exec/memory-internal.h | 65 ----------------------------- accel/tcg/cputlb.c | 76 +++++++++++++++++++--------------- exec.c | 44 -------------------- 3 files changed, 42 insertions(+), 143 deletions(-)
include/exec/memory-internal.h +0 -65
@@ -49,70 +49,5 @@ void address_space_dispatch_free(AddressSpaceDispatch *d);void mtree_print_dispatch (struct AddressSpaceDispatch *d,MemoryRegion *root); - -struct page_collection ; - -/* Opaque struct for passing info from memory_notdirty_write_prepare() -* to memory_notdirty_write_complete(). Callers should treat all fields -* as private, with the exception of @active. -* -* @active is a field which is not touched by either the prepare or -* complete functions, but which the caller can use if it wishes to -* track whether it has called prepare for this struct and so needs -* to later call the complete function. -*/ -typedef struct { -CPUState *cpu; -struct page_collection *pages; -ram_addr_t ram_addr; -vaddr mem_vaddr; -unsigned size; -bool active; -}NotDirtyInfo ; - -/** -* memory_notdirty_write_prepare: call before writing to non-dirty memory -* @ndi: pointer to opaque NotDirtyInfo struct -* @cpu: CPU doing the write -* @mem_vaddr: virtual address of write -* @ram_addr: the ram address of the write -* @size: size of write in bytes -* -* Any code which writes to the host memory corresponding to -* guest RAM which has been marked as NOTDIRTY must wrap those -* writes in calls to memory_notdirty_write_prepare() and -* memory_notdirty_write_complete(): -* -* NotDirtyInfo ndi; -* memory_notdirty_write_prepare(&ndi, ....); -* ... perform write here ... -* memory_notdirty_write_complete(&ndi); -* -* These calls will ensure that we flush any TCG translated code for -* the memory being written, update the dirty bits and (if possible) -* remove the slowpath callback for writing to the memory. -* -* This must only be called if we are using TCG; it will assert otherwise. -* -* We may take locks in the prepare call, so callers must ensure that -* they don't exit (via longjump or otherwise) without calling complete. -* -* This call must only be made inside an RCU critical section. -* (Note that while we're executing a TCG TB we're always in an -* RCU critical section, which is likely to be the case for callers -* of these functions.) -*/ -void memory_notdirty_write_prepare (NotDirtyInfo *ndi, -CPUState *cpu, -vaddr mem_vaddr, -ram_addr_t ram_addr, -unsigned size); -/** -* memory_notdirty_write_complete: finish write to non-dirty memory -* @ndi: pointer to the opaque NotDirtyInfo struct which was initialized -* by memory_not_dirty_write_prepare(). -*/ -void memory_notdirty_write_complete (NotDirtyInfo *ndi); -#endif #endif
accel/tcg/cputlb.c +42 -34
123 lines not on this page · raw message
exec.c +0 -44
50 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 16/20 cputlb: Handle TLB_NOTDIRTY in probe_access
In reply to Richard HendersonWe can use notdirty_write for the write and
return a valid host pointer for this case.
--- accel/tcg/cputlb.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
accel/tcg/cputlb.c +17 -9
@@ -1167,16 +1167,24 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size,return NULL ; } -/* Handle watchpoints. */ -if (tlb_addr &TLB_WATCHPOINT ) { -cpu_check_watchpoint (env_cpu (env), addr, size, -env_tlb (env)->d[mmu_idx].iotlb[index].attrs, - wp_access, retaddr); - } +if (unlikely (tlb_addr &TLB_FLAGS_MASK )) { +CPUIOTLBEntry *iotlbentry = &env_tlb (env)->d[mmu_idx].iotlb[index]; -/* Reject I/O access, or other required slow-path. */ -if (tlb_addr & (TLB_NOTDIRTY |TLB_MMIO |TLB_BSWAP |TLB_ROM )) { -return NULL ; +/* Reject I/O access, or other required slow-path. */ +if (tlb_addr & (TLB_MMIO |TLB_BSWAP |TLB_ROM )) { +return NULL ; + } + +/* Handle watchpoints. */ +if (tlb_addr &TLB_WATCHPOINT ) { +cpu_check_watchpoint (env_cpu (env), addr, size, + iotlbentry->attrs, wp_access, retaddr); + } + +/* Handle clean RAM pages. */ +if (tlb_addr &TLB_NOTDIRTY ) { +notdirty_write (env_cpu (env), addr, size, iotlbentry, retaddr); + } }return (void *)((uintptr_t )addr + entry->addend);
Signature · 1 line
2.17.1
PATCH v3 17/20 cputlb: Remove cpu->mem_io_vaddr
In reply to Richard HendersonWith the merge of notdirty handling into store_helper, the last user of cpu->mem_io_vaddr was removed.
--- include/hw/core/cpu.h | 2 -- accel/tcg/cputlb.c | 2 -- hw/core/cpu.c | 1 - 3 files changed, 5 deletions(-)
include/hw/core/cpu.h +0 -2
@@ -338,7 +338,6 @@ struct qemu_work_item;* @next_cpu: Next CPU sharing TB cache. * @opaque: User data. * @mem_io_pc: Host Program Counter at which the memory was accessed. -* @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending.
@@ -413,7 +412,6 @@ struct CPUState {* we store some rarely used information in the CPU context. */ uintptr_t mem_io_pc; -vaddr mem_io_vaddr;/* * This is only needed for the legacy cpu_unassigned_access() hook; * when all targets using it have been converted to use
accel/tcg/cputlb.c +0 -2
@@ -927,7 +927,6 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,cpu_io_recompile (cpu, retaddr); } - cpu->mem_io_vaddr = addr; cpu->mem_io_access_type = access_type;if (mr->global_locking && !qemu_mutex_iothread_locked ()) {
@@ -967,7 +966,6 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry,if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); } - cpu->mem_io_vaddr = addr; cpu->mem_io_pc = retaddr;if (mr->global_locking && !qemu_mutex_iothread_locked ()) {
hw/core/cpu.c +0 -1
@@ -261,7 +261,6 @@ static void cpu_common_reset(CPUState *cpu) cpu->interrupt_request =0 ; cpu->halted =0 ; cpu->mem_io_pc =0 ; - cpu->mem_io_vaddr =0 ; cpu->icount_extra =0 ;atomic_set (&cpu->icount_decr_ptr->u32,0 ); cpu->can_do_io =1 ;
Signature · 1 line
2.17.1
Re: [PATCH v3 17/20] cputlb: Remove cpu->mem_io_vaddr
Quoted 56 lines · Richard Henderson
With the merge of notdirty handling into
store_helper, the last user ofcpu->mem_io_vaddrwas removed.Signed-off-by Richard Henderson <[email protected]>--- include/hw/core/cpu.h | 2 -- accel/tcg/cputlb.c | 2 -- hw/core/cpu.c | 1 - 3 files changed, 5 deletions(-)include/hw/core/cpu.h +0
-2@@ -338,7 +338,6 @@ struct qemu_work_item;* @next_cpu: Next CPU sharing TB cache. * @opaque: User data. * @mem_io_pc: Host Program Counter at which the memory was accessed. -* @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. @@ -413,7 +412,6 @@ struct CPUState {* we store some rarely used information in the CPU context. */ uintptr_t mem_io_pc; -vaddr mem_io_vaddr;/* * This is only needed for the legacy cpu_unassigned_access() hook; * when all targets using it have been converted to use accel/tcg/cputlb.c +0
-2@@ -927,7 +927,6 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,cpu_io_recompile (cpu, retaddr); } - cpu->mem_io_vaddr = addr; cpu->mem_io_access_type = access_type;if (mr->global_locking && !qemu_mutex_iothread_locked ()) {@@ -967,7 +966,6 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry,if (!cpu->can_do_io) {cpu_io_recompile (cpu, retaddr); } - cpu->mem_io_vaddr = addr; cpu->mem_io_pc = retaddr;if (mr->global_locking && !qemu_mutex_iothread_locked ()) {hw/core/cpu.c +0
-0
hw/core/cpu.c static void cpu_common_reset(CPUState *cpu) · line 266
Quoted 7 lines
hw/core/cpu.c +0
-1@@ -261,7 +261,6 @@ static void cpu_common_reset(CPUState *cpu) cpu->interrupt_request =0 ; cpu->halted =0 ; cpu->mem_io_pc =0 ; - cpu->mem_io_vaddr =0 ; cpu->icount_extra =0 ;atomic_set (&cpu->icount_decr_ptr->u32,0 ); cpu->can_do_io =1 ;
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 18/20 cputlb: Remove tb_invalidate_phys_page_range is_cpu_write_access
In reply to Richard HendersonAll callers pass false to this argument. Remove it and pass the constant on to tb_invalidate_phys_page_range__locked.
--- accel/tcg/translate-all.h | 3 +-- accel/tcg/translate-all.c | 6 ++---- exec.c | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-)
accel/tcg/translate-all.h +1 -2
@@ -28,8 +28,7 @@ struct page_collection *page_collection_lock(tb_page_addr_t start,void page_collection_unlock (struct page_collection *set);void tb_invalidate_phys_page_fast (struct page_collection *pages,tb_page_addr_t start,int len); -void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end, -int is_cpu_write_access); +void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end);void tb_check_watchpoint (CPUState *cpu);#ifdef CONFIG_USER_ONLY
accel/tcg/translate-all.c +2 -4
@@ -1983,8 +1983,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,* * Called with mmap_lock held for user-mode emulation */ -void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end, -int is_cpu_write_access) +void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end) {struct page_collection *pages;PageDesc *p;
@@ -1996,8 +1995,7 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,return ; } pages =page_collection_lock (start, end); -tb_invalidate_phys_page_range__locked (pages, p, start, end, - is_cpu_write_access); +tb_invalidate_phys_page_range__locked (pages, p, start, end,0 );page_collection_unlock (pages); }
exec.c +2 -2
@@ -978,7 +978,7 @@ const char *parse_cpu_option(const char *cpu_option)void tb_invalidate_phys_addr (target_ulong addr) {mmap_lock (); -tb_invalidate_phys_page_range (addr, addr +1 ,0 ); +tb_invalidate_phys_page_range (addr, addr +1 );mmap_unlock (); }
@@ -1005,7 +1005,7 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)return ; } ram_addr =memory_region_get_ram_addr (mr) + addr; -tb_invalidate_phys_page_range (ram_addr, ram_addr +1 ,0 ); +tb_invalidate_phys_page_range (ram_addr, ram_addr +1 );rcu_read_unlock (); }
Signature · 1 line
2.17.1
Re: [PATCH v3 18/20] cputlb: Remove tb_invalidate_phys_page_range is_cpu_write_access
Quoted 39 lines · Richard Henderson
All callers pass false to this argument. Remove it and pass the constant on to
tb_invalidate_phys_page_range__locked.Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/translate-all.h | 3 +-- accel/tcg/translate-all.c | 6 ++---- exec.c | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-)accel/tcg/translate-all.h +1
-2@@ -28,8 +28,7 @@ struct page_collection *page_collection_lock(tb_page_addr_t start,void page_collection_unlock (struct page_collection *set);void tb_invalidate_phys_page_fast (struct page_collection *pages,tb_page_addr_t start,int len); -void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end, -int is_cpu_write_access); +void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end);void tb_check_watchpoint (CPUState *cpu);#ifdef CONFIG_USER_ONLY accel/tcg/translate-all.c +1
-2@@ -1983,8 +1983,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,* * Called with mmap_lock held for user-mode emulation */ -void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end, -int is_cpu_write_access) +void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end) {struct page_collection *pages;PageDesc *p;
accel/tcg/translate-all.c void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end, · line 1998
Quoted 6 lines
accel/tcg/translate-all.c +1
-2@@ -1996,8 +1995,7 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,return ; } pages =page_collection_lock (start, end); -tb_invalidate_phys_page_range__locked (pages, p, start, end, - is_cpu_write_access); +tb_invalidate_phys_page_range__locked (pages, p, start, end,0 );
I'd prefer "false" to highlight the semantics, but as it's and int ...
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v3 18/20] cputlb: Remove tb_invalidate_phys_page_range is_cpu_write_access
Quoted 7 lines · David Hildenbrand
accel/tcg/translate-all.c void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end, · line 1998
Quoted 3 lines
accel/tcg/translate-all.c +1
-2-tb_invalidate_phys_page_range__locked (pages, p, start, end, - is_cpu_write_access); +tb_invalidate_phys_page_range__locked (pages, p, start, end,0 );I'd prefer "false" to highlight the semantics, but as it's and int ...
Reviewed-by David Hildenbrand <[email protected]>
I did think of that, but then the next patch changes this last argument to "uintptr_t retaddr", so then it's not really a boolean argument anymore, and "0" is exactly what we want.
r~
Re: [PATCH v3 18/20] cputlb: Remove tb_invalidate_phys_page_range is_cpu_write_access
Quoted 5 lines · Richard Henderson
Quoted 4 lines · David Hildenbrand
Quoted 3 lines
accel/tcg/translate-all.c +1
-2-tb_invalidate_phys_page_range__locked (pages, p, start, end, - is_cpu_write_access); +tb_invalidate_phys_page_range__locked (pages, p, start, end,0 );
Quoted 7 lines
Quoted 3 lines
I'd prefer "false" to highlight the semantics, but as it's and int ...
Reviewed-by David Hildenbrand <[email protected]>I did think of that, but then the next patch changes this last argument to "
uintptr_tretaddr", so then it's not really a boolean argument anymore, and "0" is exactly what we want.
Yeah, 0 is fine here.
Paolo
Quoted 8 lines · Richard Henderson
Richard Henderson (20):
exec: UseTARGET_PAGE_BITS_MINfor TLB flags
exec: Split out variable page size support toexec-vary.c
exec: Use const alias forTARGET_PAGE_BITS_VARY
exec: RestrictTARGET_PAGE_BITS_VARYassert toCONFIG_DEBUG_TCG
exec: PromoteTARGET_PAGE_MASKtotarget_long
exec: TidyTARGET_PAGE_ALIGN
exec: CacheTARGET_PAGE_MASKforTARGET_PAGE_BITS_VARY
I didn't mean to include the TARGET_PAGE_BITS_VARY patches. Ignore the first 7, or review them at your pleasure. ;-)
r~
PATCH v3 19/20 cputlb: Pass retaddr to tb_invalidate_phys_page_fast
In reply to Richard HendersonRather than rely on cpu->mem_io_pc, pass retaddr down directly.
Within tb_invalidate_phys_page_range__locked, the is_cpu_write_access parameter is non-zero exactly when retaddr would be non-zero, so that is a simple replacement.
Recognize that current_tb_not_found is true only when mem_io_pc (and now retaddr) are also non-zero, so remove a redundant test.
--- accel/tcg/translate-all.h | 3 ++- accel/tcg/cputlb.c | 6 +----- accel/tcg/translate-all.c | 39 +++++++++++++++++++-------------------- 3 files changed, 22 insertions(+), 26 deletions(-)
accel/tcg/translate-all.h +2 -1
@@ -27,7 +27,8 @@ struct page_collection *page_collection_lock(tb_page_addr_t start, tb_page_addr_t end);void page_collection_unlock (struct page_collection *set);void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len); +tb_page_addr_t start,int len, +uintptr_t retaddr);void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end);void tb_check_watchpoint (CPUState *cpu);
accel/tcg/cputlb.c +1 -5
@@ -1093,11 +1093,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) {struct page_collection *pages =page_collection_lock (ram_addr, ram_addr + size); - -/* We require mem_io_pc in tb_invalidate_phys_page_range. */ - cpu->mem_io_pc = retaddr; - -tb_invalidate_phys_page_fast (pages, ram_addr, size); +tb_invalidate_phys_page_fast (pages, ram_addr, size, retaddr);page_collection_unlock (pages); }
accel/tcg/translate-all.c +19 -20
@@ -1889,7 +1889,7 @@ static void tb_invalidate_phys_page_range__locked(struct page_collection *pages, PageDesc *p, tb_page_addr_t start, tb_page_addr_t end, - int is_cpu_write_access) + uintptr_t retaddr) { TranslationBlock *tb;tb_page_addr_t tb_start, tb_end;
@@ -1897,9 +1897,9 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,#ifdef TARGET_HAS_PRECISE_SMC CPUState *cpu = current_cpu;CPUArchState *env =NULL ; -int current_tb_not_found = is_cpu_write_access; +bool current_tb_not_found = retaddr !=0 ; +bool current_tb_modified = false;TranslationBlock *current_tb =NULL ; -int current_tb_modified =0 ;target_ulong current_pc =0 ;target_ulong current_cs_base =0 ;uint32_t current_flags =0 ;
@@ -1931,24 +1931,21 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,if (!(tb_end <= start || tb_start >= end)) {#ifdef TARGET_HAS_PRECISE_SMC if (current_tb_not_found) { - current_tb_not_found =0 ; - current_tb =NULL ; -if (cpu->mem_io_pc) { -/* now we have a real cpu fault */ - current_tb =tcg_tb_lookup (cpu->mem_io_pc); - } + current_tb_not_found = false; +/* now we have a real cpu fault */ + current_tb =tcg_tb_lookup (retaddr); }if (current_tb == tb && (tb_cflags (current_tb) &CF_COUNT_MASK ) !=1 ) { -/* If we are modifying the current TB, we must stop -its execution. We could be more precise by checking -that the modification is after the current PC, but it -would require a specialized function to partially -restore the CPU state */ - - current_tb_modified =1 ; -cpu_restore_state_from_tb (cpu, current_tb, - cpu->mem_io_pc, true); +/* +* If we are modifying the current TB, we must stop +* its execution. We could be more precise by checking +* that the modification is after the current PC, but it +* would require a specialized function to partially +* restore the CPU state. +*/ + current_tb_modified = true; +cpu_restore_state_from_tb (cpu, current_tb, retaddr, true);cpu_get_tb_cpu_state (env, ¤t_pc, ¤t_cs_base, ¤t_flags); }
@@ -2042,7 +2039,8 @@ void tb_invalidate_phys_range(target_ulong start, target_ulong end)* Call with all @pages in the range [@start, @start + len[ locked. */ void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len) +tb_page_addr_t start,int len, +uintptr_t retaddr) {PageDesc *p;
@@ -2069,7 +2067,8 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages, } }else { do_invalidate: -tb_invalidate_phys_page_range__locked (pages, p, start, start + len,1 ); +tb_invalidate_phys_page_range__locked (pages, p, start, start + len, + retaddr); } }#else
Signature · 1 line
2.17.1
Re: [PATCH v3 19/20] cputlb: Pass retaddr to tb_invalidate_phys_page_fast
Quoted 121 lines · Richard Henderson
Rather than rely on
cpu->mem_io_pc, pass retaddr down directly.Within
tb_invalidate_phys_page_range__locked, theis_cpu_write_accessparameter is non-zero exactly when retaddr would be non-zero, so that is a simple replacement.Recognize that
current_tb_not_foundis true only whenmem_io_pc(and now retaddr) are also non-zero, so remove a redundant test.Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/translate-all.h | 3 ++- accel/tcg/cputlb.c | 6 +----- accel/tcg/translate-all.c | 39 +++++++++++++++++++-------------------- 3 files changed, 22 insertions(+), 26 deletions(-)accel/tcg/translate-all.h +2
-1@@ -27,7 +27,8 @@ struct page_collection *page_collection_lock(tb_page_addr_t start, tb_page_addr_t end);void page_collection_unlock (struct page_collection *set);void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len); +tb_page_addr_t start,int len, +uintptr_t retaddr);void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end);void tb_check_watchpoint (CPUState *cpu);accel/tcg/cputlb.c +1
-5@@ -1093,11 +1093,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) {struct page_collection *pages =page_collection_lock (ram_addr, ram_addr + size); - -/* We require mem_io_pc in tb_invalidate_phys_page_range. */ - cpu->mem_io_pc = retaddr; - -tb_invalidate_phys_page_fast (pages, ram_addr, size); +tb_invalidate_phys_page_fast (pages, ram_addr, size, retaddr);page_collection_unlock (pages); }accel/tcg/translate-all.c +17
-19@@ -1889,7 +1889,7 @@ static void tb_invalidate_phys_page_range__locked(struct page_collection *pages, PageDesc *p, tb_page_addr_t start, tb_page_addr_t end, - int is_cpu_write_access) + uintptr_t retaddr) { TranslationBlock *tb;tb_page_addr_t tb_start, tb_end;@@ -1897,9 +1897,9 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,#ifdef TARGET_HAS_PRECISE_SMC CPUState *cpu = current_cpu;CPUArchState *env =NULL ; -int current_tb_not_found = is_cpu_write_access; +bool current_tb_not_found = retaddr !=0 ; +bool current_tb_modified = false;TranslationBlock *current_tb =NULL ; -int current_tb_modified =0 ;target_ulong current_pc =0 ;target_ulong current_cs_base =0 ;uint32_t current_flags =0 ;@@ -1931,24 +1931,21 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,if (!(tb_end <= start || tb_start >= end)) {#ifdef TARGET_HAS_PRECISE_SMC if (current_tb_not_found) { - current_tb_not_found =0 ; - current_tb =NULL ; -if (cpu->mem_io_pc) { -/* now we have a real cpu fault */ - current_tb =tcg_tb_lookup (cpu->mem_io_pc); - } + current_tb_not_found = false; +/* now we have a real cpu fault */ + current_tb =tcg_tb_lookup (retaddr); }if (current_tb == tb && (tb_cflags (current_tb) &CF_COUNT_MASK ) !=1 ) { -/* If we are modifying the current TB, we must stop -its execution. We could be more precise by checking -that the modification is after the current PC, but it -would require a specialized function to partially -restore the CPU state */ - - current_tb_modified =1 ; -cpu_restore_state_from_tb (cpu, current_tb, - cpu->mem_io_pc, true); +/* +* If we are modifying the current TB, we must stop +* its execution. We could be more precise by checking +* that the modification is after the current PC, but it +* would require a specialized function to partially +* restore the CPU state. +*/ + current_tb_modified = true; +cpu_restore_state_from_tb (cpu, current_tb, retaddr, true);cpu_get_tb_cpu_state (env, ¤t_pc, ¤t_cs_base, ¤t_flags); }@@ -2042,7 +2039,8 @@ void tb_invalidate_phys_range(target_ulong start, target_ulong end)* Call with all @pages in the range [@start, @start + len[ locked. */ void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len) +tb_page_addr_t start,int len, +uintptr_t retaddr) {PageDesc *p;
accel/tcg/translate-all.c void tb_invalidate_phys_page_fast(struct page_collection *pages, · line 2074
Quoted 9 lines
accel/tcg/translate-all.c +2
-1@@ -2069,7 +2067,8 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages, } }else { do_invalidate: -tb_invalidate_phys_page_range__locked (pages, p, start, start + len,1 ); +tb_invalidate_phys_page_range__locked (pages, p, start, start + len, + retaddr); } }#else
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 20/20 cputlb: Pass retaddr to tb_check_watchpoint
In reply to Richard HendersonFixes the previous TLB_WATCHPOINT patches because we are currently failing to set cpu->mem_io_pc with the call to cpu_check_watchpoint. Pass down the retaddr directly because it's readily available.
--- accel/tcg/translate-all.h | 2 +- accel/tcg/translate-all.c | 6 +++--- exec.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
accel/tcg/translate-all.h +1 -1
@@ -30,7 +30,7 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages, tb_page_addr_t start, int len, uintptr_t retaddr);void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end); -void tb_check_watchpoint (CPUState *cpu); +void tb_check_watchpoint (CPUState *cpu,uintptr_t retaddr);#ifdef CONFIG_USER_ONLY int page_unprotect (target_ulong address,uintptr_t pc);
accel/tcg/translate-all.c +3 -3
@@ -2142,16 +2142,16 @@ static bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc)#endif /* user-mode: call with mmap_lock held */ -void tb_check_watchpoint (CPUState *cpu) +void tb_check_watchpoint (CPUState *cpu,uintptr_t retaddr) {TranslationBlock *tb;assert_memory_lock (); - tb =tcg_tb_lookup (cpu->mem_io_pc); + tb =tcg_tb_lookup (retaddr);if (tb) {/* We can use retranslation to find the PC. */ -cpu_restore_state_from_tb (cpu, tb, cpu->mem_io_pc, true); +cpu_restore_state_from_tb (cpu, tb, retaddr, true);tb_phys_invalidate (tb,-1 ); }else {/* The exception probably happened in a helper. The CPU state should
exec.c +1 -1
@@ -2724,7 +2724,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, cpu->watchpoint_hit = wp;mmap_lock (); -tb_check_watchpoint (cpu); +tb_check_watchpoint (cpu, ra);if (wp->flags &BP_STOP_BEFORE_ACCESS ) { cpu->exception_index =EXCP_DEBUG ;mmap_unlock ();
Signature · 1 line
2.17.1
Re: [PATCH v3 20/20] cputlb: Pass retaddr to tb_check_watchpoint
Quoted 55 lines · Richard Henderson
Fixes the previous
TLB_WATCHPOINTpatches because we are currently failing to setcpu->mem_io_pcwith the call tocpu_check_watchpoint. Pass down the retaddr directly because it's readily available.Fixes 50b107c5d61Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/translate-all.h | 2 +- accel/tcg/translate-all.c | 6 +++--- exec.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)accel/tcg/translate-all.h +1
-1@@ -30,7 +30,7 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages, tb_page_addr_t start, int len, uintptr_t retaddr);void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end); -void tb_check_watchpoint (CPUState *cpu); +void tb_check_watchpoint (CPUState *cpu,uintptr_t retaddr);#ifdef CONFIG_USER_ONLY int page_unprotect (target_ulong address,uintptr_t pc);accel/tcg/translate-all.c +3
-3@@ -2142,16 +2142,16 @@ static bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc)#endif /* user-mode: call with mmap_lock held */ -void tb_check_watchpoint (CPUState *cpu) +void tb_check_watchpoint (CPUState *cpu,uintptr_t retaddr) {TranslationBlock *tb;assert_memory_lock (); - tb =tcg_tb_lookup (cpu->mem_io_pc); + tb =tcg_tb_lookup (retaddr);if (tb) {/* We can use retranslation to find the PC. */ -cpu_restore_state_from_tb (cpu, tb, cpu->mem_io_pc, true); +cpu_restore_state_from_tb (cpu, tb, retaddr, true);tb_phys_invalidate (tb,-1 ); }else {/* The exception probably happened in a helper. The CPU state should exec.c +0
-0
exec.c void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, · line 2730
Quoted 8 lines
exec.c +1
-1@@ -2724,7 +2724,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, cpu->watchpoint_hit = wp;mmap_lock (); -tb_check_watchpoint (cpu); +tb_check_watchpoint (cpu, ra);if (wp->flags &BP_STOP_BEFORE_ACCESS ) { cpu->exception_index =EXCP_DEBUG ;mmap_unlock ();
Finally, a lot of this stuff gets cleaned up :)
Signature · 3 lines
Thanks, David / dhildenb
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Subject: [PATCH v3 00/20] Move rom and notdirty handling to cputlb
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
34dd130 cputlb: Pass retaddr to tb_check_watchpoint
7d95821 cputlb: Pass retaddr to tb_invalidate_phys_page_fast 0f82f7a cputlb: Remove tb_invalidate_phys_page_range is_cpu_write_access 143b897 cputlb: Remove cpu->mem_io_vaddr
1ac8201 cputlb: Handle TLB_NOTDIRTY in probe_access
d9ff1a3 cputlb: Merge and move memory_notdirty_write_{prepare, complete} 32abbae cputlb: Partially inline memory_region_section_get_iotlb 3976ef9 cputlb: Move NOTDIRTY handling from I/O path to TLB path 4f3e8aa cputlb: Move ROM handling from I/O path to TLB path 3c42e98 exec: Adjust notdirty tracing
e3bb276 cputlb: Introduce TLB_BSWAP
e48326a cputlb: Replace switches in load/store_helper with callback 287b700 cputlb: Disable __always_inline__ without optimization 8c801ae exec: Cache TARGET_PAGE_MASK for TARGET_PAGE_BITS_VARY 2f76655 exec: Tidy TARGET_PAGE_ALIGN
aa7fdf2 exec: Promote TARGET_PAGE_MASK to target_long 20c6e62 exec: Restrict TARGET_PAGE_BITS_VARY assert to CONFIG_DEBUG_TCG 4db4c87 exec: Use const alias for TARGET_PAGE_BITS_VARY 0d3457e exec: Split out variable page size support to exec-vary.c b4b2c05 exec: Use TARGET_PAGE_BITS_MIN for TLB flags
=== OUTPUT BEGIN ===
1/20 Checking commit b4b2c05eaa12 (exec: Use TARGET_PAGE_BITS_MIN for TLB flags) 2/20 Checking commit 0d3457ee2850 (exec: Split out variable page size support to exec-vary.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#33:
new file mode 100644
total: 0 errors, 1 warnings, 125 lines checked
Patch 2/20 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/20 Checking commit 4db4c8782d8c (exec: Use const alias for TARGET_PAGE_BITS_VARY)
ERROR: externs should be avoided in .c files
#58: FILE: exec-vary.c:53:
+extern const TargetPageBits target_page
total: 1 errors, 0 warnings, 82 lines checked
Patch 3/20 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
4/20 Checking commit 20c6e620cee9 (exec: Restrict TARGET_PAGE_BITS_VARY assert to CONFIG_DEBUG_TCG) 5/20 Checking commit aa7fdf250f2b (exec: Promote TARGET_PAGE_MASK to target_long) 6/20 Checking commit 2f766556467d (exec: Tidy TARGET_PAGE_ALIGN)
7/20 Checking commit 8c801ae246fe (exec: Cache TARGET_PAGE_MASK for TARGET_PAGE_BITS_VARY) 8/20 Checking commit 287b700d5006 (cputlb: Disable __always_inline__ without optimization)
WARNING: architecture specific defines should be avoided
#50: FILE: include/qemu/compiler.h:178:
+#if defined(__OPTIMIZE__) && __has_attribute(always_inline)
total: 0 errors, 1 warnings, 33 lines checked
Patch 8/20 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
9/20 Checking commit e48326ae3127 (cputlb: Replace switches in load/store_helper with callback) 10/20 Checking commit e3bb276cde3b (cputlb: Introduce TLB_BSWAP)
11/20 Checking commit 3c42e98e5a4a (exec: Adjust notdirty tracing)
12/20 Checking commit 4f3e8aa354bc (cputlb: Move ROM handling from I/O path to TLB path) 13/20 Checking commit 3976ef9549a0 (cputlb: Move NOTDIRTY handling from I/O path to TLB path) 14/20 Checking commit 32abbae47942 (cputlb: Partially inline memory_region_section_get_iotlb) 15/20 Checking commit d9ff1a3e3b82 (cputlb: Merge and move memory_notdirty_write_{prepare, complete}) 16/20 Checking commit 1ac820151e2f (cputlb: Handle TLB_NOTDIRTY in probe_access) 17/20 Checking commit 143b897be8e4 (cputlb: Remove cpu->mem_io_vaddr)
18/20 Checking commit 0f82f7a7365d (cputlb: Remove tb_invalidate_phys_page_range is_cpu_write_access) 19/20 Checking commit 7d95821f8ce9 (cputlb: Pass retaddr to tb_invalidate_phys_page_fast) 20/20 Checking commit 34dd130e1b50 (cputlb: Pass retaddr to tb_check_watchpoint)
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 1 line · Richard Henderson
Ok! Third time is the charm, because this time it works.
Yeay :) I don't wanna know how hard it was to debug that...
Quoted 8 lines
New to v3:
* Covert
io_mem_romwith a newTLB_ROMbit.* This in turn means that there are no longer any special RAM case along along the MMIO path -- they all have devices on the other end.
That sounds like a really nice cleanup.
Quoted 9 lines
* This in turn means that we can fold the bulk of
memory_region_section_get_iotlbintotlb_set_page_with_attrs, a couple of redundant tests vs the MemoryRegion. The result in patch 14 is, IMO, much more understandable.* Fold away uses of
cpu->mem_io_pcintb_invalidate_phys_page__locked, the cause of the problems for my previous two patch sets.
Quoted 7 lines
BTW, I was correct with my guess in the v2 cover letter that the use of memory_notdirty_write_{prepare,complete} within
atomic_mmu_lookupmust have been broken, for not settingmem_io_pc. :-P* Fix a missed use of
cpu->mem_io_pcintb_check_watchpoint, which meant that the previousTLB_WATCHPOINTcleanup was a titch broken.
So there was a PC already getting stored.
Quoted 51 lines
The remaining two users of
cpu->mem_io_pcarehw/misc/mips_itu.candtarget/i386/helper.c. I haven't looked, but I assume that these are legitimately on the MMIO path, and there probably isn't a decent way to remove the uses.r~
Richard Henderson (20):
exec: UseTARGET_PAGE_BITS_MINfor TLB flags
exec: Split out variable page size support toexec-vary.c
exec: Use const alias forTARGET_PAGE_BITS_VARY
exec: RestrictTARGET_PAGE_BITS_VARYassert toCONFIG_DEBUG_TCG
exec: PromoteTARGET_PAGE_MASKtotarget_long
exec: TidyTARGET_PAGE_ALIGN
exec: CacheTARGET_PAGE_MASKforTARGET_PAGE_BITS_VARY
cputlb: Disable__always_inline__without optimization
cputlb: Replace switches in load/store_helper with callback
cputlb: IntroduceTLB_BSWAP
exec: Adjust notdirty tracing
cputlb: Move ROM handling from I/O path to TLB path
cputlb: Move NOTDIRTY handling from I/O path to TLB path
cputlb: Partially inlinememory_region_section_get_iotlb
cputlb: Merge and move memory_notdirty_write_{prepare,complete}
cputlb: HandleTLB_NOTDIRTYinprobe_access
cputlb: Removecpu->mem_io_vaddr
cputlb: Removetb_invalidate_phys_page_rangeis_cpu_write_access
cputlb: Pass retaddr totb_invalidate_phys_page_fast
cputlb: Pass retaddr totb_check_watchpointMakefile.target | 2 +- accel/tcg/translate-all.h | 8 +- include/exec/cpu-all.h | 48 ++-- include/exec/cpu-common.h | 3 - include/exec/exec-all.h | 6 +- include/exec/memory-internal.h | 65 ------ include/hw/core/cpu.h | 2 - include/qemu-common.h | 6 + include/qemu/compiler.h | 11 + accel/tcg/cputlb.c | 388 +++++++++++++++++++-------------- accel/tcg/translate-all.c | 51 ++--- exec-vary.c | 88 ++++++++ exec.c | 192 +--------------- hw/core/cpu.c | 1 - memory.c | 20 -- trace-events | 4 +- 16 files changed, 403 insertions(+), 492 deletions(-) create mode 100644 exec-vary.c
Signature · 3 lines
Thanks, David / dhildenb