accel/tcg: Improvements to atomic128.h
Subsystems (2)
cover accel/tcg: Improvements to atomic128.h
Peter raised a good point about it not being ideal to mix inline assembly into the middle of accel/tcg/ldst_atomicity.c. We now have a host-specific structure in which to put those.
Additionally, Peter noticed that clang will incorrectly use a read-write sequence for __atomic_load_16 on AArch64, which might fault for our usage in user-only emulation.
Fixing both of these simultaneously splits atomic16_read into atomic16_read_{ro,rw}, because there is in fact room for both in the emulation -- we currently use cmpxchg directly where we can allow a read with write side-effect.
Additionally, prepare for runtime detection. Both x86_64 and aarch64 have architecture extensions that *do* allow 128-bit load and store without using cmpxchg.
To make runtime detection work, we need to remove preprocessor use of HAVE_ATOMIC128*. It turns out this was only used for the legacy helper_atomic_{ld,st}o_{be,le}_mmu functions. These uses within ppc64 and s390x can now be updated to tcg_gen_qemu_{ld,st}_i128 and cpu_{ld,st}16_mmu. After doing that, we can remove the problematic #if's entirely.
r~
Richard Henderson (27):
util: Introduce host-specific cpuinfo.h
util: Add cpuinfo-i386.c
util: Add i386 CPUINFO_ATOMIC_VMOVDQU
tcg/i386: Use host/cpuinfo.h
util/bufferiszero: Use i386 host/cpuinfo.h migration/xbzrle: Shuffle function order migration/xbzrle: Use i386 host/cpuinfo.h
migration: Build migration_files once
util: Add cpuinfo-aarch64.c
include/host: Split out atomic128-cas.h
include/host: Split out atomic128-ldst.h
meson: Fix detect atomic128 support with optimization include/qemu: Move CONFIG_ATOMIC128_OPT handling to atomic128.h target/ppc: Use tcg_gen_qemu_{ld,st}_i128 for LQARX, LQ, STQ target/s390x: Use tcg_gen_qemu_{ld,st}_i128 for LPQ, STPQ accel/tcg: Unify cpu_{ld,st}*_{be,le}_mmu target/s390x: Use cpu_{ld,st}*_mmu in do_csst target/s390x: Always use cpu_atomic_cmpxchgl_be_mmu in do_csst accel/tcg: Remove cpu_atomic_{ld,st}o_*_mmu accel/tcg: Remove prot argument to atomic_mmu_lookup accel/tcg: Eliminate #if on HAVE_ATOMIC128 and HAVE_CMPXCHG128 qemu/atomic128: Split atomic16_read
accel/tcg: Correctly use atomic128.h in ldst_atomicity.c.inc
tcg: Split out tcg/debug-assert.h
qemu/atomic128: Improve cmpxchg fallback for atomic16_set qemu/atomic128: Add runtime test for FEAT_LSE2 qemu/atomic128: Add x86_64 atomic128-ldst.h
accel/tcg/atomic_template.h | 93 +--- host/include/aarch64/host/atomic128-cas.h | 45 ++ host/include/aarch64/host/atomic128-ldst.h | 79 ++++ host/include/aarch64/host/cpuinfo.h | 22 + host/include/generic/host/atomic128-cas.h | 47 +++ host/include/generic/host/atomic128-ldst.h | 81 ++++ host/include/generic/host/cpuinfo.h | 4 + host/include/i386/host/cpuinfo.h | 39 ++ host/include/x86_64/host/atomic128-ldst.h | 54 +++ host/include/x86_64/host/cpuinfo.h | 1 + include/exec/cpu_ldst.h | 67 +-- include/qemu/atomic128.h | 146 +------ include/tcg/debug-assert.h | 17 + include/tcg/tcg.h | 9 +- migration/xbzrle.h | 5 +- target/ppc/cpu.h | 1 - target/ppc/helper.h | 9 - target/s390x/cpu.h | 3 - target/s390x/helper.h | 4 - tcg/aarch64/tcg-target.h | 6 +- tcg/i386/tcg-target.h | 28 +- accel/tcg/cputlb.c | 211 +++------ accel/tcg/user-exec.c | 332 ++++----------- migration/ram.c | 34 +- migration/xbzrle.c | 268 ++++++------ target/arm/tcg/m_helper.c | 4 +- target/ppc/mem_helper.c | 48 --- target/ppc/translate.c | 34 +- target/s390x/tcg/mem_helper.c | 136 ++---- target/s390x/tcg/translate.c | 30 +- target/sparc/ldst_helper.c | 18 +- tests/bench/xbzrle-bench.c | 469 --------------------- tests/unit/test-xbzrle.c | 49 +-- util/bufferiszero.c | 126 ++---- util/cpuinfo-aarch64.c | 67 +++ util/cpuinfo-i386.c | 99 +++++ accel/tcg/atomic_common.c.inc | 14 - accel/tcg/ldst_atomicity.c.inc | 135 +----- accel/tcg/ldst_common.c.inc | 24 +- meson.build | 10 +- migration/meson.build | 1 - target/ppc/translate/fixedpoint-impl.c.inc | 51 +-- target/s390x/tcg/insn-data.h.inc | 2 +- tcg/aarch64/tcg-target.c.inc | 40 -- tcg/i386/tcg-target.c.inc | 123 +----- tests/bench/meson.build | 6 - util/meson.build | 6 + 47 files changed, 1081 insertions(+), 2016 deletions(-) create mode 100644 host/include/aarch64/host/atomic128-cas.h create mode 100644 host/include/aarch64/host/atomic128-ldst.h create mode 100644 host/include/aarch64/host/cpuinfo.h create mode 100644 host/include/generic/host/atomic128-cas.h create mode 100644 host/include/generic/host/atomic128-ldst.h create mode 100644 host/include/generic/host/cpuinfo.h create mode 100644 host/include/i386/host/cpuinfo.h create mode 100644 host/include/x86_64/host/atomic128-ldst.h create mode 100644 host/include/x86_64/host/cpuinfo.h create mode 100644 include/tcg/debug-assert.h delete mode 100644 tests/bench/xbzrle-bench.c create mode 100644 util/cpuinfo-aarch64.c create mode 100644 util/cpuinfo-i386.c
Signature · 1 line
2.34.1
PATCH 1/27 util: Introduce host-specific cpuinfo.h
The entire contents of the header is host-specific, but the existence of such a header is not, which could prevent some host specific ifdefs at the top of the file for the include.
Add host/include/{arch,generic} to the project arguments.
--- host/include/generic/host/cpuinfo.h | 4 ++++ meson.build | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 host/include/generic/host/cpuinfo.h
host/include/generic/host/cpuinfo.h new file +4 -0
@@ -0,0 +1,4 @@ +/* +* No host specific cpu indentification. +* SPDX-License-Identifier: GPL-2.0-or-later +*/
meson.build +8 -0
@@ -512,6 +512,14 @@ add_project_arguments('-iquote', '.', '-iquote', meson.current_source_dir() / 'include', language: all_languages) +host_include = meson.current_source_dir() / 'host/include/' +if fs.is_dir(host_include / host_arch) + add_project_arguments('-iquote', host_include / host_arch, + language: all_languages) +endif +add_project_arguments('-iquote', host_include / 'generic', + language: all_languages) + sparse = find_program('cgcc', required: get_option('sparse')) if sparse.found() run_target('sparse',
Signature · 1 line
2.34.1
Re: [PATCH 01/27] util: Introduce host-specific cpuinfo.h
Quoted 29 lines · Richard Henderson
The entire contents of the header is host-specific, but the existence of such a header is not, which could prevent some host specific ifdefs at the top of the file for the include.
Add host/include/{arch,generic} to the project arguments.
Reviewed-by Juan Quintela <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- host/include/generic/host/cpuinfo.h | 4 ++++ meson.build | 8 ++++++++ 2 files changed, 12 insertions(+)create mode 100644
host/include/generic/host/cpuinfo.hhost/include/generic/host/cpuinfo.h new file +4
-0@@ -0,0 +1,4 @@ +/* +* No host specific cpu indentification. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ meson.build +0
-0
meson.build add_project_arguments('-iquote', '.', · line 519
Quoted 8 lines
meson.build +5
-0@@ -512,6 +512,14 @@ add_project_arguments('-iquote', '.', '-iquote', meson.current_source_dir() / 'include', language: all_languages) +host_include = meson.current_source_dir() / 'host/include/' +if fs.is_dir(host_include / host_arch) + add_project_arguments('-iquote', host_include / host_arch, + language: all_languages) +endif
Maybe add a comment "generic include path must come last, after host specific include path".
meson.build add_project_arguments('-iquote', '.', · line 525
Quoted 6 lines
meson.build +3
-0+add_project_arguments('-iquote', host_include / 'generic', + language: all_languages) + sparse = find_program('cgcc', required: get_option('sparse')) if sparse.found() run_target('sparse',
Re: [PATCH 01/27] util: Introduce host-specific cpuinfo.h
In reply to Richard HendersonQuoted 8 lines · Richard Henderson
The entire contents of the header is host-specific, but the existence of such a header is not, which could prevent some host specific ifdefs at the top of the file for the include.
Add host/include/{arch,generic} to the project arguments.
Reviewed-by Juan Quintela <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 2/27 util: Add cpuinfo-i386.c
In reply to Richard HendersonAdd cpuinfo.h for i386 and x86_64, and the initialization for that in util/. Populate that with a slightly altered copy of the tcg host probing code. Other uses of cpuid.h will be adjusted one patch at a time.
--- host/include/i386/host/cpuinfo.h | 38 ++++++++++++ host/include/x86_64/host/cpuinfo.h | 1 + util/cpuinfo-i386.c | 97 ++++++++++++++++++++++++++++++ util/meson.build | 4 ++ 4 files changed, 140 insertions(+) create mode 100644 host/include/i386/host/cpuinfo.h create mode 100644 host/include/x86_64/host/cpuinfo.h create mode 100644 util/cpuinfo-i386.c
host/include/i386/host/cpuinfo.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* Host specific cpu indentification for x86. +*/ + +#ifndef HOST_CPUINFO_H +#define HOST_CPUINFO_H + +/* Digested version of <cpuid.h> */ + +#define CPUINFO_ALWAYS (1u << 0)/* so cpuinfo is nonzero */ +#define CPUINFO_CMOV (1u << 1) +#define CPUINFO_MOVBE (1u << 2) +#define CPUINFO_LZCNT (1u << 3) +#define CPUINFO_POPCNT (1u << 4) +#define CPUINFO_BMI1 (1u << 5) +#define CPUINFO_BMI2 (1u << 6) +#define CPUINFO_SSE2 (1u << 7) +#define CPUINFO_SSE4 (1u << 8) +#define CPUINFO_AVX1 (1u << 9) +#define CPUINFO_AVX2 (1u << 10) +#define CPUINFO_AVX512F (1u << 11) +#define CPUINFO_AVX512VL (1u << 12) +#define CPUINFO_AVX512BW (1u << 13) +#define CPUINFO_AVX512DQ (1u << 14) +#define CPUINFO_AVX512VBMI2 (1u << 15) +#define CPUINFO_ATOMIC_VMOVDQA (1u << 16) + +/* Initialized with a constructor. */ +extern unsigned cpuinfo; + +/* +* We cannot rely on constructor ordering, so other constructors must +* use the function interface rather than the variable above. +*/ +unsigned cpuinfo_init (void ); + +#endif /* HOST_CPUINFO_H */
host/include/x86_64/host/cpuinfo.h new file +1 -0
@@ -0,0 +1 @@ +#include "host/include/i386/host/cpuinfo.h"
util/cpuinfo-i386.c new file +97 -0
97 lines not on this page · raw message
util/meson.build +4 -0
@@ -108,3 +108,7 @@ if have_block endif util_ss.add(when: 'CONFIG_LINUX', if_true: files('vfio-helpers.c')) endif + +if cpu in ['x86', 'x86_64'] + util_ss.add(files('cpuinfo-i386.c')) +endif
Signature · 1 line
2.34.1
Re: [PATCH 02/27] util: Add cpuinfo-i386.c
Quoted 13 lines · Richard Henderson
Add
cpuinfo.hfor i386 andx86_64, and the initialization for that in util/. Populate that with a slightly altered copy of the tcg host probing code. Other uses ofcpuid.hwill be adjusted one patch at a time.Reviewed-by Juan Quintela <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- host/include/i386/host/cpuinfo.h | 38 ++++++++++++ host/include/x86_64/host/cpuinfo.h | 1 + util/cpuinfo-i386.c | 97 ++++++++++++++++++++++++++++++ util/meson.build | 4 ++ 4 files changed, 140 insertions(+)
Quoted 3 lines
create mode 100644
host/include/i386/host/cpuinfo.hcreate mode 100644host/include/x86_64/host/cpuinfo.hcreate mode 100644util/cpuinfo-i386.c
Missing F: entry in MAINTAINERS file. We probably need new sections.
Re: [PATCH 02/27] util: Add cpuinfo-i386.c
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Richard Henderson
Add
cpuinfo.hfor i386 andx86_64, and the initialization for that in util/. Populate that with a slightly altered copy of the tcg host probing code. Other uses ofcpuid.hwill be adjusted one patch at a time.Reviewed-by Juan Quintela <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
host/include/i386/host/cpuinfo.h | 38 ++++++++++++host/include/x86_64/host/cpuinfo.h| 1 + util/cpuinfo-i386.c | 97 ++++++++++++++++++++++++++++++ util/meson.build | 4 ++Quoted 4 lines
4 files changed, 140 insertions(+)create mode 100644
host/include/i386/host/cpuinfo.hcreate mode 100644host/include/x86_64/host/cpuinfo.hcreate mode 100644util/cpuinfo-i386.c
Quoted 1 line
Missing F: entry in
MAINTAINERSfile. We probably need new sections.
What would you put there?
r~
Alex Bennée
Reviewed-byRe: [PATCH 02/27] util: Add cpuinfo-i386.c
Quoted 18 lines · Richard Henderson
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Richard Henderson
Add
cpuinfo.hfor i386 andx86_64, and the initialization for that in util/. Populate that with a slightly altered copy of the tcg host probing code. Other uses ofcpuid.hwill be adjusted one patch at a time.Reviewed-by Juan Quintela <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
host/include/i386/host/cpuinfo.h | 38 ++++++++++++host/include/x86_64/host/cpuinfo.h| 1 + util/cpuinfo-i386.c | 97 ++++++++++++++++++++++++++++++ util/meson.build | 4 ++4 files changed, 140 insertions(+)create mode 100644
host/include/i386/host/cpuinfo.hcreate mode 100644host/include/x86_64/host/cpuinfo.hcreate mode 100644util/cpuinfo-i386.c
Quoted 3 lines
Quoted 1 line
Missing F: entry in
MAINTAINERSfile. We probably need new sections.What would you put there?
Part of Guest CPU cores (TCG) I guess.
Anyway:
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 3/27 util: Add i386 CPUINFO_ATOMIC_VMOVDQU
In reply to Richard HendersonAdd a bit to indicate when VMOVDQU is also atomic if aligned.
--- host/include/i386/host/cpuinfo.h | 1 + util/cpuinfo-i386.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
host/include/i386/host/cpuinfo.h +1 -0
@@ -25,6 +25,7 @@#define CPUINFO_AVX512DQ (1u << 14)#define CPUINFO_AVX512VBMI2 (1u << 15)#define CPUINFO_ATOMIC_VMOVDQA (1u << 16) +#define CPUINFO_ATOMIC_VMOVDQU (1u << 17)/* Initialized with a constructor. */ extern unsigned cpuinfo;
util/cpuinfo-i386.c +3 -1
@@ -77,8 +77,10 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688 */ __cpuid (0 , a, b, c, d); -if (c == signature_INTEL_ecx || c == signature_AMD_ecx) { +if (c == signature_INTEL_ecx) { info |=CPUINFO_ATOMIC_VMOVDQA ; + }else if (c == signature_AMD_ecx) { + info |=CPUINFO_ATOMIC_VMOVDQA |CPUINFO_ATOMIC_VMOVDQU ; } } }
Signature · 1 line
2.34.1
PATCH 4/27 tcg/i386: Use host/cpuinfo.h
In reply to Richard HendersonUse the CPUINFO_* bits instead of the individual boolean variables that we had been using. Remove all of the init code that was moved over to cpuinfo-i386.c.
Note that have_avx512* check both AVX512{F,VL}, as we had previously done during tcg_target_init.
--- tcg/i386/tcg-target.h | 28 +++++---- tcg/i386/tcg-target.c.inc | 123 ++------------------------------------ 2 files changed, 22 insertions(+), 129 deletions(-)
tcg/i386/tcg-target.h +18 -10
@@ -25,6 +25,8 @@#ifndef I386_TCG_TARGET_H #define I386_TCG_TARGET_H +#include "host/cpuinfo.h" +#define TCG_TARGET_INSN_UNIT_SIZE 1#define TCG_TARGET_TLB_DISPLACEMENT_BITS 31
@@ -111,16 +113,22 @@ typedef enum {# define TCG_TARGET_CALL_RET_I128 TCG_CALL_RET_BY_REF#endif -extern bool have_bmi1; -extern bool have_popcnt; -extern bool have_avx1; -extern bool have_avx2; -extern bool have_avx512bw; -extern bool have_avx512dq; -extern bool have_avx512vbmi2; -extern bool have_avx512vl; -extern bool have_movbe; -extern bool have_atomic16; +#define have_bmi1 (cpuinfo & CPUINFO_BMI1) +#define have_popcnt (cpuinfo & CPUINFO_POPCNT) +#define have_avx1 (cpuinfo & CPUINFO_AVX1) +#define have_avx2 (cpuinfo & CPUINFO_AVX2) +#define have_movbe (cpuinfo & CPUINFO_MOVBE) +#define have_atomic16 (cpuinfo & CPUINFO_ATOMIC_VMOVDQA) + +/* +* There are interesting instructions in AVX512, so long as we have AVX512VL, +* which indicates support for EVEX on sizes smaller than 512 bits. +*/ +#define have_avx512vl ((cpuinfo & CPUINFO_AVX512VL) && \ + (cpuinfo & CPUINFO_AVX512F)) +#define have_avx512bw ((cpuinfo & CPUINFO_AVX512BW) && have_avx512vl) +#define have_avx512dq ((cpuinfo & CPUINFO_AVX512DQ) && have_avx512vl) +#define have_avx512vbmi2 ((cpuinfo & CPUINFO_AVX512VBMI2) && have_avx512vl)/* optional instructions */ #define TCG_TARGET_HAS_div2_i32 1
tcg/i386/tcg-target.c.inc +4 -119
139 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 5/27 util/bufferiszero: Use i386 host/cpuinfo.h
In reply to Richard HendersonUse cpuinfo_init() during init_accel(), and the variable cpuinfo during test_buffer_is_zero_next_accel(). Adjust the logic that cycles through the set of accelerators for testing.
--- util/bufferiszero.c | 126 ++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 81 deletions(-)
util/bufferiszero.c +45 -81
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qemu/cutils.h" #include "qemu/bswap.h" +#include "host/cpuinfo.h" static bool buffer_zero_int (const void *buf,size_t len)
@@ -184,111 +185,74 @@ buffer_zero_avx512(const void *buf, size_t len) }#endif /* CONFIG_AVX512F_OPT */ - -/* Note that for test_buffer_is_zero_next_accel, the most preferred -* ISA must have the least significant bit. -*/ -#define CACHE_AVX512F 1 -#define CACHE_AVX2 2 -#define CACHE_SSE4 4 -#define CACHE_SSE2 8 - -/* Make sure that these variables are appropriately initialized when +/* +* Make sure that these variables are appropriately initialized when * SSE2 is enabled on the compiler command-line, but the compiler is * too old to support CONFIG_AVX2_OPT. */ #if defined(CONFIG_AVX512F_OPT ) || defined(CONFIG_AVX2_OPT ) -# define INIT_CACHE 0 -# define INIT_ACCEL buffer_zero_int +# define INIT_USED 0 +# define INIT_LENGTH 0 +# define INIT_ACCEL buffer_zero_int#else # ifndef __SSE2__# error "ISA selection confusion"# endif -# define INIT_CACHE CACHE_SSE2 -# define INIT_ACCEL buffer_zero_sse2 +# define INIT_USED CPUINFO_SSE2 +# define INIT_LENGTH 64 +# define INIT_ACCEL buffer_zero_sse2#endif -static unsigned cpuid_cache =INIT_CACHE ; +static unsigned used_accel =INIT_USED ; +static unsigned length_to_accel =INIT_LENGTH ;static bool (*buffer_accel)(const void *,size_t ) =INIT_ACCEL ; -static int length_to_accel =64 ; -static void init_accel (unsigned cache) +static unsigned __attribute__((noinline)) +select_accel_cpuinfo (unsigned info) { -bool (*fn)(const void *,size_t ) = buffer_zero_int; -if (cache &CACHE_SSE2 ) { - fn = buffer_zero_sse2; - length_to_accel =64 ; - } -#ifdef CONFIG_AVX2_OPT -if (cache &CACHE_SSE4 ) { - fn = buffer_zero_sse4; - length_to_accel =64 ; - } -if (cache &CACHE_AVX2 ) { - fn = buffer_zero_avx2; - length_to_accel =128 ; - } -#endif +static const struct { +unsigned bit; +unsigned len; +bool (*fn)(const void *,size_t ); + } all[] = { #ifdef CONFIG_AVX512F_OPT -if (cache &CACHE_AVX512F ) { - fn = buffer_zero_avx512; - length_to_accel =256 ; - } + {CPUINFO_AVX512F ,256 , buffer_zero_avx512 }, #endif - buffer_accel = fn; +#ifdef CONFIG_AVX2_OPT + {CPUINFO_AVX2 ,128 , buffer_zero_avx2 }, + {CPUINFO_SSE4 ,64 , buffer_zero_sse4 }, +#endif + {CPUINFO_SSE2 ,64 , buffer_zero_sse2 }, + {CPUINFO_ALWAYS ,0 , buffer_zero_int }, + }; + +for (unsigned i =0 ; i <ARRAY_SIZE (all); ++i) { +if (info & all[i].bit) { + length_to_accel = all[i].len; + buffer_accel = all[i].fn; +return all[i].bit; + } + } +return 0 ; }#if defined(CONFIG_AVX512F_OPT ) || defined(CONFIG_AVX2_OPT ) -#include "qemu/cpuid.h" - -static void __attribute__((constructor))init_cpuid_cache (void ) +static void __attribute__((constructor))init_accel (void ) { -unsigned max =__get_cpuid_max (0 ,NULL ); -int a, b, c, d; -unsigned cache =0 ; - -if (max >=1 ) { -__cpuid (1 , a, b, c, d); -if (d & bit_SSE2) { - cache |=CACHE_SSE2 ; - } -if (c & bit_SSE4_1) { - cache |=CACHE_SSE4 ; - } - -/* We must check that AVX is not just available, but usable. */ -if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=7 ) { -unsigned bv =xgetbv_low (0 ); -__cpuid_count (7 ,0 , a, b, c, d); -if ((bv &0x6 ) ==0x6 && (b & bit_AVX2)) { - cache |=CACHE_AVX2 ; - } -/* 0xe6: -* XCR0[7:5] = 111b (OPMASK state, upper 256-bit of ZMM0-ZMM15 -* and ZMM16-ZMM31 state are enabled by OS) -* XCR0[2:1] = 11b (XMM state and YMM state are enabled by OS) -*/ -if ((bv &0xe6 ) ==0xe6 && (b & bit_AVX512F)) { - cache |=CACHE_AVX512F ; - } - } - } - cpuid_cache = cache; -init_accel (cache); + used_accel =select_accel_cpuinfo (cpuinfo_init ()); }#endif /* CONFIG_AVX2_OPT */ bool test_buffer_is_zero_next_accel (void ) { -/* If no bits set, we just tested buffer_zero_int, and there -are no more acceleration options to test. */ -if (cpuid_cache ==0 ) { -return false; - } -/* Disable the accelerator we used before and select a new one. */ - cpuid_cache &= cpuid_cache -1 ; -init_accel (cpuid_cache); -return true; +/* +* Accumulate the accelerators that we've already tested, and +* remove them from the set to test this round. We'll get back +* a zero from select_accel_cpuinfo when there are no more. +*/ +unsigned used =select_accel_cpuinfo (cpuinfo & ~used_accel); + used_accel |= used; +return used; }static bool select_accel_fn (const void *buf,size_t len)
Signature · 1 line
2.34.1
PATCH 6/27 migration/xbzrle: Shuffle function order
In reply to Richard HendersonPlace the CONFIG_AVX512BW_OPT block at the top, which will aid function selection in the next patch.
--- migration/xbzrle.c | 244 ++++++++++++++++++++++----------------------- 1 file changed, 122 insertions(+), 122 deletions(-)
migration/xbzrle.c +122 -122
@@ -15,6 +15,128 @@#include "qemu/host-utils.h" #include "xbzrle.h" +#if defined(CONFIG_AVX512BW_OPT ) +#include <immintrin.h> + +int __attribute__((target ("avx512bw" ))) +xbzrle_encode_buffer_avx512 (uint8_t *old_buf,uint8_t *new_buf,int slen, +uint8_t *dst,int dlen) +{ +uint32_t zrun_len =0 , nzrun_len =0 ; +int d =0 , i =0 , num =0 ; +uint8_t *nzrun_start =NULL ; +/* add 1 to include residual part in main loop */ +uint32_t count512s = (slen >>6 ) +1 ; +/* countResidual is tail of data, i.e., countResidual = slen % 64 */ +uint32_t count_residual = slen &0b111111 ; +bool never_same = true; +uint64_t mask_residual =1 ; + mask_residual <<= count_residual; + mask_residual -=1 ; +__m512i r =_mm512_set1_epi32 (0 ); + +while (count512s) { +int bytes_to_check =64 ; +uint64_t mask =0xffffffffffffffff ; +if (count512s ==1 ) { + bytes_to_check = count_residual; + mask = mask_residual; + } +__m512i old_data =_mm512_mask_loadu_epi8 (r, + mask, old_buf + i); +__m512i new_data =_mm512_mask_loadu_epi8 (r, + mask, new_buf + i); +uint64_t comp =_mm512_cmpeq_epi8_mask (old_data, new_data); + count512s--; + +bool is_same = (comp &0x1 ); +while (bytes_to_check) { +if (d +2 > dlen) { +return -1 ; + } +if (is_same) { +if (nzrun_len) { + d +=uleb128_encode_small (dst + d, nzrun_len); +if (d + nzrun_len > dlen) { +return -1 ; + } + nzrun_start = new_buf + i - nzrun_len; +memcpy (dst + d, nzrun_start, nzrun_len); + d += nzrun_len; + nzrun_len =0 ; + } +/* 64 data at a time for speed */ +if (count512s && (comp ==0xffffffffffffffff )) { + i +=64 ; + zrun_len +=64 ; +break ; + } + never_same = false; + num =ctz64 (~comp); + num = (num < bytes_to_check) ? num : bytes_to_check; + zrun_len += num; + bytes_to_check -= num; + comp >>= num; + i += num; +if (bytes_to_check) { +/* still has different data after same data */ + d +=uleb128_encode_small (dst + d, zrun_len); + zrun_len =0 ; + }else { +break ; + } + } +if (never_same || zrun_len) { +/* +* never_same only acts if +* data begins with diff in first count512s +*/ + d +=uleb128_encode_small (dst + d, zrun_len); + zrun_len =0 ; + never_same = false; + } +/* has diff, 64 data at a time for speed */ +if ((bytes_to_check ==64 ) && (comp ==0x0 )) { + i +=64 ; + nzrun_len +=64 ; +break ; + } + num =ctz64 (comp); + num = (num < bytes_to_check) ? num : bytes_to_check; + nzrun_len += num; + bytes_to_check -= num; + comp >>= num; + i += num; +if (bytes_to_check) { +/* mask like 111000 */ + d +=uleb128_encode_small (dst + d, nzrun_len); +/* overflow */ +if (d + nzrun_len > dlen) { +return -1 ; + } + nzrun_start = new_buf + i - nzrun_len; +memcpy (dst + d, nzrun_start, nzrun_len); + d += nzrun_len; + nzrun_len =0 ; + is_same = true; + } + } + } + +if (nzrun_len !=0 ) { + d +=uleb128_encode_small (dst + d, nzrun_len); +/* overflow */ +if (d + nzrun_len > dlen) { +return -1 ; + } + nzrun_start = new_buf + i - nzrun_len; +memcpy (dst + d, nzrun_start, nzrun_len); + d += nzrun_len; + } +return d; +} +#endif +/* page = zrun nzrun | zrun nzrun page
@@ -175,125 +297,3 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen)return d; } - -#if defined(CONFIG_AVX512BW_OPT ) -#include <immintrin.h> - -int __attribute__((target ("avx512bw" ))) -xbzrle_encode_buffer_avx512 (uint8_t *old_buf,uint8_t *new_buf,int slen, -uint8_t *dst,int dlen) -{ -uint32_t zrun_len =0 , nzrun_len =0 ; -int d =0 , i =0 , num =0 ; -uint8_t *nzrun_start =NULL ; -/* add 1 to include residual part in main loop */ -uint32_t count512s = (slen >>6 ) +1 ; -/* countResidual is tail of data, i.e., countResidual = slen % 64 */ -uint32_t count_residual = slen &0b111111 ; -bool never_same = true; -uint64_t mask_residual =1 ; - mask_residual <<= count_residual; - mask_residual -=1 ; -__m512i r =_mm512_set1_epi32 (0 ); - -while (count512s) { -int bytes_to_check =64 ; -uint64_t mask =0xffffffffffffffff ; -if (count512s ==1 ) { - bytes_to_check = count_residual; - mask = mask_residual; - } -__m512i old_data =_mm512_mask_loadu_epi8 (r, - mask, old_buf + i); -__m512i new_data =_mm512_mask_loadu_epi8 (r, - mask, new_buf + i); -uint64_t comp =_mm512_cmpeq_epi8_mask (old_data, new_data); - count512s--; - -bool is_same = (comp &0x1 ); -while (bytes_to_check) { -if (d +2 > dlen) { -return -1 ; - } -if (is_same) { -if (nzrun_len) { - d +=uleb128_encode_small (dst + d, nzrun_len); -if (d + nzrun_len > dlen) { -return -1 ; - } - nzrun_start = new_buf + i - nzrun_len; -memcpy (dst + d, nzrun_start, nzrun_len); - d += nzrun_len; - nzrun_len =0 ; - } -/* 64 data at a time for speed */ -if (count512s && (comp ==0xffffffffffffffff )) { - i +=64 ; - zrun_len +=64 ; -break ; - } - never_same = false; - num =ctz64 (~comp); - num = (num < bytes_to_check) ? num : bytes_to_check; - zrun_len += num; - bytes_to_check -= num; - comp >>= num; - i += num; -if (bytes_to_check) { -/* still has different data after same data */ - d +=uleb128_encode_small (dst + d, zrun_len); - zrun_len =0 ; - }else { -break ; - } - } -if (never_same || zrun_len) { -/* -* never_same only acts if -* data begins with diff in first count512s -*/ - d +=uleb128_encode_small (dst + d, zrun_len); - zrun_len =0 ; - never_same = false; - } -/* has diff, 64 data at a time for speed */ -if ((bytes_to_check ==64 ) && (comp ==0x0 )) { - i +=64 ; - nzrun_len +=64 ; -break ; - } - num =ctz64 (comp); - num = (num < bytes_to_check) ? num : bytes_to_check; - nzrun_len += num; - bytes_to_check -= num; - comp >>= num; - i += num; -if (bytes_to_check) { -/* mask like 111000 */ - d +=uleb128_encode_small (dst + d, nzrun_len); -/* overflow */ -if (d + nzrun_len > dlen) { -return -1 ; - } - nzrun_start = new_buf + i - nzrun_len; -memcpy (dst + d, nzrun_start, nzrun_len); - d += nzrun_len; - nzrun_len =0 ; - is_same = true; - } - } - } - -if (nzrun_len !=0 ) { - d +=uleb128_encode_small (dst + d, nzrun_len); -/* overflow */ -if (d + nzrun_len > dlen) { -return -1 ; - } - nzrun_start = new_buf + i - nzrun_len; -memcpy (dst + d, nzrun_start, nzrun_len); - d += nzrun_len; - } -return d; -} -#endif
Signature · 1 line
2.34.1
PATCH 7/27 migration/xbzrle: Use i386 host/cpuinfo.h
In reply to Richard HendersonPerform the function selection once, and only if CONFIG_AVX512_OPT is enabled. Centralize the selection to xbzrle.c, instead of spreading the init across 3 files.
Remove xbzrle-bench.c. The benefit of being able to benchmark the different implementations is less important than not peeking into the internals of the implementation.
--- migration/xbzrle.h | 5 +- migration/ram.c | 34 +-- migration/xbzrle.c | 26 +- tests/bench/xbzrle-bench.c | 469 ------------------------------------- tests/unit/test-xbzrle.c | 49 +--- tests/bench/meson.build | 6 - 6 files changed, 39 insertions(+), 550 deletions(-) delete mode 100644 tests/bench/xbzrle-bench.c
migration/xbzrle.h +1 -4
@@ -18,8 +18,5 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, uint8_t *dst, int dlen);int xbzrle_decode_buffer (uint8_t *src,int slen,uint8_t *dst,int dlen); -#if defined(CONFIG_AVX512BW_OPT ) -int xbzrle_encode_buffer_avx512 (uint8_t *old_buf,uint8_t *new_buf,int slen, -uint8_t *dst,int dlen); -#endif +#endif
migration/ram.c +3 -31
@@ -90,34 +90,6 @@#define RAM_SAVE_FLAG_MULTIFD_FLUSH 0x200/* We can't use any flag that is bigger than 0x200 */ -int (*xbzrle_encode_buffer_func)(uint8_t *,uint8_t *,int , -uint8_t *,int ) = xbzrle_encode_buffer; -#if defined(CONFIG_AVX512BW_OPT ) -#include "qemu/cpuid.h" -static void __attribute__((constructor))init_cpu_flag (void ) -{ -unsigned max =__get_cpuid_max (0 ,NULL ); -int a, b, c, d; -if (max >=1 ) { -__cpuid (1 , a, b, c, d); -/* We must check that AVX is not just available, but usable. */ -if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=7 ) { -int bv; - __asm("xgetbv" :"=a" (bv),"=d" (d) :"c" (0 )); -__cpuid_count (7 ,0 , a, b, c, d); -/* 0xe6: -* XCR0[7:5] = 111b (OPMASK state, upper 256-bit of ZMM0-ZMM15 -* and ZMM16-ZMM31 state are enabled by OS) -* XCR0[2:1] = 11b (XMM state and YMM state are enabled by OS) -*/ -if ((bv &0xe6 ) ==0xe6 && (b & bit_AVX512BW)) { - xbzrle_encode_buffer_func = xbzrle_encode_buffer_avx512; - } - } - } -} -#endif -XBZRLECacheStats xbzrle_counters;/* used by the search for pages to send */
@@ -660,9 +632,9 @@ static int save_xbzrle_page(RAMState *rs, PageSearchStatus *pss,memcpy (XBZRLE .current_buf, *current_data,TARGET_PAGE_SIZE );/* XBZRLE encoding (if there is no overflow) */ - encoded_len =xbzrle_encode_buffer_func (prev_cached_page,XBZRLE .current_buf, -TARGET_PAGE_SIZE ,XBZRLE .encoded_buf, -TARGET_PAGE_SIZE ); + encoded_len =xbzrle_encode_buffer (prev_cached_page,XBZRLE .current_buf, +TARGET_PAGE_SIZE ,XBZRLE .encoded_buf, +TARGET_PAGE_SIZE );/* * Update the cache contents, so that it corresponds to the data
migration/xbzrle.c +25 -1
@@ -17,8 +17,9 @@#if defined(CONFIG_AVX512BW_OPT )#include <immintrin.h> +#include "host/cpuinfo.h" -int __attribute__((target ("avx512bw" ))) +static int __attribute__((target ("avx512bw" )))xbzrle_encode_buffer_avx512 (uint8_t *old_buf,uint8_t *new_buf,int slen,uint8_t *dst,int dlen) {
@@ -135,6 +136,29 @@ xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen, }return d; } + +static int xbzrle_encode_buffer_int (uint8_t *old_buf,uint8_t *new_buf, +int slen,uint8_t *dst,int dlen); + +static int (*accel_func)(uint8_t *,uint8_t *,int ,uint8_t *,int ); + +static void __attribute__((constructor))init_accel (void ) +{ +unsigned info =cpuinfo_init (); +if (info &CPUINFO_AVX512BW ) { + accel_func = xbzrle_encode_buffer_avx512; + }else { + accel_func = xbzrle_encode_buffer_int; + } +} + +int xbzrle_encode_buffer (uint8_t *old_buf,uint8_t *new_buf,int slen, +uint8_t *dst,int dlen) +{ +return accel_func (old_buf, new_buf, slen, dst, dlen); +} + +#define xbzrle_encode_buffer xbzrle_encode_buffer_int#endif /*
tests/bench/xbzrle-bench.c deleted +0 -469
469 lines not on this page · raw message
tests/unit/test-xbzrle.c +10 -39
85 lines not on this page · raw message
tests/bench/meson.build +0 -6
@@ -3,12 +3,6 @@ qht_bench = executable('qht-bench', sources: 'qht-bench.c', dependencies: [qemuutil]) -if have_system -xbzrle_bench = executable('xbzrle-bench', - sources: 'xbzrle-bench.c', - dependencies: [qemuutil,migration]) -endif - qtree_bench = executable('qtree-bench', sources: 'qtree-bench.c', dependencies: [qemuutil])
Signature · 1 line
2.34.1
PATCH 8/27 migration: Build migration_files once
In reply to Richard HendersonThe items in migration_files are built for libmigration and included info softmmu_ss from there; no need to also include them directly.
--- migration/meson.build | 1 - 1 file changed, 1 deletion(-)
migration/meson.build +0 -1
@@ -8,7 +8,6 @@ migration_files = files( 'qemu-file.c', 'yank_functions.c', ) -softmmu_ss.add(migration_files) softmmu_ss.add(files( 'block-dirty-bitmap.c',
Signature · 1 line
2.34.1
PATCH 9/27 util: Add cpuinfo-aarch64.c
In reply to Richard HendersonMove the code from tcg/. The only use of these bits so far is with respect to the atomicity of tcg operations.
--- host/include/aarch64/host/cpuinfo.h | 22 ++++++++++ tcg/aarch64/tcg-target.h | 6 ++- util/cpuinfo-aarch64.c | 67 +++++++++++++++++++++++++++++ tcg/aarch64/tcg-target.c.inc | 40 ----------------- util/meson.build | 4 +- 5 files changed, 96 insertions(+), 43 deletions(-) create mode 100644 host/include/aarch64/host/cpuinfo.h create mode 100644 util/cpuinfo-aarch64.c
host/include/aarch64/host/cpuinfo.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* Host specific cpu indentification for AArch64. +*/ + +#ifndef HOST_CPUINFO_H +#define HOST_CPUINFO_H + +#define CPUINFO_ALWAYS (1u << 0)/* so cpuinfo is nonzero */ +#define CPUINFO_LSE (1u << 1) +#define CPUINFO_LSE2 (1u << 2) + +/* Initialized with a constructor. */ +extern unsigned cpuinfo; + +/* +* We cannot rely on constructor ordering, so other constructors must +* use the function interface rather than the variable above. +*/ +unsigned cpuinfo_init (void ); + +#endif /* HOST_CPUINFO_H */
tcg/aarch64/tcg-target.h +4 -2
@@ -13,6 +13,8 @@#ifndef AARCH64_TCG_TARGET_H #define AARCH64_TCG_TARGET_H +#include "host/cpuinfo.h" +#define TCG_TARGET_INSN_UNIT_SIZE 4#define TCG_TARGET_TLB_DISPLACEMENT_BITS 24#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1)
@@ -57,8 +59,8 @@ typedef enum {#define TCG_TARGET_CALL_ARG_I128 TCG_CALL_ARG_EVEN#define TCG_TARGET_CALL_RET_I128 TCG_CALL_RET_NORMAL -extern bool have_lse; -extern bool have_lse2; +#define have_lse (cpuinfo & CPUINFO_LSE) +#define have_lse2 (cpuinfo & CPUINFO_LSE2)/* optional instructions */ #define TCG_TARGET_HAS_div_i32 1
util/cpuinfo-aarch64.c new file +67 -0
67 lines not on this page · raw message
tcg/aarch64/tcg-target.c.inc +0 -40
@@ -13,12 +13,6 @@ #include "../tcg-ldst.c.inc" #include "../tcg-pool.c.inc" #include "qemu/bitops.h" -#ifdef __linux__ -#include <asm/hwcap.h> -#endif -#ifdef CONFIG_DARWIN -#include <sys/sysctl.h> -#endif /* We're going to re-use TCGType in setting of the SF bit, which controls the size of the operation performed. If we know the values match, it
@@ -77,9 +71,6 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) return TCG_REG_X0 + slot; } -bool have_lse; -bool have_lse2; - #define TCG_REG_TMP TCG_REG_X30 #define TCG_VEC_TMP TCG_REG_V31
@@ -2878,39 +2869,8 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) } } -#ifdef CONFIG_DARWIN -static bool sysctl_for_bool(const char *name) -{ - int val = 0; - size_t len = sizeof(val); - - if (sysctlbyname(name, &val, &len, NULL, 0) == 0) { - return val != 0; - } - - /* - * We might in the future ask for properties not present in older kernels, - * but we're only asking about static properties, all of which should be - * 'int'. So we shouln't see ENOMEM (val too small), or any of the other - * more exotic errors. - */ - assert(errno == ENOENT); - return false; -} -#endif - static void tcg_target_init(TCGContext *s) { -#ifdef __linux__ - unsigned long hwcap = qemu_getauxval(AT_HWCAP); - have_lse = hwcap & HWCAP_ATOMICS; - have_lse2 = hwcap & HWCAP_USCAT; -#endif -#ifdef CONFIG_DARWIN - have_lse = sysctl_for_bool("hw.optional.arm.FEAT_LSE"); - have_lse2 = sysctl_for_bool("hw.optional.arm.FEAT_LSE2"); -#endif - tcg_target_available_regs[TCG_TYPE_I32] = 0xffffffffu; tcg_target_available_regs[TCG_TYPE_I64] = 0xffffffffu; tcg_target_available_regs[TCG_TYPE_V64] = 0xffffffff00000000ull;
util/meson.build +3 -1
@@ -109,6 +109,8 @@ if have_block util_ss.add(when: 'CONFIG_LINUX', if_true: files('vfio-helpers.c')) endif -if cpu in ['x86', 'x86_64'] +if cpu == 'aarch64' + util_ss.add(files('cpuinfo-aarch64.c')) +elif cpu in ['x86', 'x86_64'] util_ss.add(files('cpuinfo-i386.c')) endif
Signature · 1 line
2.34.1
PATCH 10/27 include/host: Split out atomic128-cas.h
In reply to Richard HendersonSeparates the aarch64-specific portion into its own file.
--- host/include/aarch64/host/atomic128-cas.h | 43 ++++++++++++++++++ host/include/generic/host/atomic128-cas.h | 43 ++++++++++++++++++ include/qemu/atomic128.h | 55 +---------------------- 3 files changed, 87 insertions(+), 54 deletions(-) create mode 100644 host/include/aarch64/host/atomic128-cas.h create mode 100644 host/include/generic/host/atomic128-cas.h
host/include/aarch64/host/atomic128-cas.h new file +43 -0
@@ -0,0 +1,43 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* Compare-and-swap for 128-bit atomic operations, generic version. +* +* Copyright (C) 2018, 2023 Linaro, Ltd. +* +* See docs/devel/atomics.rst for discussion about the guarantees each +* atomic primitive is meant to provide. +*/ + +#ifndef AARCH64_ATOMIC128_CAS_H +#define AARCH64_ATOMIC128_CAS_H + +/* Through gcc 10, aarch64 has no support for 128-bit atomics. */ +#if defined(CONFIG_ATOMIC128 ) || defined(CONFIG_CMPXCHG128 ) +#include "host/include/generic/host/atomic128-cas.h" +#else +static inline Int128 atomic16_cmpxchg (Int128 *ptr,Int128 cmp,Int128 new) +{ +uint64_t cmpl =int128_getlo (cmp), cmph =int128_gethi (cmp); +uint64_t newl =int128_getlo (new), newh =int128_gethi (new); +uint64_t oldl, oldh; +uint32_t tmp; + + asm("0: ldaxp %[oldl], %[oldh], %[mem]\n\t" +"cmp %[oldl], %[cmpl]\n\t" +"ccmp %[oldh], %[cmph], #0, eq\n\t" +"b.ne 1f\n\t" +"stlxp %w[tmp], %[newl], %[newh], %[mem]\n\t" +"cbnz %w[tmp], 0b\n" +"1:" + : [mem]"+m" (*ptr), [tmp]"=&r" (tmp), + [oldl]"=&r" (oldl), [oldh]"=&r" (oldh) + : [cmpl]"r" (cmpl), [cmph]"r" (cmph), + [newl]"r" (newl), [newh]"r" (newh) + :"memory" ,"cc" ); + +return int128_make128 (oldl, oldh); +} +# define HAVE_CMPXCHG128 1 +#endif + +#endif /* AARCH64_ATOMIC128_CAS_H */
host/include/generic/host/atomic128-cas.h new file +43 -0
43 lines not on this page · raw message
include/qemu/atomic128.h +1 -54
61 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 10/27] include/host: Split out atomic128-cas.h
Quoted 17 lines · Richard Henderson
Separates the aarch64-specific portion into its own file.
Signed-off-by Richard Henderson <[email protected]>--- host/include/aarch64/host/atomic128-cas.h | 43 ++++++++++++++++++ host/include/generic/host/atomic128-cas.h | 43 ++++++++++++++++++ include/qemu/atomic128.h | 55 +---------------------- 3 files changed, 87 insertions(+), 54 deletions(-)create mode 100644
host/include/aarch64/host/atomic128-cas.hcreate mode 100644host/include/generic/host/atomic128-cas.hhost/include/aarch64/host/atomic128-cas.h new file +0
-0
host/include/aarch64/host/atomic128-cas.h line 3
Quoted 3 lines
host/include/aarch64/host/atomic128-cas.h new file +3
-0@@ -0,0 +1,43 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* Compare-and-swap for 128-bit atomic operations, generic version.
"Aarch64 specific"
Quoted 11 lines
host/include/aarch64/host/atomic128-cas.h new file +11
-0+* +* Copyright (C) 2018, 2023 Linaro, Ltd. +* +* See docs/devel/atomics.rst for discussion about the guarantees each +* atomic primitive is meant to provide. +*/ + +#ifndef AARCH64_ATOMIC128_CAS_H +#define AARCH64_ATOMIC128_CAS_H + +/* Through gcc 10, aarch64 has no support for 128-bit atomics. */
PATCH 11/27 include/host: Split out atomic128-ldst.h
In reply to Richard HendersonSeparates the aarch64-specific portion into its own file.
--- host/include/aarch64/host/atomic128-cas.h | 2 +- host/include/aarch64/host/atomic128-ldst.h | 49 ++++++++++++++ host/include/generic/host/atomic128-ldst.h | 57 +++++++++++++++++ include/qemu/atomic128.h | 74 +--------------------- 4 files changed, 108 insertions(+), 74 deletions(-) create mode 100644 host/include/aarch64/host/atomic128-ldst.h create mode 100644 host/include/generic/host/atomic128-ldst.h
host/include/aarch64/host/atomic128-cas.h +1 -1
@@ -1,6 +1,6 @@/* * SPDX-License-Identifier: GPL-2.0-or-later -* Compare-and-swap for 128-bit atomic operations, generic version. +* Compare-and-swap for 128-bit atomic operations, aarch64 version. * * Copyright (C) 2018, 2023 Linaro, Ltd. *
host/include/aarch64/host/atomic128-ldst.h new file +49 -0
49 lines not on this page · raw message
host/include/generic/host/atomic128-ldst.h new file +57 -0
57 lines not on this page · raw message
include/qemu/atomic128.h +1 -73
79 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 12/27 meson: Fix detect atomic128 support with optimization
In reply to Richard HendersonSilly typo: sizeof(16) != 16.
--- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meson.build +1 -1
@@ -2555,7 +2555,7 @@ if has_int128 # __alignof(unsigned __int128) for the host. atomic_test_128 = ''' int main(int ac, char **av) { - unsigned __int128 *p = __builtin_assume_aligned(av[ac - 1], sizeof(16)); + unsigned __int128 *p = __builtin_assume_aligned(av[ac - 1], 16); p[1] = __atomic_load_n(&p[0], __ATOMIC_RELAXED); __atomic_store_n(&p[2], p[3], __ATOMIC_RELAXED); __atomic_compare_exchange_n(&p[4], &p[5], p[6], 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
Signature · 1 line
2.34.1
Re: [PATCH 12/27] meson: Fix detect atomic128 support with optimization
Quoted 13 lines · Richard Henderson
Silly typo: sizeof(16) != 16.
Fixes e61f1efeb730 ("meson: Detect atomic128 support with optimization")Signed-off-by Richard Henderson <[email protected]>--- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)meson.build +0
-0
meson.build if has_int128 · line 2558
Quoted 5 lines
meson.build +1
-1@@ -2555,7 +2555,7 @@ if has_int128 # __alignof(unsigned __int128) for the host. atomic_test_128 = ''' int main(int ac, char **av) { - unsigned __int128 *p = __builtin_assume_aligned(av[ac - 1], sizeof(16)); + unsigned __int128 *p = __builtin_assume_aligned(av[ac - 1], 16);
PATCH 13/27 include/qemu: Move CONFIG_ATOMIC128_OPT handling to atomic128.h
In reply to Richard HendersonNot only the routines in ldst_atomicity.c.inc need markup, but also the ones in the headers.
--- host/include/generic/host/atomic128-cas.h | 12 ++++++++---- host/include/generic/host/atomic128-ldst.h | 18 ++++++++++++------ include/qemu/atomic128.h | 17 +++++++++++++++++ accel/tcg/ldst_atomicity.c.inc | 17 ----------------- 4 files changed, 37 insertions(+), 27 deletions(-)
host/include/generic/host/atomic128-cas.h +8 -4
@@ -12,24 +12,28 @@#define HOST_ATOMIC128_CAS_H #if defined(CONFIG_ATOMIC128 ) -static inline Int128 atomic16_cmpxchg (Int128 *ptr,Int128 cmp,Int128 new) +static inline Int128 ATTRIBUTE_ATOMIC128_OPT +atomic16_cmpxchg (Int128 *ptr,Int128 cmp,Int128 new) { +__int128_t *ptr_align =__builtin_assume_aligned (ptr,16 );Int128Alias r, c, n; c.s = cmp; n.s = new; - r.i =qatomic_cmpxchg__nocheck ((__int128_t *)ptr, c.i, n.i); + r.i =qatomic_cmpxchg__nocheck (ptr_align, c.i, n.i);return r.s; }# define HAVE_CMPXCHG128 1#elif defined(CONFIG_CMPXCHG128 ) -static inline Int128 atomic16_cmpxchg (Int128 *ptr,Int128 cmp,Int128 new) +static inline Int128 ATTRIBUTE_ATOMIC128_OPT +atomic16_cmpxchg (Int128 *ptr,Int128 cmp,Int128 new) { +__int128_t *ptr_align =__builtin_assume_aligned (ptr,16 );Int128Alias r, c, n; c.s = cmp; n.s = new; - r.i =__sync_val_compare_and_swap_16 ((__int128_t *)ptr, c.i, n.i); + r.i =__sync_val_compare_and_swap_16 (ptr_align, c.i, n.i);return r.s; }# define HAVE_CMPXCHG128 1
host/include/generic/host/atomic128-ldst.h +12 -6
@@ -12,32 +12,38 @@#define HOST_ATOMIC128_LDST_H #if defined(CONFIG_ATOMIC128 ) -static inline Int128 atomic16_read (Int128 *ptr) +static inline Int128 ATTRIBUTE_ATOMIC128_OPT +atomic16_read (Int128 *ptr) { +__int128_t *ptr_align =__builtin_assume_aligned (ptr,16 );Int128Alias r; - r.i =qatomic_read__nocheck ((__int128_t *)ptr); + r.i =qatomic_read__nocheck (ptr_align);return r.s; } -static inline void atomic16_set (Int128 *ptr,Int128 val) +static inline void ATTRIBUTE_ATOMIC128_OPT +atomic16_set (Int128 *ptr,Int128 val) { +__int128_t *ptr_align =__builtin_assume_aligned (ptr,16 );Int128Alias v; v.s = val; -qatomic_set__nocheck ((__int128_t *)ptr, v.i); +qatomic_set__nocheck (ptr_align, v.i); }# define HAVE_ATOMIC128 1#elif !defined(CONFIG_USER_ONLY ) &&HAVE_CMPXCHG128 -static inline Int128 atomic16_read (Int128 *ptr) +static inline Int128 ATTRIBUTE_ATOMIC128_OPT +atomic16_read (Int128 *ptr) {/* Maybe replace 0 with 0, returning the old value. */ Int128 z =int128_make64 (0 );return atomic16_cmpxchg (ptr, z, z); } -static inline void atomic16_set (Int128 *ptr,Int128 val) +static inline void ATTRIBUTE_ATOMIC128_OPT +atomic16_set (Int128 *ptr,Int128 val) {Int128 old = *ptr, cmp; do {
include/qemu/atomic128.h +17 -0
@@ -15,6 +15,23 @@#include "qemu/int128.h" +/* +* If __alignof(unsigned __int128) < 16, GCC may refuse to inline atomics +* that are supported by the host, e.g. s390x. We can force the pointer to +* have our known alignment with __builtin_assume_aligned, however prior to +* GCC 13 that was only reliable with optimization enabled. See +* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107389 +*/ +#if defined(CONFIG_ATOMIC128_OPT ) +# if !defined(__OPTIMIZE__) +# define ATTRIBUTE_ATOMIC128_OPT __attribute__((optimize("O1"))) +# endif +# define CONFIG_ATOMIC128 +#endif +#ifndef ATTRIBUTE_ATOMIC128_OPT +# define ATTRIBUTE_ATOMIC128_OPT +#endif +/* * GCC is a house divided about supporting large atomic operations. *
accel/tcg/ldst_atomicity.c.inc +0 -17
@@ -16,23 +16,6 @@ #endif #define HAVE_al8_fast (ATOMIC_REG_SIZE >= 8) -/* - * If __alignof(unsigned __int128) < 16, GCC may refuse to inline atomics - * that are supported by the host, e.g. s390x. We can force the pointer to - * have our known alignment with __builtin_assume_aligned, however prior to - * GCC 13 that was only reliable with optimization enabled. See - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107389 - */ -#if defined(CONFIG_ATOMIC128_OPT) -# if !defined(__OPTIMIZE__) -# define ATTRIBUTE_ATOMIC128_OPT __attribute__((optimize("O1"))) -# endif -# define CONFIG_ATOMIC128 -#endif -#ifndef ATTRIBUTE_ATOMIC128_OPT -# define ATTRIBUTE_ATOMIC128_OPT -#endif - #if defined(CONFIG_ATOMIC128) # define HAVE_al16_fast true #else
Signature · 1 line
2.34.1
PATCH 14/27 target/ppc: Use tcg_gen_qemu_{ld, st}_i128 for LQARX, LQ, STQ
In reply to Richard HendersonNo need to roll our own, as this is now provided by tcg. This was the last use of retxl, so remove that too.
---
Cc: [email protected]
Cc: Daniel Henrique Barboza <[email protected]>
Cc: "Cédric Le Goater" <[email protected]>
Cc: David Gibson <[email protected]>
Cc: Greg Kurz <[email protected]>
--- target/ppc/cpu.h | 1 - target/ppc/helper.h | 9 ---- target/ppc/mem_helper.c | 48 -------------------- target/ppc/translate.c | 34 ++------------- target/ppc/translate/fixedpoint-impl.c.inc | 51 +++------------------- 5 files changed, 11 insertions(+), 132 deletions(-)
target/ppc/cpu.h +0 -1
@@ -1124,7 +1124,6 @@ struct CPUArchState {/* used to speed-up TLB assist handlers */ target_ulong nip;/* next instruction pointer */ -uint64_t retxh;/* high part of 128-bit helper return */ /* when a memory exception occurs, the access type is stored here */ int access_type;
target/ppc/helper.h +0 -9
@@ -810,12 +810,3 @@ DEF_HELPER_4(DSCLIQ, void, env, fprp, fprp, i32) DEF_HELPER_1(tbegin, void, env)DEF_HELPER_FLAGS_1 (fixup_thrm,TCG_CALL_NO_RWG , void, env) - -#ifdef TARGET_PPC64 -DEF_HELPER_FLAGS_3(lq_le_parallel, TCG_CALL_NO_WG, i64, env, tl, i32) -DEF_HELPER_FLAGS_3(lq_be_parallel, TCG_CALL_NO_WG, i64, env, tl, i32) -DEF_HELPER_FLAGS_5 (stq_le_parallel,TCG_CALL_NO_WG , - void, env, tl, i64, i64, i32) -DEF_HELPER_FLAGS_5 (stq_be_parallel,TCG_CALL_NO_WG , - void, env, tl, i64, i64, i32) -#endif
target/ppc/mem_helper.c +0 -48
54 lines not on this page · raw message
target/ppc/translate.c +4 -30
@@ -3757,6 +3757,7 @@ static void gen_lqarx(DisasContext *ctx) {int rd =rD (ctx->opcode);TCGv EA , hi, lo; +TCGv_i128 t16;if (unlikely ((rd &1 ) || (rd ==rA (ctx->opcode)) || (rd ==rB (ctx->opcode)))) {
@@ -3772,36 +3773,9 @@ static void gen_lqarx(DisasContext *ctx) lo = cpu_gpr[rd +1 ]; hi = cpu_gpr[rd]; -if (tb_cflags (ctx->base.tb) &CF_PARALLEL ) { -if (HAVE_ATOMIC128 ) { -TCGv_i32 oi =tcg_temp_new_i32 (); -if (ctx->le_mode) { -tcg_gen_movi_i32 (oi,make_memop_idx (MO_LE |MO_128 |MO_ALIGN , - ctx->mem_idx)); -gen_helper_lq_le_parallel (lo, cpu_env,EA , oi); - }else { -tcg_gen_movi_i32 (oi,make_memop_idx (MO_BE |MO_128 |MO_ALIGN , - ctx->mem_idx)); -gen_helper_lq_be_parallel (lo, cpu_env,EA , oi); - } -tcg_gen_ld_i64 (hi, cpu_env, offsetof(CPUPPCState , retxh)); - }else { -/* Restart with exclusive lock. */ -gen_helper_exit_atomic (cpu_env); - ctx->base.is_jmp =DISAS_NORETURN ; -return ; - } - }else if (ctx->le_mode) { -tcg_gen_qemu_ld_i64 (lo,EA , ctx->mem_idx,MO_LEUQ |MO_ALIGN_16 ); -tcg_gen_mov_tl (cpu_reserve,EA ); -gen_addr_add (ctx,EA ,EA ,8 ); -tcg_gen_qemu_ld_i64 (hi,EA , ctx->mem_idx,MO_LEUQ ); - }else { -tcg_gen_qemu_ld_i64 (hi,EA , ctx->mem_idx,MO_BEUQ |MO_ALIGN_16 ); -tcg_gen_mov_tl (cpu_reserve,EA ); -gen_addr_add (ctx,EA ,EA ,8 ); -tcg_gen_qemu_ld_i64 (lo,EA , ctx->mem_idx,MO_BEUQ ); - } + t16 =tcg_temp_new_i128 (); +tcg_gen_qemu_ld_i128 (t16,EA , ctx->mem_idx,DEF_MEMOP (MO_128 |MO_ALIGN )); +tcg_gen_extr_i128_i64 (lo, hi, t16);tcg_gen_st_tl (hi, cpu_env, offsetof(CPUPPCState , reserve_val));tcg_gen_st_tl (lo, cpu_env, offsetof(CPUPPCState , reserve_val2));
target/ppc/translate/fixedpoint-impl.c.inc +7 -44
65 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 15/27 target/s390x: Use tcg_gen_qemu_{ld, st}_i128 for LPQ, STPQ
In reply to Richard HendersonNo need to roll our own, as this is now provided by tcg. This was the last use of retxl, so remove that too.
---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>
--- target/s390x/cpu.h | 3 -- target/s390x/helper.h | 4 --- target/s390x/tcg/mem_helper.c | 61 -------------------------------- target/s390x/tcg/translate.c | 30 +++++----------- target/s390x/tcg/insn-data.h.inc | 2 +- 5 files changed, 9 insertions(+), 91 deletions(-)
target/s390x/cpu.h +0 -3
@@ -76,9 +76,6 @@ struct CPUArchState {float_status fpu_status;/* passed to softfloat lib */ -/* The low part of a 128-bit return, or remainder of a divide. */ -uint64_t retxl; -PSW psw;S390CrashReason crash_reason;
target/s390x/helper.h +0 -4
@@ -108,10 +108,6 @@ DEF_HELPER_FLAGS_2(sfas, TCG_CALL_NO_WG, void, env, i64) DEF_HELPER_FLAGS_2(srnm, TCG_CALL_NO_WG, void, env, i64) DEF_HELPER_FLAGS_1(popcnt, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_2(stfle, i32, env, i64) -DEF_HELPER_FLAGS_2(lpq, TCG_CALL_NO_WG, i64, env, i64) -DEF_HELPER_FLAGS_2(lpq_parallel, TCG_CALL_NO_WG, i64, env, i64) -DEF_HELPER_FLAGS_4(stpq, TCG_CALL_NO_WG, void, env, i64, i64, i64) -DEF_HELPER_FLAGS_4(stpq_parallel, TCG_CALL_NO_WG, void, env, i64, i64, i64) DEF_HELPER_4(mvcos, i32, env, i64, i64, i64) DEF_HELPER_4(cu12, i32, env, i32, i32, i32)DEF_HELPER_4 (cu14, i32, env, i32, i32, i32)
target/s390x/tcg/mem_helper.c +0 -61
67 lines not on this page · raw message
target/s390x/tcg/translate.c +8 -22
@@ -335,11 +335,6 @@ static void store_freg32_i64(int reg, TCGv_i64 v)tcg_gen_st32_i64 (v, cpu_env,freg32_offset (reg)); } -static void return_low128 (TCGv_i64 dest) -{ -tcg_gen_ld_i64 (dest, cpu_env, offsetof(CPUS390XState , retxl)); -} -static void update_psw_addr (DisasContext *s) {/* psw.addr */
@@ -3130,15 +3125,9 @@ static DisasJumpType op_lpd(DisasContext *s, DisasOps *o)static DisasJumpType op_lpq (DisasContext *s,DisasOps *o) { -if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { -gen_helper_lpq (o->out, cpu_env, o->in2); - }else if (HAVE_ATOMIC128 ) { -gen_helper_lpq_parallel (o->out, cpu_env, o->in2); - }else { -gen_helper_exit_atomic (cpu_env); -return DISAS_NORETURN ; - } -return_low128 (o->out2); + o->out_128 =tcg_temp_new_i128 (); +tcg_gen_qemu_ld_i128 (o->out_128, o->in2,get_mem_index (s), +MO_TE |MO_128 |MO_ALIGN );return DISAS_NEXT ; }
@@ -4533,14 +4522,11 @@ static DisasJumpType op_stmh(DisasContext *s, DisasOps *o)static DisasJumpType op_stpq (DisasContext *s,DisasOps *o) { -if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { -gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); - }else if (HAVE_ATOMIC128 ) { -gen_helper_stpq_parallel (cpu_env, o->in2, o->out2, o->out); - }else { -gen_helper_exit_atomic (cpu_env); -return DISAS_NORETURN ; - } +TCGv_i128 t16 =tcg_temp_new_i128 (); + +tcg_gen_concat_i64_i128 (t16, o->out2, o->out); +tcg_gen_qemu_st_i128 (t16, o->in2,get_mem_index (s), +MO_TE |MO_128 |MO_ALIGN );return DISAS_NEXT ; }
target/s390x/tcg/insn-data.h.inc +1 -1
@@ -570,7 +570,7 @@ D(0xc804, LPD, SSF, ILA, 0, 0, new_P, r3_P32, lpd, 0, MO_TEUL) D(0xc805, LPDG, SSF, ILA, 0, 0, new_P, r3_P64, lpd, 0, MO_TEUQ) /* LOAD PAIR FROM QUADWORD */ - C(0xe38f, LPQ, RXY_a, Z, 0, a2, r1_P, 0, lpq, 0) + C(0xe38f, LPQ, RXY_a, Z, 0, a2, 0, r1_D64, lpq, 0) /* LOAD POSITIVE */ C(0x1000, LPR, RR_a, Z, 0, r2_32s, new, r1_32, abs, abs32) C(0xb900, LPGR, RRE, Z, 0, r2, r1, 0, abs, abs64)
Signature · 1 line
2.34.1
Re: [PATCH 15/27] target/s390x: Use tcg_gen_qemu_{ld,st}_i128 for LPQ, STPQ
Quoted 2 lines · Richard Henderson
No need to roll our own, as this is now provided by tcg. This was the last use of retxl, so remove that too.
That's nice!
Quoted 7 lines
Signed-off-by Richard Henderson <[email protected]>---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>
---
[...]
Quoted 27 lines
/* psw.addr */target/s390x/tcg/translate.c +3
-12@@ -3130,15 +3125,9 @@ static DisasJumpType op_lpd(DisasContext *s, DisasOps *o)static DisasJumpType op_lpq (DisasContext *s,DisasOps *o) { -if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { -gen_helper_lpq (o->out, cpu_env, o->in2); - }else if (HAVE_ATOMIC128 ) { -gen_helper_lpq_parallel (o->out, cpu_env, o->in2); - }else { -gen_helper_exit_atomic (cpu_env); -return DISAS_NORETURN ; - } -return_low128 (o->out2); + o->out_128 =tcg_temp_new_i128 (); +tcg_gen_qemu_ld_i128 (o->out_128, o->in2,get_mem_index (s), +MO_TE |MO_128 |MO_ALIGN );return DISAS_NEXT ; }@@ -4533,14 +4522,11 @@ static DisasJumpType op_stmh(DisasContext *s, DisasOps *o)static DisasJumpType op_stpq (DisasContext *s,DisasOps *o) { -if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { -gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); - }else if (HAVE_ATOMIC128 ) {
target/s390x/tcg/translate.c static DisasJumpType op_stmh(DisasContext *s, DisasOps *o) · line 4529
Quoted 10 lines
target/s390x/tcg/translate.c +5
-5-gen_helper_stpq_parallel (cpu_env, o->in2, o->out2, o->out); - }else { -gen_helper_exit_atomic (cpu_env); -return DISAS_NORETURN ; - } +TCGv_i128 t16 =tcg_temp_new_i128 (); + +tcg_gen_concat_i64_i128 (t16, o->out2, o->out); +tcg_gen_qemu_st_i128 (t16, o->in2,get_mem_index (s), +MO_TE |MO_128 |MO_ALIGN );
I briefly glimpsed at tcg_gen_qemu_ld_i128_int (and use_two_i64_for_i128()), does this really provide the atomic guarantees we need in all cases?
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 15/27] target/s390x: Use tcg_gen_qemu_{ld,st}_i128 for LPQ, STPQ
Quoted 10 lines · David Hildenbrand
Quoted 10 lines
target/s390x/tcg/translate.c +0
-7@@ -4533,14 +4522,11 @@ static DisasJumpType op_stmh(DisasContext *s, DisasOps *o) static DisasJumpType op_stpq(DisasContext *s, DisasOps *o) { - if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) { - gen_helper_stpq(cpu_env, o->in2, o->out2, o->out); - } else if (HAVE_ATOMIC128) { - gen_helper_stpq_parallel(cpu_env, o->in2, o->out2, o->out); - } else { - gen_helper_exit_atomic(cpu_env); - return DISAS_NORETURN;
Quoted 8 lines
target/s390x/tcg/translate.c static DisasJumpType op_stmh(DisasContext *s, DisasOps *o) · line 4529
Quoted 6 lines
target/s390x/tcg/translate.c +5
-1- } + TCGv_i128 t16 = tcg_temp_new_i128(); + + tcg_gen_concat_i64_i128(t16, o->out2, o->out); + tcg_gen_qemu_st_i128(t16, o->in2, get_mem_index(s), + MO_TE | MO_128 | MO_ALIGN);I briefly glimpsed at
tcg_gen_qemu_ld_i128_int(anduse_two_i64_for_i128()), does this really provide the atomic guarantees we need in all cases?
Yes. The CF_PARALLEL check is the same as the one removed above.
r~
PATCH 16/27 accel/tcg: Unify cpu_{ld,st}*_{be,le}_mmu
In reply to Richard HendersonWith the current structure of cputlb.c, there is no difference between the little-endian and big-endian entry points, aside from the assert. Unify the pairs of functions.
The only use of the functions with explicit endianness was in target/sparc64, and that was only to satisfy the assert.
--- include/exec/cpu_ldst.h | 58 ++----- accel/tcg/cputlb.c | 122 +++----------- accel/tcg/user-exec.c | 322 ++++++++++-------------------------- target/arm/tcg/m_helper.c | 4 +- target/sparc/ldst_helper.c | 18 +- accel/tcg/ldst_common.c.inc | 24 +-- 6 files changed, 137 insertions(+), 411 deletions(-)
include/exec/cpu_ldst.h +12 -46
@@ -207,43 +207,21 @@ void cpu_stq_le_mmuidx_ra(CPUArchState *env, abi_ptr ptr, uint64_t val, int mmu_idx, uintptr_t ra);uint8_t cpu_ldb_mmu (CPUArchState *env,abi_ptr ptr,MemOpIdx oi,uintptr_t ra); -uint16_t cpu_ldw_be_mmu (CPUArchState *env,abi_ptr ptr, -MemOpIdx oi,uintptr_t ra); -uint32_t cpu_ldl_be_mmu (CPUArchState *env,abi_ptr ptr, -MemOpIdx oi,uintptr_t ra); -uint64_t cpu_ldq_be_mmu (CPUArchState *env,abi_ptr ptr, -MemOpIdx oi,uintptr_t ra); -uint16_t cpu_ldw_le_mmu (CPUArchState *env,abi_ptr ptr, -MemOpIdx oi,uintptr_t ra); -uint32_t cpu_ldl_le_mmu (CPUArchState *env,abi_ptr ptr, -MemOpIdx oi,uintptr_t ra); -uint64_t cpu_ldq_le_mmu (CPUArchState *env,abi_ptr ptr, -MemOpIdx oi,uintptr_t ra); - -Int128 cpu_ld16_be_mmu (CPUArchState *env,abi_ptr addr, -MemOpIdx oi,uintptr_t ra); -Int128 cpu_ld16_le_mmu (CPUArchState *env,abi_ptr addr, -MemOpIdx oi,uintptr_t ra); +uint16_t cpu_ldw_mmu (CPUArchState *env,abi_ptr ptr,MemOpIdx oi,uintptr_t ra); +uint32_t cpu_ldl_mmu (CPUArchState *env,abi_ptr ptr,MemOpIdx oi,uintptr_t ra); +uint64_t cpu_ldq_mmu (CPUArchState *env,abi_ptr ptr,MemOpIdx oi,uintptr_t ra); +Int128 cpu_ld16_mmu (CPUArchState *env,abi_ptr addr,MemOpIdx oi,uintptr_t ra);void cpu_stb_mmu (CPUArchState *env,abi_ptr ptr,uint8_t val,MemOpIdx oi,uintptr_t ra); -void cpu_stw_be_mmu (CPUArchState *env,abi_ptr ptr,uint16_t val, -MemOpIdx oi,uintptr_t ra); -void cpu_stl_be_mmu (CPUArchState *env,abi_ptr ptr,uint32_t val, -MemOpIdx oi,uintptr_t ra); -void cpu_stq_be_mmu (CPUArchState *env,abi_ptr ptr,uint64_t val, -MemOpIdx oi,uintptr_t ra); -void cpu_stw_le_mmu (CPUArchState *env,abi_ptr ptr,uint16_t val, -MemOpIdx oi,uintptr_t ra); -void cpu_stl_le_mmu (CPUArchState *env,abi_ptr ptr,uint32_t val, -MemOpIdx oi,uintptr_t ra); -void cpu_stq_le_mmu (CPUArchState *env,abi_ptr ptr,uint64_t val, -MemOpIdx oi,uintptr_t ra); - -void cpu_st16_be_mmu (CPUArchState *env,abi_ptr addr,Int128 val, -MemOpIdx oi,uintptr_t ra); -void cpu_st16_le_mmu (CPUArchState *env,abi_ptr addr,Int128 val, -MemOpIdx oi,uintptr_t ra); +void cpu_stw_mmu (CPUArchState *env,abi_ptr ptr,uint16_t val, +MemOpIdx oi,uintptr_t ra); +void cpu_stl_mmu (CPUArchState *env,abi_ptr ptr,uint32_t val, +MemOpIdx oi,uintptr_t ra); +void cpu_stq_mmu (CPUArchState *env,abi_ptr ptr,uint64_t val, +MemOpIdx oi,uintptr_t ra); +void cpu_st16_mmu (CPUArchState *env,abi_ptr addr,Int128 val, +MemOpIdx oi,uintptr_t ra); uint32_t cpu_atomic_cmpxchgb_mmu(CPUArchState *env, target_ulong addr, uint32_t cmpv, uint32_t newv,
@@ -416,9 +394,6 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,# define cpu_ldsw_mmuidx_ra cpu_ldsw_be_mmuidx_ra# define cpu_ldl_mmuidx_ra cpu_ldl_be_mmuidx_ra# define cpu_ldq_mmuidx_ra cpu_ldq_be_mmuidx_ra -# define cpu_ldw_mmu cpu_ldw_be_mmu -# define cpu_ldl_mmu cpu_ldl_be_mmu -# define cpu_ldq_mmu cpu_ldq_be_mmu# define cpu_stw_data cpu_stw_be_data# define cpu_stl_data cpu_stl_be_data# define cpu_stq_data cpu_stq_be_data
@@ -428,9 +403,6 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,# define cpu_stw_mmuidx_ra cpu_stw_be_mmuidx_ra# define cpu_stl_mmuidx_ra cpu_stl_be_mmuidx_ra# define cpu_stq_mmuidx_ra cpu_stq_be_mmuidx_ra -# define cpu_stw_mmu cpu_stw_be_mmu -# define cpu_stl_mmu cpu_stl_be_mmu -# define cpu_stq_mmu cpu_stq_be_mmu#else # define cpu_lduw_data cpu_lduw_le_data# define cpu_ldsw_data cpu_ldsw_le_data
@@ -444,9 +416,6 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,# define cpu_ldsw_mmuidx_ra cpu_ldsw_le_mmuidx_ra# define cpu_ldl_mmuidx_ra cpu_ldl_le_mmuidx_ra# define cpu_ldq_mmuidx_ra cpu_ldq_le_mmuidx_ra -# define cpu_ldw_mmu cpu_ldw_le_mmu -# define cpu_ldl_mmu cpu_ldl_le_mmu -# define cpu_ldq_mmu cpu_ldq_le_mmu# define cpu_stw_data cpu_stw_le_data# define cpu_stl_data cpu_stl_le_data# define cpu_stq_data cpu_stq_le_data
@@ -456,9 +425,6 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,# define cpu_stw_mmuidx_ra cpu_stw_le_mmuidx_ra# define cpu_stl_mmuidx_ra cpu_stl_le_mmuidx_ra# define cpu_stq_mmuidx_ra cpu_stq_le_mmuidx_ra -# define cpu_stw_mmu cpu_stw_le_mmu -# define cpu_stl_mmu cpu_stl_le_mmu -# define cpu_stq_mmu cpu_stq_le_mmu#endif uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr,
accel/tcg/cputlb.c +23 -99
178 lines not on this page · raw message
accel/tcg/user-exec.c +85 -237
486 lines not on this page · raw message
target/arm/tcg/m_helper.c +2 -2
@@ -1937,8 +1937,8 @@ static bool do_v7m_function_return(ARMCPU *cpu)*/ mmu_idx =arm_v7m_mmu_idx_for_secstate (env, true); oi =make_memop_idx (MO_LEUL ,arm_to_core_mmu_idx (mmu_idx)); - newpc =cpu_ldl_le_mmu (env, frameptr, oi,0 ); - newpsr =cpu_ldl_le_mmu (env, frameptr +4 , oi,0 ); + newpc =cpu_ldl_mmu (env, frameptr, oi,0 ); + newpsr =cpu_ldl_mmu (env, frameptr +4 , oi,0 );/* Consistency checks on new IPSR */ newpsr_exc = newpsr &XPSR_EXCP ;
target/sparc/ldst_helper.c +3 -15
@@ -1334,25 +1334,13 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, ret =cpu_ldb_mmu (env, addr, oi,GETPC ());break ;case 2 : -if (asi &8 ) { - ret =cpu_ldw_le_mmu (env, addr, oi,GETPC ()); - }else { - ret =cpu_ldw_be_mmu (env, addr, oi,GETPC ()); - } + ret =cpu_ldw_mmu (env, addr, oi,GETPC ());break ;case 4 : -if (asi &8 ) { - ret =cpu_ldl_le_mmu (env, addr, oi,GETPC ()); - }else { - ret =cpu_ldl_be_mmu (env, addr, oi,GETPC ()); - } + ret =cpu_ldl_mmu (env, addr, oi,GETPC ());break ;case 8 : -if (asi &8 ) { - ret =cpu_ldq_le_mmu (env, addr, oi,GETPC ()); - }else { - ret =cpu_ldq_be_mmu (env, addr, oi,GETPC ()); - } + ret =cpu_ldq_mmu (env, addr, oi,GETPC ());break ;default :g_assert_not_reached ();
accel/tcg/ldst_common.c.inc +12 -12
@@ -26,7 +26,7 @@ uint32_t cpu_lduw_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_BEUW | MO_UNALN, mmu_idx); - return cpu_ldw_be_mmu(env, addr, oi, ra); + return cpu_ldw_mmu(env, addr, oi, ra); } int cpu_ldsw_be_mmuidx_ra(CPUArchState *env, abi_ptr addr,
@@ -39,21 +39,21 @@ uint32_t cpu_ldl_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_BEUL | MO_UNALN, mmu_idx); - return cpu_ldl_be_mmu(env, addr, oi, ra); + return cpu_ldl_mmu(env, addr, oi, ra); } uint64_t cpu_ldq_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_BEUQ | MO_UNALN, mmu_idx); - return cpu_ldq_be_mmu(env, addr, oi, ra); + return cpu_ldq_mmu(env, addr, oi, ra); } uint32_t cpu_lduw_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_LEUW | MO_UNALN, mmu_idx); - return cpu_ldw_le_mmu(env, addr, oi, ra); + return cpu_ldw_mmu(env, addr, oi, ra); } int cpu_ldsw_le_mmuidx_ra(CPUArchState *env, abi_ptr addr,
@@ -66,14 +66,14 @@ uint32_t cpu_ldl_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_LEUL | MO_UNALN, mmu_idx); - return cpu_ldl_le_mmu(env, addr, oi, ra); + return cpu_ldl_mmu(env, addr, oi, ra); } uint64_t cpu_ldq_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_LEUQ | MO_UNALN, mmu_idx); - return cpu_ldq_le_mmu(env, addr, oi, ra); + return cpu_ldq_mmu(env, addr, oi, ra); } void cpu_stb_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val,
@@ -87,42 +87,42 @@ void cpu_stw_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_BEUW | MO_UNALN, mmu_idx); - cpu_stw_be_mmu(env, addr, val, oi, ra); + cpu_stw_mmu(env, addr, val, oi, ra); } void cpu_stl_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_BEUL | MO_UNALN, mmu_idx); - cpu_stl_be_mmu(env, addr, val, oi, ra); + cpu_stl_mmu(env, addr, val, oi, ra); } void cpu_stq_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint64_t val, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_BEUQ | MO_UNALN, mmu_idx); - cpu_stq_be_mmu(env, addr, val, oi, ra); + cpu_stq_mmu(env, addr, val, oi, ra); } void cpu_stw_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_LEUW | MO_UNALN, mmu_idx); - cpu_stw_le_mmu(env, addr, val, oi, ra); + cpu_stw_mmu(env, addr, val, oi, ra); } void cpu_stl_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_LEUL | MO_UNALN, mmu_idx); - cpu_stl_le_mmu(env, addr, val, oi, ra); + cpu_stl_mmu(env, addr, val, oi, ra); } void cpu_stq_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint64_t val, int mmu_idx, uintptr_t ra) { MemOpIdx oi = make_memop_idx(MO_LEUQ | MO_UNALN, mmu_idx); - cpu_stq_le_mmu(env, addr, val, oi, ra); + cpu_stq_mmu(env, addr, val, oi, ra); } /*--------------------------*/
Signature · 1 line
2.34.1
Re: [PATCH 16/27] accel/tcg: Unify cpu_{ld,st}*_{be,le}_mmu
Hi Richard,
Quoted 6 lines · Richard Henderson
With the current structure of
cputlb.c, there is no difference between the little-endian and big-endian entry points, aside from the assert. Unify the pairs of functions.The only use of the functions with explicit endianness was in target/sparc64, and that was only to satisfy the assert.
I'm having hard time to follow all the handling of the various ASI definitions from target/sparc/asi.h. ...
target/sparc/ldst_helper.c uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
Quoted 16 lines
Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu_ldst.h | 58 ++----- accel/tcg/cputlb.c | 122 +++----------- accel/tcg/user-exec.c | 322 ++++++++++-------------------------- target/arm/tcg/m_helper.c | 4 +- target/sparc/ldst_helper.c | 18 +- accel/tcg/ldst_common.c.inc | 24 +-- 6 files changed, 137 insertions(+), 411 deletions(-)target/sparc/ldst_helper.c +0
-0@@ -1334,25 +1334,13 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
Shouldn't we propagate the ASI endianness?
...
+ memop |= (asi & 8) ? MO_LE : MO_BE;
oi = make_memop_idx(memop, idx);
switch (size) {
case 1:Quoted 18 lines
target/sparc/ldst_helper.c +2
-10ret =cpu_ldb_mmu (env, addr, oi,GETPC ());break ;case 2 : -if (asi &8 ) { - ret =cpu_ldw_le_mmu (env, addr, oi,GETPC ()); - }else { - ret =cpu_ldw_be_mmu (env, addr, oi,GETPC ()); - } + ret =cpu_ldw_mmu (env, addr, oi,GETPC ());break ;case 4 : -if (asi &8 ) { - ret =cpu_ldl_le_mmu (env, addr, oi,GETPC ()); - }else { - ret =cpu_ldl_be_mmu (env, addr, oi,GETPC ()); - } + ret =cpu_ldl_mmu (env, addr, oi,GETPC ());break ;
target/sparc/ldst_helper.c uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, · line 1346
Quoted 10 lines
target/sparc/ldst_helper.c +1
-5case 8 : -if (asi &8 ) { - ret =cpu_ldq_le_mmu (env, addr, oi,GETPC ()); - }else { - ret =cpu_ldq_be_mmu (env, addr, oi,GETPC ()); - } + ret =cpu_ldq_mmu (env, addr, oi,GETPC ());break ;default :g_assert_not_reached ();
Otherwise great simplification!
Re: [PATCH 16/27] accel/tcg: Unify cpu_{ld,st}*_{be,le}_mmu
Quoted 24 lines · Philippe Mathieu-Daudé
Hi Richard,
Quoted 6 lines · Richard Henderson
With the current structure of
cputlb.c, there is no difference between the little-endian and big-endian entry points, aside from the assert. Unify the pairs of functions.The only use of the functions with explicit endianness was in target/sparc64, and that was only to satisfy the assert.
I'm having hard time to follow all the handling of the various ASI definitions from
target/sparc/asi.h. ...Quoted 9 lines
Signed-off-by Richard Henderson <[email protected]>---
include/exec/cpu_ldst.h | 58 ++----- accel/tcg/cputlb.c | 122 +++----------- accel/tcg/user-exec.c | 322 ++++++++++-------------------------- target/arm/tcg/m_helper.c | 4 +- target/sparc/ldst_helper.c | 18 +- accel/tcg/ldst_common.c.inc | 24 +--6 files changed, 137 insertions(+), 411 deletions(-)
Quoted 8 lines
target/sparc/ldst_helper.c uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
Quoted 5 lines
target/sparc/ldst_helper.c +0
-0@@ -1334,25 +1334,13 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,Shouldn't we propagate the ASI endianness?
Already done in translate, get_asi():
/* The little-endian asis all have bit 3 set. */
if (asi & 8) {
memop ^= MO_BSWAP;
}r~
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 16/27] accel/tcg: Unify cpu_{ld,st}*_{be,le}_mmu
Quoted 35 lines · Richard Henderson
Quoted 24 lines · Philippe Mathieu-Daudé
Hi Richard,
Quoted 6 lines · Richard Henderson
With the current structure of
cputlb.c, there is no difference between the little-endian and big-endian entry points, aside from the assert. Unify the pairs of functions.The only use of the functions with explicit endianness was in target/sparc64, and that was only to satisfy the assert.
I'm having hard time to follow all the handling of the various ASI definitions from
target/sparc/asi.h. ...Quoted 9 lines
Signed-off-by Richard Henderson <[email protected]>---
include/exec/cpu_ldst.h | 58 ++----- accel/tcg/cputlb.c | 122 +++----------- accel/tcg/user-exec.c | 322 ++++++++++-------------------------- target/arm/tcg/m_helper.c | 4 +- target/sparc/ldst_helper.c | 18 +- accel/tcg/ldst_common.c.inc | 24 +--6 files changed, 137 insertions(+), 411 deletions(-)Quoted 9 lines
target/sparc/ldst_helper.c uint64_t helper_ld_asi(CPUSPARCState *env, · line 1334
Quoted 6 lines
target/sparc/ldst_helper.c +0
-0@@ -1334,25 +1334,13 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,Shouldn't we propagate the ASI endianness?
Quoted 6 lines
Already done in translate,
get_asi():/* The little-endian asis all have bit 3 set. */ if (asi & 8) {
memop ^=MO_BSWAP;
}
Just in front of my eyes 🤦♂️ So:
Maybe amend the commit description "The ASI endianness is already taken care of in get_asi() ..."?
While looking at get_asi(), ASI_FL16_* cases overwrite 'memop', possibly discarding MO_ALIGN bit. Maybe this can't happen.
Re: [PATCH 16/27] accel/tcg: Unify cpu_{ld,st}*_{be,le}_mmu
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 34 lines · Richard Henderson
Quoted 24 lines · Philippe Mathieu-Daudé
Hi Richard,
Quoted 6 lines · Richard Henderson
With the current structure of
cputlb.c, there is no difference between the little-endian and big-endian entry points, aside from the assert. Unify the pairs of functions.The only use of the functions with explicit endianness was in target/sparc64, and that was only to satisfy the assert.
I'm having hard time to follow all the handling of the various ASI definitions from
target/sparc/asi.h. ...Quoted 9 lines
Signed-off-by Richard Henderson <[email protected]>---
include/exec/cpu_ldst.h | 58 ++----- accel/tcg/cputlb.c | 122 +++----------- accel/tcg/user-exec.c | 322 ++++++++++-------------------------- target/arm/tcg/m_helper.c | 4 +- target/sparc/ldst_helper.c | 18 +- accel/tcg/ldst_common.c.inc | 24 +--6 files changed, 137 insertions(+), 411 deletions(-)Quoted 8 lines
target/sparc/ldst_helper.c uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
Quoted 5 lines
target/sparc/ldst_helper.c +0
-0@@ -1334,25 +1334,13 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,Shouldn't we propagate the ASI endianness?
Quoted 6 lines
Already done in translate,
get_asi():/* The little-endian asis all have bit 3 set. */ if (asi & 8) {
memop ^=MO_BSWAP;
}
Quoted 6 lines
Just in front of my eyes 🤦♂️ So:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Maybe amend the commit description "The ASI endianness is already taken care of in
get_asi()..."?
That's what I was trying to say with "only there to satisfy the assert". I have expanded on that a bit.
Quoted 3 lines
While looking at
get_asi(), ASI_FL16_* cases overwrite 'memop', possibly discardingMO_ALIGNbit. Maybe this can't happen.
Ah, that does look like a bug in one of my recent conversions.
r~
PATCH 17/27 target/s390x: Use cpu_{ld,st}*_mmu in do_csst
In reply to Richard HendersonUse cpu_ld16_mmu and cpu_st16_mmu to eliminate the special case, and change all of the *_data_ra functions to match.
---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>
--- target/s390x/tcg/mem_helper.c | 65 ++++++++++++++--------------------- 1 file changed, 26 insertions(+), 39 deletions(-)
target/s390x/tcg/mem_helper.c +26 -39
@@ -1737,6 +1737,9 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, uint64_t a2, bool parallel) { uint32_t mem_idx = cpu_mmu_index(env, false); +MemOpIdx oi16 =make_memop_idx (MO_TE |MO_128 , mem_idx); +MemOpIdx oi8 =make_memop_idx (MO_TE |MO_64 , mem_idx); +MemOpIdx oi4 =make_memop_idx (MO_TE |MO_32 , mem_idx);uintptr_t ra =GETPC ();uint32_t fc =extract32 (env->regs[0 ],0 ,8 );uint32_t sc =extract32 (env->regs[0 ],8 ,8 );
@@ -1780,15 +1783,17 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, } } -/* All loads happen before all stores. For simplicity, load the entire -store value area from the parameter list. */ - svh =cpu_ldq_data_ra (env, pl +16 , ra); - svl =cpu_ldq_data_ra (env, pl +24 , ra); +/* +* All loads happen before all stores. For simplicity, load the entire +* store value area from the parameter list. +*/ + svh =cpu_ldq_mmu (env, pl +16 , oi8, ra); + svl =cpu_ldq_mmu (env, pl +24 , oi8, ra);switch (fc) {case 0 : { -uint32_t nv =cpu_ldl_data_ra (env, pl, ra); +uint32_t nv =cpu_ldl_mmu (env, pl, oi4, ra);uint32_t cv = env->regs[r3];uint32_t ov;
@@ -1801,8 +1806,8 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, ov =cpu_atomic_cmpxchgl_be_mmu (env, a1, cv, nv, oi, ra);#endif }else { - ov =cpu_ldl_data_ra (env, a1, ra); -cpu_stl_data_ra (env, a1, (ov == cv ? nv : ov), ra); + ov =cpu_ldl_mmu (env, a1, oi4, ra); +cpu_stl_mmu (env, a1, (ov == cv ? nv : ov), oi4, ra); } cc = (ov != cv); env->regs[r3] =deposit64 (env->regs[r3],32 ,32 , ov);
@@ -1811,21 +1816,20 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,case 1 : { -uint64_t nv =cpu_ldq_data_ra (env, pl, ra); +uint64_t nv =cpu_ldq_mmu (env, pl, oi8, ra);uint64_t cv = env->regs[r3];uint64_t ov;if (parallel) {#ifdef CONFIG_ATOMIC64 -MemOpIdx oi =make_memop_idx (MO_TEUQ |MO_ALIGN , mem_idx); - ov =cpu_atomic_cmpxchgq_be_mmu (env, a1, cv, nv, oi, ra); + ov =cpu_atomic_cmpxchgq_be_mmu (env, a1, cv, nv, oi8, ra);#else /* Note that we asserted !parallel above. */ g_assert_not_reached ();#endif }else { - ov =cpu_ldq_data_ra (env, a1, ra); -cpu_stq_data_ra (env, a1, (ov == cv ? nv : ov), ra); + ov =cpu_ldq_mmu (env, a1, oi8, ra); +cpu_stq_mmu (env, a1, (ov == cv ? nv : ov), oi8, ra); } cc = (ov != cv); env->regs[r3] = ov;
@@ -1834,27 +1838,19 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,case 2 : { -uint64_t nvh =cpu_ldq_data_ra (env, pl, ra); -uint64_t nvl =cpu_ldq_data_ra (env, pl +8 , ra); -Int128 nv =int128_make128 (nvl, nvh); +Int128 nv =cpu_ld16_mmu (env, pl, oi16, ra);Int128 cv =int128_make128 (env->regs[r3 +1 ], env->regs[r3]);Int128 ov;if (!parallel) { -uint64_t oh =cpu_ldq_data_ra (env, a1 +0 , ra); -uint64_t ol =cpu_ldq_data_ra (env, a1 +8 , ra); - - ov =int128_make128 (ol, oh); + ov =cpu_ld16_mmu (env, a1, oi16, ra); cc = !int128_eq (ov, cv);if (cc) { nv = ov; } - -cpu_stq_data_ra (env, a1 +0 ,int128_gethi (nv), ra); -cpu_stq_data_ra (env, a1 +8 ,int128_getlo (nv), ra); +cpu_st16_mmu (env, a1, nv, oi16, ra); }else if (HAVE_CMPXCHG128 ) { -MemOpIdx oi =make_memop_idx (MO_TE |MO_128 |MO_ALIGN , mem_idx); - ov =cpu_atomic_cmpxchgo_be_mmu (env, a1, cv, nv, oi, ra); + ov =cpu_atomic_cmpxchgo_be_mmu (env, a1, cv, nv, oi16, ra); cc = !int128_eq (ov, cv); }else {/* Note that we asserted !parallel above. */
@@ -1876,29 +1872,20 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,if (cc ==0 ) {switch (sc) {case 0 : -cpu_stb_data_ra (env, a2, svh >>56 , ra); +cpu_stb_mmu (env, a2, svh >>56 ,make_memop_idx (MO_8 , mem_idx), ra);break ;case 1 : -cpu_stw_data_ra (env, a2, svh >>48 , ra); +cpu_stw_mmu (env, a2, svh >>48 , +make_memop_idx (MO_TE |MO_16 , mem_idx), ra);break ;case 2 : -cpu_stl_data_ra (env, a2, svh >>32 , ra); +cpu_stl_mmu (env, a2, svh >>32 , oi4, ra);break ;case 3 : -cpu_stq_data_ra (env, a2, svh, ra); +cpu_stq_mmu (env, a2, svh, oi8, ra);break ;case 4 : -if (!parallel) { -cpu_stq_data_ra (env, a2 +0 , svh, ra); -cpu_stq_data_ra (env, a2 +8 , svl, ra); - }else if (HAVE_ATOMIC128 ) { -MemOpIdx oi =make_memop_idx (MO_TEUQ |MO_ALIGN_16 , mem_idx); -Int128 sv =int128_make128 (svl, svh); -cpu_atomic_sto_be_mmu (env, a2, sv, oi, ra); - }else { -/* Note that we asserted !parallel above. */ -g_assert_not_reached (); - } +cpu_st16_mmu (env, a2,int128_make128 (svl, svh), oi16, ra);break ;default :g_assert_not_reached ();
Signature · 1 line
2.34.1
Re: [PATCH 17/27] target/s390x: Use cpu_{ld,st}*_mmu in do_csst
Hi Richard,
Quoted 19 lines · Richard Henderson
Use
cpu_ld16_mmuandcpu_st16_mmuto eliminate the special case, and change all of the*_data_rafunctions to match.Signed-off-by Richard Henderson <[email protected]>---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>--- target/s390x/tcg/mem_helper.c | 65 ++++++++++++++--------------------- 1 file changed, 26 insertions(+), 39 deletions(-)target/s390x/tcg/mem_helper.c +0
-0@@ -1737,6 +1737,9 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, uint64_t a2, bool parallel) {
target/s390x/tcg/mem_helper.c static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,
Quoted 10 lines
target/s390x/tcg/mem_helper.c +3
-2uint32_t mem_idx =cpu_mmu_index (env, false); +MemOpIdx oi16 =make_memop_idx (MO_TE |MO_128 , mem_idx); +MemOpIdx oi8 =make_memop_idx (MO_TE |MO_64 , mem_idx);if (parallel) {#ifdef CONFIG_ATOMIC64 -MemOpIdx oi =make_memop_idx (MO_TEUQ |MO_ALIGN , mem_idx); - ov =cpu_atomic_cmpxchgq_be_mmu (env, a1, cv, nv, oi, ra); + ov =cpu_atomic_cmpxchgq_be_mmu (env, a1, cv, nv, oi8, ra);
Why is it safe to remove MO_ALIGN here?
Quoted 4 lines
#else
/* Note that we asserted !parallel above. */
g_assert_not_reached();
#endifRe: [PATCH 17/27] target/s390x: Use cpu_{ld,st}*_mmu in do_csst
Quoted 27 lines · Philippe Mathieu-Daudé
Hi Richard,
Quoted 22 lines · Richard Henderson
Use
cpu_ld16_mmuandcpu_st16_mmuto eliminate the special case, and change all of the*_data_rafunctions to match.Signed-off-by Richard Henderson <[email protected]>---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>
---
target/s390x/tcg/mem_helper.c| 65 ++++++++++++++---------------------1 file changed, 26 insertions(+), 39 deletions(-)target/s390x/tcg/mem_helper.c +2
-0@@ -1737,6 +1737,9 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, uint64_t a2, bool parallel) { uint32_t mem_idx = cpu_mmu_index(env, false); + MemOpIdx oi16 = make_memop_idx(MO_TE | MO_128, mem_idx); + MemOpIdx oi8 = make_memop_idx(MO_TE | MO_64, mem_idx);
Quoted 7 lines
target/s390x/tcg/mem_helper.c static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, · line 1825
Quoted 5 lines
target/s390x/tcg/mem_helper.c +1
-2if (parallel) { #ifdef CONFIG_ATOMIC64 - MemOpIdx oi = make_memop_idx(MO_TEUQ | MO_ALIGN, mem_idx); - ov = cpu_atomic_cmpxchgq_be_mmu(env, a1, cv, nv, oi, ra); + ov = cpu_atomic_cmpxchgq_be_mmu(env, a1, cv, nv, oi8, ra);Why is it safe to remove
MO_ALIGNhere?
Alignment check already done at the start of the function:
/* Sanity check the alignments. */
if (extract32(a1, 0, fc + 2) || extract32(a2, 0, sc)) {
goto spec_exception;
}r~
Re: [PATCH 17/27] target/s390x: Use cpu_{ld,st}*_mmu in do_csst
In reply to Richard HendersonQuoted 9 lines · Richard Henderson
Use
cpu_ld16_mmuandcpu_st16_mmuto eliminate the special case, and change all of the*_data_rafunctions to match.Signed-off-by Richard Henderson <[email protected]>---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>
---
[...]
target/s390x/tcg/mem_helper.c static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, · line 1879
Quoted 12 lines
/* Note that we asserted !parallel above. */target/s390x/tcg/mem_helper.c +3
-2@@ -1876,29 +1872,20 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,if (cc ==0 ) {switch (sc) {case 0 : -cpu_stb_data_ra (env, a2, svh >>56 , ra); +cpu_stb_mmu (env, a2, svh >>56 ,make_memop_idx (MO_8 , mem_idx), ra);break ;case 1 : -cpu_stw_data_ra (env, a2, svh >>48 , ra); +cpu_stw_mmu (env, a2, svh >>48 , +make_memop_idx (MO_TE |MO_16 , mem_idx), ra);
To make these two cases look less special, maybe just define oi1 and oi2 as well at the top?
LGTM
Signature · 3 lines
Thanks, David / dhildenb
PATCH 18/27 target/s390x: Always use cpu_atomic_cmpxchgl_be_mmu in do_csst
In reply to Richard HendersonEliminate the CONFIG_USER_ONLY specialization.
---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>
--- target/s390x/tcg/mem_helper.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
target/s390x/tcg/mem_helper.c +1 -7
@@ -1798,13 +1798,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,uint32_t ov;if (parallel) { -#ifdef CONFIG_USER_ONLY -uint32_t *haddr =g2h (env_cpu (env), a1); - ov =qatomic_cmpxchg__nocheck (haddr, cv, nv); -#else -MemOpIdx oi =make_memop_idx (MO_TEUL |MO_ALIGN , mem_idx); - ov =cpu_atomic_cmpxchgl_be_mmu (env, a1, cv, nv, oi, ra); -#endif + ov =cpu_atomic_cmpxchgl_be_mmu (env, a1, cv, nv, oi4, ra); }else { ov =cpu_ldl_mmu (env, a1, oi4, ra);cpu_stl_mmu (env, a1, (ov == cv ? nv : ov), oi4, ra);
Signature · 1 line
2.34.1
Re: [PATCH 18/27] target/s390x: Always use cpu_atomic_cmpxchgl_be_mmu in do_csst
Quoted 8 lines · Richard Henderson
Eliminate the
CONFIG_USER_ONLYspecialization.Signed-off-by Richard Henderson <[email protected]>---
Cc: [email protected]
Cc: David Hildenbrand <[email protected]>
Cc: Ilya Leoshkevich <[email protected]>
---
Signature · 3 lines
Thanks, David / dhildenb
PATCH 19/27 accel/tcg: Remove cpu_atomic_{ld,st}o_*_mmu
In reply to Richard HendersonAtomic load/store of 128-byte quantities is now handled by cpu_{ld,st}16_mmu.
--- accel/tcg/atomic_template.h | 61 +++-------------------------------- include/exec/cpu_ldst.h | 9 ------ accel/tcg/atomic_common.c.inc | 14 -------- 3 files changed, 4 insertions(+), 80 deletions(-)
accel/tcg/atomic_template.h +4 -57
@@ -87,33 +87,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,return ret; } -#if DATA_SIZE >=16 -#if HAVE_ATOMIC128 -ABI_TYPE ATOMIC_NAME (ld )(CPUArchState *env,target_ulong addr, -MemOpIdx oi,uintptr_t retaddr) -{ -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , -PAGE_READ , retaddr); -DATA_TYPE val; - - val =atomic16_read (haddr); -ATOMIC_MMU_CLEANUP ; -atomic_trace_ld_post (env, addr, oi); -return val; -} - -void ATOMIC_NAME (st )(CPUArchState *env,target_ulong addr,ABI_TYPE val, -MemOpIdx oi,uintptr_t retaddr) -{ -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , -PAGE_WRITE , retaddr); - -atomic16_set (haddr, val); -ATOMIC_MMU_CLEANUP ; -atomic_trace_st_post (env, addr, oi); -} -#endif -#else +#if DATA_SIZE <16 ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr,ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) {
@@ -188,7 +162,7 @@ GEN_ATOMIC_HELPER_FN(smax_fetch, MAX, SDATA_TYPE, new) GEN_ATOMIC_HELPER_FN(umax_fetch, MAX, DATA_TYPE, new)#undef GEN_ATOMIC_HELPER_FN -#endif /* DATA SIZE >= 16 */ +#endif /* DATA SIZE < 16 */ #undef END
@@ -220,34 +194,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,return BSWAP (ret); } -#if DATA_SIZE >=16 -#if HAVE_ATOMIC128 -ABI_TYPE ATOMIC_NAME (ld )(CPUArchState *env,target_ulong addr, -MemOpIdx oi,uintptr_t retaddr) -{ -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , -PAGE_READ , retaddr); -DATA_TYPE val; - - val =atomic16_read (haddr); -ATOMIC_MMU_CLEANUP ; -atomic_trace_ld_post (env, addr, oi); -return BSWAP (val); -} - -void ATOMIC_NAME (st )(CPUArchState *env,target_ulong addr,ABI_TYPE val, -MemOpIdx oi,uintptr_t retaddr) -{ -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , -PAGE_WRITE , retaddr); - - val =BSWAP (val); -atomic16_set (haddr, val); -ATOMIC_MMU_CLEANUP ; -atomic_trace_st_post (env, addr, oi); -} -#endif -#else +#if DATA_SIZE <16 ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr,ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) {
@@ -326,7 +273,7 @@ GEN_ATOMIC_HELPER_FN(add_fetch, ADD, DATA_TYPE, new)#undef ADD#undef GEN_ATOMIC_HELPER_FN -#endif /* DATA_SIZE >= 16 */ +#endif /* DATA_SIZE < 16 */ #undef END#endif /* DATA_SIZE > 1 */
include/exec/cpu_ldst.h +0 -9
@@ -300,15 +300,6 @@ Int128 cpu_atomic_cmpxchgo_be_mmu(CPUArchState *env, target_ulong addr, Int128 cmpv, Int128 newv, MemOpIdx oi, uintptr_t retaddr); -Int128 cpu_atomic_ldo_le_mmu (CPUArchState *env,target_ulong addr, -MemOpIdx oi,uintptr_t retaddr); -Int128 cpu_atomic_ldo_be_mmu (CPUArchState *env,target_ulong addr, -MemOpIdx oi,uintptr_t retaddr); -void cpu_atomic_sto_le_mmu (CPUArchState *env,target_ulong addr,Int128 val, -MemOpIdx oi,uintptr_t retaddr); -void cpu_atomic_sto_be_mmu (CPUArchState *env,target_ulong addr,Int128 val, -MemOpIdx oi,uintptr_t retaddr); -#if defined(CONFIG_USER_ONLY )extern __threaduintptr_t helper_retaddr;
accel/tcg/atomic_common.c.inc +0 -14
@@ -19,20 +19,6 @@ static void atomic_trace_rmw_post(CPUArchState *env, uint64_t addr, qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_RW); } -#if HAVE_ATOMIC128 -static void atomic_trace_ld_post(CPUArchState *env, uint64_t addr, - MemOpIdx oi) -{ - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); -} - -static void atomic_trace_st_post(CPUArchState *env, uint64_t addr, - MemOpIdx oi) -{ - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); -} -#endif - /* * Atomic helpers callable from TCG. * These have a common interface and all defer to cpu_atomic_*
Signature · 1 line
2.34.1
PATCH 20/27 accel/tcg: Remove prot argument to atomic_mmu_lookup
In reply to Richard HendersonNow that load/store are gone, we're always passing PAGE_READ | PAGE_WRITE for RMW atomic operations.
--- accel/tcg/atomic_template.h | 32 ++++++-------- accel/tcg/cputlb.c | 85 ++++++++++++++----------------------- accel/tcg/user-exec.c | 8 +--- 3 files changed, 45 insertions(+), 80 deletions(-)
accel/tcg/atomic_template.h +12 -20
@@ -73,8 +73,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, ABI_TYPE cmpv, ABI_TYPE newv, MemOpIdx oi, uintptr_t retaddr) { - DATA_TYPE *haddr = atomic_mmu_lookup(env, addr, oi, DATA_SIZE, -PAGE_READ |PAGE_WRITE , retaddr); + DATA_TYPE *haddr = atomic_mmu_lookup(env, addr, oi, DATA_SIZE, retaddr);DATA_TYPE ret;#if DATA_SIZE ==16
@@ -91,8 +90,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr,ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) { -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , -PAGE_READ |PAGE_WRITE , retaddr); +DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr);DATA_TYPE ret; ret =qatomic_xchg__nocheck (haddr, val);
@@ -105,9 +103,8 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ABI_TYPE val,ABI_TYPE ATOMIC_NAME (X )(CPUArchState *env,target_ulong addr, \ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) \ { \ -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , \ -PAGE_READ |PAGE_WRITE , retaddr); \ -DATA_TYPE ret; \ +DATA_TYPE *haddr, ret; \ + haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr); \ ret = qatomic_##X(haddr, val); \ ATOMIC_MMU_CLEANUP; \ atomic_trace_rmw_post(env, addr, oi); \
@@ -137,9 +134,8 @@ GEN_ATOMIC_HELPER(xor_fetch)ABI_TYPE ATOMIC_NAME (X )(CPUArchState *env,target_ulong addr, \ABI_TYPE xval,MemOpIdx oi,uintptr_t retaddr) \ { \ -XDATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , \ -PAGE_READ |PAGE_WRITE , retaddr); \ -XDATA_TYPE cmp, old, new, val = xval; \ +XDATA_TYPE *haddr, cmp, old, new, val = xval; \ + haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr); \smp_mb (); \ cmp =qatomic_read__nocheck (haddr); \ do { \
@@ -180,8 +176,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, ABI_TYPE cmpv, ABI_TYPE newv, MemOpIdx oi, uintptr_t retaddr) { - DATA_TYPE *haddr = atomic_mmu_lookup(env, addr, oi, DATA_SIZE, -PAGE_READ |PAGE_WRITE , retaddr); + DATA_TYPE *haddr = atomic_mmu_lookup(env, addr, oi, DATA_SIZE, retaddr);DATA_TYPE ret;#if DATA_SIZE ==16
@@ -198,8 +193,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr,ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) { -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , -PAGE_READ |PAGE_WRITE , retaddr); +DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr);ABI_TYPE ret; ret =qatomic_xchg__nocheck (haddr,BSWAP (val));
@@ -212,9 +206,8 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ABI_TYPE val,ABI_TYPE ATOMIC_NAME (X )(CPUArchState *env,target_ulong addr, \ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) \ { \ -DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , \ -PAGE_READ |PAGE_WRITE , retaddr); \ -DATA_TYPE ret; \ +DATA_TYPE *haddr, ret; \ + haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr); \ ret = qatomic_##X(haddr, BSWAP(val)); \ ATOMIC_MMU_CLEANUP; \ atomic_trace_rmw_post(env, addr, oi); \
@@ -241,9 +234,8 @@ GEN_ATOMIC_HELPER(xor_fetch)ABI_TYPE ATOMIC_NAME (X )(CPUArchState *env,target_ulong addr, \ABI_TYPE xval,MemOpIdx oi,uintptr_t retaddr) \ { \ -XDATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , \ -PAGE_READ |PAGE_WRITE , retaddr); \ -XDATA_TYPE ldo, ldn, old, new, val = xval; \ +XDATA_TYPE *haddr, ldo, ldn, old, new, val = xval; \ + haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr); \smp_mb (); \ ldn =qatomic_read__nocheck (haddr); \ do { \
accel/tcg/cputlb.c +31 -54
108 lines not on this page · raw message
accel/tcg/user-exec.c +2 -6
@@ -1323,12 +1323,9 @@ uint64_t cpu_ldq_code_mmu(CPUArchState *env, abi_ptr addr,/* * Do not allow unaligned operations to proceed. Return the host address. -* -* @prot may be PAGE_READ, PAGE_WRITE, or PAGE_READ|PAGE_WRITE. */ static void *atomic_mmu_lookup (CPUArchState *env,target_ulong addr, -MemOpIdx oi,int size,int prot, -uintptr_t retaddr) +MemOpIdx oi,int size,uintptr_t retaddr) {MemOp mop =get_memop (oi);int a_bits =get_alignment_bits (mop);
@@ -1336,8 +1333,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,/* Enforce guest required alignment. */ if (unlikely (addr & ((1 << a_bits) -1 ))) { -MMUAccessType t = prot ==PAGE_READ ?MMU_DATA_LOAD :MMU_DATA_STORE ; -cpu_loop_exit_sigbus (env_cpu (env), addr, t, retaddr); +cpu_loop_exit_sigbus (env_cpu (env), addr,MMU_DATA_STORE , retaddr); }/* Enforce qemu required alignment. */
Signature · 1 line
2.34.1
PATCH 21/27 accel/tcg: Eliminate #if on HAVE_ATOMIC128 and HAVE_CMPXCHG128
In reply to Richard HendersonThese symbols will shortly become dynamic runtime tests and therefore not appropriate for the preprocessor. Use the matching CONFIG_* symbols for that purpose.
--- host/include/aarch64/host/atomic128-cas.h | 2 ++ host/include/generic/host/atomic128-ldst.h | 2 +- accel/tcg/cputlb.c | 2 +- accel/tcg/user-exec.c | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-)
host/include/aarch64/host/atomic128-cas.h +2 -0
@@ -37,6 +37,8 @@ static inline Int128 atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new) return int128_make128(oldl, oldh); } + +# define CONFIG_CMPXCHG128 1# define HAVE_CMPXCHG128 1#endif
host/include/generic/host/atomic128-ldst.h +1 -1
@@ -33,7 +33,7 @@ atomic16_set(Int128 *ptr, Int128 val) }# define HAVE_ATOMIC128 1 -#elif !defined(CONFIG_USER_ONLY ) &&HAVE_CMPXCHG128 +#elif defined(CONFIG_CMPXCHG128 ) && !defined(CONFIG_USER_ONLY ) static inline Int128 ATTRIBUTE_ATOMIC128_OPTatomic16_read (Int128 *ptr) {
accel/tcg/cputlb.c +1 -1
@@ -3038,7 +3038,7 @@ void cpu_st16_mmu(CPUArchState *env, target_ulong addr, Int128 val,#include "atomic_template.h" #endif -#if HAVE_CMPXCHG128 ||HAVE_ATOMIC128 +#if defined(CONFIG_ATOMIC128 ) || defined(CONFIG_CMPXCHG128 )#define DATA_SIZE 16#include "atomic_template.h" #endif
accel/tcg/user-exec.c +1 -1
@@ -1371,7 +1371,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,#include "atomic_template.h" #endif -#if HAVE_ATOMIC128 ||HAVE_CMPXCHG128 +#if defined(CONFIG_ATOMIC128 ) || defined(CONFIG_CMPXCHG128 )#define DATA_SIZE 16#include "atomic_template.h" #endif
Signature · 1 line
2.34.1
PATCH 22/27 qemu/atomic128: Split atomic16_read
In reply to Richard HendersonCreate both atomic16_read_ro and atomic16_read_rw. Previously we pretended that we had atomic16_read in system mode, because we "know" that all ram is always writable to the host. Now, expose read-only and read-write versions all of the time.
For aarch64, do not fall back to __atomic_read_16 even if supported by the compiler, to work around a clang bug.
--- host/include/aarch64/host/atomic128-ldst.h | 21 ++++++++------- host/include/generic/host/atomic128-ldst.h | 31 ++++++++++++++++------ target/s390x/tcg/mem_helper.c | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-)
host/include/aarch64/host/atomic128-ldst.h +12 -9
@@ -11,10 +11,18 @@#ifndef AARCH64_ATOMIC128_LDST_H #define AARCH64_ATOMIC128_LDST_H -/* Through gcc 10, aarch64 has no support for 128-bit atomics. */ -#if !defined(CONFIG_ATOMIC128) && !defined(CONFIG_USER_ONLY) -/* We can do better than cmpxchg for AArch64. */ -static inline Int128 atomic16_read(Int128 *ptr) +/* +* Through gcc 10, aarch64 has no support for 128-bit atomics. +* Through clang 16, without -march=armv8.4-a, __atomic_load_16 +* is incorrectly expanded to a read-write operation. +*/ + +#define HAVE_ATOMIC128_RO 0 +#define HAVE_ATOMIC128_RW 1 + +Int128 QEMU_ERROR("unsupported atomic") atomic16_read_ro(const Int128 *ptr); + +static inline Int128 atomic16_read_rw (Int128 *ptr) {uint64_t l, h;uint32_t tmp;
@@ -41,9 +49,4 @@ static inline void atomic16_set(Int128 *ptr, Int128 val) : [l] "r"(l), [h] "r"(h)); } -# define HAVE_ATOMIC128 1 -#else -#include "host/include/generic/host/atomic128-ldst.h" -#endif -#endif /* AARCH64_ATOMIC128_LDST_H */
host/include/generic/host/atomic128-ldst.h +23 -8
@@ -12,16 +12,25 @@#define HOST_ATOMIC128_LDST_H #if defined(CONFIG_ATOMIC128 ) +# define HAVE_ATOMIC128_RO 1 +# define HAVE_ATOMIC128_RW 1 + static inline Int128 ATTRIBUTE_ATOMIC128_OPT -atomic16_read (Int128 *ptr) +atomic16_read_ro (const Int128 *ptr) { -__int128_t *ptr_align =__builtin_assume_aligned (ptr,16 ); +const __int128_t *ptr_align =__builtin_assume_aligned (ptr,16 );Int128Alias r; r.i =qatomic_read__nocheck (ptr_align);return r.s; } +static inline Int128 ATTRIBUTE_ATOMIC128_OPT +atomic16_read_rw (Int128 *ptr) +{ +return atomic16_read_ro (ptr); +} + static inline void ATTRIBUTE_ATOMIC128_OPTatomic16_set (Int128 *ptr,Int128 val) {
@@ -32,10 +41,14 @@ atomic16_set(Int128 *ptr, Int128 val)qatomic_set__nocheck (ptr_align, v.i); } -# define HAVE_ATOMIC128 1 -#elif defined(CONFIG_CMPXCHG128 ) && !defined(CONFIG_USER_ONLY ) +#elif defined(CONFIG_CMPXCHG128 ) +# define HAVE_ATOMIC128_RO 0 +# define HAVE_ATOMIC128_RW 1 + +Int128 QEMU_ERROR("unsupported atomic") atomic16_read_ro(const Int128 *ptr); + static inline Int128 ATTRIBUTE_ATOMIC128_OPT -atomic16_read (Int128 *ptr) +atomic16_read_rw (Int128 *ptr) {/* Maybe replace 0 with 0, returning the old value. */ Int128 z =int128_make64 (0 );
@@ -52,12 +65,14 @@ atomic16_set(Int128 *ptr, Int128 val) } while (int128_ne(old, cmp)); } -# define HAVE_ATOMIC128 1#else +# define HAVE_ATOMIC128_RO 0 +# define HAVE_ATOMIC128_RW 0 +/* Fallback definitions that must be optimized away, or error. */ -Int128 QEMU_ERROR("unsupported atomic") atomic16_read(Int128 *ptr); +Int128 QEMU_ERROR("unsupported atomic") atomic16_read_ro(const Int128 *ptr); +Int128 QEMU_ERROR("unsupported atomic") atomic16_read_rw(Int128 *ptr); void QEMU_ERROR("unsupported atomic") atomic16_set(Int128 *ptr, Int128 val); -# define HAVE_ATOMIC128 0#endif #endif /* HOST_ATOMIC128_LDST_H */
target/s390x/tcg/mem_helper.c +1 -1
@@ -1778,7 +1778,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, max =3 ;#endif if ((HAVE_CMPXCHG128 ?0 : fc +2 > max) || - (HAVE_ATOMIC128 ?0 : sc > max)) { + (HAVE_ATOMIC128_RW ?0 : sc > max)) {cpu_loop_exit_atomic (env_cpu (env), ra); } }
Signature · 1 line
2.34.1
PATCH 23/27 accel/tcg: Correctly use atomic128.h in ldst_atomicity.c.inc
In reply to Richard HendersonRemove the locally defined load_atomic16 and store_atomic16, along with HAVE_al16 and HAVE_al16_fast in favor of the routines defined in atomic128.h.
--- accel/tcg/cputlb.c | 2 +- accel/tcg/ldst_atomicity.c.inc | 118 +++++++-------------------------- 2 files changed, 24 insertions(+), 96 deletions(-)
accel/tcg/cputlb.c +1 -1
@@ -2712,7 +2712,7 @@ static uint64_t do_st16_leN(CPUArchState *env, MMULookupPageData *p,case MO_ATOM_WITHIN16_PAIR :/* Since size > 8, this is the half that must be atomic. */ -if (!HAVE_al16) { +if (!HAVE_ATOMIC128_RW ) {cpu_loop_exit_atomic (env_cpu (env), ra); }return store_whole_le16 (p->haddr, p->size, val_le);
accel/tcg/ldst_atomicity.c.inc +23 -95
234 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 24/27 tcg: Split out tcg/debug-assert.h
In reply to Richard Henderson--- include/tcg/debug-assert.h | 17 +++++++++++++++++ include/tcg/tcg.h | 9 +-------- 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 include/tcg/debug-assert.h
include/tcg/debug-assert.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Define tcg_debug_assert +* Copyright (c) 2008 Fabrice Bellard +*/ + +#ifndef TCG_DEBUG_ASSERT_H +#define TCG_DEBUG_ASSERT_H + +#if definedCONFIG_DEBUG_TCG || definedQEMU_STATIC_ANALYSIS +# define tcg_debug_assert (X ) do { assert(X); } while (0) +#else +# define tcg_debug_assert (X ) \ + do { if (!(X)) { __builtin_unreachable(); } } while (0) +#endif + +#endif
include/tcg/tcg.h +1 -8
@@ -34,6 +34,7 @@#include "tcg/tcg-mo.h" #include "tcg-target.h" #include "tcg/tcg-cond.h" +#include "tcg/debug-assert.h" /* XXX: make safe guess about sizes */ #define MAX_OP_PER_INSTR 266
@@ -222,14 +223,6 @@ typedef uint64_t tcg_insn_unit;/* The port better have done this. */ #endif - -#if definedCONFIG_DEBUG_TCG || definedQEMU_STATIC_ANALYSIS -# define tcg_debug_assert (X ) do { assert(X); } while (0) -#else -# define tcg_debug_assert (X ) \ - do { if (!(X)) { __builtin_unreachable(); } } while (0) -#endif -typedef struct TCGRelocation TCGRelocation ;struct TCGRelocation {QSIMPLEQ_ENTRY (TCGRelocation) next;
Signature · 1 line
2.34.1
Re: [PATCH 24/27] tcg: Split out tcg/debug-assert.h
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/tcg/debug-assert.h | 17 +++++++++++++++++ include/tcg/tcg.h | 9 +-------- 2 files changed, 18 insertions(+), 8 deletions(-)create mode 100644
include/tcg/debug-assert.h
While here:
MAINTAINERS +1 -0
@@ -156,6 +156,7 @@ F: include/exec/target_long.h F: include/exec/helper*.h F: include/sysemu/cpus.h F: include/sysemu/tcg.h +F: include/tcg/ F: include/hw/core/tcg-cpu-ops.h
PATCH 25/27 qemu/atomic128: Improve cmpxchg fallback for atomic16_set
In reply to Richard HendersonUse __sync_bool_compare_and_swap_16 to control the loop, rather than a separate comparison.
--- host/include/generic/host/atomic128-ldst.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
host/include/generic/host/atomic128-ldst.h +7 -4
@@ -58,11 +58,14 @@ atomic16_read_rw(Int128 *ptr) static inline void ATTRIBUTE_ATOMIC128_OPTatomic16_set (Int128 *ptr,Int128 val) { -Int128 old = *ptr, cmp; +__int128_t *ptr_align =__builtin_assume_aligned (ptr,16 ); +__int128_t old; +Int128Alias new; + + new.s = val;do { - cmp = old; - old =atomic16_cmpxchg (ptr, cmp, val); - }while (int128_ne (old, cmp)); + old = *ptr_align; + }while (!__sync_bool_compare_and_swap_16 (ptr_align, old, new.i)); }#else
Signature · 1 line
2.34.1
PATCH 26/27 qemu/atomic128: Add runtime test for FEAT_LSE2
In reply to Richard HendersonWith FEAT_LSE2, load and store of int128 is directly supported.
--- host/include/aarch64/host/atomic128-ldst.h | 53 ++++++++++++++++------ 1 file changed, 40 insertions(+), 13 deletions(-)
host/include/aarch64/host/atomic128-ldst.h +40 -13
@@ -11,27 +11,48 @@#ifndef AARCH64_ATOMIC128_LDST_H #define AARCH64_ATOMIC128_LDST_H +#include "host/cpuinfo.h" +#include "tcg/debug-assert.h" +/* * Through gcc 10, aarch64 has no support for 128-bit atomics. * Through clang 16, without -march=armv8.4-a, __atomic_load_16 * is incorrectly expanded to a read-write operation. +* +* Anyway, this method allows runtime detection of FEAT_LSE2. */ -#define HAVE_ATOMIC128_RO 0 +#define HAVE_ATOMIC128_RO (cpuinfo & CPUINFO_LSE2)#define HAVE_ATOMIC128_RW 1 -Int128 QEMU_ERROR("unsupported atomic") atomic16_read_ro(const Int128 *ptr); +static inline Int128 atomic16_read_ro (const Int128 *ptr) +{ +uint64_t l, h; + +tcg_debug_assert (HAVE_ATOMIC128_RO ); +/* With FEAT_LSE2, 16-byte aligned LDP is atomic. */ + asm("ldp %[l], %[h], %[mem]" + : [l]"=r" (l), [h]"=r" (h) : [mem]"m" (*ptr)); + +return int128_make128 (l, h); +}static inline Int128 atomic16_read_rw (Int128 *ptr) {uint64_t l, h;uint32_t tmp; -/* The load must be paired with the store to guarantee not tearing. */ - asm("0: ldxp %[l], %[h], %[mem]\n\t" -"stxp %w[tmp], %[l], %[h], %[mem]\n\t" -"cbnz %w[tmp], 0b" - : [mem]"+m" (*ptr), [tmp]"=r" (tmp), [l]"=r" (l), [h]"=r" (h)); +if (cpuinfo &CPUINFO_LSE2 ) { +/* With FEAT_LSE2, 16-byte aligned LDP is atomic. */ + asm("ldp %[l], %[h], %[mem]" + : [l]"=r" (l), [h]"=r" (h) : [mem]"m" (*ptr)); + }else { +/* The load must be paired with the store to guarantee not tearing. */ + asm("0: ldxp %[l], %[h], %[mem]\n\t" +"stxp %w[tmp], %[l], %[h], %[mem]\n\t" +"cbnz %w[tmp], 0b" + : [mem]"+m" (*ptr), [tmp]"=r" (tmp), [l]"=r" (l), [h]"=r" (h)); + }return int128_make128 (l, h); }
@@ -41,12 +62,18 @@ static inline void atomic16_set(Int128 *ptr, Int128 val)uint64_t l =int128_getlo (val), h =int128_gethi (val);uint64_t t1, t2; -/* Load into temporaries to acquire the exclusive access lock. */ - asm("0: ldxp %[t1], %[t2], %[mem]\n\t" -"stxp %w[t1], %[l], %[h], %[mem]\n\t" -"cbnz %w[t1], 0b" - : [mem]"+m" (*ptr), [t1]"=&r" (t1), [t2]"=&r" (t2) - : [l] "r"(l), [h] "r"(h)); +if (cpuinfo &CPUINFO_LSE2 ) { +/* With FEAT_LSE2, 16-byte aligned STP is atomic. */ + asm("stp %[l], %[h], %[mem]" + : [mem]"=m" (*ptr) : [l]"r" (l), [h]"r" (h)); + }else { +/* Load into temporaries to acquire the exclusive access lock. */ + asm("0: ldxp %[t1], %[t2], %[mem]\n\t" +"stxp %w[t1], %[l], %[h], %[mem]\n\t" +"cbnz %w[t1], 0b" + : [mem]"+m" (*ptr), [t1]"=&r" (t1), [t2]"=&r" (t2) + : [l]"r" (l), [h]"r" (h)); + } }#endif /* AARCH64_ATOMIC128_LDST_H */
Signature · 1 line
2.34.1
PATCH 27/27 qemu/atomic128: Add x86_64 atomic128-ldst.h
In reply to Richard HendersonWith CPUINFO_ATOMIC_VMOVDQA, we can perform proper atomic load/store without cmpxchg16b.
--- host/include/x86_64/host/atomic128-ldst.h | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 host/include/x86_64/host/atomic128-ldst.h
host/include/x86_64/host/atomic128-ldst.h new file +54 -0
@@ -0,0 +1,54 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* Load/store for 128-bit atomic operations, x86_64 version. +* +* Copyright (C) 2023 Linaro, Ltd. +* +* See docs/devel/atomics.rst for discussion about the guarantees each +* atomic primitive is meant to provide. +*/ + +#ifndef AARCH64_ATOMIC128_LDST_H +#define AARCH64_ATOMIC128_LDST_H + +#include "host/cpuinfo.h" +#include "tcg/debug-assert.h" + +#define HAVE_ATOMIC128_RO likely(cpuinfo & CPUINFO_ATOMIC_VMOVDQA) +#define HAVE_ATOMIC128_RW 1 + +static inline Int128 atomic16_read_ro (const Int128 *ptr) +{ +Int128Alias r; + +tcg_debug_assert (HAVE_ATOMIC128_RO ); + asm("vmovdqa %1, %0" :"=x" (r.i) :"m" (*ptr)); + +return r.s; +} + +static inline Int128 atomic16_read_rw (Int128 *ptr) +{ +Int128Alias r; + +if (HAVE_ATOMIC128_RO ) { + asm("vmovdqa %1, %0" :"=x" (r.i) :"m" (*ptr)); + }else { + r.i =__sync_val_compare_and_swap_16 (ptr,0 ,0 ); + } +return r.s; +} + +static inline void atomic16_set (Int128 *ptr,Int128Alias val) +{ +if (HAVE_ATOMIC128_RO ) { + asm("vmovdqa %1, %0" :"=m" (*ptr) :"x" (val.i)); + }else { +Int128Alias old; +do { + old.s = *ptr; + }while (!__sync_bool_compare_and_swap_16 (ptr, old.i, val.i)); + } +} + +#endif /* AARCH64_ATOMIC128_LDST_H */
Signature · 1 line
2.34.1