All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Henry Bausley <hbausley@deltatau.com>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai] ARM LS1021A SMP Floating point Interrupt Service Routine
Date: Wed, 16 Mar 2016 05:04:03 +0100	[thread overview]
Message-ID: <20160316040403.GA6555@hermes.click-hack.org> (raw)
In-Reply-To: <1458099705.9868.11.camel@henry-ThinkCentre-M93p>

On Tue, Mar 15, 2016 at 08:41:45PM -0700, Henry Bausley wrote:
> How does one properly permit floating point operations in an ISR in a
> kernel driver running on an ARM CPU.  Our ISR is on cpu 0 and I thought
> that the code below would work.  However sometimes the userspace
> application using the floating point unit will get a segmentation fault.
> The kernel driver running floating point does not have a problem.  I am
> sure I am missing something here since I can use floating point in
> xenomai kernel threads without a problem.

That is because Xenomai takes care of handling the FPU context for
kernel threads. On the other hand, for irqs, you are on your own.

> 
> int FloatingPointISR()
> {
>   rthal_vfp_save((union vfp_state*)x, rthal_enable_fpu());
> 
>    // A bunch of floating point stuff
> 
>   rthal_vfp_load((union vfp_state*)x, 0);
> }

I guess the problem is that you do not restore at the end of the
isr, the fpu context as it was at the beginning. You can try:

int FloatingPointISR()
{
	unsigned fpexc = rthal_vfp_fmrx(FPEXC);
	rthal_vfp_save((union vfp_state*)x, rthal_enable_fpu());
 
	// A bunch of floating point stuff
 
	rthal_vfp_load((union vfp_state*)x, 0);
	rthal_vfp_fmxr(FPEXC, fpexc);
}

ALso note that x can not be a thread backup area. It must be an area
specific to your ISR. And cpu, you can not share the area between
two cpus either. And if the ISR is still reentrant, you have to shut
irqs off around this piece of code, in order to avoid a context
switch (for instance by the timer irq) in the middle.

-- 
					    Gilles.
https://click-hack.org


      reply	other threads:[~2016-03-16  4:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16  3:41 [Xenomai] ARM LS1021A SMP Floating point Interrupt Service Routine Henry Bausley
2016-03-16  4:04 ` Gilles Chanteperdrix [this message]

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=20160316040403.GA6555@hermes.click-hack.org \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=hbausley@deltatau.com \
    --cc=xenomai@xenomai.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 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.