From owner-freebsd-java@FreeBSD.ORG Sat Sep 15 18:41:44 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 664BF16A417; Sat, 15 Sep 2007 18:41:44 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id 0784A13C458; Sat, 15 Sep 2007 18:41:43 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.1/8.14.1/NETPLEX) with ESMTP id l8FISrp7017490; Sat, 15 Sep 2007 14:28:53 -0400 (EDT) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-3.0 (mail.netplex.net [204.213.176.10]); Sat, 15 Sep 2007 14:28:53 -0400 (EDT) Date: Sat, 15 Sep 2007 14:28:53 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Kris Kennaway In-Reply-To: <46EC1B55.4060202@FreeBSD.org> Message-ID: References: <46EC1B55.4060202@FreeBSD.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: java@freebsd.org, 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 Reply-To: Daniel Eischen List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Sep 2007 18:41:44 -0000 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? It's certainly not a libkse bug, at least with scope process threads libkse does the right thinng. For scope system threads and all libthr threads, it probably depends on what scheduler you are using since it's essentially a __sys_sched_yield(). On a side note, I think pthread_yield() is deprecated and not in the latest POSIX spec. sched_yield() is in the spec and is specified to account for behavior in a threaded environment. -- DE