All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lluís Vilanova" <vilanova@ac.upc.edu>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Peter Crosthwaite <crosthwaite.peter@gmail.com>,
	"Emilio G. Cota" <cota@braap.org>,
	qemu-devel@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v12 04/27] target: [tcg] Add generic translation framework
Date: Wed, 12 Jul 2017 11:59:52 +0300	[thread overview]
Message-ID: <87zicaf2t3.fsf@frigg.lan> (raw)
In-Reply-To: <87h8yialdo.fsf@linaro.org> ("Alex Bennée"'s message of "Tue, 11 Jul 2017 19:17:39 +0100")

Alex Bennée writes:

> Lluís Vilanova <vilanova@ac.upc.edu> writes:

>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>> ---
>> accel/tcg/Makefile.objs   |    1
>> accel/tcg/translator.c    |  152 +++++++++++++++++++++++++++++++++++++++++++++
>> include/exec/gen-icount.h |    2 -
>> include/exec/translator.h |   99 +++++++++++++++++++++++++++++
>> 4 files changed, 253 insertions(+), 1 deletion(-)
>> create mode 100644 accel/tcg/translator.c
>> 
>> diff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs
>> index f173cd5397..3a5da5357c 100644
>> --- a/accel/tcg/Makefile.objs
>> +++ b/accel/tcg/Makefile.objs
>> @@ -1,3 +1,4 @@
>> obj-$(CONFIG_SOFTMMU) += tcg-all.o
>> obj-$(CONFIG_SOFTMMU) += cputlb.o
>> obj-y += cpu-exec.o cpu-exec-common.o translate-all.o translate-common.o
>> +obj-y += translator.o

> There is a merge conflict here with the current master.

I'll rebase for v13.


>> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
>> new file mode 100644
>> index 0000000000..9e0343cbb1
>> --- /dev/null
>> +++ b/accel/tcg/translator.c
>> @@ -0,0 +1,152 @@
>> +/*
>> + * Generic intermediate code generation.
>> + *
>> + * Copyright (C) 2016-2017 Lluís Vilanova <vilanova@ac.upc.edu>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
>> + * See the COPYING file in the top-level directory.
>> + */
>> +
>> +#include "qemu/osdep.h"
>> +#include "qemu-common.h"
>> +#include "qemu/error-report.h"
>> +#include "cpu.h"
>> +#include "tcg/tcg.h"
>> +#include "tcg/tcg-op.h"
>> +#include "exec/exec-all.h"
>> +#include "exec/gen-icount.h"
>> +#include "exec/log.h"
>> +#include "exec/translator.h"
>> +
>> +
>> +static inline void translate_block_tcg_check(const DisasContextBase *db)
>> +{
>> +    if (tcg_check_temp_count()) {
>> +        error_report("warning: TCG temporary leaks before "TARGET_FMT_lx,
>> +                     db->pc_next);
>> +    }
>> +}
>> +
>> +void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
>> +                     CPUState *cpu, TranslationBlock *tb)
>> +{
>> +    int max_insns;
>> +
>> +    /* Initialize DisasContext */
>> +    db->tb = tb;
>> +    db->pc_first = tb->pc;
>> +    db->pc_next = db->pc_first;
>> +    db->is_jmp = DISAS_NEXT;
>> +    db->num_insns = 0;
>> +    db->singlestep_enabled = cpu->singlestep_enabled;
>> +    ops->init_disas_context(db, cpu);
>> +
>> +    /* Initialize globals */
>> +    tcg_clear_temp_count();
>> +
>> +    /* Instruction counting */
>> +    max_insns = db->tb->cflags & CF_COUNT_MASK;
>> +    if (max_insns == 0) {
>> +        max_insns = CF_COUNT_MASK;
>> +    }
>> +    if (max_insns > TCG_MAX_INSNS) {
>> +        max_insns = TCG_MAX_INSNS;
>> +    }
>> +    if (db->singlestep_enabled || singlestep) {
>> +        max_insns = 1;
>> +    }
>> +
>> +    /* Start translating */
>> +    gen_tb_start(db->tb);
>> +    ops->tb_start(db, cpu);
>> +
>> +    while (true) {
>> +        db->num_insns++;
>> +        ops->insn_start(db, cpu);
>> +
>> +        /* Early exit before breakpoint checks */
>> +        if (unlikely(db->is_jmp != DISAS_NEXT)) {
>> +            break;
>> +        }
>> +
>> +        /* Pass breakpoint hits to target for further processing */
>> +        if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
>> +            CPUBreakpoint *bp;
>> +            QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
>> +                if (bp->pc == db->pc_next) {
>> +                    BreakpointCheckType bp_check =
>> +                        ops->breakpoint_check(db, cpu, bp);
>> +                    switch (bp_check) {
>> +                    case BC_MISS:
>> +                        /* Target ignored this breakpoint, go to next */
>> +                        break;
>> +                    case BC_HIT_INSN:
>> +                        /* Hit, keep translating */
>> +                        /*
>> +                         * TODO: if we're never going to have more than one
>> +                         *       BP in a single address, we can simply use a
>> +                         *       bool here.
>> +                         */
>> +                        goto done_breakpoints;
>> +                    case BC_HIT_TB:
>> +                        /* Hit, end TB */
>> +                        goto done_generating;
>> +                    default:
>> +                        g_assert_not_reached();
>> +                    }
>> +                }
>> +            }
>> +        }
>> +    done_breakpoints:

> For the sake of keeping the core loop easy to follow maybe it would be
> better to have a helper function for the breakpoint handling? Really
> there is only one result from the helper which is do we continue the
> loop or jump to done_generating.

The new v13 has a much simpler loop that will hopefully address your concerns.

>> +
>> +        /* Accept I/O on last instruction */
>> +        if (db->num_insns == max_insns && (db->tb->cflags & CF_LAST_IO)) {
>> +            gen_io_start();
>> +        }
>> +
>> +        /* Disassemble one instruction */
>> +        db->pc_next = ops->translate_insn(db, cpu);
>> +
>> +        /**************************************************/
>> +        /* Conditions to stop translation                 */
>> +        /**************************************************/
>> +
>> +        /* Target-specific conditions set by disassembly */
>> +        if (db->is_jmp != DISAS_NEXT) {
>> +            break;
>> +        }
>> +
>> +        /* Too many instructions */
>> +        if (tcg_op_buf_full() || db->num_insns >= max_insns) {
>> +            db->is_jmp = DISAS_TOO_MANY;
>> +            break;
>> +        }
>> +
>> +        translate_block_tcg_check(db);
>> +    }

> This may be a personal taste thing but having while(true) {} and breaks
> is harder to follow than do { stuff } while (!done);

I think it is. I prefer to see the loop condition up-front, unless a do-while
makes the condition logic substantially simpler.


Thanks,
  Lluis

  reply	other threads:[~2017-07-12  9:00 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-07 11:40 [Qemu-devel] [PATCH v12 00/27] translate: [tcg] Generic translation framework Lluís Vilanova
2017-07-07 11:44 ` [PATCH v12 01/27] Pass generic CPUState to gen_intermediate_code() Lluís Vilanova
2017-07-07 11:44   ` [Qemu-devel] " Lluís Vilanova
2017-07-11 19:22   ` Alex Bennée
2017-07-11 19:22     ` [Qemu-devel] " Alex Bennée
2017-07-07 11:48 ` [Qemu-devel] [PATCH v12 02/27] cpu-exec: Avoid global variables in icount-related functions Lluís Vilanova
2017-07-11 19:25   ` Alex Bennée
2017-07-12  8:42     ` Lluís Vilanova
2017-07-12 22:06       ` Emilio G. Cota
2017-07-07 11:52 ` [PATCH v12 03/27] target: [tcg] Use a generic enum for DISAS_ values Lluís Vilanova
2017-07-07 11:52   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:10   ` Alex Bennée
2017-07-12  9:10     ` [Qemu-devel] " Alex Bennée
2017-07-12 10:56     ` Lluís Vilanova
2017-07-12 10:56       ` Lluís Vilanova
2017-07-12 16:53     ` Richard Henderson
2017-07-12 16:53       ` [Qemu-devel] " Richard Henderson
2017-07-07 11:56 ` [Qemu-devel] [PATCH v12 04/27] target: [tcg] Add generic translation framework Lluís Vilanova
2017-07-07 18:42   ` Richard Henderson
2017-07-11 16:40     ` Lluís Vilanova
2017-07-11 17:21       ` Richard Henderson
2017-07-12  8:50         ` Lluís Vilanova
2017-07-11 18:17   ` Alex Bennée
2017-07-12  8:59     ` Lluís Vilanova [this message]
2017-07-12  9:13       ` Alex Bennée
2017-07-07 12:00 ` [Qemu-devel] [PATCH v12 05/27] target/i386: [tcg] Port to DisasContextBase Lluís Vilanova
2017-07-12  9:18   ` Alex Bennée
2017-07-12 11:00     ` Lluís Vilanova
2017-07-07 12:04 ` [Qemu-devel] [PATCH v12 06/27] target/i386: [tcg] Port to init_disas_context Lluís Vilanova
2017-07-12  9:20   ` Alex Bennée
2017-07-07 12:08 ` [Qemu-devel] [PATCH v12 07/27] target/i386: [tcg] Port to insn_start Lluís Vilanova
2017-07-12  9:21   ` Alex Bennée
2017-07-07 12:13 ` [Qemu-devel] [PATCH v12 08/27] target/i386: [tcg] Port to breakpoint_check Lluís Vilanova
2017-07-07 12:17 ` [Qemu-devel] [PATCH v12 09/27] target/i386: [tcg] Port to translate_insn Lluís Vilanova
2017-07-07 12:21 ` [Qemu-devel] [PATCH v12 10/27] target/i386: [tcg] Port to tb_stop Lluís Vilanova
2017-07-07 12:25 ` [Qemu-devel] [PATCH v12 11/27] target/i386: [tcg] Port to disas_log Lluís Vilanova
2017-07-07 12:29 ` [Qemu-devel] [PATCH v12 12/27] target/i386: [tcg] Port to generic translation framework Lluís Vilanova
2017-07-07 12:33 ` [PATCH v12 13/27] target/arm: [tcg] Port to DisasContextBase Lluís Vilanova
2017-07-07 12:33   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:25   ` Alex Bennée
2017-07-12  9:25     ` [Qemu-devel] " Alex Bennée
2017-07-07 12:37 ` [PATCH v12 14/27] target/arm: [tcg] Port to init_disas_context Lluís Vilanova
2017-07-07 12:37   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:27   ` Alex Bennée
2017-07-12  9:27     ` [Qemu-devel] " Alex Bennée
2017-07-07 12:41 ` [PATCH v12 15/27] target/arm: [tcg,a64] " Lluís Vilanova
2017-07-07 12:41   ` [Qemu-devel] [PATCH v12 15/27] target/arm: [tcg, a64] " Lluís Vilanova
2017-07-12  9:30   ` [PATCH v12 15/27] target/arm: [tcg,a64] " Alex Bennée
2017-07-12  9:30     ` [Qemu-devel] [PATCH v12 15/27] target/arm: [tcg, a64] " Alex Bennée
2017-07-07 12:46 ` [PATCH v12 16/27] target/arm: [tcg] Port to tb_start Lluís Vilanova
2017-07-07 12:46   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:31   ` Alex Bennée
2017-07-12  9:31     ` [Qemu-devel] " Alex Bennée
2017-07-07 12:50 ` [PATCH v12 17/27] target/arm: [tcg] Port to insn_start Lluís Vilanova
2017-07-07 12:50   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:32   ` Alex Bennée
2017-07-12  9:32     ` [Qemu-devel] " Alex Bennée
2017-07-07 12:54 ` [PATCH v12 18/27] target/arm: [tcg,a64] " Lluís Vilanova
2017-07-07 12:54   ` [Qemu-devel] [PATCH v12 18/27] target/arm: [tcg, a64] " Lluís Vilanova
2017-07-12  9:32   ` [PATCH v12 18/27] target/arm: [tcg,a64] " Alex Bennée
2017-07-12  9:32     ` [Qemu-devel] [PATCH v12 18/27] target/arm: [tcg, a64] " Alex Bennée
2017-07-07 12:58 ` [PATCH v12 19/27] target/arm: [tcg] Port to breakpoint_check Lluís Vilanova
2017-07-07 12:58   ` [Qemu-devel] " Lluís Vilanova
2017-07-07 13:02 ` [PATCH v12 20/27] target/arm: [tcg,a64] " Lluís Vilanova
2017-07-07 13:02   ` [Qemu-devel] [PATCH v12 20/27] target/arm: [tcg, a64] " Lluís Vilanova
2017-07-07 13:06 ` [PATCH v12 21/27] target/arm: [tcg] Port to translate_insn Lluís Vilanova
2017-07-07 13:06   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:39   ` Alex Bennée
2017-07-12  9:39     ` [Qemu-devel] " Alex Bennée
2017-07-12 11:05     ` Lluís Vilanova
2017-07-12 11:05       ` Lluís Vilanova
2017-07-07 13:10 ` [PATCH v12 22/27] target/arm: [tcg,a64] " Lluís Vilanova
2017-07-07 13:10   ` [Qemu-devel] [PATCH v12 22/27] target/arm: [tcg, a64] " Lluís Vilanova
2017-07-07 13:14 ` [PATCH v12 23/27] target/arm: [tcg] Port to tb_stop Lluís Vilanova
2017-07-07 13:14   ` [Qemu-devel] " Lluís Vilanova
2017-07-07 13:18 ` [PATCH v12 24/27] target/arm: [tcg,a64] " Lluís Vilanova
2017-07-07 13:18   ` [Qemu-devel] [PATCH v12 24/27] target/arm: [tcg, a64] " Lluís Vilanova
2017-07-07 13:23 ` [PATCH v12 25/27] target/arm: [tcg] Port to disas_log Lluís Vilanova
2017-07-07 13:23   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:41   ` Alex Bennée
2017-07-12  9:41     ` [Qemu-devel] " Alex Bennée
2017-07-07 13:27 ` [PATCH v12 26/27] target/arm: [tcg,a64] " Lluís Vilanova
2017-07-07 13:27   ` [Qemu-devel] [PATCH v12 26/27] target/arm: [tcg, a64] " Lluís Vilanova
2017-07-07 13:31 ` [PATCH v12 27/27] target/arm: [tcg] Port to generic translation framework Lluís Vilanova
2017-07-07 13:31   ` [Qemu-devel] " Lluís Vilanova
2017-07-12  9:47 ` [Qemu-devel] [PATCH v12 00/27] translate: [tcg] Generic " Alex Bennée
2017-07-12 11:10   ` 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=87zicaf2t3.fsf@frigg.lan \
    --to=vilanova@ac.upc.edu \
    --cc=alex.bennee@linaro.org \
    --cc=cota@braap.org \
    --cc=crosthwaite.peter@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.