From owner-freebsd-threads@FreeBSD.ORG Wed Mar 3 06:16:30 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D6E7516A4CE; Wed, 3 Mar 2004 06:16:30 -0800 (PST) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8E80843D45; Wed, 3 Mar 2004 06:16:30 -0800 (PST) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.10/8.12.1) with ESMTP id i23EGUbN020742; Wed, 3 Mar 2004 09:16:30 -0500 (EST) Date: Wed, 3 Mar 2004 09:16:30 -0500 (EST) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Peter Grehan In-Reply-To: <40459478.9060702@freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-threads@freebsd.org Subject: Re: User-space context switch and floating-point X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2004 14:16:31 -0000 On Wed, 3 Mar 2004, Peter Grehan wrote: > Here's the comment I currently have in libpthread/.../powerpc/context.S: > > * XXX XXX > * Floating-point is a big issue. Since there's no way to determine > * if the caller has used FP, all volatile register need to be saved. > * If FP hasn't been used, this results in a lazy FP exception in > * the kernel and from that point on FP is always switched in/out > * for the thread, which may be a big performance drag for the system. > * An alternative is to use the the getcontext system call, which > * will do the right thing for floating point but will save all > * registers rather than the caller-saved subset, and has the overhead > * of a syscall. > * Maybe another option would be to give a light-weight way for a > * thread to determine if FP is in used: perhaps a syscall that > * returns this info immediately in the asm traphandler, or an > * OSX-style read-only per-thread page with a flag to indicate FP state. > > Any opinions ? I noticed the alpha/sparc64 routines don't save FP. You don't need to save floating point registers when saving the context from userland. The userland _thr_getcontext() function is called as a result of an application calling pthread_yield(), sleep(), nanosleep(), etc (yielding/sleeping calls), or by something that blocks in userland like pthread_mutex_lock(), pthread_cond_wait(), low-level libc/libpthread locks, etc. Look at the i386 thr_getcontext(); it only needs to save the FP control word. -- Dan Eischen