From owner-freebsd-mips@FreeBSD.ORG Sun Oct 2 11:14:51 2011 Return-Path: Delivered-To: freebsd-mips@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 785E4106564A for ; Sun, 2 Oct 2011 11:14:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 13DC98FC15 for ; Sun, 2 Oct 2011 11:14:50 +0000 (UTC) Received: from alf.home (alf.kiev.zoral.com.ua [10.1.1.177]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id p92B3VgS012694 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 2 Oct 2011 14:03:31 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from alf.home (kostik@localhost [127.0.0.1]) by alf.home (8.14.5/8.14.5) with ESMTP id p92B3VHM069121; Sun, 2 Oct 2011 14:03:31 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by alf.home (8.14.5/8.14.5/Submit) id p92B3VcA069120; Sun, 2 Oct 2011 14:03:31 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: alf.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 2 Oct 2011 14:03:31 +0300 From: Kostik Belousov To: Adrian Chadd Message-ID: <20111002110331.GF1511@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="nRb24sRrY2rSsMZw" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: "Jayachandran C." , Alexander Motin , freebsd-mips@freebsd.org Subject: Re: svn commit: r225892 - head/sys/mips/mips X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Oct 2011 11:14:51 -0000 --nRb24sRrY2rSsMZw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 02, 2011 at 05:28:25PM +0800, Adrian Chadd wrote: > Hi, >=20 > It doesn't look like openbsd or netbsd have tried addressing this. >=20 > I took a shot at trying to port over the relevant bits. >=20 > Linux seems to store the "can reschedule" flag in a bit of memory, > rather than calling a function to check each time. > This means that I can't simply port r4k_wait() verbose; there's no > guarantee EPC would be pointing to inside r4k_wait if it had to call > sched_runnable(). >=20 > Also, since we are calling 'wait' inside a critical section, any EPC > unwinding would have to also unwind the critical section (and maybe > reprogram the timer) before restarting things. But since that now > makes the "rollback" section even larger and unwieldy. >=20 > I really don't have the time or brain power at the moment to try and > port this solution over from Linux. >=20 > I would really appreciate it if someone would help out here. I probably need to describe some details of the mentioned "kib' idea". Looking at the x86 sti; hlt sequence, I noted that, in fact, we do not strictly need the special CPU behaviour of delaying enabling the interrupts till next instruction after sti is executed. The race there is the interrupt happen right after sti but before hlt, causing CPU to enter halted state while potentially having runnable thread. On x86 it is closed by sti not enabling interrupts till hlt started execution (it is more subtle, but let ignore the detail for the discussion). Now, if sti would not offer the useful postponing behaviour, we can easily emulate it. In the hardware interrupt handlers return path, we can check for $pc being equal to the address of the hlt instruction. If it is, we can advance $pc over the hlt, avoiding the halt if potentially we have a runnable thread. Briefly looking over the MIPS64 specifications, I do not see why we cannot implement the spirit of the trick for the ei; wait instruction sequence. ray talked about possibility of $pc living in the shadow register bank, which I think is not important. Another (minor) issue seems to be that our code does not use ei, directly manipulating the bit. My belief is that the trick can be done if only we have exact interrupts. It seems, from "run mips run" text, that possible inexact interrupts are either for much older platforms then modern MIPS SoC, or are irrelant there, because inexactness is only related to mul/div unit. [I am not on mips@] --nRb24sRrY2rSsMZw Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk6IRQMACgkQC3+MBN1Mb4imzQCgkqBbxpax7ZS0rBrGjARYiPNn X7UAn02R0lgIt0Ph2/8SllAnQbbDqfLm =FOM5 -----END PGP SIGNATURE----- --nRb24sRrY2rSsMZw--