From owner-freebsd-java@FreeBSD.ORG Mon Sep 17 02:34:10 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 D875D16A417; Mon, 17 Sep 2007 02:34:10 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id C6F3B13C457; Mon, 17 Sep 2007 02:34:10 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from [127.0.0.1] (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l8H2Y77C017951; Mon, 17 Sep 2007 02:34:08 GMT (envelope-from davidxu@freebsd.org) Message-ID: <46EDE7CF.8060100@freebsd.org> Date: Mon, 17 Sep 2007 10:34:55 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20070516 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Kennaway References: <46EC1B55.4060202@FreeBSD.org> In-Reply-To: <46EC1B55.4060202@FreeBSD.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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 List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Sep 2007 02:34:11 -0000 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 Yeah, our sched_yield() really works well, in kernel, if the thread scheduling policy is SCHED_OTHER (time-sharing), scheduler temporarily lowers its priority to PRI_MAX_TIMESHARE, it is enough to give some CPU time to other threads. Why doesn't the UNIX time-sharing work for java ? Regards, David Xu