From owner-freebsd-acpi@FreeBSD.ORG Tue Jul 16 05:26:48 2013 Return-Path: Delivered-To: freebsd-acpi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 59AF44D3 for ; Tue, 16 Jul 2013 05:26:48 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id C7AE8EDC for ; Tue, 16 Jul 2013 05:26:47 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id r6G5QhQA087230; Tue, 16 Jul 2013 08:26:43 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua r6G5QhQA087230 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id r6G5QflP087228; Tue, 16 Jul 2013 08:26:41 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 16 Jul 2013 08:26:41 +0300 From: Konstantin Belousov To: Taku YAMAMOTO Subject: Re: Revisiting FPU context resume on i386 Message-ID: <20130716052641.GE91021@kib.kiev.ua> References: <20130716070716.15b7282b9dca2cbc8a767631@tackymt.homeip.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="6CSUTDM8zwHHEeSv" Content-Disposition: inline In-Reply-To: <20130716070716.15b7282b9dca2cbc8a767631@tackymt.homeip.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-acpi@freebsd.org X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jul 2013 05:26:48 -0000 --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 > | __ < >=20 > - A chicken is an egg's way of producing more eggs. - > commit 99a24d7c19d624654afbd574e604d8a011ed28b3 > Author: Taku YAMAMOTO > 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 > +#include > =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--