diff mbox

[RFC,1/8] cputlb: add physical address to CPUTLBEntry

Message ID 1431118934-20900-2-git-send-email-cota@braap.org
State New
Headers show

Commit Message

Emilio Cota May 8, 2015, 9:02 p.m. UTC
Having the physical address in the TLB entry will allow us
to portably obtain the physical address of a memory access,
which will prove useful when implementing a scalable emulation
of atomic instructions.

Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 cputlb.c                |  1 +
 include/exec/cpu-defs.h | 11 ++++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

Comments

Richard Henderson May 8, 2015, 9:51 p.m. UTC | #1
On 05/08/2015 02:02 PM, Emilio G. Cota wrote:
> -#if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
> -#define CPU_TLB_ENTRY_BITS 4
> -#else
> +#if TARGET_LONG_BITS == 32
>  #define CPU_TLB_ENTRY_BITS 5
> +#else
> +#define CPU_TLB_ENTRY_BITS 6
>  #endif

Ouch.  24 of 64 wasted bytes for 64-bit?

I wonder if there's a better way we can encode this to avoid 3 copies of the
virtual address for read/write/code.  Or if we're better off using more than
one insn to multiply by a non-power-of-two.  Or if the hardware multiplier is
fast enough just multiply by the proper constant.


r~
diff mbox

Patch

diff --git a/cputlb.c b/cputlb.c
index 7606548..2cd5912 100644
--- a/cputlb.c
+++ b/cputlb.c
@@ -330,6 +330,7 @@  void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr,
     } else {
         te->addr_write = -1;
     }
+    te->addr_phys = paddr;
 }
 
 /* Add a new TLB entry, but without specifying the memory
diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index 3f56546..67aa0a0 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -75,10 +75,10 @@  typedef uint64_t target_ulong;
 /* use a fully associative victim tlb of 8 entries */
 #define CPU_VTLB_SIZE 8
 
-#if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
-#define CPU_TLB_ENTRY_BITS 4
-#else
+#if TARGET_LONG_BITS == 32
 #define CPU_TLB_ENTRY_BITS 5
+#else
+#define CPU_TLB_ENTRY_BITS 6
 #endif
 
 typedef struct CPUTLBEntry {
@@ -91,13 +91,14 @@  typedef struct CPUTLBEntry {
     target_ulong addr_read;
     target_ulong addr_write;
     target_ulong addr_code;
+    target_ulong addr_phys;
     /* Addend to virtual address to get host address.  IO accesses
        use the corresponding iotlb value.  */
     uintptr_t addend;
     /* padding to get a power of two size */
     uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
-                  (sizeof(target_ulong) * 3 +
-                   ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) +
+                  (sizeof(target_ulong) * 4 +
+                   ((-sizeof(target_ulong) * 4) & (sizeof(uintptr_t) - 1)) +
                    sizeof(uintptr_t))];
 } CPUTLBEntry;