From owner-freebsd-threads@FreeBSD.ORG Tue Jun 8 02:07:55 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 A85AD16A4CE; Tue, 8 Jun 2004 02:07:55 +0000 (GMT) Received: from smtp01.syd.iprimus.net.au (smtp01.syd.iprimus.net.au [210.50.30.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id 12D1F43D54; Tue, 8 Jun 2004 02:07:55 +0000 (GMT) (envelope-from tim@robbins.dropbear.id.au) Received: from robbins.dropbear.id.au (210.50.40.174) by smtp01.syd.iprimus.net.au (7.0.024) id 40B7A0DA002E6DC6; Tue, 8 Jun 2004 12:07:53 +1000 Received: by robbins.dropbear.id.au (Postfix, from userid 1000) id CD72341D0; Tue, 8 Jun 2004 12:09:40 +1000 (EST) Date: Tue, 8 Jun 2004 12:09:40 +1000 From: Tim Robbins To: David Xu Message-ID: <20040608020940.GB43197@cat.robbins.dropbear.id.au> References: <200406071810.23069.peter@wemm.org> <40C513B5.8070406@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <40C513B5.8070406@freebsd.org> User-Agent: Mutt/1.4.1i cc: freebsd-amd64@freebsd.org cc: freebsd-threads@freebsd.org Subject: Re: [tjr@FreeBSD.org: cvscommit:src/lib/libpthread/arch/amd64/amd 64 context.S] 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: Tue, 08 Jun 2004 02:07:55 -0000 On Tue, Jun 08, 2004 at 09:17:41AM +0800, David Xu wrote: > Peter Wemm wrote: > > >On Monday 07 June 2004 06:10 pm, David Xu wrote: > > > >>Is there any reason to use memory indirect jump ? did you > >>have benchmarked context switch speed before and after this commit ? > >>I won't use such indirect jump in speed sensitive case, it is > >>not CPU branch trace cache friendly, it is better to use > >>ret to match call in up level. > > > > > >Because the return address is already on the higher level stack frame, > >and copying it (read/write/ret) is more awkward than the read+indirect > >jump. Unfortunately, we can't indirectly access the flags register. > > > I would like someone to test it: > http://people.freebsd.org/~davidxu/kse/test/ctxswitch.c > tell me the result before and after this commit. System: AMD Athlon 64 3000+, ASUS K8V, FreeBSD 5.2-tjr_perf with kernel config tuned for performance (no INVARIANTS, no WITNESS), multiuser mode, XFree86 + GNOME running. Test program compiled with gcc -O2 -pthread -static. ctxold = old (broken) code using ret ctxnew = new correct code using indirect jump ctxopt = same as ctxnew but does not save scratch registers or flags, redundant checks removed, jumps aligned to dword boundary $ time ./ctxold; time ./ctxnew; time ./ctxopt testing scope process context switch speed... context switches:1779631/s testing scope system context switch speed... context switches:386696/s 21.01s real 10.40s user 9.49s system testing scope process context switch speed... context switches:1823471/s testing scope system context switch speed... context switches:383949/s 21.00s real 10.34s user 9.55s system testing scope process context switch speed... context switches:1864775/s testing scope system context switch speed... context switches:386127/s 21.01s real 10.42s user 9.48s system Tim