From patchwork Tue May 7 09:12:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Mauerer X-Patchwork-Id: 242085 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 B2E952C016D for ; Tue, 7 May 2013 19:11:04 +1000 (EST) Received: from localhost ([::1]:54504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZdvK-0000Lh-A8 for incoming@patchwork.ozlabs.org; Tue, 07 May 2013 05:11:02 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZdum-0000LY-Mf for qemu-devel@nongnu.org; Tue, 07 May 2013 05:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZduk-0001Of-PG for qemu-devel@nongnu.org; Tue, 07 May 2013 05:10:28 -0400 Received: from gecko.sbs.de ([194.138.37.40]:16331) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZduk-0000pm-Ea for qemu-devel@nongnu.org; Tue, 07 May 2013 05:10:26 -0400 Received: from mail1.sbs.de (localhost [127.0.0.1]) by gecko.sbs.de (8.13.6/8.13.6) with ESMTP id r47990RW018904; Tue, 7 May 2013 11:09:00 +0200 Received: from [139.25.109.103] (polariton.mchp.siemens.de [139.25.109.103] (may be forged)) by mail1.sbs.de (8.13.6/8.13.6) with ESMTP id r4798xDX018075; Tue, 7 May 2013 11:08:59 +0200 Message-ID: <5188C58A.3020203@siemens.com> Date: Tue, 07 May 2013 11:12:42 +0200 From: Wolfgang Mauerer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: Stefan Weil References: <50F06EF3.9070200@weilnetz.de> <1358442625-30828-1-git-send-email-wolfgang.mauerer@siemens.com> <50F85D67.9000508@weilnetz.de> In-Reply-To: <50F85D67.9000508@weilnetz.de> X-Enigmail-Version: 1.5.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 194.138.37.40 Cc: "aliguori@us.ibm.com" , "qemu-devel@nongnu.org" Subject: Re: [Qemu-devel] [[PATCH v2]] Add option to slow qemu down 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 Hello, On 17/01/13 21:21, Stefan Weil wrote: > Am 17.01.2013 18:10, schrieb Wolfgang Mauerer: >> For slow targets and fast hosts, the emulation may be faster >> than the actual hardware, which can be undesirable for various >> reasons. Add a run-time option to slow down the emulation >> by sleeping in the CPU emulation. >> (...) > Please test your patch using scripts/checkpatch.pl before sending it. all stylistic issues have already been addressed in the last iteration; do you have additional comments on the code besides those raised in http://lists.gnu.org/archive/html/qemu-devel/2013-01/msg03248.html? Here's a pull request: The following changes since commit b5803aa3583e82e5133f7621121bc15ee694f4a1: Merge remote-tracking branch 'qemu-kvm/uq/master' into staging (2013-05-06 15:45:08 -0500) are available in the git repository at: git://github.com/siemens/qemu.git for-upstream for you to fetch changes up to 3e3a2c7158139020aa9c172ba902694e6a531cbe: Add option to slow qemu down (2013-05-07 10:43:31 +0200) ---------------------------------------------------------------- Wolfgang Mauerer (1): Add option to slow qemu down cpus.c | 30 ++++++++++++++++++++++++++++++ include/qemu-common.h | 2 ++ qemu-options.hx | 14 ++++++++++++++ vl.c | 10 ++++++++++ 4 files changed, 56 insertions(+) I've also attached the patch below. Thanks, Wolfgang ###################################################################### From 3e3a2c7158139020aa9c172ba902694e6a531cbe Mon Sep 17 00:00:00 2001 From: Wolfgang Mauerer Date: Thu, 17 Jan 2013 15:53:39 +0100 Subject: [PATCH] Add option to slow qemu down For slow targets and fast hosts, the emulation may be faster than the actual hardware, which can be undesirable for various reasons. Add a run-time option to slow down the emulation by sleeping in the CPU emulation. Signed-off-by: Wolfgang Mauerer --- cpus.c | 30 ++++++++++++++++++++++++++++++ include/qemu-common.h | 2 ++ qemu-options.hx | 14 ++++++++++++++ vl.c | 10 ++++++++++ 4 files changed, 56 insertions(+) diff --git a/cpus.c b/cpus.c index c232265..2cff5f3 100644 --- a/cpus.c +++ b/cpus.c @@ -61,6 +61,7 @@ #endif /* CONFIG_LINUX */ static CPUArchState *next_cpu; +static bool use_slowdown; static bool cpu_thread_is_idle(CPUArchState *env) { @@ -106,6 +107,8 @@ static QEMUTimer *icount_warp_timer; static int64_t vm_clock_warp_start; static int64_t qemu_icount; +static double slowdown_factor; + typedef struct TimersState { int64_t cpu_ticks_prev; int64_t cpu_ticks_offset; @@ -385,6 +388,21 @@ void configure_icount(const char *option) qemu_get_clock_ns(vm_clock) + get_ticks_per_sec() / 10); } +void configure_slowdown(const char *option) +{ + if (!option) { + return; + } + + slowdown_factor = strtod(option, NULL) / 100.0; + /* We cannot provide speedups, obviously */ + if (slowdown_factor < 0) { + slowdown_factor *= -1.0; + } + + use_slowdown = true; +} + /***********************************************************/ void hw_error(const char *fmt, ...) { @@ -1121,6 +1139,8 @@ void vm_stop_force_state(RunState state) static int tcg_cpu_exec(CPUArchState *env) { int ret; + int64_t ss = 0; /* Initialise to avoid bogous maybe-uninitialized error */ + uint64_t slowdown_sleep; #ifdef CONFIG_PROFILER int64_t ti; #endif @@ -1141,7 +1161,17 @@ static int tcg_cpu_exec(CPUArchState *env) env->icount_decr.u16.low = decr; env->icount_extra = count; } + if (use_slowdown) { + ss = qemu_get_clock_ns(rt_clock); + } + ret = cpu_exec(env); + + if (use_slowdown) { + slowdown_sleep = qemu_get_clock_ns(rt_clock) - ss; + slowdown_sleep *= slowdown_factor; + g_usleep(slowdown_sleep / 1024); + } #ifdef CONFIG_PROFILER qemu_time += profile_getclock() - ti; #endif diff --git a/include/qemu-common.h b/include/qemu-common.h index b399d85..219993f 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -108,6 +108,8 @@ static inline char *realpath(const char *path, char *resolved_path) void configure_icount(const char *option); extern int use_icount; +void configure_slowdown(const char *option); + #include "qemu/osdep.h" #include "qemu/bswap.h" diff --git a/qemu-options.hx b/qemu-options.hx index fb62b75..c764e42 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2801,6 +2801,20 @@ order cores with complex cache hierarchies. The number of instructions executed often has little or no correlation with actual performance. ETEXI +DEF("slowdown", HAS_ARG, QEMU_OPTION_slowdown, \ + "-slowdown s\n" \ + " Slow down the CPU emulation by (approximately) s percent\n", + QEMU_ARCH_ALL) +STEXI +@item -slowdown @var{s} +@findex -slowdown +Slow down the virtual CPU by approximately s percent (i.e., for c time +units of execution time, sleep for c*s/100 time units). This makes it +possible to align the emulated machine's performance roughly with +the performance of physical entities, but does not provide identical +performance profiles since the emulation is not cycle accurate. +ETEXI + DEF("watchdog", HAS_ARG, QEMU_OPTION_watchdog, \ "-watchdog i6300esb|ib700\n" \ " enable virtual hardware watchdog [default=none]\n", diff --git a/vl.c b/vl.c index 6e6225f..27acf8b 100644 --- a/vl.c +++ b/vl.c @@ -2839,6 +2839,7 @@ int main(int argc, char **argv, char **envp) int i; int snapshot, linux_boot; const char *icount_option = NULL; + const char *slowdown_option = NULL; const char *initrd_filename; const char *kernel_filename, *kernel_cmdline; char boot_devices[33] = ""; @@ -3751,6 +3752,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_icount: icount_option = optarg; break; + case QEMU_OPTION_slowdown: + slowdown_option = optarg; + break; case QEMU_OPTION_incoming: incoming = optarg; runstate_set(RUN_STATE_INMIGRATE); @@ -4169,6 +4173,12 @@ int main(int argc, char **argv, char **envp) /* clean up network at qemu process termination */ atexit(&net_cleanup); + if (slowdown_option && (kvm_enabled() || xen_enabled())) { + fprintf(stderr, "-slowdown is not allowed with kvm or xen\n"); + exit(1); + } + configure_slowdown(slowdown_option); + if (net_init_clients() < 0) { exit(1); }