public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Nick Garnett <nickg@cygnus.co.uk>
To: ecos-discuss@sourceware.cygnus.com
Subject: Re: [ECOS] On demand FP context switch major problem.
Date: Thu, 18 May 2000 06:30:00 -0000	[thread overview]
Message-ID: <poaehohucn.fsf@balti.cygnus.co.uk> (raw)
In-Reply-To: <87u2fwt559.fsf@osv.javad.ru>

Sergei Organov <osv@javad.ru> writes:

> Hello,
> 
> I've almost finished the "on demand" FP context switch support in the PowerPC
> HAL, but at the end faced with a problem for which I don't see a reasonable
> solution. Here is the description of the problem.
> 
> To switch FP context on demand we need to disable FP in the usual context
> switch routine by means of clearing the "FP enable" bit in the MSR. It means
> that at thread level of execution the FP bit in the MSR could be cleared any
> time if scheduler isn't locked and/or interrupts aren't disabled. It in turn
> means that in thread code we can safely change MSR only if above condition(s)
> is(are) met. But the EE (external interrupt enable) bit is also located in the
> MSR, so it's unsafe to disable interrupts if scheduler isn't locked!
> 
> The above has unfortunate consequences for the code in the
> HAL_DISABLE_INTERRUPTS macro. With "on demand" FP context switch is used, this
> macro should somehow lock the scheduler before reading the MSR and then unlock
> it back after writing the MSR :-(
> 
> The above discussion didn't take into consideration support for the use of FPU
> in the interrupt handlers (ISRs/DSRs). If this support is added, then even
> locking of the scheduler doesn't help. In this case only disabling of
> interrupts gives us a safe way to change MSR, but once again disabling of
> interrupts needs changing of MSR :-(
> 
> Any suggestions? Hopefully I'm just missing something obvious.


This is one of the annoying features of the PowerPC, and other RISC
processors, that "global" state and "per-thread" state are mixed up in
the same register.

One option would be to always clear the FP enable bit in
HAL_DISABLE_INTERRUPTS (probably HAL_ENABLE_INTERRUPTS and
HAL_RESTORE_INTERRUPTS too). This would make your described scenario
work correctly since you would get an FP exception at step 7. In the
simple case you would also get an FP trap on the next FP instruction,
which would see that the current thread is already the FPU owner and
just set the FP enable bit.

Taking the extra trap is unpleasant, but with a suitable fast path it
should not be too expensive. It is unlikely that code which plays with
the interrupt enable is also doing a lot of floating point, and the
thread may well be timesliced or preempted before moving from one to
the other anyway. So the chances are that this will not result in any
more FP traps than before. There has to be a FP trap per thread switch
anyway, and changing the interrupt enable should be a lot less common
than that.



-- 
Nick Garnett
Cygnus Solutions, a Red Hat Company
Cambridge, UK

WARNING: multiple messages have this Message-ID
From: Nick Garnett <nickg@cygnus.co.uk>
To: ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] On demand FP context switch major problem.
Date: Wed, 05 Sep 2001 00:10:00 -0000	[thread overview]
Message-ID: <poaehohucn.fsf@balti.cygnus.co.uk> (raw)
Message-ID: <20010905001000.rFHRGzkCQ4LKBR-eq5xdaMsXjkdkSlPovsTmKmYUoIQ@z> (raw)
In-Reply-To: <87u2fwt559.fsf@osv.javad.ru>

Sergei Organov <osv@javad.ru> writes:

> Hello,
> 
> I've almost finished the "on demand" FP context switch support in the PowerPC
> HAL, but at the end faced with a problem for which I don't see a reasonable
> solution. Here is the description of the problem.
> 
> To switch FP context on demand we need to disable FP in the usual context
> switch routine by means of clearing the "FP enable" bit in the MSR. It means
> that at thread level of execution the FP bit in the MSR could be cleared any
> time if scheduler isn't locked and/or interrupts aren't disabled. It in turn
> means that in thread code we can safely change MSR only if above condition(s)
> is(are) met. But the EE (external interrupt enable) bit is also located in the
> MSR, so it's unsafe to disable interrupts if scheduler isn't locked!
> 
> The above has unfortunate consequences for the code in the
> HAL_DISABLE_INTERRUPTS macro. With "on demand" FP context switch is used, this
> macro should somehow lock the scheduler before reading the MSR and then unlock
> it back after writing the MSR :-(
> 
> The above discussion didn't take into consideration support for the use of FPU
> in the interrupt handlers (ISRs/DSRs). If this support is added, then even
> locking of the scheduler doesn't help. In this case only disabling of
> interrupts gives us a safe way to change MSR, but once again disabling of
> interrupts needs changing of MSR :-(
> 
> Any suggestions? Hopefully I'm just missing something obvious.


This is one of the annoying features of the PowerPC, and other RISC
processors, that "global" state and "per-thread" state are mixed up in
the same register.

One option would be to always clear the FP enable bit in
HAL_DISABLE_INTERRUPTS (probably HAL_ENABLE_INTERRUPTS and
HAL_RESTORE_INTERRUPTS too). This would make your described scenario
work correctly since you would get an FP exception at step 7. In the
simple case you would also get an FP trap on the next FP instruction,
which would see that the current thread is already the FPU owner and
just set the FP enable bit.

Taking the extra trap is unpleasant, but with a suitable fast path it
should not be too expensive. It is unlikely that code which plays with
the interrupt enable is also doing a lot of floating point, and the
thread may well be timesliced or preempted before moving from one to
the other anyway. So the chances are that this will not result in any
more FP traps than before. There has to be a FP trap per thread switch
anyway, and changing the interrupt enable should be a lot less common
than that.



-- 
Nick Garnett
Cygnus Solutions, a Red Hat Company
Cambridge, UK

  reply	other threads:[~2000-05-18  6:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-18  5:27 Sergei Organov
2000-05-18  6:30 ` Nick Garnett [this message]
2000-05-19  1:16   ` Sergei Organov
2000-05-19  3:37     ` [ECOS] eCos synthetic target on Sun/Sparc ? Arvind
2000-05-19  4:12       ` Bart Veer
2000-05-31  6:44     ` [ECOS] On demand FP context switch major problem Sergei Organov
2000-05-31  7:24       ` Nick Garnett
2000-06-01  2:36         ` Sergei Organov
2000-06-01  4:23           ` Nick Garnett
2000-06-02  4:51             ` Sergei Organov
2000-06-02  5:27               ` Nick Garnett
2000-06-02  6:47                 ` Sergei Organov
2001-09-05  0:10   ` Nick Garnett

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=poaehohucn.fsf@balti.cygnus.co.uk \
    --to=nickg@cygnus.co.uk \
    --cc=ecos-discuss@sourceware.cygnus.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 read-only IMAP folder(s) and NNTP newsgroup(s).