From patchwork Thu Apr 5 15:00:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Portante X-Patchwork-Id: 151020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 84B2AB7054 for ; Fri, 6 Apr 2012 06:28:12 +1000 (EST) Received: from localhost ([::1]:54738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFoBW-0004Pv-Q7 for incoming@patchwork.ozlabs.org; Thu, 05 Apr 2012 11:01:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFoBJ-0004PY-60 for qemu-devel@nongnu.org; Thu, 05 Apr 2012 11:01:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFoBE-00032G-LJ for qemu-devel@nongnu.org; Thu, 05 Apr 2012 11:00:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFoBE-000321-DG for qemu-devel@nongnu.org; Thu, 05 Apr 2012 11:00:56 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q35F0pkX021071 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 5 Apr 2012 11:00:51 -0400 Received: from frodo.bos.redhat.com (frodo.bos.redhat.com [10.16.184.50]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q35F0jYa007839; Thu, 5 Apr 2012 11:00:50 -0400 From: Peter Portante To: qemu-devel@nongnu.org Date: Thu, 5 Apr 2012 11:00:45 -0400 Message-Id: <1333638045-20806-1-git-send-email-peter.portante@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Peter Portante Subject: [Qemu-devel] [PATCH v2] qemu-timer.c: Remove 250us timeouts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Basically, the main wait loop calls qemu_run_all_timers() unconditionally. The first thing this routine used to do is to see if a timer had been serviced, and then reset the loop timeout to the next deadline. However, the new deadlines had not been calculated at that point, as qemu_run_timers() had not been called yet for each of the clocks. So qemu_rearm_alarm_timer() would end up with a negative or zero deadline, and default to setting a 250us timeout for the loop. As qemu_run_timers() is called for each clock, the real deadlines would be put in place, but because a loop timeout was already set, the loop timeout would not be changed. Once that 250us timeout fired, the real deadline would be used for the subsequent timeout. For idle VMs, this effectively doubles the number of times through the loop, doubling the number of select() system calls, timer calls, etc. putting added scheduling pressure on the kernel. And under cgroups, this really causes a big problem because the cgroup code does not scale well. By simply running the timers before trying to rearm the timer, we always rearm with a non-zero deadline, effectively halving the number of system calls. Signed-off-by: Peter Portante Reviewed-by: Avi Kivity Reviewed-by: Anthony Liguori --- qemu-timer.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qemu-timer.c b/qemu-timer.c index d7f56e5..b0845f1 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -472,16 +472,16 @@ void qemu_run_all_timers(void) { alarm_timer->pending = 0; + /* vm time timers */ + qemu_run_timers(vm_clock); + qemu_run_timers(rt_clock); + qemu_run_timers(host_clock); + /* rearm timer, if not periodic */ if (alarm_timer->expired) { alarm_timer->expired = 0; qemu_rearm_alarm_timer(alarm_timer); } - - /* vm time timers */ - qemu_run_timers(vm_clock); - qemu_run_timers(rt_clock); - qemu_run_timers(host_clock); } #ifdef _WIN32