linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Floating point in the kernel
@ 2009-12-10 18:13 Sean MacLennan
  2009-12-10 20:19 ` Benjamin Herrenschmidt
  2009-12-10 20:32 ` arnd
  0 siblings, 2 replies; 8+ messages in thread
From: Sean MacLennan @ 2009-12-10 18:13 UTC (permalink / raw)
  To: linuxppc-dev

One of our drivers has code that was originally running on a DSP. The
code makes heavy use of floating point. We have isolated all the
floating point to one kthread in the driver. Using enable_kernel_fp()
this has worked well.

But under a specific heavy RTP load, we started getting kernel panics.
To make a long story short, the scheduler disables FP when you are
context switched out. When you come back and access a FP instruction,
you trap and call load_up_fpu() and everything is fine..... unless you
are in the kernel. If you are in the kernel, like our kthread is, you
get a "kernel FP unavailable exception".

Basically we got away with it for two years because the thread is at
high priority (-20) and tries very hard to finish within 1ms. But the
RTP high load causes us to context switch out and crash. The following
patch fixes this:

diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 50504ae..3476de9 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -383,7 +383,7 @@ label:
 #define FP_UNAVAILABLE_EXCEPTION                                             \
        START_EXCEPTION(FloatingPointUnavailable)                             \
        NORMAL_EXCEPTION_PROLOG;                                              \
-       beq     1f;                                                           \
+       /* SAM beq      1f; */                                          \
        bl      load_up_fpu;            /* if from user, just load it up */   \
        b       fast_exception_return;                                        \
 1:     addi    r3,r1,STACK_FRAME_OVERHEAD;                                   \

With the patch we run fine, at the expense that we lose the ability to
catch real FP unavailable exceptions in the kernel. It is because of
this loss that I have not submitted this patch.

We also hit another problem under high RTP load... and this is the
patch that fixes it:

diff --git a/arch/powerpc/kernel/fpu.S b/arch/powerpc/kernel/fpu.S
index fc8f5b1..051a02c 100644
--- a/arch/powerpc/kernel/fpu.S
+++ b/arch/powerpc/kernel/fpu.S
@@ -83,6 +83,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX)
        stfd    fr0,THREAD_FPSCR(r4)
        PPC_LL  r5,PT_REGS(r4)
        toreal(r5)
+
+       /* Under heavy RTP load the hsp thread can have a NULL pt_regs. */
+       PPC_LCMPI       0,r5,0
+       beq     1f
+
        PPC_LL  r4,_MSR-STACK_FRAME_OVERHEAD(r5)
        li      r10,MSR_FP|MSR_FE0|MSR_FE1
        andc    r4,r4,r10               /* disable FP for previous task */

So, if you are still reading this far, I am just looking for any
suggestions. Are there better ways of handling this? Have I
missed something? Anybody know why pt_regs might be NULL?

Cheers,
   Sean

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

end of thread, other threads:[~2009-12-11 11:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-10 18:13 Floating point in the kernel Sean MacLennan
2009-12-10 20:19 ` Benjamin Herrenschmidt
2009-12-10 20:33   ` Sean MacLennan
2009-12-10 20:56     ` Benjamin Herrenschmidt
2009-12-10 21:35     ` Arnd Bergmann
2009-12-11  0:17       ` Sean MacLennan
2009-12-11 11:28         ` Arnd Bergmann
2009-12-10 20:32 ` arnd

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