From: Aurelien Jarno <aurelien@aurel32.net>
To: Pavel Dovgaluk <Pavel.Dovgaluk@ispras.ru>
Cc: pbonzini@redhat.com, rth7680@gmail.com, leon.alrae@imgtec.com,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 2/3] target-mips: improve exceptions handling
Date: Wed, 1 Jul 2015 18:37:22 +0200 [thread overview]
Message-ID: <20150701163722.GF11361@aurel32.net> (raw)
In-Reply-To: <000801d0b238$e02072c0$a0615840$@Dovgaluk@ispras.ru>
On 2015-06-29 09:57, Pavel Dovgaluk wrote:
> > From: Aurelien Jarno [mailto:aurelien@aurel32.net]
> > On 2015-06-18 16:28, Pavel Dovgalyuk wrote:
> > > This patch improves exception handling in MIPS.
> > > Instructions generate several types of exceptions.
> > > When exception is generated, it breaks the execution of the current translation
> > > block. Implementation of the exceptions handling does not correctly
> > > restore icount for the instruction which caused the exception. In most cases
> > > icount will be decreased by the value equal to the size of TB.
> > > This patch passes pointer to the translation block internals to the exception
> > > handler. It allows correct restoring of the icount value.
> > >
> > > v3 changes:
> > > This patch stops translation when instruction which always generates exception
> > > is translated. This improves the performance of the patched version compared
> > > to original one.
> > >
> > > Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> > > ---
> > > target-mips/cpu.h | 28 +++
> > > target-mips/helper.h | 1
> > > target-mips/msa_helper.c | 5 -
> > > target-mips/op_helper.c | 183 ++++++++++------------
> > > target-mips/translate.c | 379 ++++++++++++++++++++++------------------------
> > > 5 files changed, 302 insertions(+), 294 deletions(-)
> > >
> > > diff --git a/target-mips/cpu.h b/target-mips/cpu.h
> > > index f9d2b4c..70ba39a 100644
> > > --- a/target-mips/cpu.h
> > > +++ b/target-mips/cpu.h
> > > @@ -1015,4 +1015,32 @@ static inline void cpu_mips_store_cause(CPUMIPSState *env,
> > target_ulong val)
> > > }
> > > #endif
> > >
> > > +static inline void QEMU_NORETURN do_raise_exception_err(CPUMIPSState *env,
> > > + uint32_t exception,
> > > + int error_code,
> > > + uintptr_t pc)
> > > +{
> > > + CPUState *cs = CPU(mips_env_get_cpu(env));
> > > +
> > > + if (exception < EXCP_SC) {
> > > + qemu_log("%s: %d %d\n", __func__, exception, error_code);
> > > + }
> > > + cs->exception_index = exception;
> > > + env->error_code = error_code;
> > > +
> > > + if (pc) {
> > > + /* now we have a real cpu fault */
> > > + cpu_restore_state(cs, pc);
> > > + }
> > > +
> > > + cpu_loop_exit(cs);
> >
> > What about creating a cpu_loop_exit_restore(cs, pc) (maybe with a better
> > name?) in the common code, if we now have to repeat this pattern for
> > every target?
>
> Ok.
>
> > > diff --git a/target-mips/translate.c b/target-mips/translate.c
> > > index fd063a2..f87d5ac 100644
> > > --- a/target-mips/translate.c
> > > +++ b/target-mips/translate.c
> > > @@ -1677,15 +1677,21 @@ generate_exception_err (DisasContext *ctx, int excp, int err)
> > > gen_helper_raise_exception_err(cpu_env, texcp, terr);
> > > tcg_temp_free_i32(terr);
> > > tcg_temp_free_i32(texcp);
> > > + ctx->bstate = BS_STOP;
> > > }
> > >
> > > static inline void
> > > generate_exception (DisasContext *ctx, int excp)
> > > {
> > > - save_cpu_state(ctx, 1);
> > > gen_helper_0e0i(raise_exception, excp);
> > > }
> > >
> > > +static inline void
> > > +generate_exception_end(DisasContext *ctx, int excp)
> > > +{
> > > + generate_exception_err(ctx, excp, 0);
> > > +}
> > > +
> >
> > This sets error_code to 0, which is different than leaving it unchanged.
> > This might be ok, but have you checked there is no side effect?
>
> Previous version called do_raise_exception, which passes 0 as error_code.
Ok, it's all fine then.
> >
> > > /* Addresses computation */
> > > static inline void gen_op_addr_add (DisasContext *ctx, TCGv ret, TCGv arg0, TCGv arg1)
> > > {
> > > @@ -1731,7 +1737,7 @@ static inline void check_cp1_enabled(DisasContext *ctx)
> > > static inline void check_cop1x(DisasContext *ctx)
> > > {
> > > if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
> > > - generate_exception(ctx, EXCP_RI);
> > > + generate_exception_end(ctx, EXCP_RI);
> >
> > I don't think it is correct. Before triggering such an exception, we
> > were saving the CPU state, and not going through retranslation. With
> > this change, we don't save the CPU state, but we don't go through
> > retranslation either.
> >
> > The rule is to either go through retranslation, or to save the CPU state
> > before a possible exception.
>
> generate_exception_end saves CPU state and stops the translation
> through calling of generate_exception_err function.
I missed that. Thanks for pointing me to that. That looks fine then.
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://www.aurel32.net
next prev parent reply other threads:[~2015-07-01 16:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-18 13:28 [Qemu-devel] [PATCH v3 0/3] Fix exceptions handling for MIPS and i386 Pavel Dovgalyuk
2015-06-18 13:28 ` [Qemu-devel] [PATCH v3 1/3] softmmu: add helper function to pass through retaddr Pavel Dovgalyuk
2015-06-23 22:53 ` Aurelien Jarno
2015-06-25 11:28 ` Pavel Dovgaluk
2015-07-01 16:15 ` Aurelien Jarno
2015-06-18 13:28 ` [Qemu-devel] [PATCH v3 2/3] target-mips: improve exceptions handling Pavel Dovgalyuk
2015-06-23 23:32 ` Aurelien Jarno
2015-06-29 6:57 ` Pavel Dovgaluk
2015-07-01 16:37 ` Aurelien Jarno [this message]
2015-06-18 13:28 ` [Qemu-devel] [PATCH v3 3/3] target-i386: fix memory operations in helpers Pavel Dovgalyuk
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=20150701163722.GF11361@aurel32.net \
--to=aurelien@aurel32.net \
--cc=Pavel.Dovgaluk@ispras.ru \
--cc=leon.alrae@imgtec.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth7680@gmail.com \
/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).