From owner-freebsd-sparc Mon Dec 22 02:24:37 1997 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.7/8.8.7) id CAA14508 for sparc-outgoing; Mon, 22 Dec 1997 02:24:37 -0800 (PST) (envelope-from owner-freebsd-sparc@FreeBSD.ORG) Received: from mozart.canonware.com (canonware.com [206.184.206.112]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id CAA14498 for ; Mon, 22 Dec 1997 02:24:27 -0800 (PST) (envelope-from jasone@canonware.com) Received: from localhost (jasone@localhost) by mozart.canonware.com (8.8.7/8.8.7) with SMTP id CAA04512; Mon, 22 Dec 1997 02:23:34 -0800 (PST) (envelope-from jasone@canonware.com) X-Authentication-Warning: mozart.canonware.com: jasone owned process doing -bs Date: Mon, 22 Dec 1997 02:23:33 -0800 (PST) From: Jason Evans Reply-To: Jason Evans To: "Christopher R. Bowman" cc: Greg Lehey , Ric Flinn , freebsd-sparc@FreeBSD.ORG Subject: Re: Register windowing In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-sparc@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Sun, 21 Dec 1997, Christopher R. Bowman wrote: > I haven't had a chance to wade through my Sparc V9 book, but on page xvii > it does say "we've accomplished this by making register windows more > flexible than they were in earlier SPARC processors, allowing the kernel > to provide a separate register bank to each running process. Thus, the > processor can perform a context switch with essentially no overhead ..." Well, after another 4+ hours of trying to extract the (extremely scattered) info on register windowing from the SPARC V9 Manual, I think I've mostly figured it out. It turns out that a separate spill/fill trap handler can be installed for each of the windows. This means that whenever we trap into the spill handler(s) we can tell which address space the window that needs spilled belongs to. The windows are essentially arranged in a circular buffer. Every window's ins overlap with one of its neighbors's outs, and vice versa. This creates the constraint that there must always be a one window gap both at the top and bottom of each process's set of windows (if there's only one process using the windows, this degenerates to a one window gap). Note also that we can never have valid windows for more than 4 address spaces (processes) at a time, given 8 windows. This means that if we want to create another window, we may cause a spill trap for an entirely different process's window. This is fine. What gets a bit more ugly though is if we incur a fill trap (i.e. we need to load the pertinent part of a stack frame from memory) then we no longer have any windows that belong to our process. In this case we use the window we've just vacated to load the stack frame into. This works fine, but we will only ever be able to restore one stack frame at a time. This seems reasonable to me, since we're trying to be lazy, and there are no apparent benefits to being otherwise. Using such a scheme, we need some auxiliary registers to keep track of: 1) Process id for each set of windows. 2) Top window for each set. 3) Something else I can't remember right now. Well, it turns out that we've got 8 unused registers in each gap, so we could probably use these for this info without a problem. We have to create clean windows anyway when giving a process a new window, so I don't think this will add much overhead, other than possibly changing CWP (current window pointer) twice to get at the registers. (If using these registers doesn't work out, there are other reasonable options for where to store the info.) We need to keep all of this state consistent, so when we switch processes, we not only need to determine what window to start with (check if we've already got valid windows for the new process); we also need to write info on the previous process's window state. This shines to be cheap though. I hope the scheme I've outlined is clear (it's getting late). I can't think of any reason to use another scheme at the moment, since this one seems to achieve maximum laziness with no additional penalty over other possible schemes. Comments? Jason P.S. One issue that may come up is the difference between V8 and V9 architectures. V9 allows nested traps, but I don't think V8 does, which requires much more care while in supervisor mode. This could directly affect window management. P.P.S. The most applicable sections of the V9 Manual to this are: 5.1.1.[2,3] 5.2.10*, 6.3.6*, and various parts of Appendix H. Jason Evans Email: [jasone@canonware.com] Home phone: [(650) 856-8204] Work phone: [(408) 774-8007] Quote: ["Invention is 1% inspiration, 99% perspiration" - Thomas Edison]