Revisiting FPU context resume on i386
Konstantin Belousov
kostikbel at gmail.com
Tue Jul 16 05:26:48 UTC 2013
On Tue, Jul 16, 2013 at 07:07:16AM +0900, Taku YAMAMOTO wrote:
> Hi all,
>
> sys/i386/i386/swtch.s have a big FIX ME in resumectx()
> and I have occationally got bitten by it; resulting in SIGFPE disasters.
>
> After cursory looking around FPU context, I think it's the simplest way
> to set CR0_TS on resumectx() and to let npxdna() DTRT lazilly.
>
> Attached is the mods that I'm currently using without a problem at the moment.
> It at least doesn't interact with normal resume operations badly.
>
> Ah, of cource, we have a choice to throw i386 away and get on amd64,
> but at least I won't because I'd miss VOCALOIDs running on wine/i386 :)
>
> --
> -|-__ YAMAMOTO, Taku
> | __ < <taku at tackymt.homeip.net>
>
> - A chicken is an egg's way of producing more eggs. -
> commit 99a24d7c19d624654afbd574e604d8a011ed28b3
> Author: Taku YAMAMOTO <taku at tackymt.homeip.net>
> Date: Sun Jul 14 07:36:29 2013 +0900
>
> i386: defer FPU context resume from resumectx() to npxdna() by CR0_TS.
>
> diff --git a/sys/i386/i386/swtch.s b/sys/i386/i386/swtch.s
> index 80aa6c4..71efae1 100644
> --- a/sys/i386/i386/swtch.s
> +++ b/sys/i386/i386/swtch.s
> @@ -36,6 +36,7 @@
> #include "opt_sched.h"
>
> #include <machine/asmacros.h>
> +#include <machine/specialreg.h>
>
> #include "assym.s"
>
> @@ -487,6 +488,10 @@ ENTRY(resumectx)
> movl PCB_CR3(%ecx),%eax
> movl %eax,%cr3
> movl PCB_CR0(%ecx),%eax
> +#ifdef DEV_NPX
> + /* Let npxdna() restore the FPU context lazily. */
> + orl $CR0_TS,%eax
> +#endif
> movl %eax,%cr0
> jmp 1f
> 1:
> @@ -519,10 +524,6 @@ ENTRY(resumectx)
> movl PCB_DR7(%ecx),%eax
> movl %eax,%dr7
>
> -#ifdef DEV_NPX
> - /* XXX FIX ME */
> -#endif
> -
> /* Restore other registers */
> movl PCB_EDI(%ecx),%edi
> movl PCB_ESI(%ecx),%esi
If this works, fine. But I think that you also should make sure that
invariants which are checked by npxdna() are met. E.g. see the
checks for fpcurthread at the start of the routine.
Might be, just clear the pcpu fpcurthread as part of the resume ? Is it
done by suspend counterpart ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-acpi/attachments/20130716/8cdf1ccd/attachment.sig>
More information about the freebsd-acpi
mailing list