From patchwork Wed Jan 25 15:26:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 137776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 56A4F1007D5 for ; Thu, 26 Jan 2012 02:27:19 +1100 (EST) Received: from localhost ([::1]:60800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq4kk-0002ge-On for incoming@patchwork.ozlabs.org; Wed, 25 Jan 2012 10:27:14 -0500 Received: from eggs.gnu.org ([140.186.70.92]:38783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq4kP-0002ED-Om for qemu-devel@nongnu.org; Wed, 25 Jan 2012 10:27:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rq4kK-0005cT-Tc for qemu-devel@nongnu.org; Wed, 25 Jan 2012 10:26:53 -0500 Received: from mout.perfora.net ([74.208.4.195]:50554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq4kK-0005cP-Nm for qemu-devel@nongnu.org; Wed, 25 Jan 2012 10:26:48 -0500 Received: from illuin.morrigu.org (adsl-99-62-40-129.dsl.aus2tx.sbcglobal.net [99.62.40.129]) by mrelay.perfora.net (node=mrus1) with ESMTP (Nemesis) id 0MV6cn-1S6vCC2Qft-00YPiu; Wed, 25 Jan 2012 10:26:47 -0500 From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 25 Jan 2012 09:26:22 -0600 Message-Id: <1327505186-18328-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1327505186-18328-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1327505186-18328-1-git-send-email-mdroth@linux.vnet.ibm.com> X-Provags-ID: V02:K0:suAE/TPocetp5/ArgsV95Md8j9Ur1vt4MRsICLTwXjx pz+fmyf5+njoBHD9BfoS1kshHe+A8peHQs0DaolmzG7hFXHNv8 ag7V7JVsP+jcf5vnvPStqCu7PT661h306CuiI9t31+sKhEQY4o OCnTHVE+T1ju0+PK4+JjyjuTjxXbM9czLU/DA5HazduRIhqpNx GDoK6i+7fCVRizKD6YEVDUrJIF/CoGvDQC0nhSuLTfgbfI6QIp bhY0V3tjONaaR8BiKg3a/VdL9SMnVYIeE1SK0csMO/S2XMrMwe j9fW3K4YaZ6cIqc56Pwv2Me25S8gwL5VD46fsFDGlw+5DF/bvM mMIf45sh2il3aGLMgoL49O+8Xs/vuhT2bm11anH9h+UR/c89cp QqgKYDCdBmOxObmOi91mLfMud6QxXR1HkY= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.208.4.195 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 2/6] main-loop: For tools, initialize timers as part of qemu_init_main_loop() 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 In some cases initializing the alarm timers can lead to non-negligable overhead from programs that link against qemu-tool.o. At least, setting a max-resolution WinMM alarm timer via mm_start_timer() (the current default for Windows) can increase the "tick rate" on Windows OSs and affect frequency scaling, and in the case of tools that run in guest OSs such has qemu-ga, the impact can be fairly dramatic (+20%/20% user/sys time on a core 2 processor was observed from an idle Windows XP guest). This patch doesn't address the issue directly (not sure what a good solution would be for Windows, or what other situations it might be noticeable), but it at least limits the scope of the issue to programs that "opt-in" to using the main-loop.c functions by only enabling alarm timers when qemu_init_main_loop() is called, which is already required to make use of those facilities, so existing users shouldn't be affected. Signed-off-by: Michael Roth --- main-loop.c | 2 +- main-loop.h | 12 ++++++++++++ qemu-tool.c | 3 ++- vl.c | 5 +++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/main-loop.c b/main-loop.c index 62d95b9..db23de0 100644 --- a/main-loop.c +++ b/main-loop.c @@ -199,7 +199,7 @@ static int qemu_signal_init(void) } #endif -int qemu_init_main_loop(void) +int main_loop_init(void) { int ret; diff --git a/main-loop.h b/main-loop.h index f971013..4987041 100644 --- a/main-loop.h +++ b/main-loop.h @@ -41,10 +41,22 @@ * SIGUSR2, thread signals (SIGFPE, SIGILL, SIGSEGV, SIGBUS) and real-time * signals if available. Remember that Windows in practice does not have * signals, though. + * + * In the case of QEMU tools, this will also start/initialize timers. */ int qemu_init_main_loop(void); /** + * main_loop_init: Initializes main loop + * + * Internal (but shared for compatibility reasons) initialization routine + * for the main loop. This should not be used by applications directly, + * use qemu_init_main_loop() instead. + * + */ +int main_loop_init(void); + +/** * main_loop_wait: Run one iteration of the main loop. * * If @nonblocking is true, poll for events, otherwise suspend until diff --git a/qemu-tool.c b/qemu-tool.c index 6b69668..183a583 100644 --- a/qemu-tool.c +++ b/qemu-tool.c @@ -83,11 +83,12 @@ void qemu_clock_warp(QEMUClock *clock) { } -static void __attribute__((constructor)) init_main_loop(void) +int qemu_init_main_loop(void) { init_clocks(); init_timer_alarm(); qemu_clock_enable(vm_clock, false); + return main_loop_init(); } void slirp_select_fill(int *pnfds, fd_set *readfds, diff --git a/vl.c b/vl.c index 57378b6..9d14cc8 100644 --- a/vl.c +++ b/vl.c @@ -2159,6 +2159,11 @@ static void free_and_trace(gpointer mem) free(mem); } +int qemu_init_main_loop(void) +{ + return main_loop_init(); +} + int main(int argc, char **argv, char **envp) { const char *gdbstub_dev = NULL;