tcg/softmmu: Increase size of TLB cache
RFC PATCH 1/1 tcg/softmmu: Increase size of TLB cache
This patch increases the number of entries we allow in the TLB. I went over a few architectures to see if increasing it is problematic. Only armv6 seems to have a limitation that only 8 bits can be used for indexing these entries. For other architectures, I increased the number of TLB entries to a 4K-sized cache.
--- include/exec/cpu-defs.h | 5 ++++- tcg/aarch64/tcg-target.h | 1 + tcg/i386/tcg-target.h | 2 ++ tcg/mips/tcg-target.h | 1 + tcg/s390/tcg-target.h | 1 + tcg/sparc/tcg-target.h | 1 + 6 files changed, 10 insertions(+), 1 deletion(-)
include/exec/cpu-defs.h +4 -1
@@ -64,6 +64,9 @@ typedef uint64_t target_ulong;#define CPU_TLB_ENTRY_BITS 5#endif +#ifndef CPU_TLB_BITS_MAX +# define CPU_TLB_BITS_MAX 8 +#endif /* TCG_TARGET_TLB_DISPLACEMENT_BITS is used in CPU_TLB_BITS to ensure that * the TLB is not unnecessarily small, but still small enough for the * TLB lookup instruction sequence used by the TCG target.
@@ -87,7 +90,7 @@ typedef uint64_t target_ulong;* of tlb_table inside env (which is non-trivial but not huge). */ #define CPU_TLB_BITS \ - MIN(8, \ + MIN(CPU_TLB_BITS_MAX, \ TCG_TARGET_TLB_DISPLACEMENT_BITS - CPU_TLB_ENTRY_BITS - \ (NB_MMU_MODES <= 1 ? 0 : \ NB_MMU_MODES <= 2 ? 1 : \
tcg/aarch64/tcg-target.h +1 -0
@@ -15,6 +15,7 @@#define TCG_TARGET_INSN_UNIT_SIZE 4#define TCG_TARGET_TLB_DISPLACEMENT_BITS 24 +#define CPU_TLB_BITS_MAX 12#undef TCG_TARGET_STACK_GROWSUP typedef enum {
tcg/i386/tcg-target.h +2 -0
@@ -162,6 +162,8 @@ extern bool have_popcnt;# define TCG_AREG0 TCG_REG_EBP#endif +#define CPU_TLB_BITS_MAX 12 +static inline void flush_icache_range (uintptr_t start,uintptr_t stop) { }
tcg/mips/tcg-target.h +1 -0
@@ -37,6 +37,7 @@#define TCG_TARGET_INSN_UNIT_SIZE 4#define TCG_TARGET_TLB_DISPLACEMENT_BITS 16 +#define CPU_TLB_BITS_MAX 12#define TCG_TARGET_NB_REGS 32 typedef enum {
tcg/s390/tcg-target.h +1 -0
@@ -27,6 +27,7 @@#define TCG_TARGET_INSN_UNIT_SIZE 2#define TCG_TARGET_TLB_DISPLACEMENT_BITS 19 +#define CPU_TLB_BITS_MAX 12 typedef enum TCGReg { TCG_REG_R0 = 0,
tcg/sparc/tcg-target.h +1 -0
@@ -29,6 +29,7 @@#define TCG_TARGET_INSN_UNIT_SIZE 4#define TCG_TARGET_TLB_DISPLACEMENT_BITS 32 +#define CPU_TLB_BITS_MAX 12#define TCG_TARGET_NB_REGS 32 typedef enum {
Signature · 1 line
2.13.0
Quoted 7 lines · Pranith Kumar
This patch increases the number of entries we allow in the TLB. I went over a few architectures to see if increasing it is problematic. Only armv6 seems to have a limitation that only 8 bits can be used for indexing these entries. For other architectures, I increased the number of TLB entries to a 4K-sized cache.
Signed-off-by Pranith Kumar <[email protected]>
How did you benchmark this, and can you plot (at least for x86 hosts) the results as CPU_TLB_BITS_MAX grows from 8 to 12?
Thanks,
Paolo
include/exec/cpu-defs.h typedef uint64_t target_ulong; · line 68
Quoted 3 lines · Pranith Kumar
include/exec/cpu-defs.h +2
-0+#ifndef CPU_TLB_BITS_MAX +# define CPU_TLB_BITS_MAX 8
You should simply require each backend to define this.
tcg/i386/tcg-target.h extern bool have_popcnt; · line 165
Quoted 6 lines
+++
b/tcg/i386/tcg-target.htcg/i386/tcg-target.h +1
-0@@ -162,6 +162,8 @@ extern bool have_popcnt;# define TCG_AREG0 TCG_REG_EBP#endif +#define CPU_TLB_BITS_MAX 12
This is probably too much.
Exemplars:NB_MMU_MODES = 1 moxieNB_MMU_MODES = 2 m68kNB_MMU_MODES = 3 alphaNB_MMU_MODES = 7 armNB_MMU_MODES = 8 ppc64
sizeof(CPUArchState):
tlb bits \ modes 1 2 3 7 8
8 13856 25840 38952 92024 182576 12 198176 394480 591912 1382264 1657136
Having 1.5MB of TLB data seems excessive.
Please let's get some performance numbers for various tlb bit sizes.
How much improvement do you get if you increase the size of the victim tlb cache?
r~
Quoted 11 lines · Paolo Bonzini
Quoted 7 lines · Pranith Kumar
This patch increases the number of entries we allow in the TLB. I went over a few architectures to see if increasing it is problematic. Only armv6 seems to have a limitation that only 8 bits can be used for indexing these entries. For other architectures, I increased the number of TLB entries to a 4K-sized cache.
Signed-off-by Pranith Kumar <[email protected]>How did you benchmark this, and can you plot (at least for x86 hosts) the results as
CPU_TLB_BITS_MAXgrows from 8 to 12?
Pranith has some numbers but what we were seeing is the re-fill path creeping up the perf profiles. Because it is so expensive to re-compute the entries pushing up the TLB size does ameliorate the problem.
That said I don't think increasing the TLB size is our only solution. What I've asked for is some sort of idea of the pattern for the eviction of entries from the TLB and the performance of the victim cache. It may be tweaking the locality of that cache would be enough.
One idea I had was With an 8 bit TLB you could afford to have 256 dynamically grown arrays in the victim path - one per entry. Then at flush time you could simply count up the number of victims in the array for that slot. That would give you a good idea if some regions are hotter than others.
--
Alex Bennée