qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Michael Eager <eager@eagerm.com>, qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] cpu_io_recompile, icount, and re-issued instructions
Date: Tue, 2 May 2017 09:59:03 +0200	[thread overview]
Message-ID: <3a7aa06d-a419-69d7-a54a-e963d4ba748f@redhat.com> (raw)
In-Reply-To: <5906960F.2050305@eagerm.com>



On 01/05/2017 03:57, Michael Eager wrote:
> 
> 
> I'm seeing incorrect values when there is a write to a memory-mapped I/O
> device when icount is set.  What I see happening is that a TB with ~20
> instructions is executed which contains a write to the MM I/O address. 
> When it gets to the io_write routine, can_do_io is false, which results
> in a call to cpu_io_recompile.
> 
> cpu_io_recompile does what it (sort of) says it is supposed to do: it
> builds a new TB with the I/O instruction as the last instruction in the
> block, then re-issues the TB.  The problem is that the new TB contains
> the instructions before the I/O instruction, so they are executed a
> second time.

They shouldn't.  When called from cpu_io_recompile,
cpu_restore_state_from_tb should compute the I/O instruction's target PC
from the host PC (stored in retaddr).

Then what happens is the following:

- cpu_io_recompile generates a new TB ending with the I/O instruction.
This new TB has a hash table conflict with the old TB (same
PC/cs_base/flags) the old TB is implicitly removed

- cpu_io_recompile calls cpu_loop_exit_noexc, which goes back to the
execution loop with updated PC

- because the PC is different, a new TB is looked up for the I/O
instruction's PC.  The TB probably is not there and translation starts
again, this time at the I/O instruction

- the new TB, when executed, causes cpu_io_recompile to fire again.
This is the inefficient part mentioned in cpu_io_recompile

- cpu_io_recompile now compiles a one-instruction TB and goes back to
the execution loop

- finally the execution loop executes the one-instruction TB for the I/O
instruction, then it can go on

Thanks,

Paolo

  reply	other threads:[~2017-05-02  7:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-01  1:57 [Qemu-devel] cpu_io_recompile, icount, and re-issued instructions Michael Eager
2017-05-02  7:59 ` Paolo Bonzini [this message]
2017-05-02 17:59   ` Michael Eager
  -- strict thread matches above, loose matches on Subject: below --
2017-05-01  0:55 Michael Eager

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=3a7aa06d-a419-69d7-a54a-e963d4ba748f@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=eager@eagerm.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).