public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] On demand FP context switch major problem.
@ 2000-05-18  5:27 Sergei Organov
  2000-05-18  6:30 ` Nick Garnett
  0 siblings, 1 reply; 13+ messages in thread
From: Sergei Organov @ 2000-05-18  5:27 UTC (permalink / raw)
  To: ecos-discuss

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.

If above explanation of the problem isn't clear, here is a possible scenario:

1. Assume Thread1 is running with FP enable bit set (it owns FP context) and
   invokes HAL_DISABLE_INTERRUPTS macro.
2. HAL_DISABLE_INTERRUPTS macro reads current MSR value to a GPR, saves it
   into memory and clears EE bit in the GPR.
3. Thread1 is preempted by Thread2 that executes FP instruction and thus
   receives ownership of the FP context.
4. Thread2 is put to the waiting state and execution returns to the Thread1.
5. Thread1 continues execution but now FP enable bit in the MSR is cleared,
   because FP context is owned by the Thread2.
6. HAL_DISABLE_INTERRUPTS macro writes the GPR with EE bit cleared to the
   MSR and thus effectively sets the FP bit in the MSR!
7. Thread1 continues to execute with interrupts disabled and executes floating
   point instruction. As the FP enable bit is set, this doesn't produce "FP
   unavailable" exception and thus FP context isn't switched. As a result, the
   FP context of the Thread2 is clobbered by the Thread1 :-(

BR,
Sergei.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2001-09-05  0:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-18  5:27 [ECOS] On demand FP context switch major problem Sergei Organov
2000-05-18  6:30 ` Nick Garnett
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

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).