From owner-freebsd-java@FreeBSD.ORG Sat Sep 15 20:10:48 2007 Return-Path: Delivered-To: java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1BABA16A417 for ; Sat, 15 Sep 2007 20:10:48 +0000 (UTC) (envelope-from freebsd@spatula.net) Received: from turing.morons.org (turing.morons.org [208.96.51.42]) by mx1.freebsd.org (Postfix) with ESMTP id EB24B13C45B for ; Sat, 15 Sep 2007 20:10:47 +0000 (UTC) (envelope-from freebsd@spatula.net) Received: by turing.morons.org (Postfix, from userid 1001) id CB2B81704B; Sat, 15 Sep 2007 13:10:41 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by turing.morons.org (Postfix) with ESMTP id B80E617037; Sat, 15 Sep 2007 13:10:41 -0700 (PDT) Date: Sat, 15 Sep 2007 13:10:41 -0700 (PDT) From: Nick Johnson X-X-Sender: spatula@turing To: Kris Kennaway , java@freebsd.org In-Reply-To: <46EC1B55.4060202@FreeBSD.org> Message-ID: <20070915125918.R82369@turing> References: <46EC1B55.4060202@FreeBSD.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: 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: Sat, 15 Sep 2007 20:10:48 -0000 I looked up the bug # in Sun's bug database, and although it isn't there anymore, there is another bug marked as a duplicate: http://bugs.sun.com/view_bug.do?bug_id=4319085 I don't pretend to understand the details, but it looks like that bit of code was introduced to work around a Solaris kernel bug related to threads not yielding/suspending. I wonder if that might have been a problem a long time ago with libc_r that no longer troubles us. Fortunately, the bug indicates that it is very easy to repeat (though that may be more true on Solaris than FreeBSD), so it could be easy to test whether just using pthread_yield() is now sufficient. Nick On Sat, 15 Sep 2007, Kris Kennaway wrote: > Hi, > > I have been running the volano java benchmark > (http://www.volano.com/benchmarks.html) on an 8-core i386 system, and out of > the box jdk15 on FreeBSD performs extremely poorly. The system is more than > 90% idle, and profiling shows that the ~800 threads in the benchmark are > spending most of their time doing short nanosleep() calls. > > > I traced it to the following FreeBSD-specific hack in the jdk: > > // XXXBSD: understand meaning and workaround related to yield > ... > // XXXBSD: done differently in 1.3.1, take a look > int os::sleep(Thread* thread, jlong millis, bool interruptible) { > assert(thread == Thread::current(), "thread consistency check"); > ... > > if (millis <= 0) { > // NOTE: workaround for bug 4338139 > if (thread->is_Java_thread()) { > ThreadBlockInVM tbivm((JavaThread*) thread); > // BSDXXX: Only use pthread_yield here and below if the system thread > // scheduler gives time slices to lower priority threads when yielding. > #ifdef __FreeBSD__ > os_sleep(MinSleepInterval, interruptible); > #else > pthread_yield(); > #endif > > When I removed this hack (i.e. revert to pthread_yield()) I got an immediate > 7-fold performance increase, which brings FreeBSD performance on par with > Solaris. > > What is the reason why this code is necessary? Does FreeBSD's sched_yield() > really have different semantics to the other operating systems, or was this a > libkse bug that was being worked around? > > Kris > _______________________________________________ > freebsd-java@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-java > To unsubscribe, send any mail to "freebsd-java-unsubscribe@freebsd.org" > -- "Courage isn't just a matter of not being frightened, you know. It's being afraid and doing what you have to do anyway." Doctor Who - Planet of the Daleks This message has been brought to you by Nick Johnson 2.3b1 and the number 6. http://healerNick.com/ http://morons.org/ http://spatula.net/