qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Anton Johansson <anjo@rev.ng>, qemu-devel@nongnu.org
Cc: ale@rev.ng, pbonzini@redhat.com, eduardo@habkost.net,
	peter.maydell@linaro.org
Subject: Re: [PATCH 2/3] Replace `TARGET_TB_PCREL` with `CF_PCREL`
Date: Wed, 8 Feb 2023 11:14:20 -1000	[thread overview]
Message-ID: <e8aa5585-0e5a-de30-7fc6-669697a79cb0@linaro.org> (raw)
In-Reply-To: <20230207104352.11055-3-anjo@rev.ng>

On 2/7/23 00:43, Anton Johansson wrote:
> diff --git a/accel/tcg/tb-jmp-cache.h b/accel/tcg/tb-jmp-cache.h
> index b3f6e78835..083939b302 100644
> --- a/accel/tcg/tb-jmp-cache.h
> +++ b/accel/tcg/tb-jmp-cache.h
>   static inline TranslationBlock *
> -tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t hash)
> +tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t cflags, uint32_t hash)
>   {
> -#if TARGET_TB_PCREL
> -    /* Use acquire to ensure current load of pc from jc. */
> -    return qatomic_load_acquire(&jc->array[hash].tb);
> -#else
> -    /* Use rcu_read to ensure current load of pc from *tb. */
> -    return qatomic_rcu_read(&jc->array[hash].tb);
> -#endif
> +    if (cflags & CF_PCREL) {
> +        /* Use acquire to ensure current load of pc from jc. */
> +        return qatomic_load_acquire(&jc->array[hash].tb);
> +    } else {
> +        /* Use rcu_read to ensure current load of pc from *tb. */
> +        return qatomic_rcu_read(&jc->array[hash].tb);
> +    }
>   }
>   
>   static inline target_ulong
>   tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb)
>   {
> -#if TARGET_TB_PCREL
> -    return jc->array[hash].pc;
> -#else
> -    return tb_pc(tb);
> -#endif
> +    if (tb_cflags(tb) & CF_PCREL) {
> +        return jc->array[hash].pc;
> +    } else {
> +        return tb_pc(tb);
> +    }
>   }
>   
>   static inline void
>   tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash,
>                    TranslationBlock *tb, target_ulong pc)
>   {
> -#if TARGET_TB_PCREL
> -    jc->array[hash].pc = pc;
> -    /* Use store_release on tb to ensure pc is written first. */
> -    qatomic_store_release(&jc->array[hash].tb, tb);
> -#else
> -    /* Use the pc value already stored in tb->pc. */
> -    qatomic_set(&jc->array[hash].tb, tb);
> -#endif
> +    if (tb_cflags(tb) & CF_PCREL) {
> +        jc->array[hash].pc = pc;
> +        /* Use store_release on tb to ensure pc is written first. */
> +        qatomic_store_release(&jc->array[hash].tb, tb);
> +    } else{
> +        /* Use the pc value already stored in tb->pc. */
> +        qatomic_set(&jc->array[hash].tb, tb);
> +    }
>   }

These little functions made sense when they were isolating ifdefs.
When they protect a sequence of conditions,

     if (CF_PCREL) {
         a
     } else {
         b
     }
     if (CF_PCREL) {
         c
     } else {
         d
     }
     if (CF_PCREL) {
         e
     } else {
         f
     }

we probably want to hoist one check in the callers.

> +    return ((tb_cflags(a) & CF_PCREL || tb_pc(a) == tb_pc(b)) &&

Similarly things like this, where we have a PCREL test here, and also within tb_pc().

> -    h = tb_hash_func(phys_pc, (TARGET_TB_PCREL ? 0 : tb_pc(tb)),
> +    h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb_pc(tb)),

etc.

This does too much at once, and also disables TARGET_TB_PCREL for one patch, changing 
behaviour during bisection.


r~


  parent reply	other threads:[~2023-02-08 21:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07 10:43 [PATCH 0/3] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
2023-02-07 10:43 ` [PATCH 1/3] include/exec: Introduce `CF_PCREL` Anton Johansson via
2023-02-08 20:47   ` Richard Henderson
2023-02-07 10:43 ` [PATCH 2/3] Replace `TARGET_TB_PCREL` with `CF_PCREL` Anton Johansson via
2023-02-07 11:26   ` Philippe Mathieu-Daudé
2023-02-08 12:48     ` Anton Johansson via
2023-02-08 21:14   ` Richard Henderson [this message]
2023-02-07 10:43 ` [PATCH 3/3] target: Set `CF_PCREL` for arm and i386 frontends Anton Johansson via
2023-02-07 11:27   ` Philippe Mathieu-Daudé
2023-02-08 12:51     ` Anton Johansson via
2023-02-08 21:15   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e8aa5585-0e5a-de30-7fc6-669697a79cb0@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=ale@rev.ng \
    --cc=anjo@rev.ng \
    --cc=eduardo@habkost.net \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).