Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@mips.com>
To: Aleksandar Markovic <Aleksandar.Markovic@imgtec.com>
Cc: Aleksandar Markovic <aleksandar.markovic@rt-rk.com>,
	"linux-mips@linux-mips.org" <linux-mips@linux-mips.org>,
	Douglas Leung <Douglas.Leung@imgtec.com>,
	Goran Ferenc <Goran.Ferenc@imgtec.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Maciej Rozycki <Maciej.Rozycki@imgtec.com>,
	Manuel Lauss <manuel.lauss@gmail.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Miodrag Dinic <Miodrag.Dinic@imgtec.com>,
	Paul Burton <Paul.Burton@imgtec.com>,
	Petar Jovanovic <Petar.Jovanovic@imgtec.com>,
	Raghu Gandham <Raghu.Gandham@imgtec.com>,
	Ralf Baechle <ralf@linux-mips.org>
Subject: Re: [PATCH 1/2] MIPS: math-emu: Update debugfs FP exception stats for certain instructions
Date: Thu, 12 Oct 2017 11:17:54 +0100	[thread overview]
Message-ID: <20171012101753.GB15235@jhogan-linux> (raw)
In-Reply-To: <EF5FA6C3467F85449672C3E735957B85015DA0AF13@badag02.ba.imgtec.org>

[-- Attachment #1: Type: text/plain, Size: 4713 bytes --]

On Wed, Oct 11, 2017 at 04:18:49PM +0000, Aleksandar Markovic wrote:
> Thanks, James, for the review.
> 
> I've got a couple of points bellow that will, I hope, clarify several issues.
> 
> > ________________________________________
> > From: James Hogan [james.hogan@mips.com]
> > Sent: Monday, October 09, 2017 2:09 PM
> > To: Aleksandar Markovic
> > Cc: linux-mips@linux-mips.org; Aleksandar Markovic; Douglas Leung;
> > Goran Ferenc; linux-kernel@vger.kernel.org; Maciej Rozycki;
> > Manuel Lauss; Masahiro Yamada; Miodrag Dinic; Paul Burton;
> > Petar Jovanovic; Raghu Gandham; Ralf Baechle
> > Subject: Re: [PATCH 1/2] MIPS: math-emu: Update debugfs FP
> > exception stats for certain instructions
> > 
> > On Fri, Oct 06, 2017 at 07:29:00PM +0200, Aleksandar Markovic wrote:
> > > From: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
> > >
> > > Fix omission of updating of debugfs FP exception stats for
> > > instructions <CLASS|MADDF|MSUBF|MAX|MIN|MAXA|MINA>.<D|S>.
> > >
> > > CLASS.<D|S> can generate Unimplemented Operation FP exception.
> > > <MADDF|MSUBF|MAX|MIN|MAXA|MINA>>.<D|S> can generate Inexact,
> > 
> > nit: s/>>/>/
> 
> Will be fixed in v2.
> 
> > 
> > > Unimplemented Operation, Invalid Operation, Overflow, and
> > > Underflow FP exceptions. In such cases, and prior to this
> > 
> > Well, according to the manual I'm looking at MAX|MIN|MAXA|MINA can't
> > generate inexact, overflow, or underflow FP exceptions
> >
> 
> The "MIPS64® Instruction Set Reference Manual" v6.00 mentions that all
> five FP exception are possible for MAX|MIN|MAXA|MINA, but in v6.05, the
> list was reduced to only two, as you hinted. I am going to sync the commit
> message with v6.05 of the document.
> 
> > ... and in practice
> > the only FPE generated by emulating these instructions is invalid
> > operation for MADDF/MSUBF. So presumably that's the only case we really
> > care about.
> > 
> > I.e. the MADDF/MSUBF invalid operation should be counted, but crucially
> > the setting of rcsr bits allows it to generate a SIGFPE which from a
> > glance it doesn't appear to do until this patch. The other changes are
> > redundant and harmless.
> > 
> > Does that sound correct? (appologies if I'm missing something, I'm just
> > reading the code, and reading FPU emulation code late at night is
> > probably asking for trouble).
> >
> 
> You are close, but not quite, I'll explain that in a moment.
> 
> First, just to note that SIGFPE will be generated if the condition
> 
> ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E)
> 
> is met (the code is almost at the end of fpu_emu(), cp1emu.c, line 1557).
> ctx is one of the arguments of fpu_emu(), but, in the current state of the
> code, by analyzing several levels of invocations, it can be concluded
> that ctx will always be equal to &current->thread.fpu. So, the register
> current->thread.fpu->fcr31 is actually important here.
> 
> Now, let's consider, for simplicity, the case of MADDF operation resulting
> in an overflow caused by addition of two large FP numbers. The "special"
> treatment of such case will be done within invocation of ieee754dp_format(),

Ah yes, obviously an MADDF can generate those other exception bits :-)

> which will in turn (in this particular example) execute
> ieee754_setcx(IEEE754_OVERFLOW), which will further execute
> 
> 	ieee754_csr.cx |= flags;
> 	ieee754_csr.sx |= flags;
> 
> and, since ieee754_csr is macro for &current->thread.fpu.fcr31, this will result
> in setting tworelevant and correct bits in current->thread.fpu->fcr31.
> 
> This means that condition from few paragraphs above will be met, and SIGFPE
> will be generated.

But just before that condition it does:
ctx->fcr31 = (ctx->fcr31 & ~FPU_CSR_ALL_X) | rcsr;

I.e. it clears the X bits used in the condition, and overrides them
based on rcsr, which is initialised to 0 and is only set after the
copcsr label and in a couple of other cases I don't think we'd be
hitting for MADDF.

Cheers
James

> 
> Whole above scenario happens regardless of inclusion of this patch.
> 
> Actually, setting exception bits within "copcsr label code" seems redundant.
> It though does no harm. I have some theory why is this code here, and why
> we even may want to keep it as is, but this would be too much for this mail.
> 
> > 
> > Given the potential fixing of SIGFPE in that case should this be tagged
> > for stable?
> > 
> 
> As I explained above, SIGFPE behavior is already correct, without this patch.
> This patch fixes only debugfs stats. So, it is not that critical.
> 
> Looking forward to your response.
> 
> Aleksandar

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2017-10-12 10:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06 17:28 [PATCH 0/2] MIPS: Minor FPU emulation fixes Aleksandar Markovic
2017-10-06 17:29 ` [PATCH 1/2] MIPS: math-emu: Update debugfs FP exception stats for certain instructions Aleksandar Markovic
2017-10-09 21:09   ` James Hogan
2017-10-09 21:09     ` James Hogan
2017-10-11 16:18     ` Aleksandar Markovic
2017-10-11 16:18       ` Aleksandar Markovic
2017-10-12 10:17       ` James Hogan [this message]
2017-10-12 14:32         ` Aleksandar Markovic
2017-10-12 14:32           ` Aleksandar Markovic
     [not found]         ` <683c-59df7500-1-10d973a0@9889400>
2017-10-12 14:44           ` James Hogan
2017-10-12 15:54             ` Aleksandar Markovic
2017-10-12 16:33               ` James Hogan
2017-10-06 17:29 ` [PATCH 2/2] MIPS: math-emu: Use preferred flavor of unsigned integer declarations Aleksandar Markovic
2017-10-09 16:59   ` James Hogan
2017-10-09 16:59     ` James Hogan

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=20171012101753.GB15235@jhogan-linux \
    --to=james.hogan@mips.com \
    --cc=Aleksandar.Markovic@imgtec.com \
    --cc=Douglas.Leung@imgtec.com \
    --cc=Goran.Ferenc@imgtec.com \
    --cc=Maciej.Rozycki@imgtec.com \
    --cc=Miodrag.Dinic@imgtec.com \
    --cc=Paul.Burton@imgtec.com \
    --cc=Petar.Jovanovic@imgtec.com \
    --cc=Raghu.Gandham@imgtec.com \
    --cc=aleksandar.markovic@rt-rk.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=manuel.lauss@gmail.com \
    --cc=ralf@linux-mips.org \
    --cc=yamada.masahiro@socionext.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