[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/36] system/cpu-timers: Introduce ICountMode enumerator
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 12/36] system/cpu-timers: Introduce ICountMode enumerator |
Date: |
Fri, 19 Jan 2024 12:34:41 +0100 |
Rather than having to lookup for what the 0, 1, 2, ...
icount values are, use a enum definition.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20231208113529.74067-4-philmd@linaro.org>
---
include/sysemu/cpu-timers.h | 20 +++++++++++++-------
accel/tcg/icount-common.c | 16 +++++++---------
stubs/icount.c | 2 +-
system/cpu-timers.c | 2 +-
target/arm/helper.c | 3 ++-
5 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/include/sysemu/cpu-timers.h b/include/sysemu/cpu-timers.h
index b70dc7692d..3f05f29b10 100644
--- a/include/sysemu/cpu-timers.h
+++ b/include/sysemu/cpu-timers.h
@@ -17,18 +17,24 @@ void cpu_timers_init(void);
/* icount - Instruction Counter API */
-/*
- * icount enablement state:
+/**
+ * ICountMode: icount enablement state:
*
- * 0 = Disabled - Do not count executed instructions.
- * 1 = Enabled - Fixed conversion of insn to ns via "shift" option
- * 2 = Enabled - Runtime adaptive algorithm to compute shift
+ * @ICOUNT_DISABLED: Disabled - Do not count executed instructions.
+ * @ICOUNT_PRECISE: Enabled - Fixed conversion of insn to ns via "shift" option
+ * @ICOUNT_ADAPTATIVE: Enabled - Runtime adaptive algorithm to compute shift
*/
+typedef enum {
+ ICOUNT_DISABLED = 0,
+ ICOUNT_PRECISE,
+ ICOUNT_ADAPTATIVE,
+} ICountMode;
+
#ifdef CONFIG_TCG
-extern int use_icount;
+extern ICountMode use_icount;
#define icount_enabled() (use_icount)
#else
-#define icount_enabled() 0
+#define icount_enabled() ICOUNT_DISABLED
#endif
/*
diff --git a/accel/tcg/icount-common.c b/accel/tcg/icount-common.c
index dc69d6a4c6..f0f8fc7f1c 100644
--- a/accel/tcg/icount-common.c
+++ b/accel/tcg/icount-common.c
@@ -49,21 +49,19 @@ static bool icount_sleep = true;
/* Arbitrarily pick 1MIPS as the minimum allowable speed. */
#define MAX_ICOUNT_SHIFT 10
-/*
- * 0 = Do not count executed instructions.
- * 1 = Fixed conversion of insn to ns via "shift" option
- * 2 = Runtime adaptive algorithm to compute shift
- */
-int use_icount;
+/* Do not count executed instructions */
+ICountMode use_icount = ICOUNT_DISABLED;
static void icount_enable_precise(void)
{
- use_icount = 1;
+ /* Fixed conversion of insn to ns via "shift" option */
+ use_icount = ICOUNT_PRECISE;
}
static void icount_enable_adaptive(void)
{
- use_icount = 2;
+ /* Runtime adaptive algorithm to compute shift */
+ use_icount = ICOUNT_ADAPTATIVE;
}
/*
@@ -256,7 +254,7 @@ static void icount_warp_rt(void)
int64_t warp_delta;
warp_delta = clock - timers_state.vm_clock_warp_start;
- if (icount_enabled() == 2) {
+ if (icount_enabled() == ICOUNT_ADAPTATIVE) {
/*
* In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too far
* ahead of real time (it might already be ahead so careful not
diff --git a/stubs/icount.c b/stubs/icount.c
index 85c381a0ea..c2c10dfb6b 100644
--- a/stubs/icount.c
+++ b/stubs/icount.c
@@ -4,7 +4,7 @@
/* icount - Instruction Counter API */
-int use_icount;
+ICountMode use_icount = ICOUNT_DISABLED;
void icount_update(CPUState *cpu)
{
diff --git a/system/cpu-timers.c b/system/cpu-timers.c
index bdf3a41dcb..0b31c9a1b6 100644
--- a/system/cpu-timers.c
+++ b/system/cpu-timers.c
@@ -154,7 +154,7 @@ static bool adjust_timers_state_needed(void *opaque)
static bool icount_shift_state_needed(void *opaque)
{
- return icount_enabled() == 2;
+ return icount_enabled() == ICOUNT_ADAPTATIVE;
}
/*
diff --git a/target/arm/helper.c b/target/arm/helper.c
index dc8f14f433..49665bb763 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -948,7 +948,8 @@ static int64_t cycles_ns_per(uint64_t cycles)
static bool instructions_supported(CPUARMState *env)
{
- return icount_enabled() == 1; /* Precise instruction counting */
+ /* Precise instruction counting */
+ return icount_enabled() == ICOUNT_PRECISE;
}
static uint64_t instructions_get_count(CPUARMState *env)
--
2.41.0
- [PULL 02/36] backends/cryptodev: Do not ignore throttle/backends Errors, (continued)
- [PULL 02/36] backends/cryptodev: Do not ignore throttle/backends Errors, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 03/36] accel: Do not set CPUState::tcg_cflags in non-TCG accels, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 04/36] accel: Do not set CPUState::can_do_io in non-TCG accels, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 05/36] target/xtensa: use generic instruction breakpoint infrastructure, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 06/36] tests/tcg/xtensa: add icount/ibreak priority test, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 07/36] accel/tcg: Remove unused tb_invalidate_phys_addr(), Philippe Mathieu-Daudé, 2024/01/19
- [PULL 08/36] accel/tcg: Remove tb_invalidate_phys_page() from system emulation, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 09/36] target/alpha: Extract clk_helper.c from sys_helper.c, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 10/36] target/alpha: Only build sys_helper.c on system emulation, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 11/36] system/cpu-timers: Have icount_configure() return a boolean, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 12/36] system/cpu-timers: Introduce ICountMode enumerator,
Philippe Mathieu-Daudé <=
- [PULL 13/36] target/arm: Ensure icount is enabled when emulating INST_RETIRED, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 14/36] util/async: Only call icount_notify_exit() if icount is enabled, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 15/36] target/sh4: Deprecate the shix machine, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 16/36] hw/block: Deprecate the TC58128 block device, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 17/36] hw/i386/pc_piix: Make piix_intx_routing_notifier_xen() more device independent, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 18/36] hw/pflash: refactor pflash_data_write(), Philippe Mathieu-Daudé, 2024/01/19
- [PULL 19/36] hw/pflash: use ldn_{be,le}_p and stn_{be,le}_p, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 20/36] hw/pflash: implement update buffer for block writes, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 21/36] system/replay: Restrict icount to system emulation, Philippe Mathieu-Daudé, 2024/01/19
- [PULL 22/36] system/watchpoint: Move TCG specific code to accel/tcg/, Philippe Mathieu-Daudé, 2024/01/19