* [Qemu-devel] [PATCH] Add option to slow down qemu
@ 2013-01-11 13:40 Wolfgang Mauerer
2013-01-11 19:58 ` Stefan Weil
0 siblings, 1 reply; 10+ messages in thread
From: Wolfgang Mauerer @ 2013-01-11 13:40 UTC (permalink / raw)
To: qemu-devel, aliguori
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 <wolfgang.mauerer@siemens.com>
---
cpus.c | 34 ++++++++++++++++++++++++++++++++++
include/qemu-common.h | 2 ++
qemu-options.hx | 13 +++++++++++++
vl.c | 10 ++++++++++
4 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/cpus.c b/cpus.c
index 4a7782a..41a9e0c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -106,6 +106,11 @@ static QEMUTimer *icount_warp_timer;
static int64_t vm_clock_warp_start;
static int64_t qemu_icount;
+static double slowdown_factor = 0.0;
+#ifndef _WIN32
+static struct timespec slowdown_delay;
+#endif
+
typedef struct TimersState {
int64_t cpu_ticks_prev;
int64_t cpu_ticks_offset;
@@ -385,6 +390,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;
+ }
+
+ slowdown_delay.tv_sec = 0;
+}
+
/***********************************************************/
void hw_error(const char *fmt, ...)
{
@@ -1092,6 +1112,7 @@ void vm_stop_force_state(RunState state)
static int tcg_cpu_exec(CPUArchState *env)
{
int ret;
+ int64_t ss, delta;
#ifdef CONFIG_PROFILER
int64_t ti;
#endif
@@ -1112,7 +1133,20 @@ static int tcg_cpu_exec(CPUArchState *env)
env->icount_decr.u16.low = decr;
env->icount_extra = count;
}
+ ss = qemu_get_clock_ns(rt_clock);
+
ret = cpu_exec(env);
+
+ if (slowdown_factor > 0) {
+ delta = qemu_get_clock_ns(rt_clock) - ss;
+ delta *= slowdown_factor;
+#ifdef _WIN32
+ Sleep(delta/1000000l);
+#else
+ slowdown_delay.tv_nsec = delta;
+ nanosleep(&slowdown_delay, NULL);
+#endif
+ }
#ifdef CONFIG_PROFILER
qemu_time += profile_getclock() - ti;
#endif
diff --git a/include/qemu-common.h b/include/qemu-common.h
index ca464bb..652abb9 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -119,6 +119,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);
+
/* FIXME: Remove NEED_CPU_H. */
#ifndef NEED_CPU_H
diff --git a/qemu-options.hx b/qemu-options.hx
index 9df0cde..2f6580f 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2665,6 +2665,19 @@ 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. 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 79e5122..624551f 100644
--- a/vl.c
+++ b/vl.c
@@ -2524,6 +2524,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] = "cad"; /* default to HD->floppy->CD-ROM */
@@ -3402,6 +3403,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);
@@ -3765,6 +3769,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);
}
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] Add option to slow down qemu
2013-01-11 13:40 [Qemu-devel] [PATCH] Add option to slow down qemu Wolfgang Mauerer
@ 2013-01-11 19:58 ` Stefan Weil
2013-01-17 17:10 ` [Qemu-devel] [[PATCH v2]] Add option to slow qemu down Wolfgang Mauerer
2013-01-17 17:14 ` [Qemu-devel] [PATCH] Add option to slow down qemu Wolfgang Mauerer
0 siblings, 2 replies; 10+ messages in thread
From: Stefan Weil @ 2013-01-11 19:58 UTC (permalink / raw)
To: Wolfgang Mauerer; +Cc: aliguori, qemu-devel
Am 11.01.2013 14:40, 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.
>
> Signed-off-by: Wolfgang Mauerer<wolfgang.mauerer@siemens.com>
> ---
> cpus.c | 34 ++++++++++++++++++++++++++++++++++
> include/qemu-common.h | 2 ++
> qemu-options.hx | 13 +++++++++++++
> vl.c | 10 ++++++++++
> 4 files changed, 59 insertions(+), 0 deletions(-)
>
> diff --git a/cpus.c b/cpus.c
> index 4a7782a..41a9e0c 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -106,6 +106,11 @@ static QEMUTimer *icount_warp_timer;
> static int64_t vm_clock_warp_start;
> static int64_t qemu_icount;
>
> +static double slowdown_factor = 0.0;
> +#ifndef _WIN32
> +static struct timespec slowdown_delay;
> +#endif
> +
>
Hi,
slowdown_delay is used in configure_slowdown unconditionally,
so I don't expect that the _WIN32 case will compile.
What about using g_usleep? It avoids the conditional compilation.
Is the comparison of double value "slowdown_factor" with 0.0
time critical, or do all QEMU platforms have a fast FPU?
Setting a boolean value once and testing that value would
be much faster of course.
Cheers,
Stefan W.
> typedef struct TimersState {
> int64_t cpu_ticks_prev;
> int64_t cpu_ticks_offset;
> @@ -385,6 +390,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;
> + }
> +
> + slowdown_delay.tv_sec = 0;
> +}
> +
> /***********************************************************/
> void hw_error(const char *fmt, ...)
> {
> @@ -1092,6 +1112,7 @@ void vm_stop_force_state(RunState state)
> static int tcg_cpu_exec(CPUArchState *env)
> {
> int ret;
> + int64_t ss, delta;
> #ifdef CONFIG_PROFILER
> int64_t ti;
> #endif
> @@ -1112,7 +1133,20 @@ static int tcg_cpu_exec(CPUArchState *env)
> env->icount_decr.u16.low = decr;
> env->icount_extra = count;
> }
> + ss = qemu_get_clock_ns(rt_clock);
> +
> ret = cpu_exec(env);
> +
> + if (slowdown_factor> 0) {
> + delta = qemu_get_clock_ns(rt_clock) - ss;
> + delta *= slowdown_factor;
> +#ifdef _WIN32
> + Sleep(delta/1000000l);
> +#else
> + slowdown_delay.tv_nsec = delta;
> + nanosleep(&slowdown_delay, NULL);
> +#endif
> + }
> #ifdef CONFIG_PROFILER
> qemu_time += profile_getclock() - ti;
> #endif
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index ca464bb..652abb9 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -119,6 +119,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);
> +
> /* FIXME: Remove NEED_CPU_H. */
> #ifndef NEED_CPU_H
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 9df0cde..2f6580f 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2665,6 +2665,19 @@ 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. 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 79e5122..624551f 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2524,6 +2524,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] = "cad"; /* default to HD->floppy->CD-ROM */
> @@ -3402,6 +3403,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);
> @@ -3765,6 +3769,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);
> }
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Qemu-devel] [[PATCH v2]] Add option to slow qemu down
2013-01-11 19:58 ` Stefan Weil
@ 2013-01-17 17:10 ` Wolfgang Mauerer
2013-01-17 20:21 ` Stefan Weil
2013-01-17 17:14 ` [Qemu-devel] [PATCH] Add option to slow down qemu Wolfgang Mauerer
1 sibling, 1 reply; 10+ messages in thread
From: Wolfgang Mauerer @ 2013-01-17 17:10 UTC (permalink / raw)
To: sw; +Cc: aliguori, Wolfgang Mauerer, qemu-devel
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 <wolfgang.mauerer@siemens.com>
---
cpus.c | 29 +++++++++++++++++++++++++++++
include/qemu-common.h | 2 ++
qemu-options.hx | 14 ++++++++++++++
vl.c | 10 ++++++++++
4 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/cpus.c b/cpus.c
index a4390c3..eae10f4 100644
--- a/cpus.c
+++ b/cpus.c
@@ -61,6 +61,7 @@
#endif /* CONFIG_LINUX */
static CPUArchState *next_cpu;
+static bool use_slowdown = false;
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,20 @@ 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, ...)
{
@@ -1094,6 +1111,8 @@ void vm_stop_force_state(RunState state)
static int tcg_cpu_exec(CPUArchState *env)
{
int ret;
+ int64_t ss;
+ uint64_t slowdown_sleep;
#ifdef CONFIG_PROFILER
int64_t ti;
#endif
@@ -1114,7 +1133,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 ca464bb..652abb9 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -119,6 +119,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);
+
/* FIXME: Remove NEED_CPU_H. */
#ifndef NEED_CPU_H
diff --git a/qemu-options.hx b/qemu-options.hx
index 40cd683..d5eb5eb 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2667,6 +2667,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 8ce2b10..9aa44e0 100644
--- a/vl.c
+++ b/vl.c
@@ -2713,6 +2713,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] = "";
@@ -3607,6 +3608,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);
@@ -3970,6 +3974,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);
}
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [[PATCH v2]] Add option to slow qemu down
2013-01-17 17:10 ` [Qemu-devel] [[PATCH v2]] Add option to slow qemu down Wolfgang Mauerer
@ 2013-01-17 20:21 ` Stefan Weil
2013-01-18 12:04 ` Wolfgang Mauerer
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Stefan Weil @ 2013-01-17 20:21 UTC (permalink / raw)
To: Wolfgang Mauerer; +Cc: aliguori, qemu-devel
Hello Wolfgang,
please see comment below.
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.
>
> Signed-off-by: Wolfgang Mauerer<wolfgang.mauerer@siemens.com>
> ---
> cpus.c | 29 +++++++++++++++++++++++++++++
> include/qemu-common.h | 2 ++
> qemu-options.hx | 14 ++++++++++++++
> vl.c | 10 ++++++++++
> 4 files changed, 55 insertions(+), 0 deletions(-)
>
> diff --git a/cpus.c b/cpus.c
> index a4390c3..eae10f4 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -61,6 +61,7 @@
> #endif /* CONFIG_LINUX */
>
> static CPUArchState *next_cpu;
> +static bool use_slowdown = false;
"= false" is not needed.
Explicit setting of static variables to their default value
increases the image size and should be avoided.
>
> 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,20 @@ 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;
Missing blanks around "/".
> + /* We cannot provide speedups, obviously */
> + if (slowdown_factor< 0)
> + slowdown_factor *= -1.0;
Missing {}.
> +
> + use_slowdown = true;
> +}
> +
> /***********************************************************/
> void hw_error(const char *fmt, ...)
> {
> @@ -1094,6 +1111,8 @@ void vm_stop_force_state(RunState state)
> static int tcg_cpu_exec(CPUArchState *env)
> {
> int ret;
> + int64_t ss;
> + uint64_t slowdown_sleep;
> #ifdef CONFIG_PROFILER
> int64_t ti;
> #endif
> @@ -1114,7 +1133,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);
Missing blanks around "/".
> + }
> #ifdef CONFIG_PROFILER
> qemu_time += profile_getclock() - ti;
> #endif
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index ca464bb..652abb9 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -119,6 +119,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);
> +
> /* FIXME: Remove NEED_CPU_H. */
> #ifndef NEED_CPU_H
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 40cd683..d5eb5eb 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2667,6 +2667,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" \
Remove blank before \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 8ce2b10..9aa44e0 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2713,6 +2713,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] = "";
> @@ -3607,6 +3608,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);
> @@ -3970,6 +3974,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);
> }
Please test your patch using scripts/checkpatch.pl before sending it.
Kind regards,
Stefan Weil
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [[PATCH v2]] Add option to slow qemu down
2013-01-17 20:21 ` Stefan Weil
@ 2013-01-18 12:04 ` Wolfgang Mauerer
2013-01-18 12:05 ` [Qemu-devel] [PATCH] " Wolfgang Mauerer
2013-05-07 9:12 ` [Qemu-devel] [[PATCH v2]] " Wolfgang Mauerer
2 siblings, 0 replies; 10+ messages in thread
From: Wolfgang Mauerer @ 2013-01-18 12:04 UTC (permalink / raw)
To: Stefan Weil; +Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
Hello Stefan,
On 17/01/13 21:21, Stefan Weil wrote:
> Please test your patch using scripts/checkpatch.pl before sending it.
embarrassingly, I did not do that, true. Stylistically correct
version follows.
Best regards, Wolfgang
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH] Add option to slow qemu down
2013-01-17 20:21 ` Stefan Weil
2013-01-18 12:04 ` Wolfgang Mauerer
@ 2013-01-18 12:05 ` Wolfgang Mauerer
2013-05-07 9:12 ` [Qemu-devel] [[PATCH v2]] " Wolfgang Mauerer
2 siblings, 0 replies; 10+ messages in thread
From: Wolfgang Mauerer @ 2013-01-18 12:05 UTC (permalink / raw)
To: sw; +Cc: aliguori, qemu-devel
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 <wolfgang.mauerer@siemens.com>
---
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 a4390c3..b7838fd 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, ...)
{
@@ -1094,6 +1112,8 @@ void vm_stop_force_state(RunState state)
static int tcg_cpu_exec(CPUArchState *env)
{
int ret;
+ int64_t ss;
+ uint64_t slowdown_sleep;
#ifdef CONFIG_PROFILER
int64_t ti;
#endif
@@ -1114,7 +1134,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 ca464bb..652abb9 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -119,6 +119,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);
+
/* FIXME: Remove NEED_CPU_H. */
#ifndef NEED_CPU_H
diff --git a/qemu-options.hx b/qemu-options.hx
index 40cd683..2bab5aa 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2667,6 +2667,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 8ce2b10..9aa44e0 100644
--- a/vl.c
+++ b/vl.c
@@ -2713,6 +2713,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] = "";
@@ -3607,6 +3608,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);
@@ -3970,6 +3974,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);
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [[PATCH v2]] Add option to slow qemu down
2013-01-17 20:21 ` Stefan Weil
2013-01-18 12:04 ` Wolfgang Mauerer
2013-01-18 12:05 ` [Qemu-devel] [PATCH] " Wolfgang Mauerer
@ 2013-05-07 9:12 ` Wolfgang Mauerer
2013-05-07 10:56 ` Markus Armbruster
2 siblings, 1 reply; 10+ messages in thread
From: Wolfgang Mauerer @ 2013-05-07 9:12 UTC (permalink / raw)
To: Stefan Weil; +Cc: aliguori@us.ibm.com, qemu-devel@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 <wolfgang.mauerer@siemens.com>
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 <wolfgang.mauerer@siemens.com>
---
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);
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [[PATCH v2]] Add option to slow qemu down
2013-05-07 9:12 ` [Qemu-devel] [[PATCH v2]] " Wolfgang Mauerer
@ 2013-05-07 10:56 ` Markus Armbruster
2013-05-07 11:30 ` Wolfgang Mauerer
0 siblings, 1 reply; 10+ messages in thread
From: Markus Armbruster @ 2013-05-07 10:56 UTC (permalink / raw)
To: Wolfgang Mauerer; +Cc: Stefan Weil, aliguori@us.ibm.com, qemu-devel@nongnu.org
Wolfgang Mauerer <wolfgang.mauerer@siemens.com> writes:
> 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 <wolfgang.mauerer@siemens.com>
> 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 <wolfgang.mauerer@siemens.com>
> ---
> 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);
Suggest to mention this in the commit message, and perhaps the manual
(STEXI..ETEXI section in qemu-options.hx).
> + }
> + configure_slowdown(slowdown_option);
> +
> if (net_init_clients() < 0) {
> exit(1);
> }
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [[PATCH v2]] Add option to slow qemu down
2013-05-07 10:56 ` Markus Armbruster
@ 2013-05-07 11:30 ` Wolfgang Mauerer
0 siblings, 0 replies; 10+ messages in thread
From: Wolfgang Mauerer @ 2013-05-07 11:30 UTC (permalink / raw)
To: Markus Armbruster; +Cc: Stefan Weil, aliguori@us.ibm.com, qemu-devel@nongnu.org
On 07/05/13 12:56, Markus Armbruster wrote:
(...)
>> + if (slowdown_option && (kvm_enabled() || xen_enabled())) {
>> + fprintf(stderr, "-slowdown is not allowed with kvm or xen\n");
>> + exit(1);
>
> Suggest to mention this in the commit message, and perhaps the manual
> (STEXI..ETEXI section in qemu-options.hx).
sure, updated patch is attached (I've also updated the github repository).
Thanks, Wolfgang
---
>From 6c85a1d11ca0f8ceaf4fbf7c97a0aaa1b145acd2 Mon Sep 17 00:00:00 2001
From: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
Date: Tue, 7 May 2013 13:20:28 +0200
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.
The option is not available when KVM or XEN acceleration is
enabled since it would defeat the purpose.
Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
cpus.c | 30 ++++++++++++++++++++++++++++++
include/qemu-common.h | 2 ++
qemu-options.hx | 15 +++++++++++++++
vl.c | 10 ++++++++++
4 files changed, 57 insertions(+)
diff --git a/cpus.c b/cpus.c
index c232265..f59c935 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 bogus 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..fd16cb3 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2801,6 +2801,21 @@ 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 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.
+
+Note that this option cannot be used when KVM or XEN support is active.
+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);
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] Add option to slow down qemu
2013-01-11 19:58 ` Stefan Weil
2013-01-17 17:10 ` [Qemu-devel] [[PATCH v2]] Add option to slow qemu down Wolfgang Mauerer
@ 2013-01-17 17:14 ` Wolfgang Mauerer
1 sibling, 0 replies; 10+ messages in thread
From: Wolfgang Mauerer @ 2013-01-17 17:14 UTC (permalink / raw)
To: Stefan Weil; +Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
On 11/01/13 20:58, Stefan Weil wrote:
> Am 11.01.2013 14:40, 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.
>> >
>> > Signed-off-by: Wolfgang Mauerer<wolfgang.mauerer@siemens.com>
>> > ---
>> > cpus.c | 34 ++++++++++++++++++++++++++++++++++
>> > include/qemu-common.h | 2 ++
>> > qemu-options.hx | 13 +++++++++++++
>> > vl.c | 10 ++++++++++
>> > 4 files changed, 59 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/cpus.c b/cpus.c
>> > index 4a7782a..41a9e0c 100644
>> > --- a/cpus.c
>> > +++ b/cpus.c
>> > @@ -106,6 +106,11 @@ static QEMUTimer *icount_warp_timer;
>> > static int64_t vm_clock_warp_start;
>> > static int64_t qemu_icount;
>> >
>> > +static double slowdown_factor = 0.0;
>> > +#ifndef _WIN32
>> > +static struct timespec slowdown_delay;
>> > +#endif
>> > +
>> >
> Hi,
>
> slowdown_delay is used in configure_slowdown unconditionally,
> so I don't expect that the _WIN32 case will compile.
>
> What about using g_usleep? It avoids the conditional compilation.
>
> Is the comparison of double value "slowdown_factor" with 0.0
> time critical, or do all QEMU platforms have a fast FPU?
>
> Setting a boolean value once and testing that value would
> be much faster of course.
I'm not sure if the floating point comparison has a significant
impact on any important platform, but using a boolean variable
makes the code more similar to the icount mechanism, so I've
changed it accordingly. Using g_usleep is a good idea to let the
conditional _WIN32 parts go away. Revised patch follows.
Cheers, Wolfgang
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-05-07 11:26 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-11 13:40 [Qemu-devel] [PATCH] Add option to slow down qemu Wolfgang Mauerer
2013-01-11 19:58 ` Stefan Weil
2013-01-17 17:10 ` [Qemu-devel] [[PATCH v2]] Add option to slow qemu down Wolfgang Mauerer
2013-01-17 20:21 ` Stefan Weil
2013-01-18 12:04 ` Wolfgang Mauerer
2013-01-18 12:05 ` [Qemu-devel] [PATCH] " Wolfgang Mauerer
2013-05-07 9:12 ` [Qemu-devel] [[PATCH v2]] " Wolfgang Mauerer
2013-05-07 10:56 ` Markus Armbruster
2013-05-07 11:30 ` Wolfgang Mauerer
2013-01-17 17:14 ` [Qemu-devel] [PATCH] Add option to slow down qemu Wolfgang Mauerer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).