From: "Alex Bennée" <alex.bennee@linaro.org>
To: Mikhail Tyutin <m.tyutin@yadro.com>
Cc: qemu-devel@nongnu.org, richard.henderson@linaro.org,
pbonzini@redhat.com, Aleksandr Anenkov <a.anenkov@yadro.com>
Subject: Re: [PATCH] Add support of callbacks after instructions to plugin api
Date: Tue, 08 Aug 2023 16:15:41 +0100 [thread overview]
Message-ID: <87h6p97eda.fsf@linaro.org> (raw)
In-Reply-To: <20230808134435.2719-1-m.tyutin@yadro.com>
Mikhail Tyutin <m.tyutin@yadro.com> writes:
> Initially, we can only call the callback BEFORE instructions. This
> commit adds the ability to insert the callback AFTER instructions.
What is the use case for this? Because:
<snip>
>
> +
> + /* Stop translation if translate_insn so indicated. */
> + if (db->is_jmp != DISAS_NEXT) {
> + break;
> + }
> +
> /*
> * We can't instrument after instructions that change control
> * flow although this only really affects post-load operations.
> @@ -193,11 +199,6 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
> plugin_gen_insn_end();
> }
>
> - /* Stop translation if translate_insn so indicated. */
> - if (db->is_jmp != DISAS_NEXT) {
> - break;
> - }
> -
> /* Stop translation if the output buffer is full,
> or we have executed all of the allowed instructions. */
> if (tcg_op_buf_full() || db->num_insns >= db->max_insns) {
> @@ -211,6 +212,13 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
> gen_tb_end(tb, cflags, icount_start_insn, db->num_insns);
>
> if (plugin_enabled) {
> + /*
> + * Last chance to call plugin_gen_insn_end() if is skipped in translation
> + * loop above.
> + */
> + if (db->is_jmp != DISAS_NEXT && tcg_ctx->exitreq_label == NULL) {
> + plugin_gen_insn_end();
> + }
> plugin_gen_tb_end(cpu);
> }
>
<snip>
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -2819,6 +2819,22 @@ void tcg_gen_exit_tb(const TranslationBlock *tb, unsigned idx)
> tcg_debug_assert(idx == TB_EXIT_REQUESTED);
> }
>
> +#ifdef CONFIG_PLUGIN
> + /*
> + * Some of instruction generators insert exit_tb explicitelly to
> + * trigger early exit from translation block. On the other hand
> + * translation loop (translator_loop()) inserts plugin callbacks
> + * after instruction is generated, but it appears as dead code
> + * because of the explicit exit_tb insert.
> + *
> + * Calling plugin_gen_insn_end() here before the exit allows
> + * plugins to receive control before translation block exits.
> + */
> + if (tcg_ctx->plugin_insn) {
> + plugin_gen_insn_end();
> + }
> +#endif
> +
This isn't enough as we can exit the run loop in helpers. This is why
the execlog plugin jumps the hoops it does to complete handling of
execution on the next instruction.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
prev parent reply other threads:[~2023-08-08 15:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 13:44 [PATCH] Add support of callbacks after instructions to plugin api Mikhail Tyutin
2023-08-08 14:47 ` Richard Henderson
2023-08-08 15:48 ` Mikhail Tyutin
2023-08-08 15:15 ` Alex Bennée [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=87h6p97eda.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=a.anenkov@yadro.com \
--cc=m.tyutin@yadro.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@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).