diff mbox

[v2,1/5] tcg: Refactor helper_lookup_tb_ptr

Message ID 20170616201921.GB27617@flamenco (mailing list archive)
State New, archived
Headers show

Commit Message

Emilio Cota June 16, 2017, 8:19 p.m. UTC
On Wed, Jun 14, 2017 at 12:48:17 -0700, Richard Henderson wrote:
> --- a/tcg-runtime.c
> +++ b/tcg-runtime.c
(snip)
>          tb = tb_htable_lookup(cpu, addr, cs_base, flags);
> -        if (likely(tb)) {
> -            atomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(addr)], tb);
> -            goto found;
> +        if (!tb) {
> +            return ret;

While booting debian-arm I'm measuring (see below) a hit rate in the
high 90's for the htable lookups here, so adding an 'unlikely()'
hint would be a good idea.

[ I'm using the patch currently in your tcg-next branch, i.e. 0a2adf4e2 ]

		E.

The below prints during bootup+shutdown:

hit rate: 94.599500%
hit rate: 95.794100%
hit rate: 96.617900%
hit rate: 96.527275%
hit rate: 96.341320%
hit rate: 96.641883%

Comments

Richard Henderson June 16, 2017, 8:46 p.m. UTC | #1
On 06/16/2017 01:19 PM, Emilio G. Cota wrote:
> While booting debian-arm I'm measuring (see below) a hit rate in the
> high 90's for the htable lookups here, so adding an 'unlikely()'
> hint would be a good idea.

GCC already predicts null pointers unlikely.
We get identical code with and without the hint.


r~
diff mbox

Patch

diff --git a/tcg-runtime.c b/tcg-runtime.c
index ec3a34e..addc3fa 100644
--- a/tcg-runtime.c
+++ b/tcg-runtime.c
@@ -150,6 +150,7 @@  void *HELPER(lookup_tb_ptr)(CPUArchState *env, target_ulong addr)
     TranslationBlock *tb;
     target_ulong cs_base, pc;
     uint32_t flags, addr_hash;
+    static unsigned long long accesses, found;

     addr_hash = tb_jmp_cache_hash_func(addr);
     tb = atomic_rcu_read(&cpu->tb_jmp_cache[addr_hash]);
@@ -159,11 +160,16 @@  void *HELPER(lookup_tb_ptr)(CPUArchState *env, target_ulong addr)
                    && tb->pc == addr
                    && tb->cs_base == cs_base
                    && tb->flags == flags))) {
+        accesses++;
+        if (!(accesses % 1000000)) {
+            fprintf(stderr, "hit rate: %f%%\n", (double)found * 100 / accesses);
+        }
         tb = tb_htable_lookup(cpu, addr, cs_base, flags);
         if (!tb) {
             return tcg_ctx.code_gen_epilogue;
         }
         atomic_set(&cpu->tb_jmp_cache[addr_hash], tb);
+        found++;
     }

     qemu_log_mask_and_addr(CPU_LOG_EXEC, addr,