From owner-freebsd-emulation@FreeBSD.ORG Thu Dec 13 13:05:04 2012 Return-Path: Delivered-To: freebsd-emulation@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C0CA7B5A; Thu, 13 Dec 2012 13:05:04 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id DC2D98FC12; Thu, 13 Dec 2012 13:05:02 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id PAA15779; Thu, 13 Dec 2012 15:05:01 +0200 (EET) (envelope-from avg@FreeBSD.org) Message-ID: <50C9D27C.1090707@FreeBSD.org> Date: Thu, 13 Dec 2012 15:05:00 +0200 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: vbox@FreeBSD.org, freebsd-emulation@FreeBSD.org Subject: issue with under-tick waits X-Enigmail-Version: 1.4.6 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Dec 2012 13:05:04 -0000 I think that the following patch is needed in VirtualBox 4.2.4 kernel module: --- sleepqueue-r0drv-freebsd.h.orig 2012-12-12 20:09:29.675203802 +0200 +++ sleepqueue-r0drv-freebsd.h 2012-12-12 20:11:53.604203131 +0200 @@ -82,6 +82,8 @@ uint64_t cTicks = ASMMultU64ByU32DivByU32(uTimeout, hz, UINT32_C(1000000000)); if (cTicks >= INT_MAX) return RTSEMWAIT_FLAGS_INDEFINITE; + else if (cTicks == 0 && uTimeout > 0) + pWait->iTimeout = 1; else pWait->iTimeout = (int)cTicks; #endif Without this patch any waits for periods shorter than a single tick return immediately leading to a lot of unnecessary spinning. For example, I observe that my guest's idle loop does a lot of sleeps with periods slightly shorter than 1 ms (1/hz), e.g. 900us. All that waiting turns into pure spinning and VirtualBox eats 100% of a core. The above patch improves the situation significantly. Also, it (approximately) follows what tvtohz does. -- Andriy Gapon