Clean-up codegen cache size
v2 cover Clean-up codegen cache size
Hi,
A few tweaks to the final commit so we are a little less greedy for translation buffer, especially for the CONFIG_USER case. Otherwise I've applied the review tags.
Alex Bennée (4):
accel/tcg: use units.h for defining code gen buffer sizes accel/tcg: remove link between guest ram and TCG cache size accel/tcg: only USE_STATIC_CODE_GEN_BUFFER on 32 bit hosts accel/tcg: increase default code gen buffer size for 64 bit
accel/tcg/translate-all.c | 61 +++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 25 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/4 accel/tcg: use units.h for defining code gen buffer sizes
It's easier to read.
--- accel/tcg/translate-all.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
accel/tcg/translate-all.c +10 -9
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" +#include "qemu/units.h" #include "qemu-common.h" #define NO_CPU_IO_DEFS
@@ -901,33 +902,33 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1,/* Minimum size of the code gen buffer. This number is randomly chosen, but not so small that we can't have a fair number of TB's live. */ -#define MIN_CODE_GEN_BUFFER_SIZE (1024u * 1024) +#define MIN_CODE_GEN_BUFFER_SIZE (1 * MiB)/* Maximum size of the code gen buffer we'd like to use. Unless otherwise indicated, this is constrained by the range of direct branches on the host cpu, as used by the TCG implementation of goto_tb. */ #if defined(__x86_64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB)#elif defined(__sparc__) -# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB)#elif defined(__powerpc64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB)#elif defined(__powerpc__) -# define MAX_CODE_GEN_BUFFER_SIZE (32u * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (32 * MiB)#elif defined(__aarch64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB)#elif defined(__s390x__)/* We have a +- 4GB range on the branches; leave some slop. */ -# define MAX_CODE_GEN_BUFFER_SIZE (3ul * 1024 * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (3 * GiB)#elif defined(__mips__)/* We have a 256MB branch region, but leave room to make sure the main executable is also within that region. */ -# define MAX_CODE_GEN_BUFFER_SIZE (128ul * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (128 * MiB)#else # define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1)#endif -#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32u * 1024 * 1024) +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32 * MiB)#define DEFAULT_CODE_GEN_BUFFER_SIZE \ (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \
Signature · 1 line
2.20.1
PATCH v2 2/4 accel/tcg: remove link between guest ram and TCG cache size
In reply to Alex BennéeBasing the TB cache size on the ram_size was always a little heuristic and was broken by a1b18df9a4 which caused ram_size not to be fully realised at the time we initialise the TCG translation cache.
The current DEFAULT_CODE_GEN_BUFFER_SIZE may still be a little small but follow-up patches will address that.
--- accel/tcg/translate-all.c | 8 -------- 1 file changed, 8 deletions(-)
accel/tcg/translate-all.c +0 -8
@@ -938,15 +938,7 @@ static inline size_t size_code_gen_buffer(size_t tb_size) {/* Size the buffer. */ if (tb_size ==0 ) { -#ifdef USE_STATIC_CODE_GEN_BUFFER tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; -#else -/* ??? Needs adjustments. */ -/* ??? If we relax the requirement that CONFIG_USER_ONLY use the -static buffer, we could size this on RESERVED_VA, on the text -segment size of the executable, or continue to use the default. */ - tb_size = (unsigned long )(ram_size /4 ); -#endif }if (tb_size <MIN_CODE_GEN_BUFFER_SIZE ) { tb_size =MIN_CODE_GEN_BUFFER_SIZE ;
Signature · 1 line
2.20.1
Re: [PATCH v2 2/4] accel/tcg: remove link between guest ram and TCG cache size
Quoted 4 lines · Alex Bennée
Basing the TB cache size on the
ram_sizewas always a little heuristic and was broken bya1b18df9a4which causedram_sizenot to be fully realised at the time we initialise the TCG translation cache.
Quoted 8 lines
The current
DEFAULT_CODE_GEN_BUFFER_SIZEmay still be a little small but follow-up patches will address that.Fixes a1b18df9a4Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Quoted 31 lines
Cc Igor Mammedov <[email protected]>--- accel/tcg/translate-all.c | 8 -------- 1 file changed, 8 deletions(-)accel/tcg/translate-all.c +0
-6@@ -938,15 +938,7 @@ static inline size_t size_code_gen_buffer(size_t tb_size) {/* Size the buffer. */ if (tb_size ==0 ) { -#ifdef USE_STATIC_CODE_GEN_BUFFER tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; -#else -/* ??? Needs adjustments. */ -/* ??? If we relax the requirement that CONFIG_USER_ONLY use the -static buffer, we could size this on RESERVED_VA, on the text -segment size of the executable, or continue to use the default. */
accel/tcg/translate-all.c +0
-3- tb_size = (unsigned long )(ram_size /4 ); -#endif }if (tb_size <MIN_CODE_GEN_BUFFER_SIZE ) { tb_size =MIN_CODE_GEN_BUFFER_SIZE ; --2.20.1
Signature · 1 line
Niek Linnenbank
PATCH v2 3/4 accel/tcg: only USE_STATIC_CODE_GEN_BUFFER on 32 bit hosts
In reply to Alex BennéeThere is no particular reason to use a static codegen buffer on 64 bit hosts as we have address space to burn. Allow the common CONFIG_USER case to use the mmap'ed buffers like SoftMMU.
--- accel/tcg/translate-all.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
accel/tcg/translate-all.c +6 -5
@@ -892,11 +892,12 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1, } } -#if defined(CONFIG_USER_ONLY ) -/* Currently it is not recommended to allocate big chunks of data in -user mode. It will change when a dedicated libc will be used. */ -/* ??? 64-bit hosts ought to have no problem mmaping data outside the -region in which the guest needs to run. Revisit this. */ +#if defined(CONFIG_USER_ONLY ) &&TCG_TARGET_REG_BITS ==32 +/* +* For user mode on smaller 32 bit systems we may run into trouble +* allocating big chunks of data in the right place. On these systems +* we utilise a static code generation buffer directly in the binary. +*/ #define USE_STATIC_CODE_GEN_BUFFER #endif
Signature · 1 line
2.20.1
PATCH v2 4/4 accel/tcg: increase default code gen buffer size for 64 bit
In reply to Alex BennéeWhile 32mb is certainly usable a full system boot ends up flushing the codegen buffer nearly 100 times. Increase the default on 64 bit hosts to take advantage of all that spare memory. After this change I can boot my tests system without any TB flushes.
As we usually run more CONFIG_USER binaries at a time in typical usage we aren't quite as profligate for user-mode code generation usage. We also bring the static code gen defies to the same place to keep all the reasoning in the comments together.
---
v2
- 2gb->1gb for system emulation
- split user and system emulation buffer sizes
--- accel/tcg/translate-all.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
accel/tcg/translate-all.c +26 -9
@@ -892,15 +892,6 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1, } } -#if defined(CONFIG_USER_ONLY ) &&TCG_TARGET_REG_BITS ==32 -/* -* For user mode on smaller 32 bit systems we may run into trouble -* allocating big chunks of data in the right place. On these systems -* we utilise a static code generation buffer directly in the binary. -*/ -#define USE_STATIC_CODE_GEN_BUFFER -#endif -/* Minimum size of the code gen buffer. This number is randomly chosen, but not so small that we can't have a fair number of TB's live. */ #define MIN_CODE_GEN_BUFFER_SIZE (1 * MiB)
@@ -929,7 +920,33 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1,# define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1)#endif +#if TCG_TARGET_REG_BITS ==32 #define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32 * MiB) +#ifdef CONFIG_USER_ONLY +/* +* For user mode on smaller 32 bit systems we may run into trouble +* allocating big chunks of data in the right place. On these systems +* we utilise a static code generation buffer directly in the binary. +*/ +#define USE_STATIC_CODE_GEN_BUFFER +#endif +#else /* TCG_TARGET_REG_BITS == 64 */ +#ifdef CONFIG_USER_ONLY +/* +* As user-mode emulation typically means running multiple instances +* of the translator don't go too nuts with our default code gen +* buffer lest we make things too hard for the OS. +*/ +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (128 * MiB) +#else +/* +* We expect most system emulation to run one or two guests per host. +* Users running large scale system emulation may want to tweak their +* runtime setup via the tb-size control on the command line. +*/ +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (1 * GiB) +#endif +#endif #define DEFAULT_CODE_GEN_BUFFER_SIZE \ (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \
Signature · 1 line
2.20.1
Re: [PATCH v2 4/4] accel/tcg: increase default code gen buffer size for 64 bit
Quoted 5 lines · Alex Bennée
While 32mb is certainly usable a full system boot ends up flushing the codegen buffer nearly 100 times. Increase the default on 64 bit hosts to take advantage of all that spare memory. After this change I can boot my tests system without any TB flushes.
Quoted 8 lines
As we usually run more
CONFIG_USERbinaries at a time in typical usage we aren't quite as profligate for user-mode code generation usage. We also bring the static code gen defies to the same place to keep all the reasoning in the comments together.Signed-off-by Alex Bennée <[email protected]>Tested-by Niek Linnenbank <[email protected]>
Quoted 69 lines
---
v2
- 2gb->1gb for system emulation
- split user and system emulation buffer sizes--- accel/tcg/translate-all.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)accel/tcg/translate-all.c +0
-9@@ -892,15 +892,6 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1, } } -#if defined(CONFIG_USER_ONLY ) &&TCG_TARGET_REG_BITS ==32 -/* -* For user mode on smaller 32 bit systems we may run into trouble -* allocating big chunks of data in the right place. On these systems -* we utilise a static code generation buffer directly in the binary. -*/ -#define USE_STATIC_CODE_GEN_BUFFER -#endif -/* Minimum size of the code gen buffer. This number is randomly chosen, but not so small that we can't have a fair number of TB's live. */ #define
MIN_CODE_GEN_BUFFER_SIZE(1 * MiB)accel/tcg/translate-all.c +26
-0@@ -929,7 +920,33 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1,# define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1)#endif +#if TCG_TARGET_REG_BITS ==32 #define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32 * MiB) +#ifdef CONFIG_USER_ONLY +/* +* For user mode on smaller 32 bit systems we may run into trouble +* allocating big chunks of data in the right place. On these systems +* we utilise a static code generation buffer directly in the binary. +*/ +#define USE_STATIC_CODE_GEN_BUFFER +#endif +#else /* TCG_TARGET_REG_BITS == 64 */ +#ifdef CONFIG_USER_ONLY +/* +* As user-mode emulation typically means running multiple instances +* of the translator don't go too nuts with our default code gen +* buffer lest we make things too hard for the OS. +*/ +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (128 * MiB) +#else +/* +* We expect most system emulation to run one or two guests per host. +* Users running large scale system emulation may want to tweak their +* runtime setup via the tb-size control on the command line. +*/ +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (1 * GiB) +#endif +#endif #define DEFAULT_CODE_GEN_BUFFER_SIZE \(DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \--
2.20.1
Signature · 1 line
Niek Linnenbank
Richard Henderson
AppliedQuoted 6 lines · Alex Bennée
Hi,
A few tweaks to the final commit so we are a little less greedy for translation buffer, especially for the
CONFIG_USERcase. Otherwise I've applied the review tags.
Quoted 8 lines
Alex Bennée (4):
accel/tcg: useunits.hfor defining code gen buffer sizes accel/tcg: remove link between guest ram and TCG cache size accel/tcg: onlyUSE_STATIC_CODE_GEN_BUFFERon 32 bit hosts accel/tcg: increase default code gen buffer size for 64 bitaccel/tcg/translate-all.c | 61 +++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 25 deletions(-)
Applied to tcg-next.
r~