From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>
Subject: Re: [Qemu-devel] [RFC] [tcg] Idea on refactoring target code generation loop (gen_intermediate_code)
Date: Wed, 9 Mar 2016 13:54:07 -0500 [thread overview]
Message-ID: <56E0714F.1090602@twiddle.net> (raw)
In-Reply-To: <87twkfo6tn.fsf@fimbulvetr.bsc.es>
On 03/09/2016 01:16 PM, Lluís Vilanova wrote:
> Richard Henderson writes:
>
>> On 03/09/2016 09:38 AM, Lluís Vilanova wrote:
>>> Hi,
>>>
>>> NOTE: I won't be throwing patches anytime soon, I just want to know if there's
>>> interest in this for the future.
>>>
>>> While adding events for tracing guest instructions, I've found that the
>>> per-target "gen_intermediate_code()" function is very similar but not exactly
>>> the same for each of the targets. This makes architecture-agnostic features
>>> harder to maintain across targets, specially when it comes to their relative
>>> order.
>>>
>>> So, would it be worth it if I generalized part of that code into an
>>> architecture-agnostic function that calls into target-specific hooks wherever it
>>> needs extending? There are many ways to do it that we can discuss later.
>
>> It's worth talking about, since I do believe it would make long-term maintenance
>> across the targets easier.
>
>> These "target-specific hooks" probably ought not be "hooks" in the
>> traditional sense of attaching them to CPUState. I'd be more comfortable with a
>> refactoring that used include files -- maybe .h or maybe .inc.c. If we do the
>> normal sort of hook, then we've got to either expose DisasContext in places we
>> shouldn't, or dynamically allocate it. Neither seems particularly appealing.
>
> Great. I pondered about using QOM vs "template code", and I'm leaning towards
> the latter:
>
> * translate.c:
>
> struct DisasContextArch {
> DisasContext common;
> };
>
> // implement "hooks"
>
> void gen_intermediate_code(CPUArchState *env, TranslationBlock *tb)
> {
> DisasContextArch dc;
> gen_intermediate_code_template(get_cpu(env), &dc.common, tb);
Pointer down into "common" here...
> }
>
> * translate-template.h:
>
> struct DisasContext { /* ... */ };
>
> void gen_intermediate_code_template(CPUState *cpu, DisasContext *dc,
> TranslationBlock *tb)
> {
> // init dc
> // arch-specific init dc hook
>
> // gen_icount, etc.
> while (true) {
> // generic processing code with calls to hooks
... means you have to upcast to DisasContextArch here, or in the hooks themselves.
> }
> }
>
> While initially simpler, the "template code" still feels a little dirty to
> me. With QOM, you could implement a DisasContextClass that provides the
> per-target hook pointers, which can be globally allocated once per target and
> pointed to by the DisasContext allocated in stack.
>
> I'm not sure about what you mean by exposing DisasContext in places it shouldn't
> be, though.
You either split DisasContextArch / DisasContext in "odd" ways, and then have
to cast back and forth, or you have to expose the whole of DisasContextArch.
It's the latter that I considered inappropriate.
Alternately... can we broach the subject of C++? Honestly, it seems we work
too hard sometimes to re-implement templates and classes in C.
r~
next prev parent reply other threads:[~2016-03-09 18:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-09 14:38 [Qemu-devel] [RFC] [tcg] Idea on refactoring target code generation loop (gen_intermediate_code) Lluís Vilanova
2016-03-09 15:52 ` Richard Henderson
2016-03-09 18:16 ` Lluís Vilanova
2016-03-09 18:54 ` Richard Henderson [this message]
2016-03-09 22:29 ` Lluís Vilanova
2016-03-09 23:27 ` Peter Maydell
2016-03-13 13:16 ` Lluís Vilanova
2016-03-13 16:25 ` Peter Maydell
2016-03-14 7:06 ` Markus Armbruster
2016-03-14 11:13 ` Lluís Vilanova
2016-04-03 13:05 ` Lluís Vilanova
2016-04-07 14:27 ` Markus Armbruster
2016-04-07 14:49 ` Peter Maydell
2016-04-07 15:01 ` Paolo Bonzini
2016-04-08 13:15 ` Markus Armbruster
2016-04-08 14:14 ` Paolo Bonzini
2016-04-11 5:50 ` Claudio Fontana
2016-04-11 13:11 ` Lluís Vilanova
2016-03-14 12:23 ` KONRAD Frederic
2016-03-14 14:14 ` Paolo Bonzini
2016-03-14 14:26 ` Lluís Vilanova
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=56E0714F.1090602@twiddle.net \
--to=rth@twiddle.net \
--cc=crosthwaite.peter@gmail.com \
--cc=pbonzini@redhat.com \
--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).