From: Jordan Niethe <jniethe5@gmail.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, npiggin@gmail.com, bgray@linux.ibm.com
Subject: Re: [RFC PATCH] tcg/ppc: Enable direct branching tcg_out_goto_tb with TCG_REG_TB
Date: Wed, 16 Aug 2023 12:59:21 +1000 [thread overview]
Message-ID: <e36dd7ab-cc02-fdce-4cc0-cca90faad3d8@gmail.com> (raw)
In-Reply-To: <bdea1e60-9368-4a56-66f5-26269033b5d9@linaro.org>
On 16/8/23 2:07 am, Richard Henderson wrote:
> On 8/14/23 22:01, Jordan Niethe wrote:
>> Direct branch patching was disabled when using TCG_REG_TB in commit
>> 736a1588c1 ("tcg/ppc: Fix race in goto_tb implementation"). Commit
>> 7502f89c74 ("tcg/ppc: Use prefixed instructions for tcg_out_goto_tb")
>> used the support for pc relative ISAv3.1 instructions to re-enable
>> direct branch patching on POWER10.
>>
>> The issue with direct branch patching with TCG_REG_TB is the lack of
>> synchronization between the new TCG_REG_TB being established and the
>> direct branch being patched in.
>>
>> If each translation block is responsible for establishing its own
>> TCG_REG_TB then there can be no synchronization issue.
>
> That's a good idea, and can be used for other things...
>
> It also begs the question of whether power10 should continue to use
> TCG_REG_TB, loading the address with PADDI. Or whether power9 should,
> like power10, disable USE_REG_TB and use ADDPCIS throughout.
>
> I imagine it depends on usage frequency, whether use of TCG_REG_TB
> allows 1 insn, where addpcis requires 2 insns and prefixed insns require
> 2 or 3 insn slots (depending on alignment).
Yes, I agree. Your v3 series looks good, I'll try and get some
performance numbers with it so we can make a decision about which way to
go on power10 and power9.
>
>
>> + tcg_out32(s, MFSPR | RT(TCG_REG_TMP1) | LR);
>> + /* bcl 20,31,$+4 (Preferred form for getting nia.) */
>> + tcg_out32(s, BC | BO_ALWAYS | BI(7, CR_SO) | 0x4 | LK);
>> + tcg_out32(s, MFSPR | RT(TCG_REG_TB) | LR);
>> + tcg_out32(s, ADDI | TAI(TCG_REG_TB, TCG_REG_TB, -8));
>> + tcg_out32(s, MTSPR | RS(TCG_REG_TMP1) | LR);
>
> Don't need to save/restore LR. It is saved in the prologue and may be
> clobbered within the tb itself (as we do for calls >
>> @@ -2678,6 +2693,12 @@ static void tcg_out_goto_tb(TCGContext *s, int
>> which)
>> tcg_out32(s, MTSPR | RS(TCG_REG_TMP1) | CTR);
>> tcg_out32(s, BCCTR | BO_ALWAYS);
>> set_jmp_reset_offset(s, which);
>> +
>> + /* For the unlinked case, need to reset TCG_REG_TB. */
>> + if (USE_REG_TB) {
>> + tcg_out_movi_int(s, TCG_TYPE_I64, TCG_REG_TB,
>> + (tcg_target_long)s->code_buf, true);
>> + }
>> }
>
> Actually, we don't. The only time we arrive here is when an unlinked TB
> branches to itself. TCG_REG_TB is still valid.
Ok, I was not sure how that was meant to work.
>
>> diff --git a/tcg/tcg.c b/tcg/tcg.c
>> index ddfe9a96cb..20698131c2 100644
>> --- a/tcg/tcg.c
>> +++ b/tcg/tcg.c
>> @@ -6010,6 +6010,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock
>> *tb, uint64_t pc_start)
>> tcg_malloc(sizeof(uint64_t) * s->gen_tb->icount * start_words);
>> num_insns = -1;
>> +#ifdef TCG_TARGET_NEED_ENTER_TB
>> + tcg_out_enter_tb(s);
>> +#endif
>
> Better would be to not have the ifdef, and add this symbol as an empty
> function in all other tcg backends.
>
> I might play around with this a bit.
Thank you for that, adding pcrel support on POWER9 too is really cool.
>
>
> r~
>
prev parent reply other threads:[~2023-08-16 3:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 5:01 [RFC PATCH] tcg/ppc: Enable direct branching tcg_out_goto_tb with TCG_REG_TB Jordan Niethe
2023-08-15 16:07 ` Richard Henderson
2023-08-16 2:59 ` Jordan Niethe [this message]
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=e36dd7ab-cc02-fdce-4cc0-cca90faad3d8@gmail.com \
--to=jniethe5@gmail.com \
--cc=bgray@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.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).