From owner-freebsd-java@FreeBSD.ORG Tue Sep 18 11:22:06 2007 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D8D8B16A419; Tue, 18 Sep 2007 11:22:06 +0000 (UTC) (envelope-from kurt@intricatesoftware.com) Received: from mail1.intricatesoftware.com (cl-18.ewr-01.us.sixxs.net [IPv6:2001:4830:1200:11::2]) by mx1.freebsd.org (Postfix) with ESMTP id A649213C46C; Tue, 18 Sep 2007 11:22:06 +0000 (UTC) (envelope-from kurt@intricatesoftware.com) Received: from seraph.intricatesoftware.com (relay@localhost.intricatesoftware.com [IPv6:::1]) by mail1.intricatesoftware.com (8.14.1/8.13.4) with ESMTP id l8IBLovm032232; Tue, 18 Sep 2007 07:21:51 -0400 (EDT) Received: from seraph.intricatesoftware.com (truk@localhost.intricatesoftware.com [127.0.0.1]) by seraph.intricatesoftware.com (8.14.1/8.14.1) with ESMTP id l8IBLo9D002600; Tue, 18 Sep 2007 07:21:50 -0400 (EDT) Received: (from truk@localhost) by seraph.intricatesoftware.com (8.14.1/8.14.1/Submit) id l8IBLnd0020322; Tue, 18 Sep 2007 07:21:49 -0400 (EDT) X-Authentication-Warning: seraph.intricatesoftware.com: truk set sender to kurt@intricatesoftware.com using -f From: Kurt Miller To: freebsd-java@freebsd.org Date: Tue, 18 Sep 2007 07:21:48 -0400 User-Agent: KMail/1.9.7 References: <46EC1B55.4060202@FreeBSD.org> <46EDDCC9.90403@intricatesoftware.com> In-Reply-To: <46EDDCC9.90403@intricatesoftware.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_MT77G2sKRW3o4KJ" Message-Id: <200709180721.48995.kurt@intricatesoftware.com> X-SMTP-Vilter-Version: 1.3.6 X-SMTP-Vilter-Virus-Backend: clamd X-SMTP-Vilter-Status: clean X-SMTP-Vilter-clamd-Virus-Status: clean X-Spamd-Symbols: ALL_TRUSTED X-SMTP-Vilter-Spam-Backend: spamd X-Spam-Score: -1.4 X-Spam-Threshold: 5.0 X-Spam-Probability: -0.3 X-Its-A-Nuisance: This is spam X-SMTP-Vilter-Unwanted-Backend: attachment X-SMTP-Vilter-attachment-Unwanted-Status: clean X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Daniel Eischen , Kip Macy , Kris Kennaway , performance@freebsd.org Subject: Re: Massive performance loss from OS::sleep hack X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Sep 2007 11:22:07 -0000 --Boundary-00=_MT77G2sKRW3o4KJ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline David Xu confirmed for me that pthread_yield() does give some time to lower priority threads on 7.0 using thr. Attached and inline are two patches for the 1.5 port that is how I suggest the issue be addressed. For 7.0 and up default UseThreadPriorities to true and always use pthread_yield(). For < 7.0 default UseThreadPriorities to false and conditionally use pthread_yield()/os_sleep(). User's can toggle UseThreadPriorities with the command line argument -XX:+UseThreadPriorities -------- files/patch-vm::os_bsd.cpp -------- $FreeBSD: ports/java/jdk15/files/patch-vm::os_bsd.cpp,v 1.7 2007/06/09 05:14:56 glewis Exp $ --- ../../hotspot/src/os/bsd/vm/os_bsd.cpp.orig Mon Sep 17 17:39:33 2007 +++ ../../hotspot/src/os/bsd/vm/os_bsd.cpp Mon Sep 17 20:57:26 2007 @@ -508,7 +508,7 @@ #define getenv(n) ::getenv(n) #ifndef DEFAULT_LD_LIBRARY_PATH -#define DEFAULT_LD_LIBRARY_PATH "/usr/lib" /* See ld.so.1(1) */ +#define DEFAULT_LD_LIBRARY_PATH "/usr/lib:/usr/local/lib" /* See ld.so.1(1) */ #endif #define EXTENSIONS_DIR "/lib/ext" #define ENDORSED_DIR "/lib/endorsed" @@ -2273,11 +2273,14 @@ // BSDXXX: Only use pthread_yield here and below if the system thread // scheduler gives time slices to lower priority threads when yielding. -#ifdef __FreeBSD__ +// pthread_yield() can also be used when thread priorities are disabled. +// Using os_sleep() here causes significant performance degradation. +#if defined(_ALLBSD_SOURCE) && (!defined(__FreeBSD__) || __FreeBSD__ < 7) + if ( UseThreadPriorities ) os_sleep(MinSleepInterval, interruptible); -#else - pthread_yield(); + else #endif + pthread_yield(); #if SOLARIS // XXX - This code was not exercised during the Merlin RC1 @@ -2299,11 +2302,14 @@ // BSDXXX: Only use pthread_yield here and above if the system thread // scheduler gives time slices to lower priority threads when yielding. -#ifdef __FreeBSD__ - os_sleep(MinSleepInterval, interruptible); -#else - pthread_yield(); +// pthread_yield() can be also used when thread priorities are disabled. +// Using os_sleep() here causes significant performance degradation. +#if defined(_ALLBSD_SOURCE) && (!defined(__FreeBSD__) || __FreeBSD__ < 7) + if ( UseThreadPriorities ) + os_sleep(MinSleepInterval, interruptible); + else #endif + pthread_yield(); return 0; } ------- files/patch-vm::globals.hpp -------- $FreeBSD$ --- ../../hotspot/src/share/vm/runtime/globals.hpp.orig Mon Sep 17 10:12:16 2007 +++ ../../hotspot/src/share/vm/runtime/globals.hpp Mon Sep 17 10:20:32 2007 @@ -130,6 +130,12 @@ #define falseInProduct true #endif +#if !defined(_ALLBSD_SOURCE) || (defined(__FreeBSD__) && __FreeBSD__ >= 7) +#define OSUseThreadPriorities true +#else +#define OSUseThreadPriorities false +#endif + // develop flags are settable / visible only during development and are constant in the PRODUCT version // product flags are always settable / visible @@ -2546,7 +2552,7 @@ "beginning to throw OutOfMemoryErrors in each compile") \ \ /* Priorities */ \ - product(bool, UseThreadPriorities, true, \ + product(bool, UseThreadPriorities, OSUseThreadPriorities, \ "Use native thread priorities") \ \ product(intx, ThreadPriorityPolicy, 0, \ --Boundary-00=_MT77G2sKRW3o4KJ--