Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jul 2013 08:26:41 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Taku YAMAMOTO <taku@tackymt.homeip.net>
Cc:        freebsd-acpi@freebsd.org
Subject:   Re: Revisiting FPU context resume on i386
Message-ID:  <20130716052641.GE91021@kib.kiev.ua>
In-Reply-To: <20130716070716.15b7282b9dca2cbc8a767631@tackymt.homeip.net>
References:  <20130716070716.15b7282b9dca2cbc8a767631@tackymt.homeip.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--6CSUTDM8zwHHEeSv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jul 16, 2013 at 07:07:16AM +0900, Taku YAMAMOTO wrote:
> Hi all,
>=20
> sys/i386/i386/swtch.s have a big FIX ME in resumectx()
> and I have occationally got bitten by it; resulting in SIGFPE disasters.
>=20
> 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.
>=20
> Attached is the mods that I'm currently using without a problem at the mo=
ment.
> It at least doesn't interact with normal resume operations badly.
>=20
> 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 :)
>=20
> --=20
> -|-__   YAMAMOTO, Taku
>  | __ <     <taku@tackymt.homeip.net>
>=20
>       - A chicken is an egg's way of producing more eggs. -

> commit 99a24d7c19d624654afbd574e604d8a011ed28b3
> Author: Taku YAMAMOTO <taku@tackymt.homeip.net>
> Date:   Sun Jul 14 07:36:29 2013 +0900
>=20
>     i386: defer FPU context resume from resumectx() to npxdna() by CR0_TS.
>=20
> 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"
> =20
>  #include <machine/asmacros.h>
> +#include <machine/specialreg.h>
> =20
>  #include "assym.s"
> =20
> @@ -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
> =20
> -#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 ?

--6CSUTDM8zwHHEeSv
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (FreeBSD)

iQIcBAEBAgAGBQJR5NmRAAoJEJDCuSvBvK1BMpYP/37GFsTkTCcZtWhOyhfuTNb3
4yuHI1VWQ25NM2RyTaER9OFscMDXNWOaLPmPsvZe1EAwdxknQ1f0SIhXuonxtbIB
YYnLnFtwdwpHtrBUKqKT1JZ26CV4L4CSx5OfeS4YdKchlCcD6gHKUJ/EbVee6WtT
h6felsDqwD7WjOuh8OYkndTcltC8BtcBfGpZMDjyL3zPltxGvoqRTt/238WuiKp+
yz3xhyyYmjWCIS7Y50g7XEc9BbVY5E0dPc+yvymPxyEIDfpsFSXBPd6zdKgnX4vv
xGrYJr04rD4+G6b03VIrROLbWLXVpxuV8eK22M5gJ0b585U8LxYvkZEePgCEn5tT
UtmIeJcwMYUvplj/K3EC9qmMvS/4Wgn94Qil8l7WSso2fKfu7IHQ9rr3jXEXiB+4
0VXe1oISPnjFKT9q8VDUEIPvn0PHvnpeIn6WrAV7rdWeHgszErMN4WAnoTQ5Ajfg
MhptFGw+TkVWOq1j57ah8gY9kshEJ2MDd5GXygXBkLJ+FUrY6kQ+LYzTkov1ur62
qDkyVYGHAmX+5L56/x0N+I7ogIBx6seFQBey4Zf0XeRPLtXYPSxYafNyyaxuI2ec
1KjpPpyBZh6Ck5AFt/d7GY1l+Hn04q2PLSm9mkzEtJuZh5yd/NIEvArFDAIAm/wB
s4yrJRLTINeDL5dsyTqv
=Nymy
-----END PGP SIGNATURE-----

--6CSUTDM8zwHHEeSv--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130716052641.GE91021>