From owner-freebsd-arch Mon Jan 7 1: 8: 1 2002 Delivered-To: freebsd-arch@freebsd.org Received: from gull.prod.itd.earthlink.net (gull.mail.pas.earthlink.net [207.217.120.84]) by hub.freebsd.org (Postfix) with ESMTP id 4B10037B419 for ; Mon, 7 Jan 2002 01:07:58 -0800 (PST) Received: from pool0183.cvx21-bradley.dialup.earthlink.net ([209.179.192.183] helo=mindspring.com) by gull.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16NVkj-0000xh-00; Mon, 07 Jan 2002 01:07:34 -0800 Message-ID: <3C396554.9B6A9053@mindspring.com> Date: Mon, 07 Jan 2002 01:07:32 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Jake Burkholder Cc: Bernd Walter , Alfred Perlstein , Dan Eischen , arch@FreeBSD.ORG Subject: Re: Request for review: getcontext, setcontext, etc References: <3C37E559.B011DF29@vigrid.com> <20020106032709.A82406@elvis.mu.org> <3C381B48.AADDCA2B@mindspring.com> <20020106113847.A15885@cicely8.cicely.de> <20020107015228.E39321@locore.ca> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Jake Burkholder wrote: > > > > > Is there a reason that getcontext and setcontext need to be > > > > > system calls? > > > > Atomicity? > > > To flush register windows on setcontext() on SPARC. > > wflush isn't a priviledged instruction and usualy emulated on < sparcv9. > > mit-pthreads use it from userland. > > Yes, this (flushw) is the best way to flush the windows on v9 at least. > > > > > Are there any performance reasons to flush windows in kernel? > > No, doing so is actually more complicated (slightly) due to having > to use copyout and due potentialy having to deal with 32bit applications > running on 64bit kernels. It is easier if the spills look like normal > spills. The "flushw" is not enough. The following paper discusses the original implementation of the "liblwp" code on SunOS 4.x: http://www.cs.washington.edu/research/compiler/papers.d/thread-regwin.html Here, if you are allergic to PostScript, and want a PDF or other format: http://citeseer.nj.nec.com/keppel91register.html -- Multiple lightweight processes or threads have multiple stacks, and a thread context switch moves execution from one stack to another. On the SPARC architecture, parts of a thread's stack can be cached in register windows while the thread is running. The cached data must be flushed to memory when the thread is suspended. Doing the flushing both efficiently and correctly can be tricky. This document discusses the implementation of a non-preemptive user-space threads package under SunOS. %A David Keppel %A Register Windows and User-Space Threads on the SPARC %R UWCSE 91-08-01 %I University of Washington Department of Computer Science and Engineering %D August 1991 -- See also: http://citeseer.nj.nec.com/15548.html The basic problem is that stack is cached in registers, not flushed to RAM, and you may be resuming on another processor while another one still hasn't written the register caches back so that the memory image you load on the new processor is valid. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message